SPRUI04F july 2015 – april 2023
The compiler RTS library supports two low-level time-related standard C functions in
time.h
:
clock_t clock(void);
time_t time(time_t *timer);
The time() function returns the wall-clock time. The clock() function returns the number of clock cycles since the program began executing; it has nothing to do with wall-clock time.
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 might be available in a register on the device itself, 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 should provide an implementation of time().
The time() function returns the number of seconds since an epoch. On POSIX systems, the epoch is defined as the number of seconds since midnight UTC January 1, 1970. However, the C standard does not require any particular epoch, and the default TI version of time() uses a different epoch: midnight UTC-6 (CST) Jan 1, 1900. Also, the default TI time_t type is a 32-bit type, while POSIX systems typically use a 64-bit time_t type.
The RTS library provides a non-default implementation of the time() function that uses the midnight UTC January 1, 1970 epoch and the 64-bit time_t type, which is then a typedef for __type64_t.
If your code works with raw time values, you can handle the epoch issue in one of the following ways:
__time32_t | __time64_t | |
---|---|---|
Epoch (start) | Jan. 1, 1900 CST-0600 | Jan. 1, 1970 UTC-0000 |
End date | Feb. 7, 2036 06:28:14 | year 292277026596 |
Sign | Unsigned, so cannot represent dates before the epoch. | Signed, so can represent dates before the epoch. |