win32/osal.c
Go to the documentation of this file.
1 /******************************************************************************
2  * * *** ***
3  * *** *** ***
4  * *** **** ********** *** ***** *** **** *****
5  * ********* ********** *** ********* ************ *********
6  * **** *** *** *** *** **** ***
7  * *** *** ****** *** *********** *** **** *****
8  * *** *** ****** *** ************* *** **** *****
9  * *** **** **** *** *** *** **** ***
10  * *** ******* ***** ************** ************* *********
11  * *** ***** *** ******* ** ** ****** *****
12  * t h e r e a l t i m e t a r g e t e x p e r t s
13  *
14  * http://www.rt-labs.com
15  * Copyright (C) 2009. rt-labs AB, Sweden. All rights reserved.
16  *------------------------------------------------------------------------------
17  * $Id: osal.c 411 2012-12-02 20:16:39Z rtlaka $
18  *------------------------------------------------------------------------------
19  */
20 
21 #include <winsock2.h>
22 #include <osal.h>
23 #include "osal_win32.h"
24 
26 static double qpc2usec;
27 
28 #define USECS_PER_SEC 1000000
29 
30 int osal_gettimeofday (struct timeval *tv, struct timezone *tz)
31 {
32  int64_t wintime, usecs;
33  if(!sysfrequency)
34  {
35  QueryPerformanceFrequency((LARGE_INTEGER *)&sysfrequency);
36  qpc2usec = 1000000.0 / sysfrequency;
37  }
38  QueryPerformanceCounter((LARGE_INTEGER *)&wintime);
39  usecs = (int64_t)((double)wintime * qpc2usec);
40  tv->tv_sec = (long)(usecs / 1000000);
41  tv->tv_usec = (long)(usecs - (tv->tv_sec * 1000000));
42 
43  return 1;
44 }
45 
47 {
48  struct timeval current_time;
49  ec_timet return_value;
50 
51  osal_gettimeofday (&current_time, 0);
52  return_value.sec = current_time.tv_sec;
53  return_value.usec = current_time.tv_usec;
54  return return_value;
55 }
56 
57 void osal_timer_start (osal_timert * self, uint32 timeout_usec)
58 {
59  struct timeval start_time;
60  struct timeval timeout;
61  struct timeval stop_time;
62 
63  osal_gettimeofday (&start_time, 0);
64  timeout.tv_sec = timeout_usec / USECS_PER_SEC;
65  timeout.tv_usec = timeout_usec % USECS_PER_SEC;
66  timeradd (&start_time, &timeout, &stop_time);
67 
68  self->stop_time.sec = stop_time.tv_sec;
69  self->stop_time.usec = stop_time.tv_usec;
70 }
71 
72 boolean osal_timer_is_expired (const osal_timert * self)
73 {
74  struct timeval current_time;
75  struct timeval stop_time;
76  int is_not_yet_expired;
77 
78  osal_gettimeofday (&current_time, 0);
79  stop_time.tv_sec = self->stop_time.sec;
80  stop_time.tv_usec = self->stop_time.usec;
81  is_not_yet_expired = timercmp (&current_time, &stop_time, <);
82 
83  return is_not_yet_expired == FALSE;
84 }
85 
87 {
88  SleepEx(usec / 1000, FALSE);
89  return 1;
90 }
ec_timet osal_current_time(void)
Definition: win32/osal.c:46
int osal_usleep(uint32 usec)
Definition: win32/osal.c:86
#define timeradd(a, b, result)
Definition: osal_win32.h:27
Definition: osal.h:53
#define FALSE
Definition: osal.h:29
int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
Definition: win32/osal.c:30
#define timercmp(a, b, CMP)
Definition: rtk/osal.c:27
#define USECS_PER_SEC
Definition: win32/osal.c:28
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
Definition: win32/osal.c:57
static int64_t sysfrequency
Definition: win32/osal.c:25
signed __int64 int64_t
Definition: stdint.h:89
uint32_t uint32
Definition: osal.h:35
static double qpc2usec
Definition: win32/osal.c:26
boolean osal_timer_is_expired(const osal_timert *self)
Definition: win32/osal.c:72


youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Jun 10 2019 15:46:24