SPRUIG8J January 2018 – March 2024
The compiler RTS library supports two low-level time-related standard C functions in
time.h
:
clock_t
clock(void);
The clock() function returns the number of clock cycles since the program began executing; the clock() function has nothing to do with wall-clock time.
time_t time(time_t
*timer);
The time() function returns the wall-clock time.
Time-related and clock-related RTS library source files are provided in the
/lib/src
directory of the compiler installation.
The default implementations of these functions require that the program be run under CCS or a similar tool that supports the CIO System Call Protocol. If CIO is not available and you need to use one of these functions, you must provide your own definition of the function.
The clock() function returns the number of clock cycles since the program began executing. This information is available in a register on some devices, but the location varies from platform to platform. The compiler's RTS library provides an implementation that uses the CIO System Call Protocol to communicate with CCS, which figures out how to compute the right value for this device.
If CCS is not available, you must provide an implementation of the clock() function that gathers clock cycle information from the appropriate location on the device.
The time() function returns the real-world time, in terms of seconds since an epoch.
On many embedded systems, there is no internal real-world clock, so a program needs to discover the time from an external source. The compiler's RTS library provides an implementation that uses the CIO System Call Protocol to communicate with CCS, which provides the real-world time.
If CCS is not available, you must provide an implementation of the time() function that finds the time from some other source. If the program is running under an operating system, that operating system typically provides an implementation of time().
The time() function returns the number of seconds since an epoch. On C7000 systems, the epoch is defined as the number of seconds since midnight UTC January 1, 1970.
The TI RTS library does not provide time zone lookup tables. The local time zone is
specified by a global variable _tz
of type struct TZ, which is
defined in tmzone.c
in the RTS library source code. This struct is
used by the mktime() and strftime() functions. To change the local time zone, assign
new values to the following fields in this struct:
_tz.daylight
field to the exact value for the mktime()
function to assign to the struct tm
member
tm_isdst
._tz.timezone
field to a signed integer representing the
number of seconds west of UTC. For example, Central Standard Time (UTC+6) is
21600 seconds west of UTC. Use a negative value for timezones east of UTC._tz.tzname
field to the abbreviated name of the local
time zone. This string is used verbatim by the strftime() function for the %Z
conversion. For example, if the local time zone is Central Standard Time, use
"CST" for this field._tz.dstname
field is currently unused by the RTS
library.