CANopenNode
CANopen protocol stack
|
CANopen Time-stamp protocol. More...
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. | |
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()
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.
TIME | This object will be initialized. | |
OD_1012_cobIdTimeStamp | OD entry for 0x1012 - "COB-ID time stamp", entry is required. | |
CANdevRx | CAN device for TIME reception. | |
CANdevRxIdx | Index of receive buffer in the above CAN device. | |
CANdevTx | CAN device for TIME transmission. | |
CANdevTxIdx | Index of transmit buffer in the above CAN device. | |
[out] | errInfo | Additional information in case of error, may be NULL. |
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.
TIME | This object. |
object | Pointer to object, which will be passed to pFunctSignalPre(). |
pFunctSignalPre | Pointer to the callback function. Not called if NULL. |
|
inlinestatic |
Set current time.
TIME | This object. |
ms | Milliseconds after midnight |
days | Number of days since January 1, 1984 |
producerInterval_ms | Interval time for time producer in milliseconds |
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.
TIME | This object. |
timeDifference_us | Time difference from previous function call in [microseconds]. |
NMTisPreOrOperational | True if this node is NMT_PRE_OPERATIONAL or NMT_OPERATIONAL state. |