📄 nf.lst
字号:
C51 COMPILER V7.50 NF 09/20/2005 21:47:45 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE NF
OBJECT MODULE PLACED IN nf.obj
COMPILER INVOKED BY: e:\Keil\C51\BIN\C51.EXE lib_mem\nf_1x_512b\nf.c OPTIMIZE(7,SPEED) BROWSE INCDIR(.\modules\system;.\
-;.\;.\lib_refd) DEFINE(KEIL) DEBUG OBJECTEXTEND PRINT(.\nf.lst) OBJECT(nf.obj)
line level source
1 /*C**************************************************************************
2 * NAME: nf.c
3 *----------------------------------------------------------------------------
4 * Copyright (c) 2003 Atmel.
5 *----------------------------------------------------------------------------
6 * RELEASE: snd1c-refd-nf-4_0_3
7 * REVISION: 1.26
8 *----------------------------------------------------------------------------
9 * PURPOSE:
10 * This file contains the high level NF routines
11 *****************************************************************************/
12
13 /*_____ I N C L U D E S ____________________________________________________*/
14
15
16 #include "config.h" /* system configuration */
17 #include "board.h" /* board definition */
18 #include "lib_mcu\usb\usb_drv.h" /* usb driver definition */
19 #include "nf.h" /* NF definition */
20
21
22 /*_____ M A C R O S ________________________________________________________*/
23
24 #ifndef NF_CAPACITY_AUTO_DETECT
#error NF_CAPACITY_AUTO_DETECT must be defined in board.h
#endif
27
28 #if NF_CONFIG != NF_1X_512B
#error NF_CONFIG must be defined with NF_1X_512B in config.h
#endif
31
32 #ifndef NF_FULL_CHIP_ERASE
#error NF_FULL_CHIP_ERASE must be set to TRUE or FALSE in config.h
#endif
35
36 #ifndef MEM_RESERVED_SIZE
#error MEM_RESERVED_SIZE must be defined in config.h
#endif
39
40 /*_____ D E F I N I T I O N ________________________________________________*/
41
42 xdata Byte nf_send_cmd At(NF_CMD_LATCH_ENABLE_ADD); /* Command */
43 xdata Byte nf_send_add At(NF_ADD_LATCH_ENABLE_ADD); /* Address */
44 xdata Byte volatile nf_data At(NF_ADDRESS_CMD_DATA);/* Data */
45
46
47 /*_____ D E C L A R A T I O N ______________________________________________*/
48
49 extern data Uint32 gl_ptr_mem; /* memory data pointer */
50 extern pdata Byte gl_buffer[];
51 extern bit reserved_disk_space;
52
53 data Uint32 nf_current_physical_sector_addr; /* address of current phys. sect. */
54 data Uint32 gl_address; /* general address variable */
C51 COMPILER V7.50 NF 09/20/2005 21:47:45 PAGE 2
55 data Uint16 nf_look_up_table_block; /* lut address (block) */
56 data Byte nf_zone; /* current zone number */
57 data Byte nf_gl_buf_idx; /* idx for cache */
58 data Byte gl_buf_free_idx ; /* idx for cache for free blocks */
59 data Uint16 gl_cpt_page; /* internal page counter */
60
61 bdata bit nf_block_used; /* set when a block was used */
62 bdata bit nf_busy; /* nand flash busy flag */
63 bdata bit nf_lut_modified; /* LUT modified flag */
64 bdata bit nf_reserved_space = FALSE;
65
66 idata Uint16 nf_logical_block; /* current logical block */
67 idata Byte nf_gl_buf_idx_max; /* max index for updating lut */
68
69 xdata Byte nf_spare_block; /* number of free block */
70 xdata Uint16 nf_lut_block[NF_ZONE_MAX]; /* lut address / zone (block) */
71 xdata Uint16 nf_buf_free[24]; /* contain free physical block address */
72 xdata Uint16 nf_block_to_be_deleted; /* give the address of the next deleted block */
73 xdata Uint16 nf_block_min; /* first address block in the buffer */
74 xdata Uint16 nf_block_max; /* last address block in the buffer */
75 xdata Union16 nf_buf[NF_BUFFER_SIZE]; /* cache for write operation */
76 xdata Byte nf_old_zone; /* for zone change */
77 xdata Byte nf_lut_index[NF_ZONE_MAX]; /* give the index for updating LUT */
78 xdata Byte nf_spare_block_number[NF_ZONE_MAX]; /* number of free spare block in each zone */
79
80 extern idata Uint16 nf_redundant_logical_block_value;/* Logical block value in the redundant area */
81
82 #if (NF_CAPACITY_AUTO_DETECT == TRUE) /* If autodetect capacity nand flash is active */
83 xdata Byte nf_zone_max; /* nf_zone_max definition */
84 xdata Byte nf_device_type; /* nf_device_type definition */
85 bdata bit nf_4_cycle_address; /* nf_4_cycle_address definition */
86 #endif
87
88
89 xdata Uint32 nf_mem_size;
90 xdata Uint32 nf_reserved_space_start;
91 /*F**************************************************************************
92 * NAME: nf_read_spare_byte
93 *----------------------------------------------------------------------------
94 * PARAMS:
95 *
96 * return:
97 * OK : LUT construction complete
98 * KO : pb for LUT
99 *----------------------------------------------------------------------------
100 * PURPOSE:
101 * read spare data byte and construct the look up table.
102 *----------------------------------------------------------------------------
103 * EXAMPLE:
104 *----------------------------------------------------------------------------
105 * NOTE:
106 *----------------------------------------------------------------------------
107 * REQUIREMENTS:
108 *****************************************************************************/
109 bit nf_read_spare_byte(void)
110 {
111 1 Byte byte_5;
112 1 Byte byte_6;
113 1 Byte lut_is_present;
114 1 Uint16 block;
115 1 Uint16 j; /* counter */
116 1 Union16 block2;
C51 COMPILER V7.50 NF 09/20/2005 21:47:45 PAGE 3
117 1 bit block_valid;
118 1 xdata Uint16 last_physical_used_block[NF_ZONE_MAX]; /* Last physical block used */
119 1
120 1 #define half_page block_valid
121 1 #define temp_address gl_ptr_mem
122 1 #define i nf_zone
123 1 #define start gl_cpt_page
124 1 #define end nf_look_up_table_block
125 1 #define free_bloc_pos nf_logical_block
126 1
127 1 Nf_CS_ON();
128 1 Nf_wait_busy();
129 1 /* Global media initialization */
130 1 nf_block_min = 0xFFFF; /* Starting buffer value */
131 1 nf_gl_buf_idx_max = 0; /* Max index in the buffer */
132 1 nf_lut_modified = FALSE; /* Buffer change flag */
133 1 nf_gl_buf_idx = 0; /* Main buffer index */
134 1 gl_buf_free_idx = 0; /* Free physical buffer idx */
135 1 nf_old_zone = 0xFF; /* Previous zone number */
136 1 for (i = 0; i < NF_ZONE_MAX_CPT; i++)
137 1 {
138 2 nf_lut_index[i] = 0; /* LUT index */
139 2 }
140 1 lut_is_present = 0x00;
141 1
142 1 /***************************************************/
143 1 /* For each zone, this following lines : */
144 1 /* Search bad block */
145 1 /* Determine if a LUT is present */
146 1 /* Determine the last physical block */
147 1 /***************************************************/
148 1 gl_address = 0; /* Start from physical sector 0 */
149 1 for (i = 0; i < NF_ZONE_MAX_CPT; i++) /* for each zone */
150 1
151 1 {
152 2 nf_spare_block_number[i] = 23; /* Initialize the spare block table */
153 2 last_physical_used_block[i] = (Uint16)(i) << 10;/* Initialize the last used physical block value */
154 2
155 2 for (j = NF_BLOCK_PER_ZONE; j != 0; j--)/* for each block */
156 2 {
157 3 Nf_read_open_C_area(gl_address, 0x05);
158 3 if ( Nf_rd_byte() != 0xFF ) /* block status data : valid/invalid block */
159 3 {
160 4 nf_spare_block_number[i]--; /* Defect block */
161 4 }
162 3 else /* Block is valid */
163 3 {
164 4 /* Determine if the block is a specific block */
165 4 byte_6 = Nf_rd_byte();
166 4 if ((byte_6 == 0x00) || /* 0x00 = specific block */
167 4 ((byte_6 != 0xFF) && ((byte_6 & 0xF8) != 0x10) && /* Value in redundant spare area not correct
- */
168 4 (byte_6 != 0xE8)) /* Don't care about LUT block */
169 4 )
170 4 {
171 5 nf_spare_block_number[i]--; /* specific or invalid block */
172 5 if (nf_spare_block_number[i] < 4)
173 5 return KO;
174 5 }
175 4 else
176 4 {
177 5 /* Determine if the block is the look up table */
C51 COMPILER V7.50 NF 09/20/2005 21:47:45 PAGE 4
178 5 if (byte_6 == 0xE8) /* look up table ? */
179 5 {
180 6 lut_is_present |= (0x01) << i;
181 6 nf_lut_block[i] = gl_address >> 5;
182 6
183 6 }
184 5 /* Determine the last physical used block */
185 5 if ((byte_6 & 0xF8) == 0x10) /* Used block */
186 5 {
187 6 last_physical_used_block[i] = gl_address >> 5;
188 6 }
189 5 }
190 4 }
191 3 gl_address += 32;
192 3 }
193 2 }
194 1
195 1
196 1 for (i = 0; i < NF_ZONE_MAX_CPT; i++)
197 1 { /* Determine the index for each correct lut */
198 2 if ((lut_is_present & (0x01 << i)))
199 2 {
200 3 gl_address = (Uint32)(nf_lut_block[i]) << 5;
201 3 do
202 3 {
203 4 Nf_wait_busy();
204 4 Nf_read_open_C_area(gl_address, 0x06);
205 4 nf_lut_index[i]++;
206 4 gl_address+=4;
207 4 }
208 3 while (Nf_rd_byte() == 0xE8);
209 3 nf_lut_index[i]-=2;
210 3 gl_address = gl_address - 8;
211 3 Nf_read_open_C_area(gl_address, 0x00);
212 3 if (Nf_rd_byte() != 0xFF) /* LUT has been modified */
213 3 {
214 4 nf_block_erase(gl_address);
215 4 lut_is_present &= ~((0x01) << i); /* Reset bit */
216 4 nf_lut_index[i] = 0;
217 4 }
218 3 }
219 2 }
220 1 /*****************************************************************/
221 1 /* Find free physical block for LUT for each zone */
222 1 /*****************************************************************/
223 1 for (i = 0; i < NF_ZONE_MAX_CPT; i++)
224 1 {
225 2 if (!(lut_is_present & (0x01 << i)))
226 2 {
227 3 block = last_physical_used_block[i];
228 3 start = (Uint16)(i) << 10; /* starting value for each zone */
229 3 j = 0;
230 3 if (block == start) /* starting block for scan */
231 3 {
232 4 block = start + 1023;
233 4 }
234 3 block_valid = FALSE; /* init flag block valid */
235 3 Nf_wait_busy();
236 3 do
237 3 {
238 4 gl_address = (Uint32)(block) << 5;
239 4 Nf_read_open_C_area(gl_address, 0x05);
C51 COMPILER V7.50 NF 09/20/2005 21:47:45 PAGE 5
240 4 byte_5 = Nf_rd_byte();
241 4 byte_6 = Nf_rd_byte();
242 4
243 4 if ((byte_5 == 0xFF) && (byte_6 == 0xFF)) /* not assigned and valid block */
244 4 {
245 5 block_valid = TRUE; /* find a correct block */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -