📄 nv_flash.c
字号:
/*****************************************************************************
* This file contains code for the NVM module.
*
*
* (c) Copyright 2006, Freescale, Inc. All rights reserved.
*
* Freescale Semiconductor Confidential Proprietary
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale Semiconductor Danmark A/S.
*****************************************************************************/
#include "NV_Data.h"
#if (gNV_FlashIncluded_d)
#include "Beestack_Globals.h"
#include "NV_Flash.h"
#include "NV_FlashHAL.h"
#include "FunctionLib.h"
#include "IrqControlLib.h"
#include "AppAspInterface.h"
#include "BeeStackUtil.h"
#include "ZdoNwkInterface.h"
#ifndef gRouterCapability_d
#define gRouterCapability_d 0
#endif
#ifndef gCoordinatorCapability_d
#define gCoordinatorCapability_d 0
#endif
#ifndef gEndDevCapability_d
#define gEndDevCapability_d 0
#endif
extern uint8_t NWK_INFOBASE_SetPIBAttributeValue
(
uint8_t pibAttribute,
uint8_t* pibAttributeValue
);
/*****************************************************************************
******************************************************************************
* Private macros
******************************************************************************
*****************************************************************************/
#define gCapInfoRcvrOnIdle_c 0x08
#define mNumRetries_c 500
/*****************************************************************************
******************************************************************************
* Private prototypes
******************************************************************************
*****************************************************************************/
void SetupNVPointers (void);
void NVM_FindNVRAM (void);
bool_t FlashProgByte (uint8_t , uint8_t* );
bool_t FlashEraseSector (uint8_t);
bool_t NVmemcpy (uint8_t*,uint8_t*, uint16_t);
/*****************************************************************************
******************************************************************************
* Private type definitions
******************************************************************************
*****************************************************************************/
/* None */
/*****************************************************************************
******************************************************************************
* Private memory declarations
******************************************************************************
*****************************************************************************/
#pragma CONST_SEG BOOTLOADER_VER_NUMBER
const volatile uint8_t HCS08FlashLibVersionString[] \
= HCS08FlashLibVersionText;
#pragma CONST_SEG DEFAULT
#pragma DATA_SEG NV_FLASH_RAM
pfNVFlashCommomExecuteCMD_tag pfNVFlashCommomExecuteCMD_t; /* Pointer to
NV function copied to RAM */
#pragma DATA_SEG DEFAULT
volatile uint8_t gNVMCriticalSectionActiveFlag;
/*****************************************************************************
******************************************************************************
* Public functions
******************************************************************************
*****************************************************************************/
/************************************************************************************
* Set the NVM write operation semaphore.
*
* This function will set the NVM write operation semaphore so that the idle task wont
* do a NVM write operation unless this is released by calling
* NVM_ClearCriticalNVMSection.
*
* Interface assumptions:
* None
*
* Return value:
* None
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 230606 SP Created
*
************************************************************************************/
void NVM_SetCriticalNVMSection(void)
{
uint8_t ccr;
IrqControlLib_BackupIrqStatus(ccr);/*To protect from re entrant*/
IrqControlLib_DisableAllIrqs();
gNVMCriticalSectionActiveFlag++;
IrqControlLib_RestoreIrqStatus(ccr);
}
/************************************************************************************
* Release the NVM write operation semaphore.
*
* This function will release the NVM write operation semaphore so that the idle task
* can do a NVM write operation.
*
* Interface assumptions:
* None
*
* Return value:
* None
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 230606 SP Created
*
************************************************************************************/
void NVM_ClearCriticalNVMSection(void)
{
uint8_t ccr;
IrqControlLib_BackupIrqStatus(ccr);/*To protect from re entrant*/
IrqControlLib_DisableAllIrqs();
gNVMCriticalSectionActiveFlag--;
IrqControlLib_RestoreIrqStatus(ccr);
}
/*****************************************************************************
* Updates the specified NV RAM section. The new data will be written to other
* NV RAM section. All other data must be copied too.
*
* Interface assumptions:
*
* Return value:
* TRUE - NV RAM updated succcessfully, FALSE - Something went wrong (error)
*
* Revison history:
*
* date Author Comments
* ------ ------ --------
* 290301 FSL,LS Created
*****************************************************************************/
bool_t NVM_WriteNVRAM(
uint8_t *pNVRAMDestination, /*IN:points where data to be written in active
NV RAM section. */
uint8_t *pSource, /*IN:points where data must be read from RAM */
uint16_t cSourceLength /* IN:Length of the data to be updated */
)
{
bool_t copyStatus;
uint8_t ccr;
volatile uint8_t *pNVRAMCopyFrom;
volatile uint8_t *pNVRAMCopyTo;
volatile uint8_t *pNVRAMLastCopyTo;
void *pTemp;
/* Initial state */
copyStatus = TRUE;
/* Whole NVM write has to be protected from interrupt as the NVM pointer is
getting changed because of NVM write. */
IrqControlLib_BackupIrqStatus( ccr );
IrqControlLib_DisableAllIrqs();
/* always copy to is scratch pad location */
pNVRAMCopyTo = ( uint8_t* )gpScratchPadNvram;
pNVRAMLastCopyTo = ( uint8_t* )(( uint16_t )gpScratchPadNvram +
NvramScratchpadSize_c );
/* Setup the Copy from and copy to pointers. Here it is assumed each sector
is 512 bytes. */
if((( uint8_t* )gpMacNvram <= pNVRAMDestination ) && ( pNVRAMDestination <
( uint8_t* )gpMacNvram + NvramSize_c )) {
/* setup MAC pointer */
pNVRAMCopyFrom = ( uint8_t* )gpMacNvram;
pTemp = ( void* )gpMacNvram;
gpMacNvram = ( NvramStruct_t* )gpScratchPadNvram;
gpScratchPadNvram = ( void* )pTemp;
}
if((( uint8_t* )gapBeeStackNvram[ 0 ] <= pNVRAMDestination ) &&
( pNVRAMDestination < ( uint8_t* )gapBeeStackNvram[ 0 ] + gNVMSectorSize_c )){
/* setup ZS1 pointer */
pNVRAMCopyFrom = ( uint8_t* )gapBeeStackNvram[ 0 ];
pTemp = ( void* )gapBeeStackNvram[ 0 ];
gapBeeStackNvram[ 0 ] = ( NvramSectorStruct_t* )gpScratchPadNvram;
gpScratchPadNvram = pTemp;
}
if((( uint8_t* )gapBeeStackNvram[ 1 ] <= pNVRAMDestination ) &&
( pNVRAMDestination < ( uint8_t* )gapBeeStackNvram[ 1 ] + gNVMSectorSize_c )){
/* setup ZS2 pointer */
pNVRAMCopyFrom = ( uint8_t* )gapBeeStackNvram[ 1 ];
pTemp = ( void* )gapBeeStackNvram[ 1 ];
gapBeeStackNvram[ 1 ] = ( NvramSectorStruct_t* )gpScratchPadNvram;
gpScratchPadNvram = ( void* )pTemp;
}
/* Copy current NV data and new updated data to copy section. */
while( pNVRAMCopyTo < pNVRAMLastCopyTo ) {
/* Check for data to update */
if(( pNVRAMCopyFrom < (( uint8_t* )pNVRAMDestination )) || ( pNVRAMCopyFrom >=
(( uint8_t* )((( uint16_t )pNVRAMDestination ) + cSourceLength )))) {
/* Copy "old" stored NV RAM */
if( FlashProgByte( *pNVRAMCopyFrom, ( uint8_t* )pNVRAMCopyTo ) == FALSE ){
/* At least one error has occured - but continue */
copyStatus = FALSE;
}
}
else {
/* Copy new data to NV RAM */
if( FlashProgByte( *pSource++, ( uint8_t* )pNVRAMCopyTo ) == FALSE ){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -