CANopen Bootloader Documentation
Version 4.10.00
Loading...
Searching...
No Matches
Bootloader callback functions
//====================================================================================================================//
// File: cbl_user.c //
// Description: Application specific functions of CANopen FD bootloader //
// //
// 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 **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
#include "cbl_mgr.h" // CANopen bootloader management functions
#include "cbl_nmt.h" // CANopen bootloader NMT service
#include "cbl_objs.h" // CANopen bootloader objects
#include "cbl_sdo.h" // CANopen bootloader SDO service
#include "mc_iap.h"
#include "mc_flash.h"
/*--------------------------------------------------------------------------------------------------------------------*\
** Definitions **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
#ifndef CBL_PRODUCT_CODE
#define CBL_PRODUCT_CODE 0
#endif
//-------------------------------------------------------------------------------------------------
enum CblProgControlApp_e {
eCBL_PROG_CONTROL_APP_VALID = eCBL_PROG_CONTROL_MANUFACTURER,
eCBL_PROG_CONTROL_APP_NOT_VALID
};
/*--------------------------------------------------------------------------------------------------------------------*\
** Variables **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
uint32_t ulIdx1000_DeviceTypeG = 0x00000000;
#if CBL_DICT_OBJ_1008 == 1
uint8_t aubIdx1008_DeviceNameG[] = "Boot";
#endif
//------------------------------------------------------------------------------------------------------
// this variable holds the version number of the target hardware as visible string
//
#if CBL_DICT_OBJ_1009 == 1
uint8_t aubIdx1009_HwVersionG[] = "1.00";
#endif
//------------------------------------------------------------------------------------------------------
// this variable holds the version number of the application firmware as visible string
//
#if CBL_DICT_OBJ_100A == 1
uint8_t aubIdx100A_SwVersionG[] = "1.00";
#endif
//------------------------------------------------------------------------------------------------------
// Identity object
//
uint8_t ubIdx1018_SubNumberG = 0x04;
uint32_t ulIdx1018_VendorIdG = ((uint32_t) 0x0000000E);
uint32_t ulIdx1018_ProductCodeG = ((uint32_t) CBL_PRODUCT_CODE);
uint32_t ulIdx1018_RevisionNumG = ((uint32_t) CBL_VERSION_MAJOR << 24) | ((uint32_t) CBL_VERSION_MINOR << 16) | 0x0100;
/*--------------------------------------------------------------------------------------------------------------------*\
** Functions **
** **
\*--------------------------------------------------------------------------------------------------------------------*/
//--------------------------------------------------------------------------------------------------------------------//
// CblLedModGreen() //
// //
//--------------------------------------------------------------------------------------------------------------------//
void CblLedModGreen(bool_t btSwitchOnV)
{
if(btSwitchOnV)
{
}
else
{
}
}
//--------------------------------------------------------------------------------------------------------------------//
// CblLedModRed() //
// //
//--------------------------------------------------------------------------------------------------------------------//
void CblLedModRed(bool_t btSwitchOnV)
{
if(btSwitchOnV)
{
}
else
{
}
}
//--------------------------------------------------------------------------------------------------------------------//
// CblLedNetGreen() //
// //
//--------------------------------------------------------------------------------------------------------------------//
void CblLedNetGreen(bool_t btSwitchOnV)
{
if(btSwitchOnV)
{
}
else
{
}
}
//--------------------------------------------------------------------------------------------------------------------//
// CblLedNetRed() //
// //
//--------------------------------------------------------------------------------------------------------------------//
void CblLedNetRed(bool_t btSwitchOnV)
{
if(btSwitchOnV)
{
}
else
{
}
}
//--------------------------------------------------------------------------------------------------------------------//
// CblMgrBufferStore() //
// store data in flash memory //
//--------------------------------------------------------------------------------------------------------------------//
void CblMgrBufferStore(uint8_t ubProgNumV, uint8_t * pubBufferV, uint16_t uwSizeV)
{
static uint32_t ulAddrStartS = (CBL_APP_START_ADDR);
static uint32_t ulBlockNumS = 0;
//---------------------------------------------------------------------------------------------------
// This function is called by the CANopen bootloader when new data shall be stored inside the Flash
// memory. The global variable 'ubCblMgrBufferStoreG' is > 0 when data needs to be stored. This
// function has to set the value back to 0 when data store is done.
//
if (ubCblMgrBufferStoreG > 0)
{
//-------------------------------------------------------------------------------------------
// Test if flash is empty: we initialize the start address then and set the block counter
// to 0.
//
{
ulAddrStartS = (CBL_APP_START_ADDR);
ulBlockNumS = 0;
}
//-------------------------------------------------------------------------------------------
// At this point the flash status shall be eCBL_FLASH_STATUS_PROGRESS, otherwise something
// went really wrong.
//
{
//-----------------------------------------------------------------------------------
// unlock flash
//
ulBlockNumS++;
//-----------------------------------------------------------------------------------
// Write data from SRAM buffer to flash, the size must be an even value
//
if (uwSizeV % 2)
{
uwSizeV++;
}
if (McFlashWrite(ulAddrStartS, pubBufferV, uwSizeV) != eFLASH_ERR_OK)
{
}
//-----------------------------------------------------------------------------------
// Increase the start address for the next call of this function
//
ulAddrStartS = ulAddrStartS + uwSizeV;
//-----------------------------------------------------------------------------------
// lock flash
//
}
//-------------------------------------------------------------------------------------------
// store operation finished
//
ubCblMgrBufferStoreG = 0;
}
}
//--------------------------------------------------------------------------------------------------------------------//
// CblMgrEventBusOff() //
// Handler for Bus-Off condition //
//--------------------------------------------------------------------------------------------------------------------//
{
//---------------------------------------------------------------------------------------------------
// Todo: handle CAN bus-off condition
//
}
//--------------------------------------------------------------------------------------------------------------------//
// CblMgrEventProgControl() //
// Function handler for manufacturer specific program control //
//--------------------------------------------------------------------------------------------------------------------//
void CblMgrEventProgControl(uint8_t ubProgNumV, uint8_t ubProgControlV)
{
//---------------------------------------------------------------------------------------------------
// Todo: handle manufacturer specific action
//
switch(ubProgControlV)
{
case eCBL_PROG_CONTROL_APP_VALID:
break;
case eCBL_PROG_CONTROL_APP_NOT_VALID:
break;
default:
break;
}
//---------------------------------------------------------------------------------------------------
// set the program control register to a defined value, e.g. eCBL_PROG_CONTROL_STOP
//
}
//--------------------------------------------------------------------------------------------------------------------//
// CblMgrFlashDelete() //
// delete flash memory //
//--------------------------------------------------------------------------------------------------------------------//
void CblMgrFlashDelete(uint8_t ubProgNumV)
{
//---------------------------------------------------------------------------------------------------
// Unlock flash memory
//
//---------------------------------------------------------------------------------------------------
// Set status in object 1F57h: flash operation in progress
//
//---------------------------------------------------------------------------------------------------
// Erase flash and set status in object 1F57h
//
{
}
else
{
}
//---------------------------------------------------------------------------------------------------
// lock flash
//
//---------------------------------------------------------------------------------------------------
// clear software identification
//
aulIdx1F56_SoftIdentG[ubProgNumV] = 0x00000000;
}
//--------------------------------------------------------------------------------------------------------------------//
// CblMgrFlashFinalize() //
// final flash operation after download //
//--------------------------------------------------------------------------------------------------------------------//
void CblMgrFlashFinalize(uint8_t ubProgNumV, uint32_t ulSizeV)
{
uint8_t * pubMemStartT; // memory start address
//---------------------------------------------------------------------------------------------------
// The function is called after the download is completed. We store the infomration about the
// program size and the program CRC inside the IAP block.
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
// If the flash status is not equal to eCBL_FLASH_STATUS_PROGRESS something went wrong
//
{
aulIdx1F56_SoftIdentG[ubProgNumV] = 0;
}
else
{
//-------------------------------------------------------------------------------------------
// build checksum over stored data
//
pubMemStartT = (uint8_t *)(CBL_APP_START_ADDR);
aulIdx1F56_SoftIdentG[ubProgNumV] = CblMgrBufferCrc(pubMemStartT, ulSizeV);
}
}
//--------------------------------------------------------------------------------------------------------------------//
// CblMgrGetBitrate() //
// get module bit-rate setting //
//--------------------------------------------------------------------------------------------------------------------//
uint8_t CblMgrGetBitrate(void)
{
uint8_t ubBitrateT = eCP_BITRATE_500K;
//---------------------------------------------------------------------------------------------------
// read DIP switch settings here or value from NVM
//
return (ubBitrateT);
}
//--------------------------------------------------------------------------------------------------------------------//
// CblMgrGetNodeId() //
// get module address setting //
//--------------------------------------------------------------------------------------------------------------------//
uint8_t CblMgrGetNodeId(void)
{
uint8_t ubNodeIdT = 126;
//---------------------------------------------------------------------------------------------------
// read DIP switch settings here or value from NVM
//
return (ubNodeIdT);
}
//--------------------------------------------------------------------------------------------------------------------//
// CblMgrGetSerialNumber() //
// get Serial Number of module //
//--------------------------------------------------------------------------------------------------------------------//
uint32_t CblMgrGetSerialNumber(void)
{
uint32_t ulSerNumT;
//---------------------------------------------------------------------------------------------------
// read serial number from NVM
//
ulSerNumT = 1;
return(ulSerNumT);
}
//--------------------------------------------------------------------------------------------------------------------//
// CblNmtServiceOnPreOperational() //
// Function handler for NMT Pre-Operational //
//--------------------------------------------------------------------------------------------------------------------//
{
}
//--------------------------------------------------------------------------------------------------------------------//
// CblNmtServiceOnStart() //
// Function handler for NMT Start //
//--------------------------------------------------------------------------------------------------------------------//
void CblNmtEventStart(void)
{
}
//--------------------------------------------------------------------------------------------------------------------//
// CblNmtServiceOnStop() //
// Function handler for NMT Stop //
//--------------------------------------------------------------------------------------------------------------------//
void CblNmtEventStop(void)
{
}
//--------------------------------------------------------------------------------------------------------------------//
// CblSdoSegFinal() //
// //
//--------------------------------------------------------------------------------------------------------------------//
uint8_t CblSdoSegFinal(uint8_t CPP_PARM_UNUSED(ubReqCodeV), uint16_t CPP_PARM_UNUSED(uwIndexV),
uint8_t CPP_PARM_UNUSED(ubSubIndexV))
{
return (eCblSdo_WRITE_OK);
}
//--------------------------------------------------------------------------------------------------------------------//
// CblSdoBlkUpObjectSize //
// //
//--------------------------------------------------------------------------------------------------------------------//
#if CBL_SDO_BLOCK_RD > 0
uint32_t CblSdoBlkUpObjectSize(uint16_t uwIndexV, uint8_t ubSubIndexV)
{
uint32_t ulObjSizeT = 0;
//----------------------------------------------------------------
// example for reading the object size
//
if((uwIndexV == 0x1F50) && (ubSubIndexV == 0))
{
ulObjSizeT = 32768; // set correct value here
}
return (ulObjSizeT);
}
#endif
@ eCP_BITRATE_500K
Definition canpie.h:677
#define CBL_APP_START_ADDR
Definition cbl_conf.h:291
#define CBL_VERSION_MAJOR
Definition cbl_defs.h:72
#define CBL_VERSION_MINOR
Definition cbl_defs.h:82
void CblLedNetGreen(bool_t btSwitchOnV)
void CblLedNetRed(bool_t btSwitchOnV)
void CblLedModGreen(bool_t btSwitchOnV)
void CblLedModRed(bool_t btSwitchOnV)
CANopen Bootloader Management Functions .
uint32_t CblMgrBufferCrc(uint8_t *pubMemStartV, uint32_t ulSizeV)
void CblMgrBufferStore(uint8_t ubProgNumV, uint8_t *pubBufferV, uint16_t uwSizeV)
void CblMgrFlashFinalize(uint8_t ubProgNumV, uint32_t ulSizeV)
uint32_t CblMgrGetSerialNumber(void)
@ eCBL_PROG_CONTROL_MANUFACTURER
Definition cbl_mgr.h:139
@ eCBL_PROG_CONTROL_STOP
Definition cbl_mgr.h:127
@ eCBL_FLASH_FAIL_NO_PROGRAM
Definition cbl_mgr.h:94
@ eCBL_FLASH_FAIL_WRITE_ERROR
Definition cbl_mgr.h:106
void CblMgrEventProgControl(uint8_t ubProgNumV, uint8_t ubProgControlV)
uint8_t CblMgrGetBitrate(void)
void CblMgrFlashDelete(uint8_t ubProgNumV)
void CblMgrEventBusOff(void)
@ eCBL_FLASH_STATUS_OK
Definition cbl_mgr.h:75
@ eCBL_FLASH_STATUS_PROGRESS
Definition cbl_mgr.h:78
uint8_t CblMgrGetNodeId(void)
CANopen Bootloader Network Management functions .
void CblNmtEventStart(void)
void CblNmtEventStop(void)
void CblNmtEventPreOperational(void)
CANopen Bootloader objects .
uint32_t ulIdx1018_RevisionNumG
Identity object - revision number - index 1018:03h
uint8_t aubIdx1F51_ControlG[]
Program control - index 1F51:0xh
uint32_t aulIdx1F57_FlashStatusG[]
Flash status identification - index 1F57:0xh
uint32_t ulIdx1018_VendorIdG
Identity object - vendor ID - index 1018:01h
uint8_t aubIdx1008_DeviceNameG[]
Manufacturer device name - index 1008h
uint8_t aubIdx100A_SwVersionG[]
Manufacturer software version - index 100Ah
uint32_t ulIdx1018_ProductCodeG
Identity object - product code - index 1018:02h
uint32_t aulIdx1F56_SoftIdentG[]
Program software identification - index 1F56:0xh
uint8_t aubIdx1009_HwVersionG[]
Manufacturer hardware version - index 1009h
uint32_t ulIdx1000_DeviceTypeG
Device type - index 1008h
CANopen Bootloader SDO functions .
#define CPP_PARM_UNUSED(x)
Definition mc_compiler.h:260
MCL - erase and write flash memory .
Status_tv McFlashLock(void)
Lock the Flash memory controller.
@ eFLASH_ERR_OK
Definition mc_flash.h:77
Status_tv McFlashWrite(uint32_t ulAddressV, void *pvdDataV, uint32_t ulSizeV)
Write data.
Status_tv McFlashUnlock(void)
Unlock the Flash memory controller.
Status_tv McFlashErase(uint32_t ulFlashAddrV, uint32_t ulSizeV)
Erase page of selected address.
MCL - In-Application Programming framework .
uint32_t McIapAppSizeLimit(void)