CANopen Slave Documentation
Version 6.16.04
Loading...
Searching...
No Matches
Setting PDO mapping parameter

PDO mapping allows automatic distribution of values received by a RPDO to the corresponding entries of the object dictionary. In the same way values stored in the object dictionary can be copied into a TPDO, as shown in the next figure.

If PDO mapping is used, the possible mapping entries (i.e. data elements of the object dictionary which can be mapped into a PDO) are defined in different *.inc files. The file cos_mobj_rpdo.inc contains a list with possible mapping entries for RPDOs, the file cos_mobj_tpdo.inc contains a list with possible mapping entries for TPDOs. In addition to the mapping entries, optional callback handlers can be added as an option. For a RPDO the handler is called after PDO reception, for a TPDO the handler is called before PDO transmission.

On reception of a RPDO data will be distributed to all mapped values defined by structure CosPdoMapping_s::pvdData before the optional handler (CosPdoMapping_s::pfnHandler) is called. On transmission of a TPDO the data will be collected from all mapped values defined by CosPdoMapping_s::pvdData after the optional handler (CosPdoMapping_s::pfnHandler) has been called.

When using optional add-on modules (device profiles), the mapping tables are already part of the device profile.

Default configuration of a RPDO or TPDO mapping is done inside the CosPdoComSetup() function.

RPDO mapping example

The function CosPdoRcvMapAdd() is used to map entries to the desired position inside the RPDO. The RPDO mapping example from the figure above would require the following file contents of cos_mobj_rpdo.inc:

//----------------------------------------------------------------------------------
// cos_mobj_rpdo.inc
{
//--------------------------------------------------------------------------
// 2000:00h, 8 bit size, variable ubCosMob_ObjectA
//
.ulMapEntry = 0x20000108, // mapping entry
.pvdData = &ubCosMob_ObjectA, // pointer to variable
.pfnHandler = CosMob_PdoRcvHandler // optional handler
},
{
//--------------------------------------------------------------------------
// 2000:02h, 16 bit size, variable uwCosMob_ObjectB
//
.ulMapEntry = 0x20000210, // mapping entry
.pvdData = &uwCosMob_ObjectB, // pointer to variable
.pfnHandler = CosMob_PdoRcvHandler // optional handler
},
{
//--------------------------------------------------------------------------
// 2000:03h, 8 bit size, variable ubCosMob_ObjectC
//
.ulMapEntry = 0x20000308, // mapping entry
.pvdData = &ubCosMob_ObjectC, // pointer to variable
.pfnHandler = CosMob_PdoRcvHandler // optional handler
},
void CosMob_PdoRcvHandler(uint32_t ulMapEntryV)
Demo implementation of callback handler for a mapping entry.

In the application, the RPDO is configured in the following manner:

void CosPdoComSetup(void)
{
// .. other code
//------------------------------------------------------------------------------------
// configure mapping for RPDO1
//
CosPdoRcvMapEnable(0, 0); // delete existing mapping, if present
CosPdoRcvMapAdd( 0, 0, 0x20000308); // map object C, 2000:03h
CosPdoRcvMapAdd( 0, 1, 0x20000210); // map object B, 2000:02h
CosPdoRcvMapAdd( 0, 2, 0x20000108); // map object A, 2000:01h
CosPdoRcvMapEnable(0, 3); // enable 3 mapping entries
// .. other code
}
uint8_t CosPdoRcvMapAdd(uint8_t ubPdoNumberV, uint8_t ubMapIdxV, uint32_t ulMapEntryV)
void CosPdoComSetup(void)
Setup application specific PDO communication parameter.
uint8_t CosPdoRcvMapEnable(uint8_t ubPdoNumberV, uint8_t ubMapNumberV)

TPDO mapping example

The function CosPdoTrmMapAdd() is used to map entries to the desired position inside the TPDO. The TPDO mapping example from the figure above would require the following file contents of cos_mobj_tpdo.inc:

//----------------------------------------------------------------------------------
// cos_mobj_tpdo.inc
{
//--------------------------------------------------------------------------
// 2001:00h, 8 bit size, variable ubCosMob_ObjectD
//
.ulMapEntry = 0x20010008, // mapping entry
.pvdData = &ubCosMob_ObjectD, // pointer to variable
.pfnHandler = CosMob_PdoTrmHandler // optional handler
},
{
//--------------------------------------------------------------------------
// 2002:00h, 16 bit size, variable ubCosMob_ObjectE
//
.ulMapEntry = 0x20020010, // mapping entry
.pvdData = &uwCosMob_ObjectE, // pointer to variable
.pfnHandler = 0L // optional handler
},
{
//--------------------------------------------------------------------------
// 2003:00h, 32 bit size, variable ubCosMob_ObjectF
//
.ulMapEntry = 0x20030020, // mapping entry
.pvdData = &ubCosMob_ObjectF, // pointer to variable
.pfnHandler = 0L // optional handler
},
void CosMob_PdoTrmHandler(uint32_t ulMapEntryV)
Demo implementation of callback handler for a mapping entry.

In the application, the TPDO is configured in the following manner:

void CosPdoComSetup(void)
{
// .. other code
//------------------------------------------------------------------------------------
// configure mapping for TPDO1
//
CosPdoTrmMapEnable(0, 0); // delete existing mapping, if present
CosPdoTrmMapAdd( 0, 0, 0x20010008); // map object D, 2001:00h
CosPdoTrmMapAdd( 0, 1, 0x20030020); // map object F, 2003:00h
CosPdoTrmMapEnable(0, 2); // enable 2 mapping entries
// .. other code
}
uint8_t CosPdoTrmMapEnable(uint8_t ubPdoNumberV, uint8_t ubMapNumberV)
uint8_t CosPdoTrmMapAdd(uint8_t ubPdoNumberV, uint8_t ubMapIdxV, uint32_t ulMapEntryV)