CANopen Bootloader Documentation
Version 4.10.00
Loading...
Searching...
No Matches
Complete startup
//====================================================================================================================//
// File: cbl_main.c //
// Description: Template for CANopen FD Bootloader 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 Bootloader Protocol Stack header files
//
#include "cbl_led.h"
#include "cbl_mgr.h"
#include "cbl_nmt.h"
#include "cbl_objs.h"
#include "cbl_time.h"
//------------------------------------------------------------------------------------------------------
// HAL header files
//
#include "mc_cpu.h"
#include "mc_flash.h"
#include "mc_iap.h"
#include "mc_tmr.h"
#include "mc_wdt.h"
//------------------------------------------------------------------------------------------------------
// CANopen Bootloader demo application
//
#include "cbl_demo_app.h"
/*--------------------------------------------------------------------------------------------------------------------*\
** Definitions **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
//------------------------------------------------------------------------------------------------------
// Specific configuration of CANopen Bootloader Protocol Stack
//
#ifndef TMPL_CBL_CONFIG
#define TMPL_CBL_CONFIG 0
#endif
//------------------------------------------------------------------------------------------------------
// Run CANopen Bootloader Protocol Stack for internal testing if > 0
//
#ifndef TMPL_CBL_TEST_MAIN
#define TMPL_CBL_TEST_MAIN 0
#endif
//------------------------------------------------------------------------------------------------------
// Select physical CAN interface for CANopen Bootloader Protocol Stack
//
#ifndef TMPL_CBL_USE_CAN_IF
#define TMPL_CBL_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
//---------------------------------------------------------------------------------------------------
// Initialize the target CPU
//
//---------------------------------------------------------------------------------------------------
// Initialize the timer resource on the target CPU
//
//---------------------------------------------------------------------------------------------------
// Initialize flash driver
//
//---------------------------------------------------------------------------------------------------
// Initialize the CANopen Bootloader demo application, this is individual for every target
//
CblDemoAppInit();
//---------------------------------------------------------------------------------------------------
// Initialize the CANopen bootloader
//
CblMgrInit(TMPL_CBL_USE_CAN_IF, TMPL_CBL_CONFIG);
//---------------------------------------------------------------------------------------------------
// Try to jump to application. This has to be made after calling CblMgrInit(), because several
// global variables are initialized in the CblMgrInit() call.
//
// We check if the application is valid and the boot-lock is disabled.
//
//---------------------------------------------------------------------------------------------------
// Check if the bootloader is locked
//
if (McIapIsBootLocked() == false)
{
//-------------------------------------------------------------------------------------------
// Start application if it is marked with the "autostart" flag
//
{
//-----------------------------------------------------------------------------------
// Jump to the application: this function never returns
//
}
}
//---------------------------------------------------------------------------------------------------
// execute the CblTmrEvent() every 1 ms
//
//---------------------------------------------------------------------------------------------------
// read the actual bit-rate setting
//
slBitrateSelT = CblMgrGetBitrate();
//---------------------------------------------------------------------------------------------------
// read the actual node ID setting
//
ubNodeIdT = CblMgrGetNodeId();
//---------------------------------------------------------------------------------------------------
// start the CANopen slave stack
//
CblMgrStart(slBitrateSelT, ubNodeIdT);
//---------------------------------------------------------------------------------------------------
// this is the main loop of the embedded application
//
while (1)
{
//-------------------------------------------------------------------------------------------
// check the result of the CANopen manager call
//
{
//-----------------------------------------------------------------------------------
// Release all CAN resources and restart the application
//
}
//-------------------------------------------------------------------------------------------
// The following code is for automatic testing only
//
#if TMPL_CBL_TEST_MAIN > 0
static uint32_t ulTestMainCounterS = TMPL_CBL_TEST_MAIN;
if (ulTestMainCounterS == 0) break;
ulTestMainCounterS--;
#endif
} // end while (1)
return(0);
}
@ eCblErr_NODE_RESET
Definition cbl_defs.h:241
LED Management .
CANopen Bootloader Management Functions .
uint8_t CblMgrStart(uint8_t ubBitrateSelV, uint8_t ubNodeIdV)
uint8_t CblMgrRelease(void)
uint8_t CblMgrProcess(void)
uint8_t CblMgrInit(uint8_t ubCanIfV, uint16_t uwConfigV)
uint8_t CblMgrGetBitrate(void)
uint8_t CblMgrGetNodeId(void)
CANopen Bootloader Network Management functions .
CANopen Bootloader objects .
CANopen Bootloader timing functions .
void CblTmrEvent(void)
Execute Timer-based Services.
MCL - CPU control .
void McCpuReset(void)
void McCpuInit(void)
MCL - erase and write flash memory .
Status_tv McFlashInit(void)
Initialise flash of MCU.
MCL - In-Application Programming framework .
@ eIAP_APP_AUTOSTART
Definition mc_iap.h:109
uint8_t McIapIsAppValid(void)
bool_t McIapIsBootLocked(void)
void McIapJumpToApp(void)
MCL - timer control .
@ eTMR_CTRL_START
Definition mc_tmr.h:164
void McTmrInit(void)
Initialise Timer.
Status_tv McTmrFunctionInit(TmrHandler_fn fnHandlerV, uint32_t ulTicksV, uint8_t ubControlV)
Initialise function timer.
uint32_t McTmrTimeToTicks(uint32_t ulTimeV)
Convert time value to ticks.
MCL - Watchdog support functions .