SNTP Client API#

SNTPc_ConfigureMemSeg()#

Description#

Configures the memory segment to use when allocating control data and buffers.

Files#

sntp_client.h/sntp_client.c

Prototype#

void  SNTPc_ConfigureMemSeg (MEM_SEG  *p_mem_seg)

Arguments#

p_mem_seg

Pointer to memory segment to use when allocating control data. DEF_NULL means general purpose heap segment.

Returned Value#

None.

Notes / Warnings#

  1. Calling this function is optional, if it is not called, the default value will be used.

  2. This function MUST be called before the SNTPc client is initialized via the SNTPc_Init() function.

SNTPc_Init()#

Description#

Initializes the SNTPc Module.

Files#

sntp_client.h/sntp_client.c

Prototype#

void  SNTPc_Init (RTOS_ERR  *p_err)

Arguments#

p_err

Pointer to the variable that will receive one of the following error code(s) from this function:

  • RTOS_ERR_NONE

  • RTOS_ERR_NOT_AVAIL

  • RTOS_ERR_OS_ILLEGAL_RUN_TIME

  • RTOS_ERR_POOL_EMPTY

  • RTOS_ERR_BLK_ALLOC_CALLBACK

  • RTOS_ERR_SEG_OVF

Returned Value#

None.

Notes / Warnings#

None.

SNTPc_DfltCfgSet()#

Description#

Sets the default server configurations.

Files#

sntp_client.h/sntp_client.c

Prototype#

void  SNTPc_DfltCfgSet (NET_PORT_NBR         port_nbr,
                        NET_IP_ADDR_FAMILY   addr_family,
                        CPU_INT32U           rx_timeout_ms,
                        RTOS_ERR            *p_err)

Arguments#

port_nbr

Port number to use.

addr_family

Address family. Use NET_IP_ADDR_FAMILY_NONE if you are unsure.

rx_timeout_ms

Timeout, in milliseconds, for the reception.

p_err

Pointer to the variable that will receive one of the following error code(s) from this function:

  • RTOS_ERR_NONE

Returned Value#

  • DEF_TRUE, if the new default server configuration is successfully set.

  • DEF_FALSE, otherwise.

Notes / Warnings#

None.

SNTPc_ReqRemoteTime()#

Description#

Send a request to an NTP server and receive an SNTPc packet to compute.

Files#

sntp_client.h/sntp_client.c

Prototype#

void  SNTPc_ReqRemoteTime (CPU_CHAR  *hostname,
                           SNTP_PKT  *p_pkt,
                           RTOS_ERR  *p_err)

Arguments#

hostname

String that contains the NTP server hostname.

p_pkt

Pointer to an SNTP_PKT variable that will contain the received SNTPc packet.

p_err

Pointer to the variable that will receive one of the following error code(s) from this function:

  • RTOS_ERR_NONE

  • RTOS_ERR_INVALID_TYPE

  • RTOS_ERR_NET_RETRY_MAX

  • RTOS_ERR_NET_SOCK_CLOSED

  • RTOS_ERR_BLK_ALLOC_CALLBACK

  • RTOS_ERR_SEG_OVF

  • RTOS_ERR_NOT_SUPPORTED

  • RTOS_ERR_NET_CONN_CLOSE_RX

  • RTOS_ERR_OS_SCHED_LOCKED

  • RTOS_ERR_NOT_AVAIL

  • RTOS_ERR_FAIL

  • RTOS_ERR_NET_INVALID_ADDR_SRC

  • RTOS_ERR_WOULD_OVF

  • RTOS_ERR_NET_IF_LINK_DOWN

  • RTOS_ERR_CODE_GET(err_rtn

  • RTOS_ERR_INVALID_HANDLE

  • RTOS_ERR_WOULD_BLOCK

  • RTOS_ERR_INVALID_STATE

  • RTOS_ERR_ABORT

  • RTOS_ERR_TIMEOUT

  • RTOS_ERR_NET_OP_IN_PROGRESS

  • RTOS_ERR_TX

  • RTOS_ERR_NOT_FOUND

  • RTOS_ERR_ALREADY_EXISTS

  • RTOS_ERR_CODE_GET(local_err

  • RTOS_ERR_NET_INVALID_CONN

  • RTOS_ERR_NET_STR_ADDR_INVALID

  • RTOS_ERR_NOT_READY

  • RTOS_ERR_POOL_EMPTY

  • RTOS_ERR_OS_OBJ_DEL

  • RTOS_ERR_NET_ADDR_UNRESOLVED

  • RTOS_ERR_NET_NEXT_HOP

  • RTOS_ERR_NET_CONN_CLOSED_FAULT

Returned Value#

None.

Notes / Warnings#

None.

SNTPc_GetRemoteTime()#

Description#

Gets the remote time (NTP timestamp) from a received NTP packet.

Files#

sntp_client.h/sntp_client.c

Prototype#

SNTP_TS  SNTPc_GetRemoteTime (SNTP_PKT  *p_pkt,
                              RTOS_ERR  *p_err)

Arguments#

p_pkt

Pointer to received SNTP message packet.

p_err

Pointer to the variable that will receive one of the following error code(s) from this function:

  • RTOS_ERR_NONE

Returned Value#

NTP timestamp.

Notes / Warnings#

None.

SNTPc_GetRoundTripDly_us()#

Description#

Gets SNTP packet round trip delay from a received SNTP message packet.

Files#

sntp_client.h/sntp_client.c

Prototype#

CPU_INT32U  SNTPc_GetRoundTripDly_us (SNTP_PKT   *p_pkt,
                                      RTOS_ERR   *p_err)

Arguments#

p_kt

Pointer to received SNTP message packet.

p_err

Pointer to the variable that will receive one of the following error code(s) from this function:

  • RTOS_ERR_NONE

Returned Value#

SNTP packet round trip delay in microseconds.

Notes / Warnings#

  1. If the round trip delay is faster than the precision of the system clock, then the round trip delay is approximated to 0.

  2. Only the integer part of the round trip delay is returned.