CANopen Slave Documentation
Version 6.16.04
Loading...
Searching...
No Matches
cos_pdo.h File Reference

Detailed Description

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:

  • RPDO communication parameter index = 1400h + COS_PDO_RCV_NUMBER - 1
  • TPDO communication parameter index = 1800h + COS_PDO_TRM_NUMBER - 1
  • RPDO mapping parameter index = 1600h + COS_PDO_RCV_NUMBER - 1
  • TPDO mapping parameter index = 1A00h + COS_PDO_TRM_NUMBER - 1

For each PDO the pair of communication and mapping parameter is mandatory.

+ Include dependency graph for cos_pdo.h:

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 Documentation

◆ CosPdoCom_ts

typedef struct CosPdoCom_s CosPdoCom_ts

PDO communication parameter.

The structure CosPdoCom_s describes the communication parameters of a PDO:

  • Identifier
  • Transmission Type
  • Inhibit time (only for transmit PDO)
  • Event Timer

If a transmit PDO is triggered by a SYNC or the internal timer, these events are counted by the members ubSyncCount resp. uwEventTick.

◆ CosPdoMap_ts

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).

CosPdoMap_ts atsTrmPdoMapG[] =
{
//--- Index 1A00 -----------------------------
{ 0x7130, 0x01, 0x10 },
{ 0x7130, 0x02, 0x10 },
{ 0x7130, 0x03, 0x10 },
{ 0x7130, 0x04, 0x10 },
{ 0x0000, 0x00, 0x00 },
{ 0x0000, 0x00, 0x00 },
{ 0x0000, 0x00, 0x00 },
{ 0x0000, 0x00, 0x00 },
//--- Index 1A01 -----------------------------
{ 0x6000, 0x01, 0x08 },
{ 0x6000, 0x02, 0x08 },
PDO mapping parameter (static mapping)
Definition cos_pdo.h:301

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

CosPdoMapHandler_fn
Parameters
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.

Enumeration Type Documentation

◆ PdoType_e

enum PdoType_e

PDO transmission types.

The common used PDO transmission types are defined in this enumeration.

Enumerator
ePDO_TYPE_SYNC_0 

Synchronous, acyclic PDO

ePDO_TYPE_SYNC_1 

Synchronous, cyclic every SYNC

ePDO_TYPE_SYNC_2 

Synchronous, cyclic every 2nd SYNC

ePDO_TYPE_SYNC_3 

Synchronous, cyclic every 3rd SYNC

ePDO_TYPE_SYNC_4 

Synchronous, cyclic every 4th SYNC

ePDO_TYPE_SYNC_5 

Synchronous, cyclic every 5th SYNC

ePDO_TYPE_SYNC_6 

Synchronous, cyclic every 6th SYNC

ePDO_TYPE_SYNC_7 

Synchronous, cyclic every 7th SYNC

ePDO_TYPE_SYNC_8 

Synchronous, cyclic every 8th SYNC

ePDO_TYPE_SYNC_240 

Synchronous, cyclic every 240th SYNC

ePDO_TYPE_EVENT_MANUFACTURER 

Event-driven PDO, manufacturer specific

ePDO_TYPE_EVENT_PROFILE 

Event-driven PDO, profile specific

Function Documentation

◆ CosPdoAppEvent()

void CosPdoAppEvent ( uint8_t  ubPdoNumberV)
Parameters
[in]ubPdoNumberVZero based index of PDO
See also
CosPdoTrmMapEvent()

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).

◆ CosPdoComSetup()

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:

  • Transmission type: 0xFF (event)
  • Inhibit time : 0
  • Event timer : 0

Inside the CosPdoComSetup() function it is possible to change these default values. Here is an example for the first transmit/receive PDO:

void CosPdoComSetup(void)
{
//----------------------------------------------------------------
// 1. Transmit PDO: set to SYNC
//
//----------------------------------------------------------------
// 1. Receive PDO: set to SYNC
//
}
CosPdoCom_ts atsTrmPdoComG[]
@ ePDO_TYPE_SYNC_1
Definition cos_pdo.h:160
void CosPdoComSetup(void)
Setup application specific PDO communication parameter.
CosPdoCom_ts atsRcvPdoComG[]
uint8_t ubTransType
Definition cos_pdo.h:224

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.

◆ CosPdoGetMapIndex()

uint16_t CosPdoGetMapIndex ( uint32_t  ulMapEntryV)
Parameters
[in]ulMapEntryVMapping entry
Returns
Index field of mapping entry

This helper function returns the index value of the mapping entry (see structure CosPdoMapping_s) defined by the parameter ulMapEntryV.

◆ CosPdoGetMapLength()

uint8_t CosPdoGetMapLength ( uint32_t  ulMapEntryV)
Parameters
[in]ulMapEntryVMapping entry
Returns
Length field of mpping entry

This helper function returns the length (in number of bits) of the mapping entry (see structure CosPdoMapping_s) defined by the parameter ulMapEntryV.

◆ CosPdoGetMapSubIndex()

uint8_t CosPdoGetMapSubIndex ( uint32_t  ulMapEntryV)
Parameters
[in]ulMapEntryVMapping entry
Returns
Sub-index field of mapping entry

This helper function returns the sub-index value of the mapping entry (see structure CosPdoMapping_s) defined by the parameter ulMapEntryV.

◆ CosPdoRcvDataUpdate()

void CosPdoRcvDataUpdate ( uint8_t  ubPdoNumberV)
Parameters
[in]ubPdoNumberVZero based index of PDO
See also
CosPdoTrmDataUpdate()

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

◆ CosPdoRcvMapAdd()

uint8_t CosPdoRcvMapAdd ( uint8_t  ubPdoNumberV,
uint8_t  ubMapIdxV,
uint32_t  ulMapEntryV 
)
Parameters
[in]ubPdoNumberVZero based index of PDO
[in]ubMapIdxVIndex for mapping entry
[in]ulMapEntryVMapping entry, according to CiA 301
Returns
Error code defined by enumeration CosSdo_e
See also
CosPdoRcvMapEnable()

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:

if (eCosSdo_WRITE_OK == CosPdoRcvMapAdd(0, 0, 0x20010108))
{
// successfully added first mapping entry to first RPDO
}
@ eCosSdo_WRITE_OK
Definition cos_defs.h:315
uint8_t CosPdoRcvMapAdd(uint8_t ubPdoNumberV, uint8_t ubMapIdxV, uint32_t ulMapEntryV)

◆ CosPdoRcvMapEnable()

uint8_t CosPdoRcvMapEnable ( uint8_t  ubPdoNumberV,
uint8_t  ubMapNumberV 
)
Parameters
[in]ubPdoNumberVZero based index of PDO
[in]ubMapNumberVNumber of mapping entries
Returns
Error code defined by enumeration CosSdo_e
See also
CosPdoRcvMapAdd()

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:

{
// successfully enabled one mapping entry for RPDO1
}
uint8_t CosPdoRcvMapEnable(uint8_t ubPdoNumberV, uint8_t ubMapNumberV)

Mapping entries can be added or modified by usage of CosPdoRcvMapAdd().

◆ CosPdoRcvMapFill()

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.

Parameters
[in]ubStartPdoNumberVThe number of the PDO at which the filling process is to be started.
[in]uwMapIndexVThe index of the data element that is to be mapped into the PDO.
[in]ubStartMapSubIndexVStart number of sub index
[in]ubMapLenghtVThe length of the data element that is to be mapped, given in bits.
[in]ubCountVThe number of data elements that are to be mapped in the PDO(s).
Returns
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:

if (eCosSdo_WRITE_OK == CosPdoRcvMapFill(0, 0x2001, 0x01, 32, 4))
{
// Four entries have been successfully mapped to PDO1 and PDO2 and both PDOs have been enabled.
// If present, PDOs 3 and 4 have not been modified.
}
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.

◆ CosPdoTrmDataChangeEnable()

void CosPdoTrmDataChangeEnable ( uint8_t  ubPdoNumberV,
uint8_t  ubTransTypeV 
)
Parameters
[in]ubPdoNumberVZero based index of TPDO
[in]ubTransTypeVTransmission 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.

◆ CosPdoTrmDataUpdate()

void CosPdoTrmDataUpdate ( uint8_t  ubPdoNumberV)
Parameters
[in]ubPdoNumberVZero based index of PDO
See also
CosPdoRcvDataUpdate()

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 CosPdoTrmDataUpdate(uint8_t ubPdoNumberV)
{
//----------------------------------------------------------------
// example for PDO transmit update
//
aubTrmPdoDataT[0] = 0x2F;
aubTrmPdoDataT[1] = 0x01;
aubTrmPdoDataT[2] = 0x20;
aubTrmPdoDataT[3] = 0x00;
aubTrmPdoDataT[4] = 0x01;
aubTrmPdoDataT[5] = 0x00;
aubTrmPdoDataT[6] = 0x00;
aubTrmPdoDataT[7] = 0x00;
CpCoreBufferSetData(&tsCanPortG,
eCosBuf_PDO1_TRM + ubPdoNumberV,
&aubTrmPdoDataT[0], 0, 8);
CpCoreBufferSetDlc(&tsCanPortG,
eCosBuf_PDO1_TRM + ubPdoNumberV,
8);
}
@ eCosBuf_PDO1_TRM
Definition cos_defs.h:213
void CosPdoTrmDataUpdate(uint8_t ubPdoNumberV)
CpStatus_tv CpCoreBufferSetDlc(CpPort_ts *ptsPortV, uint8_t ubBufferIdxV, uint8_t ubDlcV)
Set DLC of specified buffer.
CpStatus_tv CpCoreBufferSetData(CpPort_ts *ptsPortV, uint8_t ubBufferIdxV, uint8_t *pubSrcDataV, uint8_t ubStartPosV, uint8_t ubSizeV)
Set data of message buffer.

◆ CosPdoTrmEvent()

void CosPdoTrmEvent ( uint8_t  ubPdoNumberV)
Parameters
[in]ubPdoNumberVZero 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.

◆ CosPdoTrmMapAdd()

uint8_t CosPdoTrmMapAdd ( uint8_t  ubPdoNumberV,
uint8_t  ubMapIdxV,
uint32_t  ulMapEntryV 
)
Parameters
[in]ubPdoNumberVZero based index of PDO
[in]ubMapIdxVIndex for mapping entry
[in]ulMapEntryVMapping entry, according to CiA 301
Returns
Error code defined by enumeration CosSdo_e
See also
CosPdoTrmMapEnable()

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:

if (eCosSdo_WRITE_OK == CosPdoTrmMapAdd(0, 0, 0x20110108))
{
// successfully added first mapping entry to first TPDO
}
uint8_t CosPdoTrmMapAdd(uint8_t ubPdoNumberV, uint8_t ubMapIdxV, uint32_t ulMapEntryV)

◆ CosPdoTrmMapEnable()

uint8_t CosPdoTrmMapEnable ( uint8_t  ubPdoNumberV,
uint8_t  ubMapNumberV 
)
Parameters
[in]ubPdoNumberVZero based index of PDO
[in]ubMapNumberVNumber of mapping entries
Returns
Error code defined by enumeration CosSdo_e
See also
CosPdoTrmMapAdd()

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:

{
// successfully enabled one mapping entry for TPDO1
}
uint8_t CosPdoTrmMapEnable(uint8_t ubPdoNumberV, uint8_t ubMapNumberV)

Mapping entries can be added or modified by usage of CosPdoTrmMapAdd().

◆ CosPdoTrmMapEvent()

void CosPdoTrmMapEvent ( uint32_t  ulMapEntryV)
Parameters
[in]ulMapEntryVMapping entry, according to CiA 301
See also
CosPdoAppEvent()

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).

◆ CosPdoTrmMapFill()

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.

Parameters
[in]ubStartPdoNumberVThe number of the PDO at which the filling process is to be started.
[in]uwMapIndexVThe index of the data element that is to be mapped into the PDO.
[in]ubStartMapSubIndexVStart number of sub index
[in]ubMapLenghtVThe length of the data element that is to be mapped, given in bits.
[in]ubCountVThe number of data elements that are to be mapped in the PDO(s).
Returns
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:

if (eCosSdo_WRITE_OK == CosPdoTrmMapFill(0, 0x2011, 0x01, 32, 4))
{
// Four entries have been successfully mapped to PDO1 and PDO2 and both PDOs have been enabled.
// If present, PDOs 3 and 4 have not been modified.
}
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.

Variable Documentation

◆ atsRcvPdoComG

atsRcvPdoComG
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.

◆ atsTrmPdoComG

atsTrmPdoComG
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.