CANopen Slave Documentation
Version 6.16.04
Loading...
Searching...
No Matches
CosPdoMapping_s Struct Reference

Detailed Description

The structure CosPdoMapping_s describes the mappable objects of a device with dynamic PDO mapping. Dynamic PDO mapping is selected by setting the symbol COS_PDO_MAPPING to a value greater than 0.

The element ulMapEntry describes a mapping entry (see CiA 301). The void pointer pvdData links the mapping entry to application data. The function pointer pfnHandler links to a handler that is called after reception of a RPDO or before transmission of a TPDO.

If dynamic PDO mapping is used, the possible mapping entries of the application are defined in several *.inc files. The file cos_user_rpdo.inc contains a list with valid mapping entries for
RPDOs and the cos_user_tpdo.inc a list with mapping entries for the TrPDOs. In addition to the mapping entries, callback handlers can be added as an option. For a RPDO the handler is called after reception, for a Transmit-PDO the handler is called before transmission.

On reception of a PDO data will be distributed to all mapped values defined by pvdData before the corresponding handler (pfnHandler) is called. On transmission of a PDO the data will be collected from all mapped values defined by pvdData after the corresponding handler (pfnHandler) has been called.

As an example, the available mapping entries for a RPDO defined in cos_user_rpdo.inc are:

{
// mapping entry Index 2002h Sub-Idex 00h and 8 bit long
.ulMapEntry = 0x20020008,
// pointer to the corresponding variable
.pvdData = &ubCosMob_Var2002G,
// a handler that will be called after value reception and modification
.pfnHandler = CosMob_PdoRcvHandler
},
{
// mapping entry Index 2003h Sub-Idex 00h and 16 bit long
.ulMapEntry = 0x20030010,
// pointer to the corresponding variable
.pvdData = &uwCosMob_Var2003G,
// no handler should be triggered after value reception and modification
.pfnHandler = 0L
},
uint8_t ubCosMob_Var2002G
void CosMob_PdoRcvHandler(uint32_t ulMapEntryV)
Demo implementation of callback handler for a mapping entry.
uint16_t uwCosMob_Var2003G

Starting from this list you can use the function CosPdoRcvMapAdd() to map the entries to the desired position inside the PDO. Upon PDO reception, the variables ubCosMob_Var2002G and/or uwCosMob_Var2003G are updated and the handler CosMob_PdoRcvHandler() is called.

The file cos_user_tpdo.inc contains an example for TPDO mapping entries:

{
// mapping entry Index 2002h Sub-Idex 00h and 8 bit long
.ulMapEntry = 0x20040020,
// pointer to the corresponding variable
.pvdData = &ulCosMob_Var2004G,
// a handler that will be called after value reception and modification
.pfnHandler = CosMob_PdoTrmHandler
},
#if CPP_DATA_SIZE > 32
{
// mapping entry Index 2003h Sub-Idex 00h and 16 bit long
.ulMapEntry = 0x20050040,
// pointer to the corresponding variable
.pvdData = &uqCosMob_Var2005G,
// a handler that will be called after value reception and modification
.pfnHandler = CosMob_PdoTrmHandler
},
#endif
void CosMob_PdoTrmHandler(uint32_t ulMapEntryV)
Demo implementation of callback handler for a mapping entry.
uint32_t ulCosMob_Var2004G

Starting from this list you can use the function CosPdoTrmMapAdd() to map the entries to the desired position in the PDO. Upon transmission, the function CosMob_PdoTrmHandler() will be called and the content of the variables ulCosMob_Var2004G and/or uqCosMob_Var2005G will be copied into the PDO payload.

+ Collaboration diagram for CosPdoMapping_s:

Data Fields

uint32_t ulMapEntry
 
void * pvdData
 
CosPdoMapHandler_fn pfnHandler
 

Field Documentation

◆ pfnHandler

CosPdoMapping_s::pfnHandler

Function Handler of corresponding mapping entry.

◆ pvdData

CosPdoMapping_s::pvdData

Pointer to corresponding value

◆ ulMapEntry

uint32_t CosPdoMapping_s::ulMapEntry

Mapping entry, according to CiA 301

Bit 31 .. Bit 16 Bit 15 .. Bit 8 Bit 7 .. Bit 0
Index Sub-Index Length

The functions CosPdoGetMapIndex(), CosPdoGetMapSubIndex() and CosPdoGetMapLength() can be used to access the individual values.