CANopen Master Documentation
Version 6.06.04
|
The real-time data transfer is performed by means of "Process Data Objects (PDO)". The transfer of PDOs is performed with no protocol overhead. The PDOs correspond to entries in the device Object Dictionary and provide the interface to the application objects. Data type and mapping of application objects into a PDO is determined by a corresponding default PDO mapping structure within the Device Object Dictionary. If variable PDO-mapping is supported the number of PDOs and the mapping of application objects into a PDO may be transmitted to a device during the device configuration process by applying the SDO services (see com_sdo_cln.h) to the corresponding entries of the Object Dictionary. Number and length of PDOs of a device is application specific and are specified within the device profile.
There are two kinds of use for PDOs. The first is data transmission and the second data reception. It is distinguished in Transmit-PDOs (TPDOs) and Receive-PDOs (RPDOs). Devices supporting TPDOs are PDO producer and devices which are able to receive PDOs are called PDO consumer.
In order to access the maximum number of PDOs, the API uses the parameter uwPdoNumV, which is called PDO number. The value for PDO number is 0 to COM_PDO_RCV_MAX - 1 for Receive PDOs and 0 to COM_PDO_TRM_MAX - 1 for Transmit PDOs.
The PDO communication section explains in detail the usage of the API and provides examples.
RPDO messages can be stored in a queue, the queue is disabled by default. The function ComPdoRcvQueueEnable() is used to enable a queue for RPDO messages. By means of the function ComPdoRcvQueueCount() the number of messages stored inside the queue can be retrieved. RPDO messages can be fetched from the queue by calling ComPdoRcvQueueFetch(). The example in RPDO Queue shows how to read messages.
Data Structures | |
struct | ComPdoMapping_s |
Typedefs | |
typedef void(* | ComPdoMapHandler_fn) (uint32_t ulMapEntryV) |
Enumerations | |
enum | PdoDir_e { ePDO_DIR_RCV = 0 , ePDO_DIR_TRM } |
enum | PdoType_e { ePDO_TYPE_SYNC_0 = 0 , ePDO_TYPE_SYNC_1 = 1 , ePDO_TYPE_SYNC_2 = 2 , ePDO_TYPE_SYNC_3 = 3 , ePDO_TYPE_SYNC_4 = 4 , ePDO_TYPE_SYNC_5 = 5 , ePDO_TYPE_SYNC_6 = 6 , ePDO_TYPE_SYNC_7 = 7 , ePDO_TYPE_SYNC_8 = 8 , ePDO_TYPE_SYNC_240 = 240 , ePDO_TYPE_res241 = 241 , ePDO_TYPE_res253 = 253 , ePDO_TYPE_EVENT_MANUFACTURER = 254 , ePDO_TYPE_EVENT_PROFILE = 255 } |
Functions | |
ComStatus_tv | ComPdoAddMappingList (uint8_t ubNetV, CPP_CONST ComPdoMapping_ts *ptsRcvMapListV, CPP_CONST ComPdoMapping_ts *ptsTrmMapListV) |
ComStatus_tv | ComPdoConfig (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubPdoDirV, uint32_t ulIdV, uint8_t ubDlcV, uint8_t ubTypeV, uint16_t uwTimeV) |
ComStatus_tv | ComPdoEnable (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubPdoDirV, uint8_t ubEnableV) |
void | ComPdoEventReceive (uint8_t ubNetV, uint16_t uwPdoNumV) |
void | ComPdoEventTimeout (uint8_t ubNetV, uint16_t uwPdoNumV) |
ComStatus_tv | ComPdoGetId (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubPdoDirV, uint32_t *pulIdV) |
uint16_t | ComPdoGetMapIndex (uint32_t ulMapEntryV) |
uint8_t | ComPdoGetMapLength (uint32_t ulMapEntryV) |
uint8_t | ComPdoGetMapSubIndex (uint32_t ulMapEntryV) |
ComStatus_tv | ComPdoGetTimer (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubPdoDirV, uint16_t *puwTimeV) |
ComStatus_tv | ComPdoGetType (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubPdoDirV, uint8_t *pubTypeV) |
ComStatus_tv | ComPdoIsEnabled (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubPdoDirV, uint8_t *pubPdoEnableV) |
ComSdoStatus_tv | ComPdoRcvMapAdd (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubMapIdxV, uint32_t ulMapEntryV) |
ComSdoStatus_tv | ComPdoRcvMapEnable (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubMapNumberV) |
ComStatus_tv | ComPdoRcvQueueClear (uint8_t ubNetV) |
ComStatus_tv | ComPdoRcvQueueCount (uint8_t ubNetV, uint16_t *puwCountV) |
ComStatus_tv | ComPdoRcvQueueDisable (uint8_t ubNetV) |
ComStatus_tv | ComPdoRcvQueueEnable (uint8_t ubNetV) |
ComStatus_tv | ComPdoRcvQueueFetch (uint8_t ubNetV, CpCanMsg_ts *ptsCanMsgV) |
ComStatus_tv | ComPdoRelease (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubPdoDirV) |
ComStatus_tv | ComPdoSetTimer (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubPdoDirV, uint16_t uwTimeV) |
ComStatus_tv | ComPdoSetType (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubPdoDirV, uint8_t ubTypeV) |
ComSdoStatus_tv | ComPdoTrmMapAdd (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubMapIdxV, uint32_t ulMapEntryV) |
ComSdoStatus_tv | ComPdoTrmMapEnable (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubMapNumberV) |
ComStatus_tv | ComPdoTrmMapEvent (uint8_t ubNetV, uint32_t ulMapEntryV) |
ComStatus_tv | ComPdoTrmPacket (uint8_t ubNetV, uint16_t uwPdoNumV, uint8_t ubSizeV, uint8_t *pubSrcDataV) |
ComPdoMapHandler_fn |
ulMapEntryV | Mapping entry |
Signature of handler in structure ComPdoMapping_s. The optional handler is called during the PDO mapping procedure for RPDOs and TPDOs. The parameter ulMapEntryV is the mapping entry assigned to the handler. This allows that one handler can support multiple mapping entries.
enum PdoDir_e |
enum PdoType_e |
PDO transmission types.
The common used PDO transmission types are defined in this enumeration.
ComStatus_tv ComPdoAddMappingList | ( | uint8_t | ubNetV, |
CPP_CONST ComPdoMapping_ts * | ptsRcvMapListV, | ||
CPP_CONST ComPdoMapping_ts * | ptsTrmMapListV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | ptsRcvMapListV | List of objects for RPDO mapping |
[in] | ptsTrmMapListV | List of objects for TPDO mapping |
This function adds individual PDO mapping lists for RPDO mapping defined by ptsRcvMapListV and TPDO mapping defined by ptsTrmMapListV. Each list defines which objects can be mapped into a PDO. As default a CANopen network has no mapping list. Setting the mapping list pointer to NULL disables the mapping list.
ComStatus_tv ComPdoConfig | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubPdoDirV, | ||
uint32_t | ulIdV, | ||
uint8_t | ubDlcV, | ||
uint8_t | ubTypeV, | ||
uint16_t | uwTimeV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubPdoDirV | PDO direction |
[in] | ulIdV | PDO identifier |
[in] | ubDlcV | PDO DLC value (omitted) |
[in] | ubTypeV | PDO transmission type |
[in] | uwTimeV | PDO timer |
This function adds a new PDO to the CANopen Master. The PDO direction (RPDO or TPDO) is defined by the parameter ubPdoDirV. The parameter uwPdoNumV denotes the PDO number. The first PDO (TPDO1 or RPDO1) is located at PDO number 0.
The PDO identifier is configured by parameter ulIdV. Please note that the identifier value must meet the requirements for restricted CAN IDs of CiA 301 or CiA 1301.
The parameter ubDlcV is omitted by the function, it is kept for compatibility reasons to previous versions of the CANopen API. The DLC value of the PDO is calculated upon the PDO mapping entries.
Possible PDO transmission type values for parameter ubTypeV are listed inside the enumeration PdoType_e.
The function disables the transmission of TPDOs and reception of RPDOs as default. In order to enable a PDO use ComPdoEnable() afterwards.
Example
ComStatus_tv ComPdoEnable | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubPdoDirV, | ||
uint8_t | ubEnableV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubPdoDirV | PDO direction |
[in] | ubEnableV | Enable/Disable PDO |
This function enables (ubEnableV = 1) or disables (ubEnableV = 0) a PDO. The PDO direction (RPDO or TPDO) is defined by the parameter ubPdoDirV. The parameter uwPdoNumV denotes the PDO number. The first PDO (TPDO1 or RPDO1) is located at PDO number 0. A PDO is disabled by default upon creation (refer to ComPdoConfig()).
void ComPdoEventReceive | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
The function is called by the CANopen Master stack upon reception of a Receive-PDO (RPDO). The Receive PDO has to be configured by ComPdoConfig() in advance.
void ComPdoEventTimeout | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
The function is called by the CANopen Master stack when reception of a Receive-PDO (RPDO) times out. The RPDO has to be configured by ComPdoConfig() in advance. The transmission type of the RPDO must either ePDO_TYPE_EVENT_MANUFACTURER or ePDO_TYPE_EVENT_PROFILE. In addition the RPDO timer value must be set to a value greater than 0.
ComStatus_tv ComPdoGetId | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubPdoDirV, | ||
uint32_t * | pulIdV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubPdoDirV | PDO direction |
[out] | pulIdV | Pointer to buffer for PDO identifier |
The parameter uwPdoNumV denotes the PDO number, the PDO direction (TPDO or RPDO) is defined by parameter ubPdoDirV. The first PDO (TPDO1 or RPDO1) is located at PDO number 0. The function copies the identifier for the selected PDO into the variable pulIdV. In case the selected PDO is not configured the function returns eCOM_ERR_COB_ID_VALUE.
uint16_t ComPdoGetMapIndex | ( | uint32_t | ulMapEntryV | ) |
[in] | ulMapEntryV | Mapping entry |
This helper function returns the index value of the mapping entry (see structure ComPdoMapping_s) defined by the parameter ulMapEntryV.
uint8_t ComPdoGetMapLength | ( | uint32_t | ulMapEntryV | ) |
[in] | ulMapEntryV | Mapping entry |
This helper function returns the length (in number of bits) of the mapping entry (see structure ComPdoMapping_s) defined by the parameter ulMapEntryV.
uint8_t ComPdoGetMapSubIndex | ( | uint32_t | ulMapEntryV | ) |
[in] | ulMapEntryV | Mapping entry |
This helper function returns the sub-index value of the mapping entry (see structure ComPdoMapping_s) defined by the parameter ulMapEntryV.
ComStatus_tv ComPdoGetTimer | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubPdoDirV, | ||
uint16_t * | puwTimeV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubPdoDirV | PDO direction |
[out] | puwTimeV | Pointer to buffer for PDO timer |
The parameter uwPdoNumV denotes the PDO number, the PDO direction (TPDO or RPDO) is defined by parameter ubPdoDirV. The first PDO (TPDO1 or RPDO1) is located at PDO number 0. The function copies the timer value for the selected PDO into the variable puwTimeV. In case the selected PDO is not configured the function returns eCOM_ERR_COB_TIMER.
ComStatus_tv ComPdoGetType | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubPdoDirV, | ||
uint8_t * | pubTypeV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubPdoDirV | PDO direction |
[out] | pubTypeV | Pointer to buffer for PDO transmission type |
The parameter uwPdoNumV denotes the PDO number, the PDO direction (TPDO or RPDO) is defined by parameter ubPdoDirV. The first PDO (TPDO1 or RPDO1) is located at PDO number 0. The function copies the transmission type for the selected PDO into the variable pubTypeV. In case the selected PDO is not configured the function returns eCOM_ERR_COB_TYPE.
ComStatus_tv ComPdoIsEnabled | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubPdoDirV, | ||
uint8_t * | pubPdoEnableV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubPdoDirV | PDO direction |
[out] | pubPdoEnableV | Pointer to PDO enable/disable status |
ComSdoStatus_tv ComPdoRcvMapAdd | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubMapIdxV, | ||
uint32_t | ulMapEntryV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubMapIdxV | Index for mapping entry |
[in] | ulMapEntryV | Mapping entry, according to CiA 301 / CiA 1301 |
The function allows to add or modify PDO mapping entries for a RPDO defined by the parameter uwPdoNumV. The mappings entry is defined by the value of ubMapIdxV, the first entry starts with a value of 0. The last possible entry is located at COM_PDO_MAPPING_ENTRIES - 1.
Adding or modifying a mapping entry is only possible if the current mapping is not valid (disabled). Refer to ComPdoRcvMapEnable() for enabling or disabling of a mapping entry.
The following code snippet depicts how to add object 2001:01h as first mapping entry for RPDO1:
For a more detailed explanation please refer to the RPDO mapping example.
ComSdoStatus_tv ComPdoRcvMapEnable | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubMapNumberV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubMapNumberV | Number of mapping entries |
The function enables or disables a mapping for a RPDO defined by the parameter uwPdoNumV. The PDO mapping is disables when parameter ubMapNumberV is set to 0. A value > 0 for a ubMapNumberV enables the mapping, the value defines how many mapping entries are valid.
The following code snippet depicts how to enable one mapping entry for RPDO1:
Mapping entries can be added or modified by usage of ComPdoRcvMapAdd().
ComStatus_tv ComPdoRcvQueueClear | ( | uint8_t | ubNetV | ) |
[in] | ubNetV | CANopen Network channel |
The function removes all messages inside the PDO receive queue.
ComStatus_tv ComPdoRcvQueueCount | ( | uint8_t | ubNetV, |
uint16_t * | puwCountV | ||
) |
[in] | ubNetV | CANopen Network channel |
[out] | puwCountV | Number of messages present in the queue |
The function retrieves the number of pending elements inside a PDO receive queue.
ComStatus_tv ComPdoRcvQueueDisable | ( | uint8_t | ubNetV | ) |
[in] | ubNetV | CANopen Network channel |
The function disables the PDO receive queue on the selected CANopen network channel.
ComStatus_tv ComPdoRcvQueueEnable | ( | uint8_t | ubNetV | ) |
[in] | ubNetV | CANopen Network channel |
The function enables the PDO receive queue on the selected CANopen network channel.
ComStatus_tv ComPdoRcvQueueFetch | ( | uint8_t | ubNetV, |
CpCanMsg_ts * | ptsCanMsgV | ||
) |
[in] | ubNetV | CANopen Network channel |
[out] | ptsCanMsgV | Pointer to CAN message structure |
The function fetches one CAN message from the PDO receive queue.
ComStatus_tv ComPdoRelease | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubPdoDirV | ||
) |
[in] | ubNetV | - CANopen Network channel |
[in] | uwPdoNumV | - PDO number |
[in] | ubPdoDirV | - PDO direction |
This function releases a PDO from the CANopen Master. The PDO direction (RPDO or TPDO) is defined by the parameter ubPdoDirV. The parameter uwPdoNumV denotes the PDO number. The first PDO (TPDO1 or RPDO1) is located at PDO number 0.
ComStatus_tv ComPdoSetTimer | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubPdoDirV, | ||
uint16_t | uwTimeV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubPdoDirV | PDO direction |
[in] | uwTimeV | PDO timer |
The parameter uwPdoNumV denotes the PDO number, the PDO direction (TPDO or RPDO) is defined by parameter ubPdoDirV. The first PDO (TPDO1 or RPDO1) is located at PDO number 0. The function sets the timer value for the selected PDO defined by uwTimeV. In case the selected PDO is not configured the function returns eCOM_ERR_COB_TIMER.
ComStatus_tv ComPdoSetType | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubPdoDirV, | ||
uint8_t | ubTypeV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubPdoDirV | PDO direction |
[out] | ubTypeV | PDO transmission type |
The parameter uwPdoNumV denotes the PDO number, the PDO direction (TPDO or RPDO) is defined by parameter ubPdoDirV. The first PDO (TPDO1 or RPDO1) is located at PDO number 0. The function sets the transmission type for the selected PDO defined by ubTypeV. In case the selected PDO is not configured the function returns eCOM_ERR_COB_TYPE.
ComSdoStatus_tv ComPdoTrmMapAdd | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubMapIdxV, | ||
uint32_t | ulMapEntryV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubMapIdxV | Index for mapping entry |
[in] | ulMapEntryV | Mapping entry, according to CiA 301 |
The function allows to add or modify PDO mapping entries for a TPDO defined by the parameter uwPdoNumV. The mappings entry is defined by the value of ubMapIdxV, the first entry starts with a value of 0.
Adding or modifying a mapping entry is only possible if the current mapping is not valid (disabled). Refer to ComPdoTrmMapEnable() for enabling or disabling of a mapping entry.
The following code snippet depicts how to add object 2011:01h as first mapping entry for TPDO1:
For a more detailed explanation please refer to the TPDO mapping example.
ComSdoStatus_tv ComPdoTrmMapEnable | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubMapNumberV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubMapNumberV | Number of mapping entries |
The function enables or disables a mapping for a RPDO defined by the parameter uwPdoNumV. The PDO mapping is disables when parameter ubMapNumberV is set to 0. A value > 0 for a ubMapNumberV enables the mapping, the value defines how many mapping entries are valid.
The following code snippet depicts how to enable one mapping entry for RPDO1:
Mapping entries can be added or modified by usage of ComPdoRcvMapAdd().
ComStatus_tv ComPdoTrmMapEvent | ( | uint8_t | ubNetV, |
uint32_t | ulMapEntryV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | ulMapEntryV | Mapping entry, according to CiA 301 |
This function triggers transmission of a TPDO which contains the mapping entry defined by parameter ulMapEntryV
. The function checks if the PDO is enabled and if the correct transmission type (ie. ePDO_TYPE_EVENT_MANUFACTURER or ePDO_TYPE_EVENT_PROFILE) is configured for the TPDO.
Transmission of a PDO is only possible in NMT Operational state (eCOM_NMT_STATE_OPERATIONAL).
The function returns a negative value from ComErr_e in case of an error. A positive value denotes how many times the entry ulMapEntryV
has been mapped into a PDO.
ComStatus_tv ComPdoTrmPacket | ( | uint8_t | ubNetV, |
uint16_t | uwPdoNumV, | ||
uint8_t | ubSizeV, | ||
uint8_t * | pubSrcDataV | ||
) |
[in] | ubNetV | CANopen Network channel |
[in] | uwPdoNumV | PDO number |
[in] | ubSizeV | Size of source data |
[out] | pubSrcDataV | Pointer to source data |
This function triggers transmission of a TPDO defined by parameter uwPdoNumV. The first TPDO is located at PDO number 0.
The functions copies the the number of bytes defined by ubSizeV from pubSrcDataV to the PDO data field and pushes the CAN frame into an internal FIFO. A TPDO will only be transmitted under the following conditions:
Transmission of a PDO is only possible in NMT Operational state (eCOM_NMT_STATE_OPERATIONAL).