1 //*---------------------------------------------------------------------------
2 //* ATMEL Microcontroller Software Support - ROUSSET -
3 //*---------------------------------------------------------------------------
4 //* The software is delivered "AS IS" without warranty or condition of any
5 //* kind, either express, implied or statutory. This includes without
6 //* limitation any warranty or condition with respect to merchantability or
7 //* fitness for any particular purpose, or against the infringements of
8 //* intellectual property rights of others.
9 //*---------------------------------------------------------------------------
10 //* File Name : AT91_SpiDataFlash.h
11 //* Object : Data Flash Atmel Description File
14 //* 1.0 03/04/01 HI : Creation
16 //*---------------------------------------------------------------------------
21 /* Max value = 15Mhz to be compliant with the Continuous array read function */
23 #define AT91C_SPI_CLK 14976000/4
25 #define AT91C_SPI_CLK 14976000
28 /* AC characteristics */
29 /* DLYBS = tCSS= 250ns min and DLYBCT = tCSH = 250ns */
31 #define DATAFLASH_TCSS (0xf << 16) /* 250ns 15/60000000 */
32 #define DATAFLASH_TCHS (0x1 << 24) /* 250ns 32*1/60000000 */
35 #define AT91C_SPI_PCS0_SERIAL_DATAFLASH 0xE /* Chip Select 0 : NPCS0 %1110 */
36 #define AT91C_SPI_PCS3_DATAFLASH_CARD 0x7 /* Chip Select 3 : NPCS3 %0111 */
38 #define CFG_MAX_DATAFLASH_BANKS 2
39 #define CFG_DATAFLASH_LOGIC_ADDR_CS0 0xC0000000
40 #define CFG_DATAFLASH_LOGIC_ADDR_CS3 0xD0000000
43 unsigned long base
; /* logical base address for a bank */
44 unsigned long size
; /* total bank size */
45 unsigned long page_count
;
46 unsigned long page_size
;
47 unsigned long id
; /* device id */
50 typedef unsigned int AT91S_DataFlashStatus
;
52 /*----------------------------------------------------------------------*/
53 /* DataFlash Structures */
54 /*----------------------------------------------------------------------*/
56 /*---------------------------------------------*/
57 /* DataFlash Descriptor Structure Definition */
58 /*---------------------------------------------*/
59 typedef struct _AT91S_DataflashDesc
{
60 unsigned char *tx_cmd_pt
;
61 unsigned int tx_cmd_size
;
62 unsigned char *rx_cmd_pt
;
63 unsigned int rx_cmd_size
;
64 unsigned char *tx_data_pt
;
65 unsigned int tx_data_size
;
66 unsigned char *rx_data_pt
;
67 unsigned int rx_data_size
;
68 volatile unsigned char DataFlash_state
;
69 unsigned char command
[8];
70 } AT91S_DataflashDesc
, *AT91PS_DataflashDesc
;
72 /*---------------------------------------------*/
73 /* DataFlash device definition structure */
74 /*---------------------------------------------*/
75 typedef struct _AT91S_Dataflash
{
76 int pages_number
; /* dataflash page number */
77 int pages_size
; /* dataflash page size */
78 int page_offset
; /* page offset in command */
79 int byte_mask
; /* byte mask in command */
81 } AT91S_DataflashFeatures
, *AT91PS_DataflashFeatures
;
84 /*---------------------------------------------*/
85 /* DataFlash Structure Definition */
86 /*---------------------------------------------*/
87 typedef struct _AT91S_DataFlash
{
88 AT91PS_DataflashDesc pDataFlashDesc
; /* dataflash descriptor */
89 AT91PS_DataflashFeatures pDevice
; /* Pointer on a dataflash features array */
90 } AT91S_DataFlash
, *AT91PS_DataFlash
;
93 typedef struct _AT91S_DATAFLASH_INFO
{
95 AT91S_DataflashDesc Desc
;
96 AT91S_DataflashFeatures Device
; /* Pointer on a dataflash features array */
97 unsigned long logical_address
;
98 unsigned int id
; /* device id */
99 } AT91S_DATAFLASH_INFO
, *AT91PS_DATAFLASH_INFO
;
102 /*-------------------------------------------------------------------------------------------------*/
104 #define AT45DB161 0x2c
105 #define AT45DB321 0x34
106 #define AT45DB642 0x3c
107 #define AT45DB128 0x10
109 #define AT91C_DATAFLASH_TIMEOUT 20000 /* For AT91F_DataFlashWaitReady */
111 /* DataFlash return value */
112 #define AT91C_DATAFLASH_BUSY 0x00
113 #define AT91C_DATAFLASH_OK 0x01
114 #define AT91C_DATAFLASH_ERROR 0x02
115 #define AT91C_DATAFLASH_MEMORY_OVERFLOW 0x03
116 #define AT91C_DATAFLASH_BAD_COMMAND 0x04
117 #define AT91C_DATAFLASH_BAD_ADDRESS 0x05
125 /* DataFlash Driver State */
126 #define GET_STATUS 0x0F
128 /*-------------------------------------------------------------------------------------------------*/
129 /* Command Definition */
130 /*-------------------------------------------------------------------------------------------------*/
133 #define DB_CONTINUOUS_ARRAY_READ 0xE8 /* Continuous array read */
134 #define DB_BURST_ARRAY_READ 0xE8 /* Burst array read */
135 #define DB_PAGE_READ 0xD2 /* Main memory page read */
136 #define DB_BUF1_READ 0xD4 /* Buffer 1 read */
137 #define DB_BUF2_READ 0xD6 /* Buffer 2 read */
138 #define DB_STATUS 0xD7 /* Status Register */
140 /* PROGRAM and ERASE COMMANDS */
141 #define DB_BUF1_WRITE 0x84 /* Buffer 1 write */
142 #define DB_BUF2_WRITE 0x87 /* Buffer 2 write */
143 #define DB_BUF1_PAGE_ERASE_PGM 0x83 /* Buffer 1 to main memory page program with built-In erase */
144 #define DB_BUF1_PAGE_ERASE_FASTPGM 0x93 /* Buffer 1 to main memory page program with built-In erase, Fast program */
145 #define DB_BUF2_PAGE_ERASE_PGM 0x86 /* Buffer 2 to main memory page program with built-In erase */
146 #define DB_BUF2_PAGE_ERASE_FASTPGM 0x96 /* Buffer 1 to main memory page program with built-In erase, Fast program */
147 #define DB_BUF1_PAGE_PGM 0x88 /* Buffer 1 to main memory page program without built-In erase */
148 #define DB_BUF1_PAGE_FASTPGM 0x98 /* Buffer 1 to main memory page program without built-In erase, Fast program */
149 #define DB_BUF2_PAGE_PGM 0x89 /* Buffer 2 to main memory page program without built-In erase */
150 #define DB_BUF2_PAGE_FASTPGM 0x99 /* Buffer 1 to main memory page program without built-In erase, Fast program */
151 #define DB_PAGE_ERASE 0x81 /* Page Erase */
152 #define DB_BLOCK_ERASE 0x50 /* Block Erase */
153 #define DB_PAGE_PGM_BUF1 0x82 /* Main memory page through buffer 1 */
154 #define DB_PAGE_FASTPGM_BUF1 0x92 /* Main memory page through buffer 1, Fast program */
155 #define DB_PAGE_PGM_BUF2 0x85 /* Main memory page through buffer 2 */
156 #define DB_PAGE_FastPGM_BUF2 0x95 /* Main memory page through buffer 2, Fast program */
158 /* ADDITIONAL COMMANDS */
159 #define DB_PAGE_2_BUF1_TRF 0x53 /* Main memory page to buffer 1 transfert */
160 #define DB_PAGE_2_BUF2_TRF 0x55 /* Main memory page to buffer 2 transfert */
161 #define DB_PAGE_2_BUF1_CMP 0x60 /* Main memory page to buffer 1 compare */
162 #define DB_PAGE_2_BUF2_CMP 0x61 /* Main memory page to buffer 2 compare */
163 #define DB_AUTO_PAGE_PGM_BUF1 0x58 /* Auto page rewrite throught buffer 1 */
164 #define DB_AUTO_PAGE_PGM_BUF2 0x59 /* Auto page rewrite throught buffer 2 */
166 /*-------------------------------------------------------------------------------------------------*/
168 extern AT91S_DATAFLASH_INFO dataflash_info
[CFG_MAX_DATAFLASH_BANKS
];
170 extern void AT91F_SpiInit(void);
171 extern int AT91F_DataflashProbe(int i
, AT91PS_DataflashDesc pDesc
);
172 extern int AT91F_DataFlashRead(AT91PS_DataFlash
, unsigned long , unsigned long, char *);
173 extern AT91S_DataFlashStatus
AT91F_DataFlashWrite(AT91PS_DataFlash
,unsigned char *, int, int);
174 extern AT91S_DataFlashStatus
AT91F_DataFlashErase(AT91PS_DataFlash pDataFlash
);
175 extern int AT91F_DataflashInit(void);
176 extern void AT91F_DataflashPrintInfo(void);
177 extern int read_dataflash(unsigned long addr
, unsigned long size
, char *result
);
178 extern int write_dataflash(unsigned long addr_dest
, unsigned int addr_src
, unsigned int size
);
179 extern int erase_dataflash(unsigned long addr_dest
);