CANopenNode

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_RECEIVED = 1, CO_SYNC_OUTSIDE_WINDOW = 2 }
 Return value for CO_SYNC_process. More...
 

Functions

CO_ReturnError_t CO_SYNC_init (CO_SYNC_t *SYNC, CO_EM_t *em, CO_SDO_t *SDO, CO_NMT_internalState_t *operatingState, uint32_t COB_ID_SYNCMessage, uint32_t communicationCyclePeriod, uint8_t synchronousCounterOverflowValue, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx)
 Initialize SYNC object. More...
 
void CO_SYNC_initCallbackPre (CO_SYNC_t *SYNC, void *object, void(*pFunctSignalPre)(void *object))
 Initialize SYNC callback function. More...
 
CO_ReturnError_t CO_SYNCsend (CO_SYNC_t *SYNC)
 Send SYNC message. More...
 
CO_SYNC_status_t CO_SYNC_process (CO_SYNC_t *SYNC, uint32_t timeDifference_us, uint32_t ObjDict_synchronousWindowLength, uint32_t *timerNext_us)
 Process SYNC communication. More...
 

Detailed Description

CANopen Synchronisation protocol.

For CAN identifier see CO_Default_CAN_ID_t

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 

SYNC not received.

CO_SYNC_RECEIVED 

SYNC received.

CO_SYNC_OUTSIDE_WINDOW 

SYNC received outside SYNC window.

Function Documentation

◆ CO_SYNC_init()

CO_ReturnError_t CO_SYNC_init ( CO_SYNC_t SYNC,
CO_EM_t em,
CO_SDO_t *  SDO,
CO_NMT_internalState_t operatingState,
uint32_t  COB_ID_SYNCMessage,
uint32_t  communicationCyclePeriod,
uint8_t  synchronousCounterOverflowValue,
CO_CANmodule_t CANdevRx,
uint16_t  CANdevRxIdx,
CO_CANmodule_t CANdevTx,
uint16_t  CANdevTxIdx 
)

Initialize SYNC object.

Function must be called in the communication reset section.

Parameters
SYNCThis object will be initialized.
emEmergency object.
SDOSDO server object.
operatingStatePointer to variable indicating CANopen device NMT internal state.
COB_ID_SYNCMessageFrom Object dictionary (index 0x1005).
communicationCyclePeriodFrom Object dictionary (index 0x1006).
synchronousCounterOverflowValueFrom Object dictionary (index 0x1019).
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.
Returns
CO_ReturnError_t: CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT.

◆ CO_SYNC_initCallbackPre()

void CO_SYNC_initCallbackPre ( CO_SYNC_t SYNC,
void *  object,
void(*)(void *object)  pFunctSignalPre 
)

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(). Can be NULL
pFunctSignalPrePointer to the callback function. Not called if NULL.

◆ CO_SYNCsend()

CO_ReturnError_t CO_SYNCsend ( CO_SYNC_t SYNC)

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,
uint32_t  timeDifference_us,
uint32_t  ObjDict_synchronousWindowLength,
uint32_t timerNext_us 
)

Process SYNC communication.

Function must be called cyclically.

Parameters
SYNCThis object.
timeDifference_usTime difference from previous function call in [microseconds].
ObjDict_synchronousWindowLengthSynchronous window length variable from Object dictionary (index 0x1007).
[out]timerNext_usinfo to OS - see CO_process_SYNC_PDO().
Returns
CO_SYNC_status_t: CO_SYNC_NONE, CO_SYNC_RECEIVED or CO_SYNC_OUTSIDE_WINDOW.