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

📄 nv_data.c

📁 FREESCALE的基于802.15.4无线通讯原代码
💻 C
字号:
/*****************************************************************************
* This file contains the NV Data information
*
* Note!! The specified link sequence is very important for the allocation of
* NV RAM
* A changed link sequence can change the NV RAM layout and the pointer cannot
* read the correct NV RAM data.
*
*
* 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 "EmbeddedTypes.h"
#include "AppToPlatformConfig.h" /* For SYSTEM_CLOCK  */
#include "NV_Data.h"
#include "FunctionLib.h"


/*****************************************************************************
******************************************************************************
* Private macros
******************************************************************************
*****************************************************************************/
#define SYSTEM_CLOCK_16MHZ

#define mSizeReservedForNWKNVRAM_c  512
#define mSizeReservedForSSPNVRAM_c  512
#define mSizeReservedForAPSNVRAM_c  300
#define mSizeReservedForZDONVRAM_c  212



/*****************************************************************************
******************************************************************************
* Private prototypes
******************************************************************************
*****************************************************************************/
/* None */

/*****************************************************************************
******************************************************************************
* Private type definitions
******************************************************************************
*****************************************************************************/
/* None */

/*****************************************************************************
******************************************************************************
* Private memory declarations
******************************************************************************
*****************************************************************************/

#pragma PLACE_CONST_SEG(BOOTLOADER_APP_NV_DATA0)

#define SPACE " "

/* Initialized with default values  */
volatile const InitNvramStruct_t mNvramMac =
{
	"Demo Appli Ver 1.00 Build: "__DATE__ SPACE __TIME__,
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	0xFF,0xFF,
	0x0002,
	0x00,
	0x02,
	
#ifdef SYSTEM_CLOCK_8MHZ
	0x08, /* 8 MHz  */
	(ABEL_XTAL_TRIM | ABEL_XTAL_BIAS_CURRENT | ABEL_CHIP_RATE | ABEL_CLKO_FREQ),
	(ABEL_CCA_ENERGY_DETECT_THRESHOLD | ABEL_POWER_COMPENSATION_OFFSET),
/* ICG  */
	0x18,
	0x00, /* 0x00 => CPU clk=16 MHz, Buc clk = 8 MHz  */
/* ICG Filter */
	0x02,
	0x40,
/* SCI  */
	0x00,
	0x1A, /* 1A => 19200 @ 8 MHz  */
#endif SYSTEM_CLOCK_8MHZ

#ifdef SYSTEM_CLOCK_12MHZ
	0x0C, /* 12 MHz */
	(ABEL_XTAL_TRIM | ABEL_XTAL_BIAS_CURRENT | ABEL_CHIP_RATE | ABEL_CLKO_FREQ),
	(ABEL_CCA_ENERGY_DETECT_THRESHOLD | ABEL_POWER_COMPENSATION_OFFSET),
/* ICG clock  */
	0x18,
	0x41, /* 0x41 => CPU clk=24 MHz, Buc clk = 12 MHz  */
/* ICG Filter */
	0x02,
	0x40,
/* SCI  */
	0x00,
	0x27, /* 0x27 => 19200 @ 12 MHz */
#endif SYSTEM_CLOCK_12MHZ

#ifdef SYSTEM_CLOCK_16MHZ
	0x10, /* 16 MHz */
	(ABEL_XTAL_TRIM | ABEL_XTAL_BIAS_CURRENT | ABEL_CHIP_RATE | ABEL_CLKO_FREQ),
	(ABEL_CCA_ENERGY_DETECT_THRESHOLD | ABEL_POWER_COMPENSATION_OFFSET),
/* ICG clock  */
	0x18,
	0x20, /* 0x20 => CPU clk=32 MHz, Buc clk = 16 MHz */
/* ICG Filter */
	0x02,
	0x40,
/* SCI  */
	0x00,
	0x34, /* 0x34 => 19200 @ 16 MHz */   
#endif SYSTEM_CLOCK_16MHZ

#ifdef SYSTEM_CLOCK_16780MHZ
	0x10, /* 16 MHz -> ~16,78 MHz */
	/*  0x3646, */
  (ABEL_XTAL_TRIM | ABEL_XTAL_BIAS_CURRENT | ABEL_CHIP_RATE | 6),
	(ABEL_CCA_ENERGY_DETECT_THRESHOLD | ABEL_POWER_COMPENSATION_OFFSET),
/* ICG clock  */
	0x18,
	0x60, /* 0x60 => CPU clk=32,78 MHz, Buc clk = 16,39 MHz */
/* ICG Filter */
	0x02,
	0x40,
/* SCI  */
	0x00,
	0x09, /* 0x09 => 115200 @ 16,78 MHz */
#endif SYSTEM_CLOCK_16780MHZ

  /*	_CONST uint8_t MAC_Address[8];*/
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*_CONST uint8_t ChannelSelect; */
	0x0A,
	/*_CONST uint8_t SleepModeEnable  */
	0x00,
	/*_CONST uint8_t HWName_Revision[18]  */
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*_CONST uint8_t PA_Level[2]*/
	0x00,0xBC,
	/*_CONST uint8_t SerialNumber[10]*/
	0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x00,
	/*_CONST uint16_t ProductionSite*/
	0x020F,
	/*_CONST uint8_t CountryCode*/
	0x01,
	/*_CONST uint8_t ProductionWeekCode*/
	0x04,
	/*_CONST uint8_t ProductionYearCode*/
	0x04,
  /*defaultPowerLevel*/
	0xBC,
	/*paPowerLevelLimits*/
	NULL,
	/*useDualAntenna*/
//#ifdef TARGET_TOROWEAP
#if (defined(TARGET_TOROWEAP)) 
  TRUE,
#elif (defined(TARGET_USER_DEFINED) )  
  #include "PortConfig.h"
  #if(gUserTransceiverType_d == MC1321x)
    TRUE,  
  #else
    FALSE,
  #endif  
#else	
	FALSE,
#endif /* TARGET_TOROWEAP */
	/*Reserved*/
	0xFF,0xFF,0xFF,0xFF,
	/* Application_Section  */
	0xFF,0xF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ATA1)
 volatile const uint8_t gZS2Nvram[ gNVMDataPerSector_c ] = 0;
#pragma RESTORE_CONST_SEG  



#pragma PLACE_CONST_SEG(NVM_ZIGBEE_DATA0_INIT)
#define BEESTACK_VERSION 0x01
volatile const NvramIdentificationStruct_t gNvramZS1 =
{
/*  DO NOT CHANGE FOLLOWING BYTES */
/*	_CONST uint8_t Version      */
  BEESTACK_VERSION,
/*	_CONST uint8_t aString[4];  == ZS1 */
  "ZS1",
/*	_CONST uint8_t SystemFlag; */
  NvramSystemFlag_c
};
#pragma RESTORE_CONST_SEG

#pragma PLACE_CONST_SEG(NVM_ZIGBEE_DATA1_INIT)
volatile const NvramIdentificationStruct_t gNvramZS2 =
{
/*  DO NOT CHANGE FOLLOWING BYTES */
/*	_CONST uint8_t Version      */
  BEESTACK_VERSION,
/*	_CONST uint8_t aString[4];  == ZS2 */
  "ZS2",
/*	_CONST uint8_t SystemFlag; */
  NvramSystemFlag_c
};
#pragma RESTORE_CONST_SEG


/*Init values for sectors*/
#pragma PLACE_CONST_SEG(BOOTLOADER_APP_NV_DATA0)
  volatile const InitNvramStruct_t mNvramMac; /* Initialized with default
                                               values for MAC sector  */
#pragma RESTORE_CONST_SEG

#pragma PLACE_CONST_SEG(NVM_ZIGBEE_DATA0_INIT)
  volatile const NvramIdentificationStruct_t gNvramZS1;
#pragma RESTORE_CONST_SEG

#pragma PLACE_CONST_SEG(NVM_ZIGBEE_DATA1_INIT)
  volatile const NvramIdentificationStruct_t gNvramZS2;
#pragma RESTORE_CONST_SEG

/*  Pointers to access sectors  */
#pragma PLACE_DATA_SEG(NVM_SCRATCHPAD_POINTER)
  volatile void *gpScratchPadNvram; /* A pointer to NV Scratch pad Data */
#pragma RESTORE_DATA_SEG

#pragma PLACE_DATA_SEG( MAC_NV_RAM_POINTER )
  /* A pointer to MAC NV Data, variable did not changed to keep MAC 
  compatibility. */
  volatile NvramStruct_t *gpMacNvram; 
#pragma RESTORE_DATA_SEG

#pragma PLACE_DATA_SEG( ZS_NV_RAM_POINTER )
  /* A pointer to NWK NV  Data */
  volatile NvramSectorStruct_t *gapBeeStackNvram[ gNumOfZigBeeSectors_c ]; 
#pragma RESTORE_DATA_SEG


/*  guserTriggerdReset is part of rst management. But it will be good to place
here as even for other purpose the variable memory can be used.*/
#pragma PLACE_DATA_SEG(RST_APP_VARIABLE)
  volatile uint8_t guserTriggerdReset = FALSE;
#pragma RESTORE_DATA_SEG


/*****************************************************************************
******************************************************************************
* Private functions
******************************************************************************
*****************************************************************************/
void NV_Data_Init(void)
{
	/* Setup NV RAM pointer after update. */
}


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

/*****************************************************************************
* locates the NV RAM to use.There are 2 NVM sectors.It sets apointer to 
* valid sector.    
*
* Interface assumptions:
*
* Return value:
* None
*
* Revison history:
*
* date   Author   Comments
* ------ ------   --------
* 290301 FSL,ANP  Created
*****************************************************************************/

void NVM_FindNVRAM( void )
{
    NvramSectorStruct_t * pSectorStruct;
    NvramStruct_t *pMacStruct;

		uint16_t iCounter = 0;
		
		uint8_t mac[4] = "MAC";
    uint8_t zs1[4] = "ZS1";
    uint8_t zs2[4] = "ZS2";
		/* Array of pointers to NVM Sectors  */
		void * apSectors[4] = 
		  { pStoredNvram0_c, pStoredNvram1_c, pStoredNvram2_c, 
		  pStoredNvram3_c};
	
	  	  
    gpMacNvram = NULL;        /*  MAC NVRAM Not found */
    gapBeeStackNvram[0] = NULL;
    gapBeeStackNvram[1] = NULL;
    gpScratchPadNvram = NULL; /*  SP NVRAM Not found  */

	  /* loop to find the corresponding NVM sector */
    for( iCounter = 0; iCounter < 4; iCounter++ ){
    
      pSectorStruct = ( NvramSectorStruct_t * )( apSectors[ iCounter ] );
      pMacStruct =  ( NvramStruct_t * )( apSectors[ iCounter ] );
    
      if( FLib_MemCmp(( void* )pSectorStruct->aString, 
        ( void* )zs1, 3 ))  {
        gapBeeStackNvram[0] = ( NvramSectorStruct_t * )( apSectors[ iCounter ]);
      }
      else if( FLib_MemCmp(( void* )pSectorStruct->aString,
        ( void* )zs2, 3 )) {
        gapBeeStackNvram[1] = ( NvramSectorStruct_t * )( apSectors[ iCounter ]);
      }      
      else if( FLib_MemCmp(( void* )pMacStruct->MAC_Version, 
        ( void* )mac, 3 )) {
        gpMacNvram = ( NvramStruct_t * )( apSectors[ iCounter ]);
      }
      else  {
         gpScratchPadNvram = ( void * )( apSectors[ iCounter ]);
      } 
    }	 	
	return;
}

/*****************************************************************************
******************************************************************************
* Private Debug stuff
******************************************************************************
*****************************************************************************/
/* None */

⌨️ 快捷键说明

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