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