/******************************************************************************
Filename: OSAL_Nv.c
Revised: $Date: 2014-12-19 13:07:30 -0800 (Fri, 19 Dec 2014) $
Revision: $Revision: 41556 $
Description: This module contains the OSAL non-volatile memory functions.
Copyright 2006-2014 Texas Instruments Incorporated. All rights reserved.
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED �AS IS� WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
******************************************************************************/
/******************************************************************************
Notes:
- A trick buried deep in initPage() requires that the MSB of the NV Item Id
is to be reserved for use by this module.
******************************************************************************/
/*********************************************************************
* INCLUDES
*/
#include "hal_adc.h"
#include "hal_flash.h"
#include "hal_types.h"
#include "OSAL_Nv.h"
#include "ZComDef.h"
#ifdef HAL_MCU_CC2533
#include "hal_batmon.h"
#endif
#include "OnBoard.h"
/*********************************************************************
* CONSTANTS
*/
#define OSAL_NV_PAGE_SIZE HAL_FLASH_PAGE_SIZE
#define OSAL_NV_PAGES_USED HAL_NV_PAGE_CNT
#define OSAL_NV_PAGE_BEG HAL_NV_PAGE_BEG
#define OSAL_NV_PAGE_END (OSAL_NV_PAGE_BEG + OSAL_NV_PAGES_USED - 1)
#define OSAL_NV_ACTIVE 0x00
#define OSAL_NV_ERASED 0xFF
#define OSAL_NV_ERASED_ID 0xFFFF
#define OSAL_NV_ZEROED_ID 0x0000
// Reserve MSB of Id to signal a search for the "old" source copy (new write interrupted/failed.)
#define OSAL_NV_SOURCE_ID 0x8000
// In case pages 0-1 are ever used, define a null page value.
#define OSAL_NV_PAGE_NULL 0
// In case item Id 0 is ever used, define a null item value.
#define OSAL_NV_ITEM_NULL 0
#define OSAL_NV_WORD_SIZE HAL_FLASH_WORD_SIZE
#define OSAL_NV_PAGE_HDR_OFFSET 0
#define OSAL_NV_MAX_HOT 3
static const uint16 hotIds[OSAL_NV_MAX_HOT] = {
ZCD_NV_NWKKEY,
ZCD_NV_NWK_ACTIVE_KEY_INFO,
ZCD_NV_NWK_ALTERN_KEY_INFO,
};
/*********************************************************************
* MACROS
*/
#if (defined HAL_MCU_CC2530 || defined HAL_MCU_CC2531)
#define OSAL_NV_CHECK_BUS_VOLTAGE OnBoard_CheckVoltage()
#elif defined HAL_MCU_CC2533
# define OSAL_NV_CHECK_BUS_VOLTAGE (HalBatMonRead( HAL_BATMON_MIN_FLASH ))
#else
# warning No implementation of a low Vdd check.
# define OSAL_NV_CHECK_BUS_VOLTAGE
#endif
#define OSAL_NV_DATA_SIZE( LEN ) \
(((LEN) >= ((uint16)(65536UL - OSAL_NV_WORD_SIZE))) ? \
((uint16)(65536UL - OSAL_NV_WORD_SIZE)) : \
((((LEN) + OSAL_NV_WORD_SIZE - 1) / OSAL_NV_WORD_SIZE) * OSAL_NV_WORD_SIZE))
#define OSAL_NV_ITEM_SIZE( LEN ) \
(((LEN) >= ((uint16)(65536UL - OSAL_NV_WORD_SIZE - OSAL_NV_HDR_SIZE))) ? \
((uint16)(65536UL - OSAL_NV_WORD_SIZE)) : \
(((((LEN) + OSAL_NV_WORD_SIZE - 1) / OSAL_NV_WORD_SIZE) * OSAL_NV_WORD_SIZE) + OSAL_NV_HDR_SIZE))
#define COMPACT_PAGE_CLEANUP( COM_PG ) st ( \
/* In order to recover from a page compaction that is interrupted,\
* the logic in osal_nv_init() depends upon the following order:\
* 1. State of the target of compaction is changed to ePgInUse.\
* 2. Compacted page is erased.\
*/\
setPageUse( pgRes, TRUE ); /* Mark the reserve page as being in use. */\
erasePage( (COM_PG) ); \
\
pgRes = (COM_PG); /* Set the reserve page to be the newly erased page. */\
)
/*********************************************************************
* TYPEDEFS
*/
typedef struct
{
uint16 id;
uint16 len; // Enforce Flash-WORD size on len.
uint16 chk; // Byte-wise checksum of the 'len' data bytes of the item.
uint16 stat; // Item status.
} osalNvHdr_t;
// Struct member offsets.
#define OSAL_NV_HDR_ID 0
#define OSAL_NV_HDR_LEN 2
#define OSAL_NV_HDR_CHK 4
#define OSAL_NV_HDR_STAT 6
#define OSAL_NV_HDR_ITEM 2 // Length of any item of a header struct.
#define OSAL_NV_HDR_SIZE 8
#define OSAL_NV_HDR_HALF (OSAL_NV_HDR_SIZE / 2)
typedef struct
{
uint16 active;
uint16 inUse;
uint16 xfer;
uint16 spare;
} osalNvPgHdr_t;
// Struct member offsets.
#define OSAL_NV_PG_ACTIVE 0
#define OSAL_NV_PG_INUSE 2
#define OSAL_NV_PG_XFER 4
#define OSAL_NV_PG_SPARE 6
#define OSAL_NV_PAGE_HDR_SIZE 8
#define OSAL_NV_PAGE_HDR_HALF (OSAL_NV_PAGE_HDR_SIZE / 2)
typedef enum
{
eNvXfer,
eNvZero
} eNvHdrEnum;
typedef enum
{
ePgActive,
ePgInUse,
ePgXfer,
ePgSpare
} ePgHdrEnum;
/*********************************************************************
* GLOBAL VARIABLES
*/
#ifndef OAD_KEEP_NV_PAGES
// When NV pages are to remain intact during OAD download,
// the image itself should not include NV pages.
#pragma location="ZIGNV_ADDRESS_SPACE"
__no_init uint8 _nvBuf[OSAL_NV_PAGES_USED * OSAL_NV_PAGE_SIZE];
#pragma required=_nvBuf
#endif // OAD_KEEP_NV_PAGES
/*********************************************************************
* LOCAL VARIABLES
*/
// Offset into the page of the first available erased space.
static uint16 pgOff[OSAL_NV_PAGES_USED];
// Count of the bytes lost for the zeroed-out items.
static uint16 pgLost[OSAL_NV_PAGES_USED];
static uint8 pgRes; // Page reserved for item compacting transfer.
// Saving ~100 code bytes to move a uint8* parameter/return value from findItem() to a global.
static uint8 findPg;
// NV page and offsets for hot items.
static uint8 hotPg[OSAL_NV_MAX_HOT];
static uint16 hotOff[OSAL_NV_MAX_HOT];
/*********************************************************************
* LOCAL FUNCTIONS
*/
static uint8 initNV( void );
static void setPageUse( uint8 pg, uint8 inUse );
static uint16 initPage( uint8 pg, uint16 id, uint8 findDups );
static void erasePage( uint8 pg );
static uint8 compactPage( uint8 srcPg, uint16 skipId );
static uint16 findItem( ui
没有合适的资源?快使用搜索试试~ 我知道了~
OSAL.rar_OSAL纯净版_Osal
共77个文件
h:39个
c:31个
s51:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 79 浏览量
2022-09-15
02:04:11
上传
评论 1
收藏 225KB RAR 举报
温馨提示
OSAL为Operating System Abstraction Layer,即操作系统抽象层,支持多任务运行,它并不是一个传统意义上的操作系统,但是实现了部分类似操作系统的功能。
资源详情
资源评论
资源推荐
收起资源包目录
OSAL.rar (77个子文件)
OSAL
Components
hal
target
Hardware
HalHardwareApi_CC2530.h 9KB
HalHardwareDefine_CC2530.h 34KB
HalHardwareApi_CC2530.c 28KB
CC2530EB
font.c 30KB
hal_types.h 4KB
hal_ota.h 5KB
hal_dma.c 5KB
hal_dma.h 12KB
hal_key.c 26KB
_hal_uart_dma.c 24KB
hal_uart.c 9KB
hal_oad.c 17KB
hal_flash.c 7KB
hal_mac_cfg.h 3KB
hal_oad.h 5KB
hal_adc.c 12KB
hal_aes.h 5KB
hal_timer.c 3KB
hal_ccm.h 3KB
hal_mcu.h 9KB
hal_startup.c 4KB
hal_sleep.c 20KB
_hal_uart_isr.c 17KB
hal_board_cfg.h 18KB
hal_oled_spi.c 29KB
hal_led.c 16KB
font.h 300B
hal_ota.c 15KB
include
hal_key.h 6KB
hal_assert.h 5KB
hal_adc.h 6KB
hal_uart.h 8KB
hal_sleep.h 3KB
hal_rpc.h 6KB
hal_lcd.h 6KB
hal_drivers.h 4KB
hal_led.h 4KB
hal_defs.h 6KB
hal_timer.h 12KB
hal_flash.h 5KB
hal_board.h 28B
common
hal_drivers.c 9KB
hal_assert.c 10KB
osal
include
OSAL_Memory.h 5KB
OSAL.h 8KB
OSAL_Timers.h 5KB
OSAL_Tasks.h 4KB
OSAL_Clock.h 5KB
ZComDef.h 20KB
OSAL_PwrMgr.h 5KB
osal_task.h 14KB
OSAL_Nv.h 5KB
comdef.h 5KB
common
OSAL.c 34KB
OSAL_Task.c 14KB
OSAL_Clock.c 14KB
OSAL_Memory.c 21KB
OSAL_PwrMgr.c 7KB
OSAL_Timers.c 17KB
mcu
cc2530
OSAL_Math.s51 6KB
OSAL_Nv.c 44KB
Projects
zstack
HomeAutomation
GenericApp
CC2530DB
GenericApp.ewd 24KB
settings
GenericApp.wsdt 2KB
GenericApp.eww 747B
GenericApp.ewp 49KB
Source
Task_1.c 3KB
zcl_genericapp.h 3KB
Task_1.h 2KB
OSAL_GenericApp.c 4KB
Task_2.c 4KB
zcl_genericapp.c 10KB
Task_2.h 2KB
Tools
CC2530DB
f8w2530.xcl 10KB
ZMain
TI2530DB
OnBoard.h 10KB
chipcon_cstartup.s51 15KB
OnBoard.c 12KB
ZMain.c 4KB
共 77 条
- 1
小波思基
- 粉丝: 70
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0