00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef _NFC_DRV_H_
00045 #define _NFC_DRV_H_
00046
00047 #undef _GLOBEXT_
00048 #if (defined _nfc_drv_c_)
00049 # define _GLOBEXT_
00050 #else
00051 # define _GLOBEXT_ extern
00052 #endif
00053
00054
00055 #define CLK_DFC_NFC_40MHz 0
00056 #define CLK_DFC_NFC_30MHz 0
00057 #define CLK_DFC_NFC_24MHz 0
00058
00059
00063 #define NFC_ACT_NOP 0
00064 #define NFC_ACT_DEV_SELECT 1
00065 #define NFC_ACT_READ 2
00066 #define NFC_ACT_WRITE 3
00067 #define NFC_ACT_ASSERT_CE 4
00068 # define NFC_EXT_CELOW 1
00069 # define NFC_EXT_NOP 0
00070 #define NFC_ACT_STOP 5
00071 #define NFC_ACT_ADC_EXT 6
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 #define NF_ADD_LATCH_ENABLE_ADD 0x3A00 // Address Latch Enable Address
00087 #define NF_CMD_LATCH_ENABLE_ADD 0x3900 // Command Latch Enable Address
00088 #define NF_ADDRESS_CMD_DATA 0x3800 // Command / Data Address register
00089
00090
00091
00092 # define Nf_rd_byte() (nf_data)
00093 # define Nf_wr_byte(b) (nf_data = b)
00094 #if (NF_CLE_ALE_MANUAL == ENABLED)
00095 # define Nf_send_command(command) {Nandflash_CLE_select(); nf_send_cmd = command; Nandflash_CLE_unselect(); }
00096 # define Nf_send_address(address) {Nandflash_ALE_select(); nf_send_add = address; Nandflash_ALE_unselect(); }
00097 #else
00098 # define Nf_send_command(command) (nf_send_cmd = command)
00099 # define Nf_send_address(address) (nf_send_add = address)
00100 #endif
00101
00102
00103 #define Mcu_set_sfr_page_nfc()
00104 #define Nfc_set_cmd(command) Nf_send_command(command)
00105 #define Nfc_rd_status() Nf_rd_byte() // once the STATUS cmd has been sent, all read commands will read the status
00106 #define Nfc_rd_data() Nf_rd_byte()
00107 #define Nfc_rd_data_fetch_next() Nf_rd_byte()
00108 #define Nfc_wr_data(dat) Nf_wr_byte(dat)
00109 #define Nfc_set_adc(adr) Nf_send_address(adr)
00110 #define Nfc_set_adr(adr) Nf_send_address(adr)
00111 #define Nfc_unprotect_all_flash() // assumes that memories are not write protected
00112
00113 #define Nfc_action(a,b) { if( a == NFC_ACT_DEV_SELECT ) nfc_select_dev(b); }
00114 #define nfc_init(a,b) nf_XMCR_enable()
00115 #define Nfc_get_ecc() (0xFF)
00116 #define Nfc_init_ecc()
00117
00118
00119
00129 #define Nfc_open_page_read( page_addr, byte_addr) \
00130 if ( Is_nf_512() ) \
00131 { \
00132 if ( (byte_addr)<256 ) \
00133 { \
00134 Nfc_set_cmd(NF_READ_A_AREA_CMD); \
00135 Nfc_set_adc( LSB( byte_addr) ); \
00136 Nfc_set_adr( LSB0(page_addr) ); \
00137 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_CELOW); \
00138 Nfc_set_adr( LSB1(page_addr) ); \
00139 if ( 3==G_N_ROW_CYCLES ) \
00140 { \
00141 Nfc_set_adr( MSB1(page_addr) ); \
00142 } \
00143 nfc_wait_busy(); \
00144 if(G_CE_TOGGLE) \
00145 { Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_NOP);} \
00146 } \
00147 else if ( (byte_addr)<512 ) \
00148 { \
00149 Nfc_set_cmd(NF_READ_B_AREA_CMD); \
00150 Nfc_set_adc( LSB( byte_addr) ); \
00151 Nfc_action(NFC_ACT_ADC_EXT, 1); \
00152 Nfc_set_adr( LSB0(page_addr) ); \
00153 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_CELOW); \
00154 Nfc_set_adr( LSB1(page_addr) ); \
00155 if ( 3==G_N_ROW_CYCLES ) \
00156 { \
00157 Nfc_set_adr( MSB1(page_addr) ); \
00158 } \
00159 nfc_wait_busy(); \
00160 if(G_CE_TOGGLE) \
00161 { Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_NOP);} \
00162 } \
00163 else \
00164 { \
00165 Nfc_set_cmd(NF_READ_C_AREA_CMD); \
00166 Nfc_set_adc( LSB( byte_addr) ); \
00167 Nfc_action(NFC_ACT_ADC_EXT, 2); \
00168 Nfc_set_adr( LSB0(page_addr) ); \
00169 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_CELOW); \
00170 Nfc_set_adr( LSB1(page_addr) ); \
00171 if ( 3==G_N_ROW_CYCLES ) \
00172 { \
00173 Nfc_set_adr( MSB1(page_addr) ); \
00174 } \
00175 nfc_wait_busy(); \
00176 if(G_CE_TOGGLE) \
00177 { Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_NOP);} \
00178 } \
00179 } \
00180 if ( Is_nf_2k() ) \
00181 { \
00182 Nfc_set_cmd(NF_READ_CMD); \
00183 Nfc_set_adc( LSB( byte_addr) ); \
00184 Nfc_set_adc( MSB( byte_addr) ); \
00185 Nfc_set_adr( LSB0(page_addr) ); \
00186 Nfc_set_adr( LSB1(page_addr) ); \
00187 if ( 3==G_N_ROW_CYCLES ) \
00188 { \
00189 Nfc_set_adr( MSB1(page_addr) ); \
00190 } \
00191 Nfc_set_cmd(NF_READ_CMD2); \
00192 nfc_wait_busy(); \
00193 } \
00194 Nfc_set_cmd(NF_READ_CMD);
00195
00196
00197
00198
00208 #define Nfc_open_page_write( page_addr, byte_addr) \
00209 Nfc_wait_cache_busy(); \
00210 Nfc_unprotect_all_flash(); \
00211 \
00212 if ( Is_nf_512() ) \
00213 { \
00214 if ( (byte_addr)<256 ) \
00215 { \
00216 Nfc_set_cmd(NF_READ_A_AREA_CMD); \
00217 Nfc_set_cmd(NF_SEQUENTIAL_DATA_INPUT_CMD); \
00218 Nfc_set_adc( LSB( byte_addr) ); \
00219 Nfc_set_adr( LSB0(page_addr) ); \
00220 Nfc_set_adr( LSB1(page_addr) ); \
00221 if ( 3==G_N_ROW_CYCLES ) \
00222 { \
00223 Nfc_set_adr( MSB1(page_addr) ); \
00224 } \
00225 } \
00226 else if ( (byte_addr)<512 ) \
00227 { \
00228 Nfc_set_cmd(NF_READ_B_AREA_CMD); \
00229 Nfc_set_cmd(NF_SEQUENTIAL_DATA_INPUT_CMD); \
00230 Nfc_set_adc( LSB( byte_addr) ); \
00231 Nfc_action(NFC_ACT_ADC_EXT, 1); \
00232 Nfc_set_adr( LSB0(page_addr) ); \
00233 Nfc_set_adr( LSB1(page_addr) ); \
00234 if ( 3==G_N_ROW_CYCLES ) \
00235 { \
00236 Nfc_set_adr( MSB1(page_addr) ); \
00237 } \
00238 } \
00239 else \
00240 { \
00241 Nfc_set_cmd(NF_READ_C_AREA_CMD); \
00242 Nfc_set_cmd(NF_SEQUENTIAL_DATA_INPUT_CMD); \
00243 Nfc_set_adc( LSB( byte_addr) ); \
00244 Nfc_action(NFC_ACT_ADC_EXT, 2); \
00245 Nfc_set_adr( LSB0(page_addr) ); \
00246 Nfc_set_adr( LSB1(page_addr) ); \
00247 if ( 3==G_N_ROW_CYCLES ) \
00248 { \
00249 Nfc_set_adr( MSB1(page_addr) ); \
00250 } \
00251 } \
00252 } \
00253 if ( Is_nf_2k() ) \
00254 { \
00255 Nfc_set_cmd(NF_SEQUENTIAL_DATA_INPUT_CMD); \
00256 Nfc_set_adc( LSB( byte_addr) ); \
00257 Nfc_set_adc( MSB( byte_addr) ); \
00258 Nfc_set_adr( LSB0(page_addr) ); \
00259 Nfc_set_adr( LSB1(page_addr) ); \
00260 if ( 3==G_N_ROW_CYCLES ) \
00261 { \
00262 Nfc_set_adr( MSB1(page_addr) ); \
00263 } \
00264 }
00265
00266
00267
00268
00269
00270
00271 #define NF_MAX_DEVICES 2
00274
00275 #define NF_MAX_RB_TIMEOUT 0xFF
00276
00277
00281 #define NF_READ_A_AREA_CMD 0x00
00282 #define NF_READ_B_AREA_CMD 0x01
00283 #define NF_READ_C_AREA_CMD 0x50
00284
00285 #define NF_READ_CMD 0x00
00286 #define NF_READ_CMD2 0x30
00287 #define NF_RANDOM_READ_CMD_C1 0x05
00288 #define NF_RANDOM_READ_CMD_C2 0xE0
00289
00290 #define NF_READ_ID_CMD 0x90
00291 #define NF_READ_ID2_CMD 0x91
00292
00293 #define NF_RESET_CMD 0xff
00294
00295 #define NF_SEQUENTIAL_DATA_INPUT_CMD 0x80
00296 #define NF_PAGE_PROGRAM_CMD 0x10
00297
00298 #define NF_RANDOM_DATA_INPUT_CMD 0x85
00299 #define NF_COPY_BACK_CMD 0x35
00300 #define NF_CACHE_PROGRAM_CMD 0x15
00301
00302 #define NF_BLOCK_ERASE_CMD 0x60
00303 #define NF_BLOCK_ERASE_CONFIRM_CMD 0xD0
00304
00305 #define NF_READ_STATUS_CMD 0x70
00306
00307
00308
00309
00313 #define NF_MASK_STATUS_FAIL (1<<0)
00314 #define NF_MASK_STATUS_READY (1<<6)
00315 #define NF_MASK_STATUS_T_RDY_2KB (1<<5)
00316 #define NF_MASK_STATUS_T_RDY_512B (1<<6)
00317
00318
00319
00320
00323 #define Nfc_wait_cache_busy() \
00324 { \
00325 register int Reg; \
00326 Nfc_set_cmd(NF_READ_STATUS_CMD); \
00327 Reg = Nfc_rd_status(); \
00328 while( (Nfc_rd_status() & NF_MASK_STATUS_READY)==0 ); \
00329 while( (Nfc_rd_status() & NF_MASK_STATUS_READY)==0 ); \
00330 }
00331
00332 #define SIZE_PAGE_BYTE ((U16)1<<G_SHIFT_PAGE_BYTE)
00333 #define SIZE_SECTOR_BYTE ((U16)1<<S_SHIFT_SECTOR_BYTE)
00334 #define SIZE_BLOCK_PAGE ((U8)1<<G_SHIFT_BLOCK_PAGE)
00335 #define SIZE_PAGE_SECTOR ((U8)1<<(G_SHIFT_PAGE_BYTE - S_SHIFT_SECTOR_BYTE))
00336
00337
00338
00339
00340
00341 #define NFC_SPARE_OFST_1_BLK_ID 1
00342 #define NFC_BLK_ID_SYSTEM 0x39 // System block (Font, screen, firmware, ...)
00343 #define NFC_BLK_ID_SUBLUT 0xE8 // sub-LUT block
00344 #define NFC_BLK_ID_RCV 0x72 // Recovery block
00345 #define NFC_BLK_ID_FBB 0xB4 // Free-blocks block
00346 #define NFC_BLK_ID_DATA 0xFF // Data block (mass storage). Also the default value after an erase
00347 #define NFC_BLK_ID_QUARANTINE 0x8D // Block which encountered an ECC error not recoverable. Not yet bad...
00348
00349 #define NFC_SPARE_OFST_2_BYTE_2 2
00350 #define NFC_SPARE_OFST_3_BYTE_3 3 // NFC_BLK_ID_DATA: used as 'data valid'
00351 #define NFC_OFST_3_DATA_SRC 0x00 // Identify a source block (recovery)
00352 #define NFC_OFST_3_DATA_DST 0xFF // Identify a recipient block (recovery)
00353
00354 #define NFC_SPARE_OFST_4_BYTE_4 4
00355 #define NFC_OFST_4_FBB_DRIVER_RELEASE 0x01 // Current NF release. When a new firmware implies that LUT and FBB must be rebuild, just increment this number.
00356 #define NFC_SPARE_DATA_VALID 0xFF
00357 #define NFC_SPARE_DATA_INVALID 0
00358 #define NFC_SPARE_OFST_EXPORT 11
00359
00360 #define NFC_SPARE_OFST_6_LBA 6 // and 7
00361 #define NFC_OFST_6_FBB_VALID 0xFF
00362 #define NFC_OFST_6_FBB_INVALID 0
00363
00364 #define NFC_SPARE_OFST_ECC2 8 // and 9, 10
00365 #define NFC_SPARE_OFST_ECC1 13 // and 14, 15
00366
00367 #if( NF_BAD_CONFIG==(FALSE) )
00368 # if (NF_GENERIC_DRIVER==TRUE) || (NF_AUTO_DETECT_2KB==TRUE) || (NF_AUTO_DETECT_512B==TRUE)
00369 _GLOBEXT_ _MEM_TYPE_SLOW_ U8 g_n_zones ;
00370 _GLOBEXT_ _MEM_TYPE_SLOW_ U16 g_n_blocks ;
00371 _GLOBEXT_ _MEM_TYPE_FAST_ U8 g_n_row_cycles ;
00372 _GLOBEXT_ _MEM_TYPE_SLOW_ U8 g_copy_back_cont ;
00373 _GLOBEXT_ _MEM_TYPE_SLOW_ U8 g_copy_back_discont;
00374 _GLOBEXT_ Bool g_cache_program ;
00375 _GLOBEXT_ Bool g_ce_toggle ;
00376 _GLOBEXT_ _MEM_TYPE_SLOW_ U8 g_clock_dfc_nfc ;
00377 _GLOBEXT_ _MEM_TYPE_SLOW_ U8 g_dev_maker ;
00378 _GLOBEXT_ _MEM_TYPE_SLOW_ U8 g_dev_id ;
00379 # define G_N_ZONES g_n_zones
00380 # define G_N_BLOCKS g_n_blocks
00381 # define G_N_ROW_CYCLES g_n_row_cycles
00382 # define G_COPY_BACK_CONT g_copy_back_cont
00383 # define G_COPY_BACK_DISCONT g_copy_back_discont
00384 # define G_CACHE_PROG g_cache_program
00385 # define G_CE_TOGGLE g_ce_toggle
00386 # define G_CLK_DFC_NFC g_clock_dfc_nfc
00387 # define G_DEV_MAKER g_dev_maker
00388 # define G_DEV_ID g_dev_id
00389 # else
00390 # define G_N_ZONES (NF_N_ZONES)
00391 # define G_N_BLOCKS (NF_N_BLOCKS)
00392 # define G_N_ROW_CYCLES (NF_N_ROW_CYCLES)
00393 # define G_COPY_BACK_CONT (NF_COPYBACK_CONT)
00394 # define G_COPY_BACK_DISCONT (NF_COPYBACK_DISCONT)
00395 # define G_CACHE_PROG (NF_CACHE_PROGRAM)
00396 # define G_CE_TOGGLE (NF_CE_TOGGLE)
00397 # define G_CLK_DFC_NFC (CLK_DFC_NFC)
00398 # define G_DEV_MAKER (NF_DEV_MAKER)
00399 # define G_DEV_ID (NF_DEV_ID)
00400 # endif
00401
00402 # if (NF_GENERIC_DRIVER==TRUE)
00403 _GLOBEXT_ _MEM_TYPE_FAST_ U8 g_shift_page_byte ;
00404 _GLOBEXT_ _MEM_TYPE_FAST_ U8 g_shift_block_page ;
00405 _GLOBEXT_ _MEM_TYPE_SLOW_ U8 g_ofst_blk_status ;
00406 # define Is_nf_2k() (11==g_shift_page_byte )
00407 # define Is_not_nf_2k() (11!=g_shift_page_byte )
00408 # define Is_nf_512() ( 9==g_shift_page_byte )
00409 # define Is_not_nf_512() ( 9!=g_shift_page_byte )
00410 # define G_SHIFT_BLOCK_PAGE g_shift_block_page
00411 # define G_SHIFT_PAGE_BYTE g_shift_page_byte
00412 # define G_OFST_BLK_STATUS g_ofst_blk_status
00413 # define NF_SPARE_POS ( Is_nf_2k() ? 2048 : 512 )
00414 # define NF_N_GOOD_STATIC_BLOCK ( Is_nf_2k() ? 32 : 256 )
00415 #else
00416 # if (NF_SHIFT_PAGE_BYTE==11) // 2KB pages
00417 # define Is_nf_2k() ( TRUE )
00418 # define Is_not_nf_2k() ( FALSE )
00419 # define Is_nf_512() ( FALSE )
00420 # define Is_not_nf_512() ( TRUE )
00421 # define NF_SPARE_POS 2048 // Spare zone starts at this byte offset in the page
00422 # define NF_N_GOOD_STATIC_BLOCK 32 // Number of the *valid* blocks in the static area
00423 # define G_OFST_BLK_STATUS 0 // Offset of the Bad Block information in spare zone
00424 # endif
00425 # if (NF_SHIFT_PAGE_BYTE==9) // 512B pages
00426 # define Is_nf_2k() ( FALSE )
00427 # define Is_not_nf_2k() ( TRUE )
00428 # define Is_nf_512() ( TRUE )
00429 # define Is_not_nf_512() ( FALSE )
00430 # define NF_SPARE_POS 512 // Spare zone starts at this byte offset in the page
00431 # define NF_N_GOOD_STATIC_BLOCK 256 // Number of the *valid* blocks in the static area
00432 # define G_OFST_BLK_STATUS 5 // Offset of the Bad Block information in spare zone
00433 # endif
00434 # define G_SHIFT_BLOCK_PAGE (NF_SHIFT_BLOCK_PAGE)
00435 # define G_SHIFT_PAGE_BYTE (NF_SHIFT_PAGE_BYTE)
00436 # endif
00437
00438 #endif // NF_BAD_CONFIG
00439
00440
00441
00442
00443 #define NO_NF_CONNECTED 0xFF
00444 #define NF_UNKNOW 0xFE
00445
00446
00447
00448 void nf_XMCR_enable( void );
00449 void nf_XMCR_disable( void );
00450 void nfc_select_dev( U8 dev );
00451 void nfc_init( U8 nb_dev, U16 last_protected_block );
00452 Status_bool nfc_check_status( void );
00453 U8 nfc_check_type( U8 nb_dev );
00454 void nfc_reset_nands( U8 nb_dev );
00455 void nfc_open_page_read( U32 page_addr, U16 byte_addr);
00456 void nfc_open_page_write( U32 page_addr, U16 byte_addr);
00457 void nfc_mark_bad_block( U32 page_addr );
00458 void nfc_erase_block( U32 page_addr, U8 force_erase );
00459 void nfc_copy_back_init( U32 page_addr );
00460 void nfc_copy_back_conf( U32 page_addr );
00461 U32 nfc_read_id( U8 read_id_cmd, U8 nf_num );
00462 U8 nfc_detect( void );
00463 void nfc_wait_busy( void );
00464
00465 void nfc_read_spare_byte(
00466 U8 _MEM_TYPE_SLOW_ * p_byte
00467 , U8 n_byte
00468 , U32 page_addr
00469 );
00470
00471 void nfc_print_block( U16 block_addr, U8 dev_id);
00472
00473 #endif // _NFC_DRV_H_