linux/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 416 2013-01-08 21:54:25Z smf.arthur $
18  *------------------------------------------------------------------------------
19  */
20 
21 #include <time.h>
22 #include <sys/time.h>
23 #include <unistd.h>
24 #include <osal.h>
25 
26 #define USECS_PER_SEC 1000000
27 
28 int osal_usleep (uint32 usec)
29 {
30  struct timespec ts;
31  ts.tv_sec = usec / USECS_PER_SEC;
32  ts.tv_nsec = (usec % USECS_PER_SEC) * 1000;
33  /* usleep is depricated, use nanosleep instead */
34  return nanosleep(&ts, NULL);
35 }
36 
37 int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
38 {
39  struct timespec ts;
40  int return_value;
41 
42  /* Use clock_gettime to prevent possible live-lock.
43  * Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust.
44  * If this function preempts timeadjust and it uses vpage it live-locks.
45  * Also when using XENOMAI, only clock_gettime is RT safe */
46  return_value = clock_gettime (CLOCK_MONOTONIC, &ts), 0;
47  tv->tv_sec = ts.tv_sec;
48  tv->tv_usec = ts.tv_nsec / 1000;
49  return return_value;
50 }
51 
53 {
54  struct timeval current_time;
55  ec_timet return_value;
56 
57  osal_gettimeofday (&current_time, 0);
58  return_value.sec = current_time.tv_sec;
59  return_value.usec = current_time.tv_usec;
60  return return_value;
61 }
62 
63 void osal_timer_start (osal_timert * self, uint32 timeout_usec)
64 {
65  struct timeval start_time;
66  struct timeval timeout;
67  struct timeval stop_time;
68 
69  osal_gettimeofday (&start_time, 0);
70  timeout.tv_sec = timeout_usec / USECS_PER_SEC;
71  timeout.tv_usec = timeout_usec % USECS_PER_SEC;
72  timeradd (&start_time, &timeout, &stop_time);
73 
74  self->stop_time.sec = stop_time.tv_sec;
75  self->stop_time.usec = stop_time.tv_usec;
76 }
77 
79 {
80  struct timeval current_time;
81  struct timeval stop_time;
82  int is_not_yet_expired;
83 
84  osal_gettimeofday (&current_time, 0);
85  stop_time.tv_sec = self->stop_time.sec;
86  stop_time.tv_usec = self->stop_time.usec;
87  is_not_yet_expired = timercmp (&current_time, &stop_time, <);
88 
89  return is_not_yet_expired == FALSE;
90 }
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
Definition: linux/osal.c:63
#define timeradd(a, b, result)
Definition: osal_win32.h:27
int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
Definition: linux/osal.c:37
boolean osal_timer_is_expired(osal_timert *self)
Definition: linux/osal.c:78
ec_timet osal_current_time(void)
Definition: linux/osal.c:52
Definition: osal.h:53
#define FALSE
Definition: osal.h:29
#define timercmp(a, b, CMP)
Definition: rtk/osal.c:27
uint32_t uint32
Definition: osal.h:35
int osal_usleep(uint32 usec)
Definition: linux/osal.c:28
#define USECS_PER_SEC
Definition: linux/osal.c:26


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