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

📄 复件 flash.h.bak

📁 在SoC单片机上实现对内部Flash的操作,基于uc/os-II.
💻 BAK
字号:
/*flash.h*/
#include "upsd3200.h"

/////////////


#define FLASH_COMMON_XAAA (volatile unsigned char xdata *) 0x0AAA //定义成volatile避免被编译器优化掉
#define FLASH_COMMON_X555 (volatile unsigned char xdata *) 0x0555
// 扇区基址,采用扇区分页,都映射到0x0000-->0x7FFF
#define SECTOR_BASE_ADDRESS 0x0000

/***********************************************************************/
//        检测flash状态位

#define UNUSED    0x00           //flash闲置     
#define USED  0x80               //当扇区被使用时完全被占用.
                                      //只有写入数据时才会发生擦除    
#define WAITFORFLASH  1000          //锁flash   延时1000个时钟脉冲  ??多长合适??                                       
/***********************************************************************/
#define NVM_DATA_POLL 0X88            //数据轮询位DQ7定义
#define NVM_DATA_TOGGLE 0X40          //数据触发位DQ6定义
#define NVM_ERROR 0x20                //超时错误位DQ5定义

// 主flash扇区定义
#define SECTOR_0	0x00
#define SECTOR_1	0x01
#define SECTOR_2	0x02
#define SECTOR_3	0x03
#define SECTOR_4	0x04
#define SECTOR_5	0x05
#define SECTOR_6	0x06
#define SECTOR_7	0x07


#ifndef TRUE
  #define TRUE 0x01
#endif 
#ifndef FALSE
  #define FALSE 0x00
#endif 

extern unsigned char MemLock;
/***************************用户API,仅仅提供这几个函数***************************/
  void init_flash(void)reentrant;
 unsigned char ycc_mem_write(unsigned int *buf, int len,unsigned long pos)reentrant;

 unsigned char ycc_mem_read(unsigned int *buf, int len,unsigned long pos)reentrant;
 /********************以下两个函数********************************/
// Fetch a configuration data item from flash, returns 'false' if not found. 
 unsigned char ljc_flash_get_config(char *key, void *val, int type)reentrant;
// Add a new configuration data item to configuration data base.
// Returns 'false' if no space is available. 
// unsigned char ljc_flash_add_config(struct config_option *opt, bool update);
   unsigned char ljc_flash_add_config(struct config_option *opt, unsigned char update)reentrant;
/*************************底层函数用户不可见,以下函数的操作范围在某扇区内,寻址范围 0x0000->0x7FFF**************************/
//
void Move_from_flash (unsigned int *src, unsigned int *dest,  int len)reentrant;
//
unsigned char Move_to_flash (unsigned int *src, unsigned int *dest,  int len)reentrant;

//在flash中写入一个字节,用数据轮询方式
unsigned char flash_write_with_poll(volatile unsigned char xdata* addr, unsigned char dat)reentrant;

//擦除整个主flash所有扇区
unsigned char flash_erase_bulk(volatile unsigned char xdata* flash_bulk_erase_address)reentrant;//擦除整个主flash所有扇区

//擦除扇区sector
unsigned char flash_erase_the_sector(unsigned char sector)reentrant;

//擦除特定的扇区,调用该函数前要指明psd页寄存器
unsigned char flash_erase_sector(volatile unsigned char xdata * sector_erase_address)reentrant;
/*****************以下两个做扩展用*********************/
void flash_reset()reentrant;                   //复位主flash到读状态

unsigned char flash_read_id(volatile unsigned char *flash_id_address)reentrant;    //读主flash标识

   //擦除主flash的特定扇区void Move (unsigned char *src, unsigned char *dest,  int len);

⌨️ 快捷键说明

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