?? nf_drv.lst
字號(hào):
C51 COMPILER V7.00 NF_DRV 04/28/2004 09:31:55 PAGE 1
C51 COMPILER V7.00, COMPILATION OF MODULE NF_DRV
OBJECT MODULE PLACED IN C:\Documents and Settings\lvxc\桌面\AA\nf_drv.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lib_mem\nf_1x_512b\nf_drv.c OPTIMIZE(7,SPEED) BROWSE INCDIR(.\modules\syste
-m;.\;.\;.\lib_refd) DEFINE(KEIL) DEBUG OBJECTEXTEND PRINT(.\nf_drv.lst) OBJECT(C:\Documents and Settings\lvxc\桌面\AA\nf
-_drv.obj)
stmt level source
1 /*C**************************************************************************
2 * NAME: nf_drv.c
3 *----------------------------------------------------------------------------
4 * Copyright (c) 2003 Atmel.
5 *----------------------------------------------------------------------------
6 * RELEASE: snd1c-refd-nf-4_0_3
7 * REVISION: 1.17
8 *----------------------------------------------------------------------------
9 * PURPOSE:
10 * This file contains the NF driver routines
11 *****************************************************************************/
12
13 /*_____ I N C L U D E S ____________________________________________________*/
14
15 #include "config.h" /* system configuration */
16 #include "board.h" /* board definition */
17 #include "nf_drv.h" /* nf driver definition */
18
19
20 /*_____ M A C R O S ________________________________________________________*/
21
22 #ifndef NF_CAPACITY_AUTO_DETECT
#error NF_CAPACITY_AUTO_DETECT must be defined in board.h
#endif
25
26 #if NF_CONFIG != NF_1X_512B
#error NF_CONFIG must be defined with NF_1X_512B in config.h
#endif
29
30 #ifndef NF_FULL_CHIP_ERASE
#error NF_FULL_CHIP_ERASE must be set to TRUE or FALSE in config.h
#endif
33
34 #ifndef MEM_RESERVED_SIZE
#error MEM_RESERVED_SIZE must be defined in config.h
#endif
37
38 /*_____ D E F I N I T I O N ________________________________________________*/
39
40
41 /*_____ D E C L A R A T I O N ______________________________________________*/
42
43 extern pdata Byte gl_buffer[]; /* global buffer of 256 bytes */
44 extern xdata Byte nf_send_cmd; /* Command */
45 extern xdata Byte nf_send_add; /* Address */
46 extern xdata Byte volatile nf_data; /* Data */
47
48 extern data Uint32 gl_ptr_mem; /* memory data pointer */
49 extern data Uint32 gl_address; /* general address variable */
50 extern data Uint16 nf_look_up_table_block; /* Look up table block address */
51 extern data Byte gl_buf_free_idx ;
52 extern data Byte nf_gl_buf_idx;
53 extern data Uint32 nf_current_physical_sector_addr; /* give the address of the current sector */
C51 COMPILER V7.00 NF_DRV 04/28/2004 09:31:55 PAGE 2
54 extern data Byte nf_zone;
55
56
57 idata Uint16 nf_redundant_logical_block_value;/* Logical block value in the redundant area */
58 extern idata Byte nf_gl_buf_idx_max;
59 extern idata Uint16 nf_logical_block;
60
61 extern xdata Byte nf_spare_block_number[NF_ZONE_MAX];/* Number of free spare block in each zone */
62 extern xdata Byte nf_lut_index[NF_ZONE_MAX];
63 extern xdata Uint16 nf_buf_free[24];
64 extern xdata Uint16 nf_block_to_be_deleted;
65 extern xdata Uint16 nf_block_min;
66 extern xdata Uint16 nf_lut_block[NF_ZONE_MAX]; /* LUT address in block value */
67 extern xdata Union16 nf_buf[NF_BUFFER_SIZE]; /* Buffer for write operation: contains physical blo
-ck address */
68 extern xdata Byte nf_spare_block;
69 extern xdata Uint32 nf_reserved_space_start;
70
71 #if (NF_CAPACITY_AUTO_DETECT == TRUE) /* If autodetect capacity nand flash is acti
-ve */
72 extern xdata Byte nf_zone_max; /* nf_zone_max definition */
73 extern xdata Byte nf_device_type; /* nf_device_type definition */
74 extern bdata bit nf_4_cycle_address; /* nf_4_cycle_address definition */
75 #endif
76
77
78 /*F**************************************************************************
79 * NAME: nf_check_status
80 *----------------------------------------------------------------------------
81 * PARAMS:
82 *
83 * return:
84 * NF status
85 *----------------------------------------------------------------------------
86 * PURPOSE:
87 * Check the status of the device after a program or an erase operation
88 *----------------------------------------------------------------------------
89 * EXAMPLE:
90 *----------------------------------------------------------------------------
91 * NOTE:
92 *----------------------------------------------------------------------------
93 * REQUIREMENTS:
94 * ram/xram:
95 * cycle:
96 * stack:
97 * code:
98
99 *****************************************************************************/
100 bit nf_check_status (void)
101 {
102 1 Nf_wait_busy();
103 1 /* Status Type Command */
104 1 Nf_send_command(NF_READ_STATUS_CMD);
105 1
106 1 if ( (Nf_rd_byte() & 0x01) == 0x00)
107 1 {
108 2 return OK;
109 2 }
110 1 else
111 1 {
112 2 return KO;
113 2 }
C51 COMPILER V7.00 NF_DRV 04/28/2004 09:31:55 PAGE 3
114 1 }
115
116 /*F**************************************************************************
117 * NAME: nf_calc_logical_block
118 *----------------------------------------------------------------------------
119 * PARAMS:
120 *
121 * return:
122 *----------------------------------------------------------------------------
123 * PURPOSE:
124 * Calculate the logical block value (used in spare data area)
125 *----------------------------------------------------------------------------
126 * EXAMPLE:
127 *----------------------------------------------------------------------------
128 * NOTE:
129 *----------------------------------------------------------------------------
130 * REQUIREMENTS:
131 * ram/xram:
132 * cycle:
133 * stack:
134 * code:
135 *****************************************************************************/
136 void nf_calc_logical_block (void)
137 {
138 1 volatile Byte dummy;
139 1 bdata bit parity_bit;
140 1
141 1 nf_redundant_logical_block_value = (nf_logical_block << 1) + 0x1000;
142 1 /* Parity bit calculation */
143 1 dummy = nf_redundant_logical_block_value;
144 1 parity_bit = P;
145 1 dummy = ((Byte*)&nf_redundant_logical_block_value)[0];
146 1 if (P) parity_bit = ~parity_bit;
147 1
148 1 if (parity_bit)
149 1 nf_redundant_logical_block_value++;
150 1 }
151
152
153 /*F**************************************************************************
154 * NAME: nf_update_spare_data
155 *----------------------------------------------------------------------------
156 * PARAMS:
157 *
158 * return:
159 *----------------------------------------------------------------------------
160 * PURPOSE:
161 * Update the value of the logical block on the spare data area
162 *----------------------------------------------------------------------------
163 * EXAMPLE:
164 *----------------------------------------------------------------------------
165 * NOTE:
166 *----------------------------------------------------------------------------
167 * REQUIREMENTS:
168 * ram/xram:
169 * cycle:
170 * stack:
171 * code:
172 *****************************************************************************/
173 void nf_update_spare_data (void)
174 {
175 1 Nf_wr_byte(0xFF);
C51 COMPILER V7.00 NF_DRV 04/28/2004 09:31:55 PAGE 4
176 1 Nf_wr_byte(0xFF);
177 1 Nf_wr_byte(0xFF);
178 1 Nf_wr_byte(0xFF);
179 1 Nf_wr_byte(0xFF);
180 1 Nf_wr_byte(0xFF);
181 1 Nf_wr_byte(nf_redundant_logical_block_value >> 8);
182 1 Nf_wr_byte(nf_redundant_logical_block_value );
183 1 Nf_wr_byte(0xFF);
184 1 Nf_wr_byte(0xFF);
185 1 Nf_wr_byte(0xFF);
186 1 Nf_wr_byte(nf_redundant_logical_block_value >> 8 );
187 1 Nf_wr_byte(nf_redundant_logical_block_value );
188 1 Nf_wr_byte(0xFF);
189 1 Nf_wr_byte(0xFF);
190 1 Nf_wr_byte(0xFF);
191 1 }
192
193
194 /*F**************************************************************************
195 * NAME: nf_init_spare
196 *----------------------------------------------------------------------------
197 * PARAMS:
198 *
199 * return:
200 *----------------------------------------------------------------------------
201 * PURPOSE:
202 * Initialize logical value in redundant data when a block is opened for
203 * the first time and the sector inside the block is not 0.
204 *----------------------------------------------------------------------------
205 * EXAMPLE:
206 *----------------------------------------------------------------------------
207 * NOTE:
208 *----------------------------------------------------------------------------
209 * REQUIREMENTS:
210 * ram/xram:
211 * cycle:
212 * stack:
213 * code:
214 *****************************************************************************/
215 void nf_init_spare (void)
216 {
217 1 Byte j;
218 1
219 1 for (j = (((Byte*)&gl_ptr_mem)[3] & NF_BLOCK_MASK); j != 0 ; j--)
220 1 {
221 2 Nf_wait_busy();
222 2 /* Write open on spare data area */
223 2 Nf_write_open_C_area(nf_current_physical_sector_addr, 0x00);
224 2 /* Update spare data */
225 2 nf_update_spare_data();
226 2
227 2 /* Send program command */
228 2 Nf_send_command (NF_PAGE_PROGRAM_CMD);
229 2 ((Byte*)&nf_current_physical_sector_addr)[3]++;
230 2 }
231 1 }
232
233
234 /*F**************************************************************************
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -