CANopen Slave Protocol Stack 
Version 7.08.00
Loading...
Searching...
No Matches
Initialization Process

The CANopen Slave is initialised with CosMgrInit(). This routine will setup the CAN controller and initialize all necessary services. Afterwards the stack can be started by calling the CosMgrStart() function.

In summary three functions are necessary to run the CANopen Slave:

The initialization functions of the CANopen Slave Protocol Stack have to be executed prior to any other API functions.

Starting in Classical CANopen mode

void MyCosInit(void)
{
//---------------------------------------------------------------------------------------------------
// Initialise the CANopen slave stack
//
//---------------------------------------------------------------------------------------------------
// Start the CANopen Slave, node-ID = 1, nominal bitrate = 500 kBit/s,
//
}
@ eCP_BITRATE_500K
Definition canpie.h:660
@ eCP_BITRATE_NONE
Definition canpie.h:625
@ eCP_CHANNEL_1
Definition canpie.h:714
uint8_t CosMgrInit(uint8_t ubCanIfV, uint16_t uwConfigV)
uint8_t CosMgrStart(uint8_t ubNodeIdV, int32_t slBitrateNomSelV, int32_t slBitrateDatSelV)
#define COS_CONF_SLAVE
Definition cos_mgr.h:90

Starting in CANopen FD mode

void MyCosInit(void)
{
//---------------------------------------------------------------------------------------------------
// Initialise the CANopen slave stack
//
//---------------------------------------------------------------------------------------------------
// Start the CANopen FD Slave, node-ID = 1, nominal bitrate = 500 kBit/s, data bitrate = 2 MBit/s
//
}
@ eCP_BITRATE_2M
Definition canpie.h:675
#define COS_CONF_FD
Definition cos_mgr.h:125

Main loop wiring

After the stack has been started, two functions must be called continuously from the application's main loop:

  • CosTmrEvent() — advances all internal stack timers (heartbeat producer, PDO event timers, SYNC producer, …). It must be called at the period defined by #COS_TIMER_PERIOD in cos_conf.h (default: 1 ms). For interrupt-driven timer wiring see CosTmrEvent().
  • CosMgrProcess() — dispatches incoming CAN messages, runs background processing, and returns eCOS_ERR_NODE_RESET when the stack needs to be restarted (e.g. after an NMT Reset Node command).

The following example (taken from the template application) shows both calls in a polling loop:

Timer tick handling:

//-------------------------------------------------------------------------------------------
// handle timer tick for the stack
//
if ((McTmrTick() - ulLastTimerTickT) > 0)
{
ulLastTimerTickT = McTmrTick();
}

Main process loop:

//-------------------------------------------------------------------------------------------
// Check the result of the CANopen manager call
//
{
//-----------------------------------------------------------------------------------
// Trigger the watch-dog timer each time we run successful through the
// CANopen manager
//
}
else
{
//-----------------------------------------------------------------------------------
// Release all CAN resources and wait for the watchdog timer to restart
// the application
//
}

When CosMgrProcess() returns eCOS_ERR_NODE_RESET, release all CAN resources with CosMgrRelease() and reset the CPU to apply the new parameters.