Suppose you have an embedded microcontroller based system with a nice C implemtation and standard library. How does one hook up the uC tick counter to be used with the time.h functions? That is, I it is 15:19
15-Jan-2004 at 0x0000'0349 ticks of the time base register, how can I "initialize" the C time functions to return calendar time based upon this knowledge?
If your library is open source, you dive right into the library source. If it isn't open source, see if time.h (or any headers it includes) provides a means to inform it of time scale and/or ticks. If none of the above, dig through the documentation for the vendor/maintainer contact info.
--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn't fall far from the tree.
These functions will be part of either the kernel, if your system has one, or provided by libstdC. Note both of these are implementation (i.e hardware) dependent.
Ian Bell wrote in news:40070222_1@mk- nntp-1.news.uk.worldonline.com:
The Diab compiler for PowerPC and the kernel (RTOS) doesn't supply this. So I have found time.c and time.h from Diab and it looks like I have to modify these.
Morris Dovey wrote in news:CNCNb.53$ snipped-for-privacy@news.uswest.net:
Thanks Morris. Taking your advice I found time.c (and time.h) from the vendor (Diab). I guess I don't normally expect the library sources with an implementation. Hopefully I can hook my timer into Diab's time library.
Mark, assuming that you have an ANSI compliant time implementation.
Please check the controller specific implementation below: It assumes a clock divider of CLOCKS_PER_SEC. 100 clocks per sec or 100 Hertz Interrupt seems reasonable. The interrupt servic routine counts the long integer representing the ANSI time counter.
source file:
============== SNIP SNIP ===================== /* $Id$ * $Revision$ * $Date$ ** ANSI_time.c ** time functions using a timer interrupt and the associated * ANSI library functions to set and get time & date as string * */
/* * $Log$ */ #define ANSI_TIME_C
/************** time.h/time.c functions to create a system clock **********/ #include #include #include #include "ANSI_time.h"
=================== SNIP SNIP ================== /* $Id$ * $Revision$ * $Date$ ** system_time.h ** time functions using a timer interrupt and the associated * ANSI library functions to set and get time & date as string * all library ANSI library time processing functions will work * based on these */
the parse date and parse time are taken from Bob Stout's SNIPPETS collection ('97) the ANSI timer init function is specific for an M16C but can be modified for any MCU with a timer unit.
Mark A. Odell schrieb in im Newsbeitrag: Xns94719C102B528CopyrightMarkOdell@130.133.1.4...
"Mark A. Odell" wrote in news:Xns94719C102B528CopyrightMarkOdell@130.133.1.4:
Thanks to all for their help. It turns out to be quite simple. I take a seed value from the host over the network and "bind" it to my 64-bit timebase counter. Since I now know what Fri Jan 16 14:18:31 2004 is in
64-bit CPU ticks I just apply a simple ratio for use by time() which I override. That is:
x = time in seconds from C epoch t = seed time in seconds from C epoch k0 = 64-bit count at seed time k1 = 64-bit count now
solving for x:
x t
--- = --- ====> x = t (k1/k0) k1 k0
Actually, I diff the k's and scale the diff back into seconds and add to t to get x but it's the same basic idea. So to summarize for the Diab compiler for the PowerPC:
Create a function that snapshots t and k0 and then override C's time() function to do the above calculation. Since the time() function is an "on demand" function I see no reason to add code to my timer ISR to support calendar time.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.