CANopen FD Master Library
Making your systems precise, reliable and high-quality - 5.10.01
com_demo_pdo.c

//============================================================================//
// File: com_demo_pdo.c //
// Description: Examples for PDO service in CANopen Master stack //
// //
// Copyright (C) MicroControl GmbH & Co. KG //
// 53844 Troisdorf - Germany //
// www.microcontrol.net //
// //
//----------------------------------------------------------------------------//
// The copyright to the computer program(s) herein is the property of //
// MicroControl GmbH & Co. KG, Germany. The program(s) may be used //
// and/or copied only with the written permission of MicroControl GmbH & //
// Co. KG or in accordance with the terms and conditions stipulated in //
// the agreement/contract under which the program(s) have been supplied. //
// //
//============================================================================//
#include "com_pdo.h" // CANopen Master PDO service
#include "com_mgr.h" // CANopen Master management
//----------------------------------------------------------------------------//
// DemoComPdoTrmInit() //
// initialise Transmit PDOs //
//----------------------------------------------------------------------------//
#if COM_PDO_TRM_MAX == 0
ComStatus_tv ComDemoPdoTrmInit(uint8_t CPP_PARM_UNUSED(ubNetV))
{
}
#else
ComStatus_tv ComDemoPdoTrmInit(uint8_t ubNetV)
{
uint8_t aubPdoDataT[] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
uint16_t uwIdOffsetT;
//----------------------------------------------------------------
// calculate ID offset
//
uwIdOffsetT = ComMgrNodeId(ubNetV);
//----------------------------------------------------------------
// initialise TPDOs
//
ComPdoConfig(ubNetV, 0,
ePDO_DIR_TRM, // direction
0x0180 + uwIdOffsetT, // identifier
3, // DLC
ePDO_TYPE_SYNC_1, // transmissions type
0); // event timer
ComPdoSetData(ubNetV, 0, ePDO_DIR_TRM, &aubPdoDataT[0]);
ComPdoEnable(ubNetV, 0, ePDO_DIR_TRM, 1);
ComPdoConfig(ubNetV, 1,
ePDO_DIR_TRM, // direction
0x0280 + uwIdOffsetT, // identifier
8, // DLC
ePDO_TYPE_EVENT_PROFILE, // transmissions type
250); // event timer
aubPdoDataT[0] = 0x02;
ComPdoSetData(ubNetV,1, ePDO_DIR_TRM, &aubPdoDataT[0]);
ComPdoEnable(ubNetV, 1, ePDO_DIR_TRM, 1);
ComPdoConfig(ubNetV, 3,
ePDO_DIR_TRM, // direction
0x0380 + uwIdOffsetT, // identifier
4, // DLC
ePDO_TYPE_EVENT_PROFILE, // transmissions type
500); // event timer
aubPdoDataT[0] = 0x03;
ComPdoSetData(ubNetV, 3, ePDO_DIR_TRM, &aubPdoDataT[0]);
ComPdoEnable(ubNetV, 3, ePDO_DIR_TRM, 1);
ComPdoSendAsync(ubNetV, 0);
ComPdoSendAsync(ubNetV, 1);
ComPdoSendAsync(ubNetV, 3);
return(eCOM_ERR_OK);
}
#endif
//----------------------------------------------------------------------------//
// DemoComPdoRcvInit() //
// initialise Receive PDOs //
//----------------------------------------------------------------------------//
#if COM_PDO_RCV_MAX == 0
ComStatus_tv DemoComPdoRcvInit(uint8_t CPP_PARM_UNUSED(ubNetV))
{
}
#else
ComStatus_tv DemoComPdoRcvInit(uint8_t ubNetV)
{
uint16_t uwIdOffsetT;
//----------------------------------------------------------------
// calculate ID offset
//
uwIdOffsetT = ComMgrNodeId(ubNetV);
//----------------------------------------------------------------
// initialise RPDOs
//
ComPdoConfig(ubNetV, 0,
ePDO_DIR_RCV, // direction
0x0200 + uwIdOffsetT, // identifier
8, // DLC
ePDO_TYPE_EVENT_PROFILE, // transmissions type
0); // event timer
ComPdoEnable(ubNetV, 0, ePDO_DIR_RCV, 1);
ComPdoConfig(ubNetV, 1,
ePDO_DIR_RCV, // direction
0x0300 + uwIdOffsetT, // identifier
8, // DLC
ePDO_TYPE_EVENT_PROFILE, // transmissions type
0); // event timer
ComPdoEnable(ubNetV, 1, ePDO_DIR_RCV, 1);
ComPdoConfig(ubNetV, 2,
ePDO_DIR_RCV, // direction
0x0400 + uwIdOffsetT, // identifier
8, // DLC
ePDO_TYPE_EVENT_PROFILE, // transmissions type
0); // event timer
ComPdoEnable(ubNetV, 2, ePDO_DIR_RCV, 1);
return(eCOM_ERR_OK);
} // DemoComPdoRcvInit
#endif