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

CANopen Synchronisation protocol. More...

+ Collaboration diagram for SYNC:

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.
 

Detailed Description

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.

Contents of 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.

SYNC in CANopenNode

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.

Enumeration Type Documentation

◆ CO_SYNC_status_t

Return value for CO_SYNC_process.

Enumerator
CO_SYNC_NONE 

No SYNC event in last cycle.

CO_SYNC_RX_TX 

SYNC message was received or transmitted in last cycle.

CO_SYNC_PASSED_WINDOW 

Time has just passed SYNC window (OD_1007) in last cycle.

Function Documentation

◆ CO_SYNC_init()

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.

Parameters
SYNCThis object will be initialized.
emEmergency object.
OD_1005_cobIdSyncOD entry for 0x1005 - "COB-ID SYNC message", entry is required.
OD_1006_commCyclePeriodOD entry for 0x1006 - "Communication cycle period", entry is required if device is sync producer.
OD_1007_syncWindowLenOD entry for 0x1007 - "Synchronous window length", entry is optional, may be NULL.
OD_1019_syncCounterOvfOD entry for 0x1019 - "Synchronous counter overflow value", entry is optional, may be NULL.
CANdevRxCAN device for SYNC reception.
CANdevRxIdxIndex of receive buffer in the above CAN device.
CANdevTxCAN device for SYNC 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_SYNC_initCallbackPre()

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.

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

◆ CO_SYNCsend()

static CO_ReturnError_t CO_SYNCsend ( CO_SYNC_t * SYNC)
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().

Parameters
SYNCSYNC object.
Returns
Same as CO_CANsend().

◆ CO_SYNC_process()

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.

Parameters
SYNCThis object.
NMTisPreOrOperationalTrue if this node is NMT_PRE_OPERATIONAL or NMT_OPERATIONAL state.
timeDifference_usTime difference from previous function call in [microseconds].
[out]timerNext_usinfo to OS - see CO_process().
Returns
CO_SYNC_status_t