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

CANopen Process Data Object protocol. More...

+ Collaboration diagram for PDO:

Files

file  CO_PDO.h
 CANopen Process Data Object protocol.
 

Data Structures

struct  CO_PDO_common_t
 PDO object, common properties. More...
 
struct  CO_RPDO_t
 RPDO object. More...
 
struct  CO_TPDO_t
 TPDO object. More...
 

Macros

#define CO_PDO_MAX_SIZE   8U
 Maximum size of PDO message, 8 for standard CAN.
 
#define CO_PDO_MAX_MAPPED_ENTRIES   8U
 Maximum number of entries, which can be mapped to PDO, 8 for standard CAN, may be less to preserve RAM usage.
 
#define CO_RPDO_DEFAULT_CANID_COUNT   4U
 Number of CANopen RPDO objects, which uses default CAN indentifiers.
 
#define CO_TPDO_DEFAULT_CANID_COUNT   4U
 Number of CANopen TPDO objects, which uses default CAN indentifiers.
 
#define CO_RPDO_CAN_BUFFERS_COUNT   2
 Number of buffers for received CAN message for RPDO.
 

Typedefs

typedef uint8_t CO_PDO_size_t
 Variable of type CO_PDO_size_t contains data length in bytes of PDO.
 

Enumerations

enum  CO_PDO_transmissionTypes_t {
  CO_PDO_TRANSM_TYPE_SYNC_ACYCLIC = 0U , CO_PDO_TRANSM_TYPE_SYNC_1 = 1U , CO_PDO_TRANSM_TYPE_SYNC_240 = 0xF0U , CO_PDO_TRANSM_TYPE_SYNC_EVENT_LO = 0xFEU ,
  CO_PDO_TRANSM_TYPE_SYNC_EVENT_HI = 0xFFU
}
 PDO transmission Types. More...
 

Functions

CO_ReturnError_t CO_RPDO_init (CO_RPDO_t *RPDO, OD_t *OD, CO_EM_t *em, CO_SYNC_t *SYNC, uint16_t preDefinedCanId, OD_entry_t *OD_14xx_RPDOCommPar, OD_entry_t *OD_16xx_RPDOMapPar, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, uint32_t *errInfo)
 Initialize RPDO object.
 
void CO_RPDO_initCallbackPre (CO_RPDO_t *RPDO, void *object, void(*pFunctSignalPre)(void *object))
 Initialize RPDO callback function.
 
void CO_RPDO_process (CO_RPDO_t *RPDO, uint32_t timeDifference_us, uint32_t *timerNext_us, bool_t NMTisOperational, bool_t syncWas)
 Process received PDO messages.
 
CO_ReturnError_t CO_TPDO_init (CO_TPDO_t *TPDO, OD_t *OD, CO_EM_t *em, CO_SYNC_t *SYNC, uint16_t preDefinedCanId, OD_entry_t *OD_18xx_TPDOCommPar, OD_entry_t *OD_1Axx_TPDOMapPar, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx, uint32_t *errInfo)
 Initialize TPDO object.
 
static void CO_TPDOsendRequest (CO_TPDO_t *TPDO)
 Request transmission of TPDO message.
 
void CO_TPDO_process (CO_TPDO_t *TPDO, uint32_t timeDifference_us, uint32_t *timerNext_us, bool_t NMTisOperational, bool_t syncWas)
 Process transmitting PDO messages.
 

Detailed Description

CANopen Process Data Object protocol.

Process data objects are used for real-time data transfer with no protocol overhead.

TPDO with specific identifier is transmitted by one device and recieved by zero or more devices as RPDO. PDO communication parameters(COB-ID, transmission type, etc.) are in the Object Dictionary at index 0x1400+ and 0x1800+. PDO mapping parameters (size and contents of the PDO) are in the Object Dictionary at index 0x1600+ and 0x1A00+.

Features of the PDO as implemented in CANopenNode:

CAN identifiers for PDO

Each PDO can be configured with any valid 11-bit CAN identifier. Lower numbers have higher priorities on CAN bus. As a general rule, each CAN message is identified with own CAN-ID, which must be unique and produced by single source. The same is with PDO objects: Any TPDO produced on the CANopen network must have unique CAN-ID and there can be zero to many RPDOs (from different devices) configured to match the CAN-ID of the TPDO of interest.

CANopen standard provides pre-defined connection sets for four RPDOs and four TPDOs on each device with specific 7-bit Node-ID. These are default values and are usable in configuration, where CANopen network contains a master device, which directly communicates with many slaves. In de-centralized systems, where devices operate without a master, it makes sense to configure CAN-IDs of the RPDOs to the non-default values.

Default CAN identifiers for first four TPDOs on device with specific CANopen Node-Id are: 0x180+NodeId, 0x280+NodeId, 0x380+NodeId and 0x480+NodeId.

Default CAN identifiers for first four RPDOs on device with specific CANopen Node-Id are: 0x200+NodeId, 0x300+NodeId, 0x400+NodeId and 0x500+NodeId.

CANopenNode handles default (pre-defined) CAN-IDs. If it is detected, that PDO is configured with default CAN-ID (when writing to OD variable PDO communication parameter, COB-ID), then COB-ID is stored without Node-Id to the Object Dictionary. If Node-ID is changed, then COB-ID will always contain correct default CAN-ID (default CAN-ID + Node-ID). If PDO is configured with non-default CAN-ID, then it will be stored to the Object Dictionary as is.

If configuration CO_CONFIG_FLAG_OD_DYNAMIC is enabled in CO_CONFIG_PDO, then PDOs can be configured dynamically, also in NMT operational state. Otherwise PDOs are configured only in reset communication section and also default CAN-IDs are always stored to OD as is, no default node-id is handled.

Configure PDO by writing to the OD variables in the following procedure:

Macro Definition Documentation

◆ CO_RPDO_DEFAULT_CANID_COUNT

#define CO_RPDO_DEFAULT_CANID_COUNT   4U

Number of CANopen RPDO objects, which uses default CAN indentifiers.

By default first four RPDOs have pre-defined CAN identifiers, which depends on node-id. This constant may be set to 0 to disable functionality or set to any other value. For example, if there are several logical devices inside single CANopen device, then more than four RPDOs may have pre-defined CAN identifiers. In that case RPDO5 has CAN_ID=0x200+NodeId+1, RPDO6 has CAN_ID=0x300+NodeId+1, RPDO9 has CAN_ID=0x200+NodeId+2 and so on.

◆ CO_TPDO_DEFAULT_CANID_COUNT

#define CO_TPDO_DEFAULT_CANID_COUNT   4U

Number of CANopen TPDO objects, which uses default CAN indentifiers.

If value is more than four, then pre-defined pre-defined CAN identifiers are: TPDO5 has CAN_ID=0x180+NodeId+1, TPDO6 has CAN_ID=0x280+NodeId+1, TPDO9 has CAN_ID=0x180+NodeId+2 and so on. For description see CO_RPDO_DEFAULT_CANID_COUNT.

Enumeration Type Documentation

◆ CO_PDO_transmissionTypes_t

PDO transmission Types.

Enumerator
CO_PDO_TRANSM_TYPE_SYNC_ACYCLIC 

synchronous (acyclic)

CO_PDO_TRANSM_TYPE_SYNC_1 

synchronous (cyclic every sync)

CO_PDO_TRANSM_TYPE_SYNC_240 

synchronous (cyclic every 240-th sync)

CO_PDO_TRANSM_TYPE_SYNC_EVENT_LO 

event-driven, lower value (manufacturer specific),

CO_PDO_TRANSM_TYPE_SYNC_EVENT_HI 

event-driven, higher value (device profile and application profile specific)

Function Documentation

◆ CO_RPDO_init()

CO_ReturnError_t CO_RPDO_init ( CO_RPDO_t * RPDO,
OD_t * OD,
CO_EM_t * em,
CO_SYNC_t * SYNC,
uint16_t preDefinedCanId,
OD_entry_t * OD_14xx_RPDOCommPar,
OD_entry_t * OD_16xx_RPDOMapPar,
CO_CANmodule_t * CANdevRx,
uint16_t CANdevRxIdx,
uint32_t * errInfo )

Initialize RPDO object.

Function must be called in the end of the communication reset section, after all application initialization. Otherwise mapping to application OD variables will not be correct.

Parameters
RPDOThis object will be initialized.
ODObject Dictionary.
emEmergency object.
SYNCSYNC object, may be NULL.
preDefinedCanIdCAN identifier from pre-defined connection set, including node-id for first four PDOs, or 0 otherwise, see CO_PDO_CAN_ID
OD_14xx_RPDOCommParOD entry for 0x1400+ - "RPDO communication parameter", entry is required.
OD_16xx_RPDOMapParOD entry for 0x1600+ - "RPDO mapping parameter", entry is required.
CANdevRxCAN device for PDO reception.
CANdevRxIdxIndex of receive 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_RPDO_initCallbackPre()

void CO_RPDO_initCallbackPre ( CO_RPDO_t * RPDO,
void * object,
void(* pFunctSignalPre )(void *object) )

Initialize RPDO callback function.

Function initializes optional callback function, which should immediately start processing of CO_RPDO_process() function. Callback is called after RPDO message is received from the CAN bus.

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

◆ CO_RPDO_process()

void CO_RPDO_process ( CO_RPDO_t * RPDO,
uint32_t timeDifference_us,
uint32_t * timerNext_us,
bool_t NMTisOperational,
bool_t syncWas )

Process received PDO messages.

Function must be called cyclically in any NMT state. It copies data from RPDO to Object Dictionary variables if: new PDO receives and PDO is valid and NMT operating state is operational. Synchronous RPDOs are processed after next SYNC message.

Parameters
RPDOThis object.
timeDifference_usTime difference from previous function call.
[out]timerNext_usinfo to OS - see CO_process().
NMTisOperationalTrue if this node is in NMT_OPERATIONAL state.
syncWasTrue, if CANopen SYNC message was just received or transmitted.

◆ CO_TPDO_init()

CO_ReturnError_t CO_TPDO_init ( CO_TPDO_t * TPDO,
OD_t * OD,
CO_EM_t * em,
CO_SYNC_t * SYNC,
uint16_t preDefinedCanId,
OD_entry_t * OD_18xx_TPDOCommPar,
OD_entry_t * OD_1Axx_TPDOMapPar,
CO_CANmodule_t * CANdevTx,
uint16_t CANdevTxIdx,
uint32_t * errInfo )

Initialize TPDO object.

Function must be called in the end of the communication reset section, after all application initialization. Otherwise mapping to application OD variables will not be correct.

Parameters
TPDOThis object will be initialized.
ODObject Dictionary.
emEmergency object.
SYNCSYNC object, may be NULL.
preDefinedCanIdCAN identifier from pre-defined connection set, including node-id for first four PDOs, or 0 otherwise, see CO_PDO_CAN_ID
OD_18xx_TPDOCommParOD entry for 0x1800+ - "TPDO communication parameter", entry is required.
OD_1Axx_TPDOMapParOD entry for 0x1A00+ - "TPDO mapping parameter", entry is required.
CANdevTxCAN device used for PDO 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_TPDOsendRequest()

static void CO_TPDOsendRequest ( CO_TPDO_t * TPDO)
inlinestatic

Request transmission of TPDO message.

If TPDO transmission type is 0, 254 or 255, then TPDO will be sent by CO_TPDO_process() after inhibit timer expires. See also OD_requestTPDO() and OD_TPDOtransmitted().

Parameters
TPDOTPDO object.

◆ CO_TPDO_process()

void CO_TPDO_process ( CO_TPDO_t * TPDO,
uint32_t timeDifference_us,
uint32_t * timerNext_us,
bool_t NMTisOperational,
bool_t syncWas )

Process transmitting PDO messages.

Function must be called cyclically in any NMT state. It prepares and sends TPDO if necessary.

Parameters
TPDOThis object.
timeDifference_usTime difference from previous function call.
[out]timerNext_usinfo to OS - see CO_process().
NMTisOperationalTrue if this node is in NMT_OPERATIONAL state.
syncWasTrue, if CANopen SYNC message was just received or transmitted.