Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Set External timestamp.

Files

clk.h / Application’s source file

Called from

  Clk_SetTS()

Prototype

Code Block
languagecpp
CPU_BOOLEAN  Clk_ExtTS_Set (CLK_TS_SEC  ts_sec);


Arguments

ts_sec

External timestamp value to set (in seconds, UTC+00).

Returned Values

DEF_OK, if External timestamp succesfully set;

DEF_FAIL, otherwise.

Required Configuration

Required callback function that must be implemented in your application if CLK_CFG_EXT_EN is DEF_ENABLED in clk_cfg.h (see section 3-1-1) in see Module Configuration) in order for the clock/calendar to be maintained by an external clock/timestamp mechanism.

Notes / Warnings

External timestamp values are converted from Clock timestamp’s CLK_TS_SEC data type. If the External timestamp has more bits than the CLK_TS_SEC data type, Clk_ExtTS_Set() must pad the External timestamp’s higher order bits with 0 bits. If the External timestamp has less bits than the CLK_TS_SEC data type, Clk_ExtTS_Set() must truncate the Clock timestamp’s higher order bits greater than the External timestamp.

...

The External timestamp is calculated by one of the following equations where:

Clock TS

Clock timestamp (in seconds, from UTC+00)

External TS

Converted External timestamp (in seconds)

Clock start year

Clock epoch start year (CLK_EPOCH_YR_START)

External start year

External timestamp epoch start year

External end year

External timestamp epoch end year

Leap day count

Number of leap days between Clock epoch start year and External epoch start year

Seconds per day

Number of seconds per day (86400)

External TZ

Time zone offset applied to External timestamp (in seconds, from UTC+00)

When External epoch start year is less than Clock epoch start year (CLK_EPOCH_YR_START):

External TS = Clock TS
            + [(((Clock start year - External start year) * 365)
            + leap day count) * seconds per day]
            + External TZ

Examples with a 32-bit External timestamp:

  • Valid equivalent date to convert is before External epoch end year:

...

This example underflows to a negative External timestamp since the equivalent date to convert is incorrectly less than the External epoch start year.

Example Template

Anchor
Listing - Clk_ExtTS_Set() Example Template
Listing - Clk_ExtTS_Set() Example Template

Code Block
languagecpp
titleListing - Clk_ExtTS_Set() Example Template
linenumberstrue
CPU_BOOLEAN  Clk_ExtTS_Set (CLK_TS_SEC  ts_sec)
{
    BSP_ClockSetTS(ts_sec);
    return (DEF_OK);
}