CANopenNode
CANopen protocol stack
|
CANopen Safety Related Data Object protocol More...
Files | |
file | CO_SRDO.h |
CANopen Safety Related Data Object protocol. | |
Data Structures | |
struct | CO_SRDOGuard_t |
Guard Object for SRDO. More... | |
struct | CO_SRDO_t |
SRDO object. More... | |
Macros | |
#define | CO_SRDO_MAX_SIZE 8U |
Maximum size of SRDO message, 8 for standard CAN. | |
#define | CO_SRDO_MAX_MAPPED_ENTRIES 16U |
Maximum number of entries, which can be mapped to SRDO, 2*8 for standard CAN, may be less to preserve RAM usage. | |
Typedefs | |
typedef uint8_t | CO_SRDO_size_t |
Variable of type CO_SRDO_size_t contains data length in bytes of SRDO. | |
Enumerations | |
enum | CO_SRDO_state_t { CO_SRDO_state_error_internal = -10 , CO_SRDO_state_error_configuration = -9 , CO_SRDO_state_error_txNotInverted = -6 , CO_SRDO_state_error_txFail = -5 , CO_SRDO_state_error_rxTimeoutSRVT = -4 , CO_SRDO_state_error_rxTimeoutSCT = -3 , CO_SRDO_state_error_rxNotInverted = -2 , CO_SRDO_state_error_rxShort = -1 , CO_SRDO_state_unknown = 0 , CO_SRDO_state_nmtNotOperational = 1 , CO_SRDO_state_initializing = 2 , CO_SRDO_state_communicationEstablished = 3 , CO_SRDO_state_deleted = 10 } |
SRDO internal state. More... | |
Functions | |
CO_ReturnError_t | CO_SRDOGuard_init (CO_SRDOGuard_t *SRDOGuard, OD_entry_t *OD_13FE_configurationValid, OD_entry_t *OD_13FF_safetyConfigurationSignature, uint32_t *errInfo) |
Initialize SRDOGuard object. | |
CO_ReturnError_t | CO_SRDO_init (CO_SRDO_t *SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t *SRDOGuard, OD_t *OD, CO_EM_t *em, uint8_t nodeId, uint16_t defaultCOB_ID, OD_entry_t *OD_130x_SRDOCommPar, OD_entry_t *OD_138x_SRDOMapPar, CO_CANmodule_t *CANdevRxNormal, CO_CANmodule_t *CANdevRxInverted, uint16_t CANdevRxIdxNormal, uint16_t CANdevRxIdxInverted, CO_CANmodule_t *CANdevTxNormal, CO_CANmodule_t *CANdevTxInverted, uint16_t CANdevTxIdxNormal, uint16_t CANdevTxIdxInverted, uint32_t *errInfo) |
Initialize SRDO object. | |
void | CO_SRDO_initCallbackPre (CO_SRDO_t *SRDO, void *object, void(*pFunctSignalPre)(void *object)) |
Initialize SRDO callback function. | |
CO_ReturnError_t | CO_SRDO_config (CO_SRDO_t *SRDO, uint8_t SRDO_Index, CO_SRDOGuard_t *SRDOGuard, uint32_t *errInfo) |
Configure SRDO object. | |
CO_ReturnError_t | CO_SRDO_requestSend (CO_SRDO_t *SRDO) |
Send SRDO on event. | |
CO_SRDO_state_t | CO_SRDO_process (CO_SRDO_t *SRDO, uint32_t timeDifference_us, uint32_t *timerNext_us, bool_t NMTisOperational) |
Process transmitting/receiving individual SRDO message. | |
CANopen Safety Related Data Object protocol
Safety Related Data Object protocol is specified by standard EN 50325-5:2010 (formerly CiA304). Its functionality is very similar to that of the PDOs. The main differences is every message is send and received twice. The second message must be bitwise inverted. The delay between the two messages and between each message pair is monitored. The distinction between sending and receiving SRDO is made at runtime (for PDO it is compile time). If the security protocol is used, at least one SRDO is mandatory.
If there is erroneous structure of OD entries for SRDO parameters, then CO_SRDO_init() function returns error and CANopen device doesn't work. It is necessary to repair Object Dictionary and reprogram the device.
If there are erroneous values inside SRDO parameters, then Emergency message CO_EM_SRDO_CONFIGURATION is sent. Info code (32bit) contains OD index, subindex and additional byte, which helps to determine erroneous OD object.
SRDO is first configured in CANopen in CANopen initialization section after all other CANopen objects are initialized. It consists of one CO_SRDOGuard_init() and CO_SRDO_init() for each SRDO. On transition to NMT operational CO_SRDO_config() must be called for each SRDO.
CO_SRDO_process() must be executed cyclically, similar as PDO processing. Function is fast, no time consuming tasks. Function returns CO_SRDO_state_t value, which may be used to determine working-state or safe-state of safety related device. If return values from all SRDO objects are >= CO_SRDO_state_communicationEstablished, then working state is allowed. Otherwise SR device must be in safe state.
Requirement for mapped objects:
#define CO_SRDO_MAX_MAPPED_ENTRIES 16U |
Maximum number of entries, which can be mapped to SRDO, 2*8 for standard CAN, may be less to preserve RAM usage.
Must be multiple of 2.
enum CO_SRDO_state_t |
SRDO internal state.
Enumerator | |
---|---|
CO_SRDO_state_error_internal | internal software error |
CO_SRDO_state_error_configuration | error in parameters, emergency message was sent |
CO_SRDO_state_error_txNotInverted | Transmitting SRDO messages was not inverted. |
CO_SRDO_state_error_txFail | SRDO CAN message transmission failed. |
CO_SRDO_state_error_rxTimeoutSRVT | SRDO message didn't receive inside SRVT time. |
CO_SRDO_state_error_rxTimeoutSCT | SRDO inverted message didn't receive inside SCT time. |
CO_SRDO_state_error_rxNotInverted | Received SRDO messages was not inverted. |
CO_SRDO_state_error_rxShort | Received SRDO message is too short. |
CO_SRDO_state_unknown | unknown state, set by CO_SRDO_init() |
CO_SRDO_state_nmtNotOperational | Internal NMT operating state is not NMT operational. |
CO_SRDO_state_initializing | Just entered NMT operational state, SRDO message not yet received or transmitted. |
CO_SRDO_state_communicationEstablished | SRDO communication established, fully functional. |
CO_SRDO_state_deleted | informationDirection for this SRDO is set to 0 |
CO_ReturnError_t CO_SRDOGuard_init | ( | CO_SRDOGuard_t * | SRDOGuard, |
OD_entry_t * | OD_13FE_configurationValid, | ||
OD_entry_t * | OD_13FF_safetyConfigurationSignature, | ||
uint32_t * | errInfo ) |
Initialize SRDOGuard object.
Function must be called in the communication reset section before CO_SRDO_init() functions.
SRDOGuard | This object will be initialized. | |
OD_13FE_configurationValid | Pointer to Configuration valid variable from Object dictionary (index 0x13FE). | |
OD_13FF_safetyConfigurationSignature | Pointer to Safety configuration signature variable from Object dictionary (index 0x13FF). | |
[out] | errInfo | Additional information in case of error, may be NULL. |
CO_ReturnError_t CO_SRDO_init | ( | CO_SRDO_t * | SRDO, |
uint8_t | SRDO_Index, | ||
CO_SRDOGuard_t * | SRDOGuard, | ||
OD_t * | OD, | ||
CO_EM_t * | em, | ||
uint8_t | nodeId, | ||
uint16_t | defaultCOB_ID, | ||
OD_entry_t * | OD_130x_SRDOCommPar, | ||
OD_entry_t * | OD_138x_SRDOMapPar, | ||
CO_CANmodule_t * | CANdevRxNormal, | ||
CO_CANmodule_t * | CANdevRxInverted, | ||
uint16_t | CANdevRxIdxNormal, | ||
uint16_t | CANdevRxIdxInverted, | ||
CO_CANmodule_t * | CANdevTxNormal, | ||
CO_CANmodule_t * | CANdevTxInverted, | ||
uint16_t | CANdevTxIdxNormal, | ||
uint16_t | CANdevTxIdxInverted, | ||
uint32_t * | errInfo ) |
Initialize SRDO object.
Function must be called in the communication reset section.
SRDO | This object will be initialized. | |
SRDO_Index | OD index of this SRDO, 0 for the first. | |
SRDOGuard | SRDOGuard object. | |
OD | CANopen Object Dictionary | |
em | Emergency object. | |
nodeId | CANopen Node ID of this device. If default COB_ID is used, value will be added. | |
defaultCOB_ID | Default COB ID for this SRDO for plain data (without NodeId). | |
OD_130x_SRDOCommPar | Pointer to SRDO communication parameter record from Object dictionary (index 0x1301+). | |
OD_138x_SRDOMapPar | Pointer to SRDO mapping parameter record from Object dictionary (index 0x1381+). | |
CANdevRxNormal | CAN device used for SRDO reception for normal object. | |
CANdevRxInverted | CAN device used for SRDO reception for inverted object. | |
CANdevRxIdxNormal | Index of receive buffer in the above CAN device (normal). | |
CANdevRxIdxInverted | Index of receive buffer in the above CAN device (inverted). | |
CANdevTxNormal | CAN device used for SRDO transmission for normal object. | |
CANdevTxInverted | CAN device used for SRDO transmission for inverted object. | |
CANdevTxIdxNormal | Index of transmit buffer in the above CAN device (normal). | |
CANdevTxIdxInverted | Index of transmit buffer in the above CAN device (inverted). | |
[out] | errInfo | Additional information in case of error, may be NULL. |
void CO_SRDO_initCallbackPre | ( | CO_SRDO_t * | SRDO, |
void * | object, | ||
void(* | pFunctSignalPre )(void *object) ) |
Initialize SRDO callback function.
Function initializes optional callback function, which should immediately start processing of CO_SRDO_process() function. Callback is called after SRDO message is received from the CAN bus.
SRDO | This object. |
object | Pointer to object, which will be passed to pFunctSignalPre(). Can be NULL |
pFunctSignalPre | Pointer to the callback function. Not called if NULL. |
CO_ReturnError_t CO_SRDO_config | ( | CO_SRDO_t * | SRDO, |
uint8_t | SRDO_Index, | ||
CO_SRDOGuard_t * | SRDOGuard, | ||
uint32_t * | errInfo ) |
Configure SRDO object.
Function must be called in on transition to NMT operational. Function is also called from CO_SRDO_init() function.
SRDO | This object will be configured. | |
SRDO_Index | OD index of this SRDO, 0 for the first. | |
SRDOGuard | SRDOGuard object. | |
[out] | errInfo | Additional information in case of error, may be NULL. |
CO_ReturnError_t CO_SRDO_requestSend | ( | CO_SRDO_t * | SRDO | ) |
Send SRDO on event.
Sends SRDO before the next refresh timer tiggers. The message itself is send in CO_SRDO_process(). Note that RTOS have to trigger its processing quickly. After the transmission the timer is reset to the full refresh time.
SRDO | This object. |
CO_SRDO_state_t CO_SRDO_process | ( | CO_SRDO_t * | SRDO, |
uint32_t | timeDifference_us, | ||
uint32_t * | timerNext_us, | ||
bool_t | NMTisOperational ) |
Process transmitting/receiving individual SRDO message.
SRDO | This object. | |
timeDifference_us | Time difference from previous function call in [microseconds]. | |
[out] | timerNext_us | info to OS, may be null. |
NMTisOperational | True if this node is in NMT_OPERATIONAL state. |