CANopen Slave Documentation
Version 6.16.04
Loading...
Searching...
No Matches
Complete Startup Process
//====================================================================================================================//
// File: cos_main.c //
// Description: Example for integration of CANopen Slave Protocol 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 files **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
//------------------------------------------------------------------------------------------------------
// CANopen Slave Protocol Stack header files
//
#include "cos_led.h"
#include "cos_mgr.h"
#include "cos_nmt.h"
#include "cos_time.h"
#include "cos301.h"
//------------------------------------------------------------------------------------------------------
// HAL header files
//
#include "mc_cpu.h"
#include "mc_tmr.h"
#include "mc_tmr.h"
#include "mc_wdt.h"
//------------------------------------------------------------------------------------------------------
// CANopen Slave demo application
//
#include "cos_demo_app.h"
/*--------------------------------------------------------------------------------------------------------------------*\
** Definitions **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
//------------------------------------------------------------------------------------------------------
// Specific configuration of CANopen Slave Protocol Stack
//
#ifndef TMPL_COS_CONFIG
#define TMPL_COS_CONFIG COS_CONF_SLAVE
#endif
//------------------------------------------------------------------------------------------------------
// Run CANopen Slave Protocol Stack for internal testing if > 0
//
#ifndef TMPL_COS_TEST_MAIN
#define TMPL_COS_TEST_MAIN 0
#endif
//------------------------------------------------------------------------------------------------------
// Select physical CAN interface for CANopen Slave Protocol Stack
//
#ifndef TMPL_COS_USE_CAN_IF
#define TMPL_COS_USE_CAN_IF eCP_CHANNEL_1
#endif
//--------------------------------------------------------------------------------------------------------------------//
// main() //
// //
//--------------------------------------------------------------------------------------------------------------------//
int main(void)
{
int32_t slBitrateSelT; // selected CANopen bit-rate
uint8_t ubNodeIdT; // selected CANopen Node-ID
uint32_t ulLastTimerTickT = 0; // value from timer tick
//---------------------------------------------------------------------------------------------------
// Initialise the target CPU
//
//---------------------------------------------------------------------------------------------------
// Initialise the timer resource on the target CPU
//
//---------------------------------------------------------------------------------------------------
// read the actual bit-rate setting and test if it is valid
//
slBitrateSelT = CosMgrGetBitrate();
if (slBitrateSelT > eCP_BITRATE_MAX)
{
//-------------------------------------------------------------------------------------------
// bit-rate value is out of limit:
// - show failure status
// - stop program here in endless loop
//
#if COS_LED_SUPPORT > 0
#endif
#if COS_LED_SUPPORT > 1
#endif
while (1) { };
}
//---------------------------------------------------------------------------------------------------
// read the actual node ID setting and test if it is valid
//
ubNodeIdT = CosMgrGetNodeId();
if (ubNodeIdT > 127)
{
//-------------------------------------------------------------------------------------------
// address value is out of limit:
// - show failure status
// - stop program here in endless loop
//
#if COS_LED_SUPPORT > 0
#endif
#if COS_LED_SUPPORT > 1
#endif
while (1) { };
}
//---------------------------------------------------------------------------------------------------
// Initialise the CANopen slave stack
//
CosMgrInit(TMPL_COS_USE_CAN_IF, TMPL_COS_CONFIG);
//---------------------------------------------------------------------------------------------------
// Initialise the CANopen Slave demo application, this is individual for every target
//
//---------------------------------------------------------------------------------------------------
// start the CANopen Slave Protocol Stack
//
CosMgrStart(ubNodeIdT, slBitrateSelT, eCP_BITRATE_NONE);
//---------------------------------------------------------------------------------------------------
// Initialise the watchdog timer on the target CPU
//
//---------------------------------------------------------------------------------------------------
// This is the main loop of the embedded application
//
while (1)
{
//-------------------------------------------------------------------------------------------
// handle timer tick for the stack
//
if ((McTmrTick() - ulLastTimerTickT) > 0)
{
ulLastTimerTickT = McTmrTick();
}
//-------------------------------------------------------------------------------------------
// 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
//
}
//-------------------------------------------------------------------------------------------
// The following code is for automatic testing only
//
#if TMPL_COS_TEST_MAIN > 0
static uint32_t ulTestMainCounterS = TMPL_COS_TEST_MAIN;
if (ulTestMainCounterS == 0) break;
ulTestMainCounterS--;
#endif
} // end while (1)
return (0);
}
@ eCP_BITRATE_NONE
Definition canpie.h:642
CANopen Slave Stack - CiA 301 objects .
@ eCOS_ERR_NODE_RESET
Definition cos_defs.h:516
CANopen Slave Stack - Manufacturer specific objects .
void CosDemoAppInit(void)
CANopen Slave Stack - LED management .
void CosLedNetworkError(uint8_t ubErrorV)
Network Error LED.
@ eCosLedMod_FAIL_BAUD
Definition cos_led.h:107
@ eCosLedMod_FAIL_ADDR
Definition cos_led.h:110
void CosLedModuleStatus(uint8_t ubStatusV)
Module Status LED.
@ eCosLedErr_BUS_OFF
Definition cos_led.h:168
CANopen Slave Stack - Management functions .
uint8_t CosMgrRelease(void)
Release the CANopen Slave protocol stack.
uint8_t CosMgrInit(uint8_t ubCanIfV, uint16_t uwConfigV)
Initialise the CANopen Slave.
uint8_t CosMgrGetNodeId(void)
uint8_t CosMgrGetBitrate(void)
Get module bit-rate.
uint8_t CosMgrProcess(void)
Process CANopen message queue.
uint8_t CosMgrStart(uint8_t ubNodeIdV, int32_t slBitrateNomSelV, int32_t slBitrateDatSelV)
CANopen Slave Stack - Network management functions (NMT) .
CANopen Slave Stack - Timing functions .
void CosTmrEvent(void)
Execute Timer-based Services.
MCL - CPU control .
void McCpuReset(void)
void McCpuInit(void)
MCL - timer control .
uint32_t McTmrTick(void)
Get timer tick.
void McTmrInit(void)
Initialise Timer.
MCL - Watchdog support functions .
void McWdtTrigger(void)
Status_tv McWdtInit(void)
Initialize watchdog.