Versions Compared

Key

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

...

Anchor10514561051456 Clk_DateTimeToTS_NTP() Anchor10514571051457Convert a date/time structure to NTP timestamp.anchor10514581051458

Files

...

clk.h/clk.c

...

Prototype


                                   CLK_DATE_TIME  *p_date_time);
HTML Tablecode
classCode_Listing
Table Row (tr)
Table Cell (td)
rowspan5
Anchor
10546261054626
languagecpp
CPU_BOOLEAN  Clk_DateTimeToTS_NTP (CLK_TS_SEC     *p_ts_ntp_sec,
Anchor
10514621051462
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)

...


...

Arguments

Anchor10673921067392p_ts_ntp_sec

Pointer to variable that will receive the NTP timestamp:

...

In seconds UTC+00, if no errors;
CLK_TS_SEC_NONE, otherwise.

Anchor10514731051473p_date_time

Date/time structure to convert.

...

Returned Values

Anchor10547271054727DEF_OK, if date/time structure successfully converted.anchor

10514751051475DEF_FAIL, otherwise. Anchor10514761051476

Required Configuration

Anchor10616431061643Available only if CLK_CFG_NTP_EN is DEF_ENABLED in clk_cfg.h (see section 3-1-1 Module Configuration).anchor10514781051478

Notes / Warnings

Anchor10698091069809Date/time structure (p_date_time) must be representable in NTP timestamp. Thus date to convert must be greater than or equal to CLK_NTP_EPOCH_YR_START and less than CLK_NTP_EPOCH_YR_END. Date/time should be set to local time with correct time zone offset (p_date_time->TZ_sec). Clk_DateTimeToTS_NTP() removes the time zone offset from the date/time to calculate and return an NTP timestamp at UTC+00.

Example Usage

Anchor
10698441069844Listing - Clk_DateTimeToTS_NTP() Example Usage

...

classCode_Listing

...

rowspan8

...

Listing - Clk_DateTimeToTS_NTP() Example Usage


CLK_DATE_TIME  date_time;

CPU_BOOLEAN
valid;   /*
    valid;
 
                                  /* 2010/09/18   11:11:11 UTC-05:00  */
valid =

valid = Clk_DateTimeMake(&date_time, 2010, 9, 18, 11, 11, 11, -18000);
if

if (valid == DEF_OK)
{
 {
    printf("Date/time successfully created");
} else {

} else {
    printf("Clock Date/time error\n\r");
}   valid =

}
 
valid = Clk_DateTimeToTS_NTP(&ts_ntp_sec, &date_time);
if

if (valid == DEF_OK)
{
 {
    printf("Timestamp = %u", ts_ntp_sec);
} else {

} else {
    printf("Clock Date/time to NTP timestamp error\n\r");
}tr

}
Code Block
languagecpp
titleListing - Clk_DateTimeToTS_NTP() Example Usage
linenumberstrue
CLK_TS_SEC     ts_ntp_sec;
Anchor
10698131069813
Anchor
10698141069814
Anchor
10698151069815
Anchor
10698161069816
Anchor
10698171069817
Anchor
10698181069818
Anchor
10698191069819
Anchor
10698201069820
Anchor
10698211069821
Anchor
10698221069822
Anchor
10698231069823
Anchor
10698241069824
Anchor
10698251069825
Anchor
10698261069826
Anchor
10698271069827
Anchor
10698281069828
Anchor
10698291069829
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)
Table Row (tr)