📄 dataflash.h
字号:
/*************************************** Copyright (c) *************************************************
*
* POLAR STAR
* 北天星国际有限公司
* http://www.po-star.com
*
*文 件 名: dataflash.h
*
*编译环境:ADS1.2
*
********************************************************************************************************/
#ifndef _DATAFLASH_H
#define _DATAFLASH_H
// SPI CLOCK
#define AT91C_SPI_CLK 8000000
// AC characteristics
// DLYBS = tCSS= 250ns min and DLYBCT = tCSH = 250ns
#define DATAFLASH_TCSS (0xc << 16) // 250ns min (tCSS) <=> 12/48000000 = 250ns
#define DATAFLASH_TCHS (0x1 << 24) // 250ns min (tCSH) <=> (64*1+SCBR)/(2*48000000)
// Chip Select 0 : NPCS0 %1110
#define AT91C_SPI_PCS0_DATAFLASH 0xE
// Chip Select 1 : NPCS1 %1101
#define AT91C_SPI_PCS1_DATAFLASH 0xD
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Command Definition
/////////////////////////////////////////////////////////////////////////////////////////////////////
/* READ COMMANDS */
#define DB_CONTINUOUS_ARRAY_READ 0xE8 /* Continuous array read */
#define DB_BURST_ARRAY_READ 0xE8 /* Burst array read */
#define DB_PAGE_READ 0xD2 /* Main memory page read */
#define DB_BUF1_READ 0xD4 /* Buffer 1 read */
#define DB_BUF2_READ 0xD6 /* Buffer 2 read */
#define DB_STATUS 0xD7 /* Status Register */
/* PROGRAM and ERASE COMMANDS */
#define DB_BUF1_WRITE 0x84 /* Buffer 1 write */
#define DB_BUF2_WRITE 0x87 /* Buffer 2 write */
#define DB_BUF1_PAGE_ERASE_PGM 0x83 /* Buffer 1 to main memory page program with built-In erase */
#define DB_BUF1_PAGE_ERASE_FASTPGM 0x93 /* Buffer 1 to main memory page program with built-In erase, Fast program */
#define DB_BUF2_PAGE_ERASE_PGM 0x86 /* Buffer 2 to main memory page program with built-In erase */
#define DB_BUF2_PAGE_ERASE_FASTPGM 0x96 /* Buffer 1 to main memory page program with built-In erase, Fast program */
#define DB_BUF1_PAGE_PGM 0x88 /* Buffer 1 to main memory page program without built-In erase */
#define DB_BUF1_PAGE_FASTPGM 0x98 /* Buffer 1 to main memory page program without built-In erase, Fast program*/
#define DB_BUF2_PAGE_PGM 0x89 /* Buffer 2 to main memory page program without built-In erase */
#define DB_BUF2_PAGE_FASTPGM 0x99 /* Buffer 1 to main memory page program without built-In erase, Fast program*/
#define DB_PAGE_ERASE 0x81 /* Page Erase */
#define DB_BLOCK_ERASE 0x50 /* Block Erase */
#define DB_PAGE_PGM_BUF1 0x82 /* Main memory page through buffer 1 */
#define DB_PAGE_FASTPGM_BUF1 0x92 /* Main memory page through buffer 1, Fast program */
#define DB_PAGE_PGM_BUF2 0x85 /* Main memory page through buffer 2 */
#define DB_PAGE_FastPGM_BUF2 0x95 /* Main memory page through buffer 2, Fast program */
/* ADDITIONAL COMMANDS */
#define DB_PAGE_2_BUF1_TRF 0x53 /* Main memory page to buffer 1 transfert */
#define DB_PAGE_2_BUF2_TRF 0x55 /* Main memory page to buffer 2 transfert */
#define DB_PAGE_2_BUF1_CMP 0x60 /* Main memory page to buffer 1 compare */
#define DB_PAGE_2_BUF2_CMP 0x61 /* Main memory page to buffer 2 compare */
#define DB_AUTO_PAGE_PGM_BUF1 0x58 /* Auto page rewrite throught buffer 1 */
#define DB_AUTO_PAGE_PGM_BUF2 0x59 /* Auto page rewrite throught buffer 2 */
/////////////////////////////////////////////////////////////////////////////////////////////////////
// ATMEL Dataflash description
/////////////////////////////////////////////////////////////////////////////////////////////////////
#define AT45DB011B 0x0C
#define AT45DB021B 0x14
#define AT45DB041B 0x1C
#define AT45DB081B 0x24
#define AT45DB161B 0x2C
#define AT45DB321B 0x34
#define AT45DB642 0x3C
#define AT45DB1282 0x10
#define AT45DB2562 0x18
#define AT45DB5122 0x20
/*#define AT45DB642 { 8192, 1056, 11, 8, 0x700 }
#define AT45DB321B { 8192, 528, 10, 8, 0x300 }
#define AT45DCB004 AT45DB321B
#define AT45DCB008 AT45DB642
*/
#define AT91C_DF_TIMEOUT 10000000
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Dataflash Interface Definition
/////////////////////////////////////////////////////////////////////////////////////////////////////
typedef enum _AT91S_DF_SEM {
UNLOCKED,
LOCKED
} AT91S_DF_SEM;
typedef enum _AT91S_DF_STATE {
START_COMMAND,
WAIT_FOR_BUSY,
ERASE,
END_OF_ERASE,
START_WRITE,
END_OF_WRITE,
START_READ,
END_OF_READ,
READ_GET_STATUS,
WAIT_FOR_READ_STATUS
} AT91S_DF_STATE;
// Dataflash Description Structure
typedef struct _AT91S_DF_DESC {
int pages_number; //* dataflash page number
int pages_size; //* dataflash page size
int page_offset; //* page offset in command
int block_size; //* nb page per block
int byte_mask; //* byte mask in command
} AT91S_DF_DESC, *AT91PS_DF_DESC;
// Dataflash Descriptor Structure
typedef struct _AT91S_DF
{
AT91PS_SPI pSpi;
unsigned char bCs;
AT91S_DF_SEM bSemaphore; //* SPI semaphore
unsigned int command[2];
AT91S_DF_DESC dfDescription;
}AT91S_DF, *AT91PS_DF;
#define AT91C_DF_NB_BLOCS(pDf) (pDf->dfDescription.pages_number / pDf->dfDescription.block_size)
#define AT91C_DF_BLOC_SIZE(pDf) (pDf->dfDescription.block_size * pDf->dfDescription.pages_size)
#define AT91C_DF_NB_PAGE(pDf) (pDf->dfDescription.pages_number)
#define AT91C_PAGE_SIZE(pDf) (pDf->dfDescription.pages_size)
#define AT91C_PAGE_OFFSET(pDf) (pDf->dfDescription.page_offset)
extern char AT91F_DF_send_command (
AT91PS_DF pDataFlash,
unsigned char bCmd, // Command value
unsigned char bCmdSize, // Command Size
char *pData, // Data to be sent
unsigned int dDataSize, // Data Size
unsigned int dAddress); // Dataflash Address
extern char AT91F_DF_wait_ready(
AT91PS_DF pDataFlash);
extern AT91S_DF_SEM AT91F_DF_is_busy(
AT91PS_DF pDataFlash);
extern unsigned char AT91F_DF_read(
AT91PS_DF pDf,
char *pData,
unsigned int dAddress);
extern unsigned char AT91F_DF_write(
AT91PS_DF pDf,
char *pData,
unsigned int dAddress);
extern unsigned char AT91F_DF_erase(
AT91PS_DF pDf,
unsigned int dAddress);
/* ============ READ COMMANDS =============== */
#define AT91F_DF_continuous_read(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_CONTINUOUS_ARRAY_READ, 8, pData, dDataSize, dAddress)
#define AT91F_DF_page_read(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_PAGE_READ, 8, pData, dDataSize, dAddress)
#define AT91F_DF_read_buf1(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_BUF1_READ, 5, pData, dDataSize, dAddress)
#define AT91F_DF_read_buf2(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_BUF2_READ, 5, pData, dDataSize, dAddress)
#define AT91F_DF_get_status(pDf) \
AT91F_DF_send_command(pDf, DB_STATUS, 2, (char *) 0, 0, 0)
/* ============ WRITE COMMANDS =============== */
#define AT91F_DF_write_buf1(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_BUF1_WRITE, 4, pData, dDataSize, dAddress)
#define AT91F_DF_write_buf2(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_BUF2_WRITE, 4, pData, dDataSize, dAddress)
#define AT91F_DF_pgm_erase_buf1(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_BUF1_PAGE_ERASE_PGM, 4, pData, dDataSize, dAddress)
#define AT91F_DF_pgm_erase_buf2(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_BUF2_PAGE_ERASE_PGM, 4, pData, dDataSize, dAddress)
#define AT91F_DF_pgm_buf1(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_BUF1_PAGE_PGM, 4, pData, dDataSize, dAddress)
#define AT91F_DF_pgm_buf2(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_BUF2_PAGE_PGM, 4, pData, dDataSize, dAddress)
#define AT91F_DF_page_write(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_PAGE_PGM_BUF1, 4, pData, dDataSize, dAddress)
/* ============ ERASE COMMANDS =============== */
#define AT91F_DF_page_erase(pDf, dAddress) \
AT91F_DF_send_command(pDf, DB_PAGE_ERASE, 4, (char *) 0, 0, dAddress)
#define AT91F_DF_block_erase(pDf, dAddress) \
AT91F_DF_send_command(pDf, DB_BLOCK_ERASE, 4, (char *) 0, 0, dAddress)
/* ============ ADDITIONAL COMMANDS =============== */
#define AT91F_DF_trf_buf1(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_PAGE_2_BUF1_TRF, 4, (char *) 0, 0, dAddress)
#define AT91F_DF_trf_buf2(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_PAGE_2_BUF1_TRF, 4, (char *) 0, 0, dAddress)
#define AT91F_DF_cmp_buf1(pDf, dAddress) \
AT91F_DF_send_command(pDf, DB_PAGE_2_BUF1_CMP, 4, (char *) 0, 0, dAddress)
#define AT91F_DF_cmp_buf2(pDf, dAddress) \
AT91F_DF_send_command(pDf, DB_PAGE_2_BUF2_CMP, 4, (char *) 0, 0, dAddress)
#define AT91F_DF_rwr_buf1(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_AUTO_PAGE_PGM_BUF1, 4, (char *) 0, 0, dAddress)
#define AT91F_DF_rwr_buf2(pDf, pData, dDataSize, dAddress) \
AT91F_DF_send_command(pDf, DB_AUTO_PAGE_PGM_BUF2, 4, (char *) 0, 0, dAddress)
/* ============ Status Register Fields =============== */
#define AT91F_DF_is_ready(pDf) \
((pDf)->command[0] & 0x8000)
#define AT91F_DF_is_different(pDf) \
((pDf)->command[0] & 0x4000)
//@-node:@file dataflash.h
//@-leo
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -