Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

time and gettimeofday

Posted by Lucio Cutuli on December 1, 2010

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 ;)

RE: time and gettimeofday

Posted by Dave on December 1, 2010
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).

RE: time and gettimeofday

Posted by Richard Damon on December 1, 2010
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.

RE: time and gettimeofday

Posted by Lucio Cutuli on December 1, 2010
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

RE: time and gettimeofday

Posted by Richard Damon on December 1, 2010
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).

RE: time and gettimeofday

Posted by Richard on December 1, 2010
“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.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner