CANopenNode
CANopen protocol stack
Loading...
Searching...
No Matches

CANopen Time-stamp protocol. More...

+ Collaboration diagram for TIME:

Files

file  CO_TIME.h
 CANopen Time-stamp protocol.
 

Data Structures

struct  CO_TIME_t
 TIME producer and consumer object. More...
 

Macros

#define CO_TIME_MSG_LENGTH   6U
 Length of the TIME message.
 

Functions

CO_ReturnError_t CO_TIME_init (CO_TIME_t *TIME, OD_entry_t *OD_1012_cobIdTimeStamp, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx, uint32_t *errInfo)
 Initialize TIME object.
 
void CO_TIME_initCallbackPre (CO_TIME_t *TIME, void *object, void(*pFunctSignalPre)(void *object))
 Initialize TIME callback function.
 
static void CO_TIME_set (CO_TIME_t *TIME, uint32_t ms, uint16_t days, uint32_t producerInterval_ms)
 Set current time.
 
bool_t CO_TIME_process (CO_TIME_t *TIME, bool_t NMTisPreOrOperational, uint32_t timeDifference_us)
 Process TIME object.
 

Detailed Description

CANopen Time-stamp protocol.

For CAN identifier see Default CANopen identifiers

TIME message is used for time synchronization of the nodes on the network. One node should be TIME producer, others can be TIME consumers. This is configured by COB_ID_TIME object 0x1012:

Current time can be read from CO_TIME_t->ms (milliseconds after midnight) and CO_TIME_t->days (number of days since January 1, 1984). Those values are updated on each CO_TIME_process() call, either from internal timer or from received time stamp message.

Current time can be set with CO_TIME_set() function, which is necessary at least once, if time producer. If configured, time stamp message is send from CO_TIME_process() in intervals specified by CO_TIME_set()

Function Documentation

◆ CO_TIME_init()

CO_ReturnError_t CO_TIME_init ( CO_TIME_t * TIME,
OD_entry_t * OD_1012_cobIdTimeStamp,
CO_CANmodule_t * CANdevRx,
uint16_t CANdevRxIdx,
CO_CANmodule_t * CANdevTx,
uint16_t CANdevTxIdx,
uint32_t * errInfo )

Initialize TIME object.

Function must be called in the communication reset section.

Parameters
TIMEThis object will be initialized.
OD_1012_cobIdTimeStampOD entry for 0x1012 - "COB-ID time stamp", entry is required.
CANdevRxCAN device for TIME reception.
CANdevRxIdxIndex of receive buffer in the above CAN device.
CANdevTxCAN device for TIME transmission.
CANdevTxIdxIndex of transmit buffer in the above CAN device.
[out]errInfoAdditional information in case of error, may be NULL.
Returns
CO_ReturnError_t CO_ERROR_NO on success.

◆ CO_TIME_initCallbackPre()

void CO_TIME_initCallbackPre ( CO_TIME_t * TIME,
void * object,
void(* pFunctSignalPre )(void *object) )

Initialize TIME callback function.

Function initializes optional callback function, which should immediately start processing of CO_TIME_process() function. Callback is called after TIME message is received from the CAN bus.

Parameters
TIMEThis object.
objectPointer to object, which will be passed to pFunctSignalPre().
pFunctSignalPrePointer to the callback function. Not called if NULL.

◆ CO_TIME_set()

static void CO_TIME_set ( CO_TIME_t * TIME,
uint32_t ms,
uint16_t days,
uint32_t producerInterval_ms )
inlinestatic

Set current time.

Parameters
TIMEThis object.
msMilliseconds after midnight
daysNumber of days since January 1, 1984
producerInterval_msInterval time for time producer in milliseconds

◆ CO_TIME_process()

bool_t CO_TIME_process ( CO_TIME_t * TIME,
bool_t NMTisPreOrOperational,
uint32_t timeDifference_us )

Process TIME object.

Function must be called cyclically. It updates internal time from received time stamp message or from timeDifference_us. It also sends produces timestamp message, if producer and producerInterval_ms is set.

Parameters
TIMEThis object.
timeDifference_usTime difference from previous function call in [microseconds].
NMTisPreOrOperationalTrue if this node is NMT_PRE_OPERATIONAL or NMT_OPERATIONAL state.
Returns
True if new TIME stamp message recently received (consumer).