CANopen Slave Documentation
Version 6.16.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 (see COS_PDO_MAPPING) 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 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.
The PDO communication parameter describes the communication capabilities of the PDO. The PDO mapping parameter contains information about the contents of the PDOs (device variables). The indices of the corresponding Object Dictionary entries are computed by the following formulas:
For each PDO the pair of communication and mapping parameter is mandatory.
Data Structures | |
struct | CosPdoCom_s |
struct | CosPdoMap_s |
struct | CosPdoMapping_s |
Typedefs | |
typedef struct CosPdoCom_s | CosPdoCom_ts |
typedef struct CosPdoMap_s | CosPdoMap_ts |
typedef void(* | CosPdoMapHandler_fn) (uint32_t ulMapEntryV) |
Enumerations | |
enum | PdoType_e { ePDO_TYPE_SYNC_0 = 0 , ePDO_TYPE_SYNC_1 , ePDO_TYPE_SYNC_2 , ePDO_TYPE_SYNC_3 , ePDO_TYPE_SYNC_4 , ePDO_TYPE_SYNC_5 , ePDO_TYPE_SYNC_6 , ePDO_TYPE_SYNC_7 , ePDO_TYPE_SYNC_8 , ePDO_TYPE_SYNC_240 = 240 , ePDO_TYPE_EVENT_MANUFACTURER = 254 , ePDO_TYPE_EVENT_PROFILE } |
Functions | |
void | CosPdoAppEvent (uint8_t ubPdoNumberV) |
void | CosPdoComSetup (void) |
uint16_t | CosPdoGetMapIndex (uint32_t ulMapEntryV) |
uint8_t | CosPdoGetMapLength (uint32_t ulMapEntryV) |
uint8_t | CosPdoGetMapSubIndex (uint32_t ulMapEntryV) |
void | CosPdoRcvDataUpdate (uint8_t ubPdoNumberV) |
uint8_t | CosPdoRcvMapAdd (uint8_t ubPdoNumberV, uint8_t ubMapIdxV, uint32_t ulMapEntryV) |
uint8_t | CosPdoRcvMapFill (uint8_t ubStartPdoNumberV, uint16_t uwMapIndexV, uint8_t ubStartMapSubIndexV, uint8_t ubMapLenghtV, uint8_t ubCountV) |
uint8_t | CosPdoRcvMapEnable (uint8_t ubPdoNumberV, uint8_t ubMapNumberV) |
void | CosPdoTrmDataChangeEnable (uint8_t ubPdoNumberV, uint8_t ubTransTypeV) |
void | CosPdoTrmDataUpdate (uint8_t ubPdoNumberV) |
void | CosPdoTrmEvent (uint8_t ubPdoNumberV) |
uint8_t | CosPdoTrmMapAdd (uint8_t ubPdoNumberV, uint8_t ubMapIdxV, uint32_t ulMapEntryV) |
uint8_t | CosPdoTrmMapEnable (uint8_t ubPdoNumberV, uint8_t ubMapNumberV) |
void | CosPdoTrmMapEvent (uint32_t ulMapEntryV) |
uint8_t | CosPdoTrmMapFill (uint8_t ubStartPdoNumberV, uint16_t uwMapIndexV, uint8_t ubStartMapSubIndexV, uint8_t ubMapLenghtV, uint8_t ubCountV) |
Variables | |
CosPdoCom_ts | atsRcvPdoComG [] |
CosPdoCom_ts | atsTrmPdoComG [] |
typedef struct CosPdoCom_s CosPdoCom_ts |
PDO communication parameter.
The structure CosPdoCom_s describes the communication parameters of a PDO:
If a transmit PDO is triggered by a SYNC or the internal timer, these events are counted by the members ubSyncCount resp. uwEventTick.
typedef struct CosPdoMap_s CosPdoMap_ts |
PDO mapping parameter (static mapping)
The structure CosPdoMap_s describes the mapping parameters of a PDO with static mapping. For static PDO mapping the symbol COS_PDO_MAPPING is set to 0.
The following code snippet is taken from the cos_user.c file. In this static mapping table, the first PDO has four entries (objects 7130h:01h to 7130h:04h). Each entry has a size of 2 byte (10h = 16 bit). The second PDO has two entries (objects 6000h:01h to 6000h:02h). Each entry has a size of 1 byte (8 bit).
Please note that the protocol stack does not copy any data to (or from) a PDO automatically. Instead, the user has to adopt the functions CosPdoRcvDataUpdate() and CosPdoTrmDataUpdate() for that purpose.
CosPdoMapHandler_fn |
ulMapEntryV | - Mapping entry, according to CiA 301 |
This type definition is used for dynamic PDO mapping, i.e. the symbol COS_PDO_MAPPING is set to a value greater than 0.
enum PdoType_e |
PDO transmission types.
The common used PDO transmission types are defined in this enumeration.
void CosPdoAppEvent | ( | uint8_t | ubPdoNumberV | ) |
[in] | ubPdoNumberV | Zero based index of PDO |
This function triggers transmission of a TPDO specified by the parameter ubPdoNrV. The function checks if the PDO is enabled and if the correct transmission type (ePDO_TYPE_EVENT_MANUFACTURER or ePDO_TYPE_EVENT_PROFILE) is configured for the TPDO.
This function can only be called if the symbol COS_PDO_MAPPING is set to 0 (i.e. static PDO mapping is configured). In case of dynamic PDO mapping (COS_PDO_MAPPING > 0) the corresponding function CosPdoTrmMapEvent() has to be used.
Transmission of a PDO is only possible in NMT Operational state (NODE_STATE_OPERATIONAL).
void CosPdoComSetup | ( | void | ) |
Setup application specific PDO communication parameter.
This function is used to setup application (or device profile) specific communication parameters. The default values for the PDOs (Pre-defined connection set) are assigned inside the function Cos301_ParmInit(). Beside the COB-ID the following values are assigned:
Inside the CosPdoComSetup() function it is possible to change these default values. Here is an example for the first transmit/receive PDO:
This function will be called by CANopen FD protocol stack upon initialization and must be provided by user application, typically within the file cos_user.c
.
uint16_t CosPdoGetMapIndex | ( | uint32_t | ulMapEntryV | ) |
[in] | ulMapEntryV | Mapping entry |
This helper function returns the index value of the mapping entry (see structure CosPdoMapping_s) defined by the parameter ulMapEntryV.
uint8_t CosPdoGetMapLength | ( | uint32_t | ulMapEntryV | ) |
[in] | ulMapEntryV | Mapping entry |
This helper function returns the length (in number of bits) of the mapping entry (see structure CosPdoMapping_s) defined by the parameter ulMapEntryV.
uint8_t CosPdoGetMapSubIndex | ( | uint32_t | ulMapEntryV | ) |
[in] | ulMapEntryV | Mapping entry |
This helper function returns the sub-index value of the mapping entry (see structure CosPdoMapping_s) defined by the parameter ulMapEntryV.
void CosPdoRcvDataUpdate | ( | uint8_t | ubPdoNumberV | ) |
[in] | ubPdoNumberV | Zero based index of PDO |
This function is called by the framework in order to update process data which is received by the device via a RPDO. his function will be called by CANopen FD protocol stack only if the symbol COS_PDO_MAPPING is set to 0 (i.e. static PDO mapping is used).
The implementation of the function is application specific. It should be provided by user application, typically within the file cos_user.c
uint8_t CosPdoRcvMapAdd | ( | uint8_t | ubPdoNumberV, |
uint8_t | ubMapIdxV, | ||
uint32_t | ulMapEntryV | ||
) |
[in] | ubPdoNumberV | Zero based index of PDO |
[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 RPDO defined by the parameter ubPdoNumberV. 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 COS_PDO_MAPPING - 1.
The function is only available for dynamic PDO mapping (i.e. the symbol COS_PDO_MAPPING is not set to 0). Adding or modifying a mapping entry is only possible if the current mapping is not valid (disabled). Refer to CosPdoRcvMapEnable() 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:
uint8_t CosPdoRcvMapEnable | ( | uint8_t | ubPdoNumberV, |
uint8_t | ubMapNumberV | ||
) |
[in] | ubPdoNumberV | Zero based index of PDO |
[in] | ubMapNumberV | Number of mapping entries |
The function enables or disables a mapping for a RPDO defined by the parameter ubPdoNumberV. 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 CosPdoRcvMapAdd().
uint8_t CosPdoRcvMapFill | ( | uint8_t | ubStartPdoNumberV, |
uint16_t | uwMapIndexV, | ||
uint8_t | ubStartMapSubIndexV, | ||
uint8_t | ubMapLenghtV, | ||
uint8_t | ubCountV | ||
) |
Automatic filling of the data elements for the receive PDO mapping with the provided entries.
[in] | ubStartPdoNumberV | The number of the PDO at which the filling process is to be started. |
[in] | uwMapIndexV | The index of the data element that is to be mapped into the PDO. |
[in] | ubStartMapSubIndexV | Start number of sub index |
[in] | ubMapLenghtV | The length of the data element that is to be mapped, given in bits. |
[in] | ubCountV | The number of data elements that are to be mapped in the PDO(s). |
eCosSdo_WRITE_OK
on success or an enumerated error code from CosSdo_e
.This function helps the user to create PDO mappings that have the same index and a continuous sub-index for the data elements. The corresponding PDOs are activated without any further changes to the communication parameters.
As this function uses the internal functions of the PDOD software module, the return code is returned unchanged.
The following code snippet shows how to perform a mapping of four 32-bit values:
void CosPdoTrmDataChangeEnable | ( | uint8_t | ubPdoNumberV, |
uint8_t | ubTransTypeV | ||
) |
[in] | ubPdoNumberV | Zero based index of TPDO |
[in] | ubTransTypeV | Transmission type |
This function is used to control the behavior of PDO transmission inside the internal PDO timer function. The transmission of a PDO can be triggered on data change if the configured transmission type is equal to the value of parameter ubTransTypeV. Possible values for ubTransTypeV are ePDO_TYPE_EVENT_MANUFACTURER or ePDO_TYPE_EVENT_PROFILE. All other values supplied will disable the data change testing.
void CosPdoTrmDataUpdate | ( | uint8_t | ubPdoNumberV | ) |
[in] | ubPdoNumberV | Zero based index of PDO |
This function is called by the framework in order to update process data which is transmitted by the device via a TPDO. his function will be called by CANopen FD protocol stack only if the symbol COS_PDO_MAPPING is set to 0 (i.e. static PDO mapping is used).
The implementation of the function is application specific. It should be provided by user application, typically within the file cos_user.c
The following code snippet shows how to copy data into a transmit PDO.
void CosPdoTrmEvent | ( | uint8_t | ubPdoNumberV | ) |
[in] | ubPdoNumberV | Zero based index of PDO |
The function triggers the transmission of a PDO by the application. The PDO transmission type must be configured to either ePDO_TYPE_EVENT_MANUFACTURER or ePDO_TYPE_EVENT_PROFILE.
uint8_t CosPdoTrmMapAdd | ( | uint8_t | ubPdoNumberV, |
uint8_t | ubMapIdxV, | ||
uint32_t | ulMapEntryV | ||
) |
[in] | ubPdoNumberV | Zero based index of PDO |
[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 ubPdoNumberV. 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 COS_PDO_MAPPING - 1.
The function is only available for dynamic PDO mapping (i.e. the symbol COS_PDO_MAPPING is not set to 0). Adding or modifying a mapping entry is only possible if the current mapping is not valid (disabled). Refer to CosPdoTrmMapEnable() 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:
uint8_t CosPdoTrmMapEnable | ( | uint8_t | ubPdoNumberV, |
uint8_t | ubMapNumberV | ||
) |
[in] | ubPdoNumberV | Zero based index of PDO |
[in] | ubMapNumberV | Number of mapping entries |
The function enables or disables a mapping for a TPDO defined by the parameter ubPdoNumberV. 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 TPDO1:
Mapping entries can be added or modified by usage of CosPdoTrmMapAdd().
void CosPdoTrmMapEvent | ( | uint32_t | ulMapEntryV | ) |
[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 (ePDO_TYPE_EVENT_MANUFACTURER) is configured for the TPDO.
The function is only available for dynamic PDO mapping (i.e. the symbol COS_PDO_MAPPING is not set to 0). In case of static PDO mapping (COS_PDO_MAPPING = 0) the corresponding function CosPdoAppEvent() has to be used.
Transmission of a PDO is only possible in NMT Operational state (NODE_STATE_OPERATIONAL).
uint8_t CosPdoTrmMapFill | ( | uint8_t | ubStartPdoNumberV, |
uint16_t | uwMapIndexV, | ||
uint8_t | ubStartMapSubIndexV, | ||
uint8_t | ubMapLenghtV, | ||
uint8_t | ubCountV | ||
) |
Automatic filling of the data elements for the receive PDO mapping with the provided entries.
[in] | ubStartPdoNumberV | The number of the PDO at which the filling process is to be started. |
[in] | uwMapIndexV | The index of the data element that is to be mapped into the PDO. |
[in] | ubStartMapSubIndexV | Start number of sub index |
[in] | ubMapLenghtV | The length of the data element that is to be mapped, given in bits. |
[in] | ubCountV | The number of data elements that are to be mapped in the PDO(s). |
eCosSdo_WRITE_OK
on success or an enumerated error code from CosSdo_e
.This function helps the user to create PDO mappings that have the same index and a continuous sub-index for the data elements. The corresponding PDOs are activated without any further changes to the communication parameters.
As this function uses the internal functions of the PDOD software module, the return code is returned unchanged.
The following code snippet shows how to perform a mapping of four 32-bit values:
|
extern |
The array atsRcvPdoComG[] provides access to RPDO communication parameters (see structure CosPdoCom_s). The size of the array is defined by the symbol COS_PDO_RCV_NUMBER. The default values of the data fields can be modified inside the CosPdoComSetup() function.
|
extern |
The array atsTrmPdoComG[] provides access to TPDO communication parameters (see structure CosPdoCom_s). The size of the array is defined by the symbol COS_PDO_TRM_NUMBER. The default values of the data fields can be modified inside the CosPdoComSetup() function.