CANopenNode
CANopen protocol stack
|
CANopen Synchronisation protocol. More...
Files | |
file | CO_SYNC.h |
CANopen Synchronisation protocol. | |
Data Structures | |
struct | CO_SYNC_t |
SYNC producer and consumer object. More... | |
Enumerations | |
enum | CO_SYNC_status_t { CO_SYNC_NONE = 0 , CO_SYNC_RX_TX = 1 , CO_SYNC_PASSED_WINDOW = 2 } |
Return value for CO_SYNC_process. More... | |
Functions | |
CO_ReturnError_t | CO_SYNC_init (CO_SYNC_t *SYNC, CO_EM_t *em, OD_entry_t *OD_1005_cobIdSync, OD_entry_t *OD_1006_commCyclePeriod, OD_entry_t *OD_1007_syncWindowLen, OD_entry_t *OD_1019_syncCounterOvf, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx, uint32_t *errInfo) |
Initialize SYNC object. | |
void | CO_SYNC_initCallbackPre (CO_SYNC_t *SYNC, void *object, void(*pFunctSignalPre)(void *object)) |
Initialize SYNC callback function. | |
static CO_ReturnError_t | CO_SYNCsend (CO_SYNC_t *SYNC) |
Send SYNC message. | |
CO_SYNC_status_t | CO_SYNC_process (CO_SYNC_t *SYNC, bool_t NMTisPreOrOperational, uint32_t timeDifference_us, uint32_t *timerNext_us) |
Process SYNC communication. | |
CANopen Synchronisation protocol.
For CAN identifier see Default CANopen identifiers
SYNC message is used for synchronization of the nodes on network. One node can be SYNC producer, others can be SYNC consumers. Synchronous TPDOs are transmitted after the CANopen SYNC message. Synchronous received PDOs are accepted(copied to OD) immediatelly after the reception of the next SYNC message.
By default SYNC message has no data. If Synchronous counter overflow value from Object dictionary (index 0x1019) is different than 0, SYNC message has one data byte: counter incremented by 1 with every SYNC transmission.
According to CANopen, synchronous RPDOs must be processed after reception of the next sync messsage. For that reason, there is a double receive buffer for each synchronous RPDO. At the moment, when SYNC is received or transmitted, internal variable CANrxToggle toggles. That variable is then used by synchronous RPDO to determine, which of the two buffers is used for RPDO reception and which for RPDO processing.
enum CO_SYNC_status_t |
Return value for CO_SYNC_process.
CO_ReturnError_t CO_SYNC_init | ( | CO_SYNC_t * | SYNC, |
CO_EM_t * | em, | ||
OD_entry_t * | OD_1005_cobIdSync, | ||
OD_entry_t * | OD_1006_commCyclePeriod, | ||
OD_entry_t * | OD_1007_syncWindowLen, | ||
OD_entry_t * | OD_1019_syncCounterOvf, | ||
CO_CANmodule_t * | CANdevRx, | ||
uint16_t | CANdevRxIdx, | ||
CO_CANmodule_t * | CANdevTx, | ||
uint16_t | CANdevTxIdx, | ||
uint32_t * | errInfo ) |
Initialize SYNC object.
Function must be called in the communication reset section.
SYNC | This object will be initialized. | |
em | Emergency object. | |
OD_1005_cobIdSync | OD entry for 0x1005 - "COB-ID SYNC message", entry is required. | |
OD_1006_commCyclePeriod | OD entry for 0x1006 - "Communication cycle period", entry is required if device is sync producer. | |
OD_1007_syncWindowLen | OD entry for 0x1007 - "Synchronous window length", entry is optional, may be NULL. | |
OD_1019_syncCounterOvf | OD entry for 0x1019 - "Synchronous counter overflow value", entry is optional, may be NULL. | |
CANdevRx | CAN device for SYNC reception. | |
CANdevRxIdx | Index of receive buffer in the above CAN device. | |
CANdevTx | CAN device for SYNC transmission. | |
CANdevTxIdx | Index of transmit buffer in the above CAN device. | |
[out] | errInfo | Additional information in case of error, may be NULL. |
void CO_SYNC_initCallbackPre | ( | CO_SYNC_t * | SYNC, |
void * | object, | ||
void(* | pFunctSignalPre )(void *object) ) |
Initialize SYNC callback function.
Function initializes optional callback function, which should immediately start processing of CO_SYNC_process() function. Callback is called after SYNC message is received from the CAN bus.
SYNC | This object. |
object | Pointer to object, which will be passed to pFunctSignalPre(). |
pFunctSignalPre | Pointer to the callback function. Not called if NULL. |
|
inlinestatic |
Send SYNC message.
This function prepares and sends a SYNC object. The application should only call this if direct control of SYNC transmission is needed, otherwise use CO_SYNC_process().
SYNC | SYNC object. |
CO_SYNC_status_t CO_SYNC_process | ( | CO_SYNC_t * | SYNC, |
bool_t | NMTisPreOrOperational, | ||
uint32_t | timeDifference_us, | ||
uint32_t * | timerNext_us ) |
Process SYNC communication.
Function must be called cyclically.
SYNC | This object. | |
NMTisPreOrOperational | True if this node is NMT_PRE_OPERATIONAL or NMT_OPERATIONAL state. | |
timeDifference_us | Time difference from previous function call in [microseconds]. | |
[out] | timerNext_us | info to OS - see CO_process(). |