⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nv_flashhal.c

📁 freescale的基于802.15.4的无线通讯例程
💻 C
字号:
/*****************************************************************************
* This file contains hardware related functions for the NVM module.
* 
*
* (c) Copyright 2005, 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"


/*****************************************************************************
******************************************************************************
* Private macros
******************************************************************************
*****************************************************************************/
/* None */

/*****************************************************************************
******************************************************************************
* Private prototypes
******************************************************************************
*****************************************************************************/
#pragma CODE_SEG NV_FLASH_FUNCTION_RAM
bool_t pfNVFlashCommomExecuteCmdInFlash(uint8_t , uint8_t*  , uint8_t );
#pragma CODE_SEG DEFAULT

#pragma MESSAGE DISABLE C1805 /* Non standard conversion used */


#pragma DATA_SEG CODE_EXECUTION_FROM_RAM
uint8_t DataToExecuteFromRAM[ CriticalFlashCodeSize_c ];
#pragma DATA_SEG DEFAULT
/*****************************************************************************
******************************************************************************
* Private type definitions
******************************************************************************
*****************************************************************************/
/* None */

/*****************************************************************************
******************************************************************************
* Private memory declarations
******************************************************************************
*****************************************************************************/
/*  None  */
/*****************************************************************************
******************************************************************************
* Private Debug stuff
******************************************************************************
*****************************************************************************/
/* None */

 
/*****************************************************************************
******************************************************************************
* Public functions
******************************************************************************
*****************************************************************************/

/*****************************************************************************
* Init function,sets flash specific registers and copies the critical flash
* execution part  to RAM for execution.                                                       
* Note! Max. 255 bytes - else change counter to uint16_t   
*
* Interface assumptions:
*
* Return value:
* None
*
* Revison history:
*
* date   Author   Comments
* ------ ------   --------
* 290301 FSL,LS  Created
*****************************************************************************/
void NVM_FlashSetup(void)
{
  uint8_t *pDestination;
  uint8_t *pSource;
  uint8_t cCounter;
  uint8_t dummyVariable = 0;							  
	/* Adjust function pointer to point to copied version in RAM */
  
	pfNVFlashCommomExecuteCMD_t = 
	  ( pfNVFlashCommomExecuteCMD_tag )DataToExecuteFromRAM;
  
  pDestination = ( uint8_t* )DataToExecuteFromRAM;
 
  pSource = (uint8_t *)pfNVFlashCommomExecuteCmdInFlash;
  cCounter = CriticalFlashCodeSize_c;
  
	for( ; cCounter > 0;cCounter--) {
	  *pDestination++ = *pSource++;
	}

	/* Setup flash registers  */

	if(gpMacNvram != NULL)  {
		FCDIV = (0x40 | ((uint8_t)(gpMacNvram->Bus_Frequency_In_MHz/2) + 2));
	}
	else  {
		FCDIV = FCDIVValue_c; /* Default  */
	}
	
	FCNFG =	FCNFGValue_c;
	
	/* Erase the scratchpad NVRAM area */ 
	( void )FlashEraseSector((uint16_t)gpScratchPadNvram >> HCS08SectorSize_c);
	
  /* This is to reflect the code space in MAP file 
  if(( ( uint8_t )gZS1Nvram[0] == 0x01 ) && ( gZS2Nvram[1] == 0x00 ) 
    && ( gScratchPadNvram[1] == 0x01 ))
    dummyVariable++;
	*/
}



/*****************************************************************************
******************************************************************************
* Private functions
******************************************************************************
*****************************************************************************/

/*****************************************************************************
* A help function with handles the actaully flashing of data.                 
* Note! this critical function MUST be located in RAM.                        
* Interrupts enabled and disabled for each call.  
*
* Interface assumptions:
*
* Return value:
* TRUE - Flash valid, FALSE - Access error to flash (aborted) 
*
* Revison history:
*
* date   Author   Comments
* ------ ------   --------
* 290301 FSL,LS  Created
*****************************************************************************/
#pragma CODE_SEG NV_FLASH_FUNCTION_RAM
/* Critical Flash routines. Must be located in RAM  */

bool_t pfNVFlashCommomExecuteCmdInFlash (
  uint8_t data, /* IN:Data to be written */
  uint8_t * pDestination, /* IN:Address where data has to be written */
  uint8_t flashCommand  /* IN:Flash command to be executed */
  )
{
  /* Wait for flash to become ready for command. Note! Line below could be
     removed if we are always sure that flash is ready for next command. */
	while((FSTAT & FlashReadyForCmdMask_c) != FlashReadyForCmdMask_c); 

	/*  Clear all errors  */
	FSTAT = FlashCmdErrorMask_c;

	/* Write data to flash on specified address   */
	*pDestination = data;

	/* Load command register with flash command.  */
	FCMD = flashCommand;

	FSTAT |= FlashReadyForCmdMask_c; /* Register command  */

	/* Wait a while before checking status  */
	WaitForCmdToComplete
	
	while((FSTAT & FlashCmdCompleteMask_c) == 0); /*  Wait for command to
	                                                 complete */

	if((FSTAT & FlashCmdErrorMask_c) != 0)  {
		return(FALSE); /* an error occured  */
	}

	return(TRUE);
}

#pragma CODE_SEG DEFAULT
#endif /*(gNV_FlashIncluded_d)*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -