erika/osal.c
Go to the documentation of this file.
1 /*
2  * Licensed under the GNU General Public License version 2 with exceptions. See
3  * LICENSE file in the project root for full license information
4  */
5 
6 #include <time.h>
7 #include <sys/time.h>
8 #include <unistd.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <osal.h>
12 
13 #include "ee_x86_64_tsc.h"
14 
15 #define USECS_PER_SEC 1000000
16 #define NSECS_PER_SEC 1000000000
17 
19 
20 void ee_usleep(uint32 usec);
21 
22 inline int osal_usleep (uint32 usec)
23 {
24  ee_usleep(usec);
25  return 0;
26 }
27 
28 int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
29 {
31  tv->tv_sec = time/NSECS_PER_SEC;
32  tv->tv_sec += 946684800UL; /* EtherCAT uses 2000-01-01 as epoch start */
33  tv->tv_usec = (time%NSECS_PER_SEC)/1000;
34  return 0;
35 }
36 
38 {
39  struct timeval current_time;
40  ec_timet ret;
41 
42  osal_gettimeofday(&current_time, 0);
43  ret.sec = current_time.tv_sec;
44  ret.usec = current_time.tv_usec;
45  return ret;
46 }
47 
48 void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
49 {
50  if (end->usec < start->usec) {
51  diff->sec = end->sec - start->sec - 1;
52  diff->usec = end->usec + USECS_PER_SEC - start->usec;
53  } else {
54  diff->sec = end->sec - start->sec;
55  diff->usec = end->usec - start->usec;
56  }
57 }
58 
59 void osal_timer_start(osal_timert *self, uint32 timeout_usec)
60 {
61  struct timeval start_time;
62  struct timeval timeout;
63  struct timeval stop_time;
64 
65  osal_gettimeofday(&start_time, 0);
66  timeout.tv_sec = timeout_usec / USECS_PER_SEC;
67  timeout.tv_usec = timeout_usec % USECS_PER_SEC;
68  timeradd(&start_time, &timeout, &stop_time);
69 
70  self->stop_time.sec = stop_time.tv_sec;
71  self->stop_time.usec = stop_time.tv_usec;
72 }
73 
75 {
76  struct timeval current_time;
77  struct timeval stop_time;
78  int is_not_yet_expired;
79 
80  osal_gettimeofday (&current_time, 0);
81  stop_time.tv_sec = self->stop_time.sec;
82  stop_time.tv_usec = self->stop_time.usec;
83  is_not_yet_expired = timercmp (&current_time, &stop_time, <);
84 /* OSEE_PRINT("current: %d:%d -- expire: %d:%d -- result: %d\n", */
85 /* current_time.tv_sec, */
86 /* current_time.tv_usec, */
87 /* stop_time.tv_sec, */
88 /* stop_time.tv_usec, */
89 /* is_not_yet_expired); */
90 
91  return is_not_yet_expired == FALSE;
92 }
93 
94 void *osal_malloc(size_t size)
95 {
96  return malloc(size);
97 }
98 
99 void osal_free(void *ptr)
100 {
101  free(ptr);
102 }
103 
boolean osal_timer_is_expired(osal_timert *self)
Definition: erika/osal.c:74
#define NSECS_PER_SEC
Definition: erika/osal.c:16
uint32 usec
Definition: osal.h:39
void osal_free(void *ptr)
Definition: erika/osal.c:99
ec_timet osal_current_time(void)
Definition: erika/osal.c:37
Definition: osal.h:36
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
Definition: erika/osal.c:48
int osal_usleep(uint32 usec)
Definition: erika/osal.c:22
#define FALSE
Definition: osal.h:22
#define timercmp(a, b, CMP)
Definition: rtk/osal.c:12
unsigned __int64 uint64_t
Definition: stdint.h:90
#define USECS_PER_SEC
Definition: erika/osal.c:15
uint64_t osEE_x86_64_tsc_read(void)
#define timeradd(a, b, result)
Definition: rtk/osal.c:16
void * osal_malloc(size_t size)
Definition: erika/osal.c:94
void ee_usleep(uint32 usec)
uint32 sec
Definition: osal.h:38
uint32_t uint32
Definition: osal.h:30
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
Definition: erika/osal.c:59
int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
Definition: erika/osal.c:28


soem
Author(s): Arthur Ketels and M.J.G. van den Molengraft
autogenerated on Mon Feb 28 2022 23:46:57