Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists