CANopenNode

Files

file  CO_PDO.h
 CANopen Process Data Object protocol.
 

Data Structures

struct  CO_RPDOCommPar_t
 RPDO communication parameter. More...
 
struct  CO_RPDOMapPar_t
 RPDO mapping parameter. More...
 
struct  CO_TPDOCommPar_t
 TPDO communication parameter. More...
 
struct  CO_TPDOMapPar_t
 TPDO mapping parameter. More...
 
struct  CO_RPDO_t
 RPDO object. More...
 
struct  CO_TPDO_t
 TPDO object. More...
 

Functions

CO_ReturnError_t CO_RPDO_init (CO_RPDO_t *RPDO, CO_EM_t *em, CO_SDO_t *SDO, CO_SYNC_t *SYNC, CO_NMT_internalState_t *operatingState, uint8_t nodeId, uint16_t defaultCOB_ID, uint8_t restrictionFlags, const CO_RPDOCommPar_t *RPDOCommPar, const CO_RPDOMapPar_t *RPDOMapPar, uint16_t idx_RPDOCommPar, uint16_t idx_RPDOMapPar, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx)
 Initialize RPDO object. More...
 
void CO_RPDO_initCallbackPre (CO_RPDO_t *RPDO, void *object, void(*pFunctSignalPre)(void *object))
 Initialize RPDO callback function. More...
 
CO_ReturnError_t CO_TPDO_init (CO_TPDO_t *TPDO, CO_EM_t *em, CO_SDO_t *SDO, CO_SYNC_t *SYNC, CO_NMT_internalState_t *operatingState, uint8_t nodeId, uint16_t defaultCOB_ID, uint8_t restrictionFlags, const CO_TPDOCommPar_t *TPDOCommPar, const CO_TPDOMapPar_t *TPDOMapPar, uint16_t idx_TPDOCommPar, uint16_t idx_TPDOMapPar, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx)
 Initialize TPDO object. More...
 
uint8_t CO_TPDOisCOS (CO_TPDO_t *TPDO)
 Verify Change of State of the PDO. More...
 
CO_ReturnError_t CO_TPDOsend (CO_TPDO_t *TPDO)
 Send TPDO message. More...
 
void CO_RPDO_process (CO_RPDO_t *RPDO, bool_t syncWas)
 Process received PDO messages. More...
 
void CO_TPDO_process (CO_TPDO_t *TPDO, bool_t syncWas, uint32_t timeDifference_us, uint32_t *timerNext_us)
 Process transmitting PDO messages. More...
 

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 Object Dictionary at index 0x1400+ and 0x1800+. PDO mapping parameters (size and contents of the PDO) are in Object Dictionary at index 0x1600+ and 0x1A00+.

Features of the PDO as implemented here, in CANopenNode:

Function Documentation

◆ CO_RPDO_init()

CO_ReturnError_t CO_RPDO_init ( CO_RPDO_t RPDO,
CO_EM_t em,
CO_SDO_t *  SDO,
CO_SYNC_t SYNC,
CO_NMT_internalState_t operatingState,
uint8_t  nodeId,
uint16_t  defaultCOB_ID,
uint8_t  restrictionFlags,
const CO_RPDOCommPar_t RPDOCommPar,
const CO_RPDOMapPar_t RPDOMapPar,
uint16_t  idx_RPDOCommPar,
uint16_t  idx_RPDOMapPar,
CO_CANmodule_t CANdevRx,
uint16_t  CANdevRxIdx 
)

Initialize RPDO object.

Function must be called in the communication reset section.

Parameters
RPDOThis object will be initialized.
emEmergency object.
SDOSDO server object.
SYNCvoid pointer to SYNC object or NULL.
operatingStatePointer to variable indicating CANopen device NMT internal state.
nodeIdCANopen Node ID of this device. If default COB_ID is used, value will be added.
defaultCOB_IDDefault COB ID for this PDO (without NodeId). See CO_Default_CAN_ID_t
restrictionFlagsFlag bits indicates, how PDO communication and mapping parameters are handled:
  • Bit1: If true, communication parameters are writeable only in pre-operational NMT state.
  • Bit2: If true, mapping parameters are writeable only in pre-operational NMT state.
  • Bit3: If true, communication parameters are read-only.
  • Bit4: If true, mapping parameters are read-only.
RPDOCommParPointer to RPDO communication parameter record from Object dictionary (index 0x1400+).
RPDOMapParPointer to RPDO mapping parameter record from Object dictionary (index 0x1600+).
idx_RPDOCommParIndex in Object Dictionary.
idx_RPDOMapParIndex in Object Dictionary.
CANdevRxCAN device for PDO reception.
CANdevRxIdxIndex of receive buffer in the above CAN device.
Returns
CO_ReturnError_t: CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT.

◆ CO_RPDO_initCallbackPre()

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

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

◆ CO_TPDO_init()

CO_ReturnError_t CO_TPDO_init ( CO_TPDO_t TPDO,
CO_EM_t em,
CO_SDO_t *  SDO,
CO_SYNC_t SYNC,
CO_NMT_internalState_t operatingState,
uint8_t  nodeId,
uint16_t  defaultCOB_ID,
uint8_t  restrictionFlags,
const CO_TPDOCommPar_t TPDOCommPar,
const CO_TPDOMapPar_t TPDOMapPar,
uint16_t  idx_TPDOCommPar,
uint16_t  idx_TPDOMapPar,
CO_CANmodule_t CANdevTx,
uint16_t  CANdevTxIdx 
)

Initialize TPDO object.

Function must be called in the communication reset section.

Parameters
TPDOThis object will be initialized.
emEmergency object.
SDOSDO object.
SYNCvoid pointer to SYNC object or NULL.
operatingStatePointer to variable indicating CANopen device NMT internal state.
nodeIdCANopen Node ID of this device. If default COB_ID is used, value will be added.
defaultCOB_IDDefault COB ID for this PDO (without NodeId). See CO_Default_CAN_ID_t
restrictionFlagsFlag bits indicates, how PDO communication and mapping parameters are handled:
  • Bit1: If true, communication parameters are writeable only in pre-operational NMT state.
  • Bit2: If true, mapping parameters are writeable only in pre-operational NMT state.
  • Bit3: If true, communication parameters are read-only.
  • Bit4: If true, mapping parameters are read-only.
TPDOCommParPointer to TPDO communication parameter record from Object dictionary (index 0x1400+).
TPDOMapParPointer to TPDO mapping parameter record from Object dictionary (index 0x1600+).
idx_TPDOCommParIndex in Object Dictionary.
idx_TPDOMapParIndex in Object Dictionary.
CANdevTxCAN device used for PDO transmission.
CANdevTxIdxIndex of transmit buffer in the above CAN device.
Returns
CO_ReturnError_t: CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT.

◆ CO_TPDOisCOS()

uint8_t CO_TPDOisCOS ( CO_TPDO_t TPDO)

Verify Change of State of the PDO.

Function verifies if variable mapped to TPDO has changed its value. Verified are only variables, which has set attribute CO_ODA_TPDO_DETECT_COS in #CO_SDO_OD_attributes_t.

Function may be called by application just before CO_TPDO_process() function, for example: TPDOx->sendRequest = CO_TPDOisCOS(TPDOx); CO_TPDO_process(TPDOx, ....

Parameters
TPDOTPDO object.
Returns
True if COS was detected.

◆ CO_TPDOsend()

CO_ReturnError_t CO_TPDOsend ( CO_TPDO_t TPDO)

Send TPDO message.

Function prepares TPDO data from Object Dictionary variables. It should not be called by application, it is called from CO_TPDO_process().

Parameters
TPDOTPDO object.
Returns
Same as CO_CANsend().

◆ CO_RPDO_process()

void CO_RPDO_process ( CO_RPDO_t RPDO,
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. It does not verify transmission type.

Parameters
RPDOThis object.
syncWasTrue, if CANopen SYNC message was just received or transmitted.

◆ CO_TPDO_process()

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

Process transmitting PDO messages.

Function must be called cyclically in any NMT state. It prepares and sends TPDO if necessary. If Change of State needs to be detected, function CO_TPDOisCOS() must be called before.

Parameters
TPDOThis object.
syncWasTrue, if CANopen SYNC message was just received or transmitted.
timeDifference_usTime difference from previous function call in [microseconds].
[out]timerNext_usinfo to OS - see CO_process_SYNC_PDO().