📄 nf_drv.h
字号:
#ifndef _nf_drv_h
#define _nf_drv_h
/*_____ I N C L U D E S ____________________________________________________*/
#include "board.h" /* board definition */
/*_____ M A C R O S ________________________________________________________*/
/************************** Read Command ************************************/
#define NF_READ_CMD 0x00
#define NF_READ_CMD2 0x30
#define NF_RANDOM_READ_CMD_C1 0x05
#define NF_RANDOM_READ_CMD_C2 0xE0
/************************** Read Command ************************************/
#define NF_READ_A_AREA_CMD 0x00
#define NF_READ_B_AREA_CMD 0x01
#define NF_READ_C_AREA_CMD 0x50
/************************** Read ID Command *********************************/
#define NF_READ_ID_CMD 0x90
#define NF_RESET_CMD 0xff
/************************** Program command *********************************/
#define NF_SEQUENTIAL_DATA_INPUT_CMD 0x80
#define NF_PAGE_PROGRAM_CMD 0x10
/************************** Erase command ***********************************/
#define NF_BLOCK_ERASE_CMD 0x60
#define NF_BLOCK_ERASE_CONFIRM_CMD 0xD0
/************************** Read Status command *****************************/
#define NF_READ_STATUS_CMD 0x70
#define Nf_wait_busy() {while (!NF_RD_BUSY);}
/************************ Block Copy command ****************************/
#define NF_COPY_BACK_CMD 0x8A
/* Low Level routine */
#define Nf_rd_byte() (nf_data)
#define Nf_wr_byte(b) (nf_data = b)
#define Nf_send_command(command) (nf_send_cmd = command)
#define Nf_send_address(address) (nf_send_add = address)
#define Nf_get_block_page(pos) ( (pos)>>9 )
#define Nf_get_column(pos) ( (pos)& 0xFF )
#define Nf_get_pointer_operation(pos) ( ((pos)>>8) & 0x01 )
#define Nf_partition_address(pos) \
nf_block_page_add=Nf_get_block_page(pos); \
nf_column_add=Nf_get_column(pos); \
nf_ptr_operation=Nf_get_pointer_operation(pos)
#define Nf_read_open(block_page_add,column_add) \
Nf_send_command(nf_ptr_operation); \
Nf_send_address(column_add); \
Nf_send_address( ((Byte*)&block_page_add)[3] ); \
Nf_send_address( ((Byte*)&block_page_add)[2] ); \
Nf_send_address( ((Byte*)&block_page_add)[1] ); \
Nf_wait_busy()
/* read the content of the first spare sector */
#define Nf_read_c_open(block_page_add) \
Nf_send_command(NF_READ_C_AREA_CMD); \
Nf_send_address( ((Byte*)&block_page_add)[3] ); \
Nf_send_address( ((Byte*)&block_page_add)[2] ); \
Nf_send_address( ((Byte*)&block_page_add)[1] ); \
Nf_wait_busy()
#define Nf_write_c_open(block_page_add) \
Nf_send_command(NF_READ_C_AREA_CMD); \
Nf_send_command(NF_SEQUENTIAL_DATA_INPUT_CMD); \
Nf_send_address( ((Byte*)&block_page_add)[3]); \
Nf_send_address( ((Byte*)&block_page_add)[2]); \
Nf_send_address( ((Byte*)&block_page_add)[1])
/*
#define Nf_read_lenth_data(block_page_add,column_add,pointer_operation) \
Nf_send_command(pointer_operation); \
Nf_send_address(column_add);
Nf_send_address(block_page_add);
*/
/*_____ D E F I N I T I O N ________________________________________________*/
extern xdata Byte nf_send_cmd; /* Command */
extern xdata Byte nf_send_add; /* Address */
extern xdata Byte volatile nf_data; /* Data */
extern idata Byte gl_buffer[GL_BUF_SIZE]; // global buffer of 256 bytes
extern Uint32 nf_block_page_add; // general block and page address
extern Uchar nf_column_add; // general column address
extern Uchar nf_ptr_operation; // general pointer operation
extern Uchar test;
/*----- Firmware Definition -----*/
/*------- Declaration --------------------------*/
bit nf_block_erase(); //删除一块
Uint16 nf_read_bytes(Int16 len); //读取len个的字节数据
Byte nf_read_byte(); //读取一个字节
void nf_read_spare_sector(); //读取所有备份区中的数据
Byte nf_read_spare_byte(); //读取备份区中一个字节数据
bit nf_write_spare_byte(Byte b); //把数据b写入到Flash的备份区中
bit nf_write_bytes(Int16 len); //写入len个字节数据
bit nf_write_byte(Byte b); //把数据b写入到Flash中
void initial_gl_buffer();
bit nf_page_copy_back(Uint32 source_add,Uint32 target_add);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -