📄 nf_drv.lst
字号:
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE NF_DRV
OBJECT MODULE PLACED IN nf_drv.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lib_mem\nf_1x_2kb\nf_drv.c OPTIMIZE(7,SPEED) BROWSE INCDIR(.\modules\system
-;.\;.\;.\lib_refd) DEFINE(KEIL) DEBUG OBJECTEXTEND PRINT(.\nf_drv.lst) OBJECT(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.7
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 low driver definition */
18
19
20 /*_____ M A C R O S ________________________________________________________*/
21
22 #if NF_CONFIG != NF_1X_2KB
#error NF_CONFIG must be defined with NF_1X_2KB in config.h
#endif
25
26 #ifndef NF_CAPACITY_AUTO_DETECT
#error NF_CAPACITY_AUTO_DETECT must be defined in board.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 /*_____ D E F I N I T I O N ________________________________________________*/
38
39
40 /*_____ D E C L A R A T I O N ______________________________________________*/
41
42 extern xdata Byte volatile nf_data; /* Data */
43 extern xdata Byte nf_send_cmd; /* Command */
44 extern xdata Byte nf_send_add; /* Address */
45
46 extern pdata Byte gl_buffer[]; /* global buffer of 256 bytes */
47 extern data Uint32 gl_ptr_mem; /* memory data pointer */
48 extern data Byte nf_zone;
49
50 extern data Uint32 gl_address; /* general address variable */
51 extern data Uint16 nf_look_up_table_block; /* Look up table block address */
52 extern data Byte gl_buf_free_idx ;
53 extern data Byte nf_gl_buf_idx;
54 extern data Uint32 nf_current_physical_sector_addr; /* give the address of the current sector */
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 2
55 extern data Uint16 gl_cpt_page; /* internal page counter (byte access) */
56
57 extern idata Byte nf_gl_buf_idx_max; /* maximum position index */
58 extern idata Uint16 nf_logical_block; /* Logical block value (0 < x <1023) */
59
60 extern bdata bit nf_busy; /* general busy flag */
61
62 extern xdata Uint32 nf_disk_size; /* Size of the disk in sector - 1 */
63 extern xdata Uint16 nf_buf_free[24]; /* free block buffer */
64 extern xdata Uint16 nf_block_to_be_deleted; /* address of block to be deleted */
65 extern xdata Uint16 nf_block_min; /* position of first block in the buffer */
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_number[NF_ZONE_MAX];/* Number of free spare block in each zone */
69 extern xdata Byte nf_lut_index[NF_ZONE_MAX]; /* Index of the last valid LUT */
70 extern xdata Byte nf_spare_block; /* Number of free block */
71 idata Uint16 nf_redundant_logical_block_value;/* Logical block value in the redundant area*/
72 extern xdata Uint32 nf_reserved_space_start;
73
74 #if (NF_CAPACITY_AUTO_DETECT == TRUE) /* If autodetect capacity nand flash is active */
75 extern xdata Byte nf_zone_max; /* nf_zone_max definition */
76 extern xdata Byte nf_device_type; /* nf_device_type definition */
77 extern bdata bit NF_5_CYCLE_ADDRESS_BIT; /* NF_5_CYCLE_ADDRESS_BIT definition */
78 #endif
79
80
81 /*F**************************************************************************
82 * NAME: nf_check_status
83 *----------------------------------------------------------------------------
84 * PARAMS:
85 *
86 * return:
87 * NF status
88 *----------------------------------------------------------------------------
89 * PURPOSE:
90 * Check the status of the device after a program or an erase operation
91 *----------------------------------------------------------------------------
92 * EXAMPLE:
93 *----------------------------------------------------------------------------
94 * NOTE:
95 *----------------------------------------------------------------------------
96 * REQUIREMENTS:
97 * ram/xram:
98 * cycle:
99 * stack:
100 * code:
101
102 *****************************************************************************/
103 bit nf_check_status (void)
104 {
105 1 Nf_wait_busy();
106 1 Nf_send_command(NF_READ_STATUS_CMD); /* Status Type Command */
107 1 if ( (Nf_rd_byte() & 0x01) == 0x00)
108 1 {
109 2 return OK;
110 2 }
111 1 else
112 1 {
113 2 return KO;
114 2 }
115 1 }
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 3
116
117 /*F**************************************************************************
118 * NAME: nf_calc_logical_block
119 *----------------------------------------------------------------------------
120 * PARAMS:
121 *
122 * return:
123 *----------------------------------------------------------------------------
124 * PURPOSE:
125 * Calculate the logical block value (used in spare data area)
126 *----------------------------------------------------------------------------
127 * EXAMPLE:
128 *----------------------------------------------------------------------------
129 * NOTE:
130 *----------------------------------------------------------------------------
131 * REQUIREMENTS:
132 * ram/xram:
133 * cycle:
134 * stack:
135 * code:
136 *****************************************************************************/
137 void nf_calc_logical_block (void)
138 {
139 1 volatile Byte dummy;
140 1 bdata bit parity_bit;
141 1
142 1 nf_redundant_logical_block_value = (nf_logical_block << 1) + 0x1000;
143 1 /* Parity bit calculation */
144 1 dummy = nf_redundant_logical_block_value;
145 1 parity_bit = P;
146 1 dummy = ((Byte*)&nf_redundant_logical_block_value)[0];
147 1 if (P) parity_bit = ~parity_bit;
148 1
149 1 if (parity_bit)
150 1 nf_redundant_logical_block_value++;
151 1 }
152
153
154 /*F**************************************************************************
155 * NAME: nf_update_spare_data
156 *----------------------------------------------------------------------------
157 * PARAMS:
158 *
159 * return:
160 *----------------------------------------------------------------------------
161 * PURPOSE:
162 * Update the value of the logical block on the spare data area
163 *----------------------------------------------------------------------------
164 * EXAMPLE:
165 *----------------------------------------------------------------------------
166 * NOTE:
167 *----------------------------------------------------------------------------
168 * REQUIREMENTS:
169 * ram/xram:
170 * cycle:
171 * stack:
172 * code:
173 *****************************************************************************/
174 void nf_update_spare_data (void)
175 {
176 1 Byte temp;
177 1 Nf_wr_byte(0xFF);
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 4
178 1 Nf_wr_byte(0xFF);
179 1 Nf_wr_byte(0xFF);
180 1 Nf_wr_byte(0xFF);
181 1 Nf_wr_byte(0xFF);
182 1 Nf_wr_byte(0xFF);
183 1 Nf_wr_byte(nf_redundant_logical_block_value >> 8);
184 1 Nf_wr_byte(nf_redundant_logical_block_value );
185 1 Nf_wr_byte(0xFF);
186 1 Nf_wr_byte(0xFF);
187 1 Nf_wr_byte(0xFF);
188 1 Nf_wr_byte(nf_redundant_logical_block_value >> 8 );
189 1 Nf_wr_byte(nf_redundant_logical_block_value );
190 1 Nf_wr_byte(0xFF);
191 1 Nf_wr_byte(0xFF);
192 1 Nf_wr_byte(0xFF);
193 1 if (gl_cpt_page != 0)
194 1 {
195 2 temp = (gl_cpt_page) >> 9;
196 2 temp = (0x01) << temp;
197 2 temp = ~temp;
198 2 Nf_wr_byte(temp);
199 2 }
200 1 else
201 1 {
202 2 Nf_wr_byte(0xFF);
203 2 }
204 1
205 1 }
206
207
208
209 /*F**************************************************************************
210 * NAME: nf_init_spare
211 *----------------------------------------------------------------------------
212 * PARAMS:
213 *
214 * return:
215 *----------------------------------------------------------------------------
216 * PURPOSE:
217 * Initialize logical value in redundant data when a block is opened for
218 * the first time and the sector inside the block is not 0.
219 *----------------------------------------------------------------------------
220 * EXAMPLE:
221 *----------------------------------------------------------------------------
222 * NOTE:
223 *----------------------------------------------------------------------------
224 * REQUIREMENTS:
225 * ram/xram:
226 * cycle:
227 * stack:
228 * code:
229 *****************************************************************************/
230 void nf_init_spare (void)
231 {
232 1 Byte j;
233 1
234 1 /* Calculate the current physical sector */
235 1 for (j = (((Byte*)&gl_ptr_mem)[3] & 0x3F); j != 0 ; j--)
236 1 {
237 2 Nf_wait_busy();
238 2 Nf_write_open_spare_area (nf_current_physical_sector_addr, 0x00);
239 2 nf_update_spare_data (); /* Update spare data */
C51 COMPILER V7.06 NF_DRV 05/05/2005 12:12:03 PAGE 5
240 2 Nf_send_command (NF_PAGE_PROGRAM_CMD); /* Send program command */
241 2 ((Byte*)&nf_current_physical_sector_addr)[3]++;
242 2 }
243 1 }
244
245
246 /*F**************************************************************************
247 * NAME: nf_copy_block_head
248 *----------------------------------------------------------------------------
249 * PARAMS:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -