time and gettimeofday

Hi everyone. I’m very new to FreeRtos and i’m trying to understand this OS but i need some help from some experienced user as you.
I have downloaded the freertos package and i configurated it to work with the stm32 hardware. It was not a hard work :)
I added to the freertos stack the intel upnp stack in order to exploit the net features. Given that this stack is made up for a Posix environment, I tried to adapt it to freertos. 99% of the convertion is done but now i have this problem:
When i try to call the gettimeofday function, the compiler gives me the error “Undefined reference to gettimeofday”.
I think that the problem is that freertos hasn’t an implementation of this function, infact if i create an empty function called gettimeofday the error disappears. Is there an implementation of this or i should do it on my own? if so, how could i do it? Please i need some advice because i’m really going to abandon hopes ;)

time and gettimeofday

gettimeofday() can only be implemented if the hardware supplies a time of day clock. Desktop computers have a time of day clock, but very few small embedded systems do. It is not possible to implement gettimeofday() in FreeRTOS because nearly all (all?) the hardware used for demonstrations have no way of maintaining time. If you embedded hardware has a time of day clock then the function could be implemented in the port layer, but not as part of the core FreeRTOS code. If you want a time in hours minutes and seconds since the system booted then this can be obtained easily enough from the tick count. If you want a time to be maintained across boots, or relative to a particular year, then I think you are out of luck (unless your hardware provides this facility).

time and gettimeofday

f4zzy, the issue is that FreeRTOS is just a kernel, not a full blown OS, and as such provides only the basic task management routines, but no I/O or similar support functions. As Dave said, true time functions require hardware support (or if your device is network connected, you might be able to fake it using NTP). The Posix spec calls for many things that FreeRTOS doesn’t include, but my guess is that you have probably include other packages (like a TCP/IP package adapted to work with FreeRTOS) to supply those needs. As a point of reference, files under the “Demo” directory aren’t really pieces of the base FreeRTOS kernel, but sample applications showing how to use it on various hardware.

time and gettimeofday

yes of course i can’t have the same gettimeofday() as the posix systems.
I believe that just  the tick count could be good for my purpose. Can you confirm that is xTickCount variable in task.c?
If so, i have to think about a solution on my code when xTickCount overflows…
Thanks a lot

time and gettimeofday

xTickCount is the variable that holds the number of ticks that have passed. The ‘proper’ way to get that value is calling xTaskGetTickCount() There is also a variable xNumOfOverflows which counts the number of times xTickCount has overflowed. There isn’t a function provided to get that value, but it wouldn’t be hard to add it. Maybe even make one to return the two values concatenated into a single large variable. (If you write that, make sure you guard the access to the two variable with a critical section).

time and gettimeofday

The ‘proper’ way to get that value is calling xTaskGetTickCount()
There is also a function xTaskGetTickCountFromISR() in the latest release.  Documentation has not quite caught up yet. Regards.