rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
nvm.c
Go to the documentation of this file.
1/************************************************************************************//**
2* \file Source/_template/nvm.c
3* \brief Bootloader non-volatile memory driver source file.
4* \ingroup Target__template_nvm
5* \internal
6*----------------------------------------------------------------------------------------
7* C O P Y R I G H T
8*----------------------------------------------------------------------------------------
9* Copyright (c) 2019 by Feaser http://www.feaser.com All rights reserved
10*
11*----------------------------------------------------------------------------------------
12* L I C E N S E
13*----------------------------------------------------------------------------------------
14* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
15* modify it under the terms of the GNU General Public License as published by the Free
16* Software Foundation, either version 3 of the License, or (at your option) any later
17* version.
18*
19* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
20* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21* PURPOSE. See the GNU General Public License for more details.
22*
23* You have received a copy of the GNU General Public License along with OpenBLT. It
24* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
25*
26* \endinternal
27****************************************************************************************/
28
29/************************************************************************************//**
30* \defgroup Target__template_nvm Non-volatile memory driver of a port
31* \brief This module implements the non-volatile memory driver of a microcontroller
32* port. Note that the default implementation if for a microcontroller that
33* has internal flash memory. At the time of this writing pretty much all
34* microcontrollers use flash EEPROM as non-volatile memory to store the
35* program code. Assuming that this is also the case for the microcontroller
36* for which the port is developed, nothing needs to be modified in this
37* source file.
38* \ingroup Target__template
39****************************************************************************************/
40
41/****************************************************************************************
42* Include files
43****************************************************************************************/
44#include "boot.h" /* bootloader generic header */
45#include "flash.h"
46
47/************************************************************************************//**
48** \brief Initializes the NVM driver.
49** \return none.
50**
51****************************************************************************************/
52void NvmInit(void)
53{
54 /* init the internal driver */
55 FlashInit();
56} /*** end of NvmInit ***/
57
58
59/************************************************************************************//**
60** \brief Reinitializes the NVM driver. This function is called at the start of each
61** firmware update as opposed to NvmInit, which is only called once during
62** power on.
63** \return none.
64**
65****************************************************************************************/
66void NvmReinit(void)
67{
68 /* reinitialize the internal driver */
70} /*** end of NvmReinit ***/
71
72
73/************************************************************************************//**
74** \brief Programs the non-volatile memory.
75** \param addr Start address.
76** \param len Length in bytes.
77** \param data Pointer to the data buffer.
78** \return BLT_TRUE if successful, BLT_FALSE otherwise.
79**
80****************************************************************************************/
82{
83 /* still here so the internal driver should try and perform the program operation */
84 return FlashWrite(addr, len, data);
85} /*** end of NvmWrite ***/
86
87
88/************************************************************************************//**
89** \brief Erases the non-volatile memory.
90** \param addr Start address.
91** \param len Length in bytes.
92** \return BLT_TRUE if successful, BLT_FALSE otherwise.
93**
94****************************************************************************************/
96{
97 /* still here so the internal driver should try and perform the erase operation */
98 return FlashErase(addr, len);
99} /*** end of NvmErase ***/
100
101
102/************************************************************************************//**
103** \brief Verifies the checksum, which indicates that a valid user program is
104** present and can be started.
105** \return BLT_TRUE if successful, BLT_FALSE otherwise.
106**
107****************************************************************************************/
109{
110 /* check checksum using the interally supported method. */
111 return FlashVerifyChecksum();
112} /*** end of NvmVerifyChecksum ***/
113
114
115/************************************************************************************//**
116** \brief Obtains the base address of the non-volatile memory available to the user
117** program. This is typically that start of the vector table.
118** \return Base address.
119**
120****************************************************************************************/
122{
124} /*** end of NvmGetUserProgBaseAddress ***/
125
126
127/************************************************************************************//**
128** \brief Once all erase and programming operations are completed, this
129** function is called, so at the end of the programming session and
130** right before a software reset is performed. It is used to calculate
131** a checksum and program this into flash. This checksum is later used
132** to determine if a valid user program is present in flash.
133** \return BLT_TRUE if successful, BLT_FALSE otherwise.
134**
135****************************************************************************************/
137{
138 /* compute and write checksum, which is programmed by the internal driver. */
139 if (FlashWriteChecksum() == BLT_FALSE)
140 {
141 return BLT_FALSE;
142 }
143
144 /* finish up internal driver operations */
145 return FlashDone();
146} /*** end of NvmDone ***/
147
148
149/*********************************** end of nvm.c **************************************/
constexpr uint8_t addr
Definition ads1015.cpp:14
blt_bool FlashWriteChecksum(void)
blt_addr FlashGetUserProgBaseAddress(void)
blt_bool FlashDone(void)
blt_bool FlashVerifyChecksum(void)
void FlashInit(void)
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
void FlashReinit(void)
blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_bool NvmErase(blt_addr addr, blt_int32u len)
Erases the non-volatile memory.
Definition nvm.c:95
blt_bool NvmVerifyChecksum(void)
Verifies the checksum, which indicates that a valid user program is present and can be started.
Definition nvm.c:108
blt_addr NvmGetUserProgBaseAddress(void)
Obtains the base address of the non-volatile memory available to the user program....
Definition nvm.c:121
blt_bool NvmDone(void)
Once all erase and programming operations are completed, this function is called, so at the end of th...
Definition nvm.c:136
void NvmInit(void)
Initializes the NVM driver.
Definition nvm.c:52
blt_bool NvmWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
Programs the non-volatile memory.
Definition nvm.c:81
void NvmReinit(void)
Reinitializes the NVM driver. This function is called at the start of each firmware update as opposed...
Definition nvm.c:66
unsigned char blt_int8u
Definition types.h:49
unsigned char blt_bool
Definition types.h:46
unsigned int blt_int32u
Definition types.h:53
unsigned long blt_addr
Definition types.h:48