Go to the source code of this file.
Defines | |
#define | _GLOBEXT_ extern |
#define | CLK_DFC_NFC_40MHz 0 |
#define | CLK_DFC_NFC_30MHz 0 |
#define | CLK_DFC_NFC_24MHz 0 |
#define | NFC_ACT_NOP 0 |
No Operation. | |
#define | NFC_ACT_DEV_SELECT 1 |
Device selection. The number is given by the extension. | |
#define | NFC_ACT_READ 2 |
Read flow through DFC. | |
#define | NFC_ACT_WRITE 3 |
Write flow through DFC. | |
#define | NFC_ACT_ASSERT_CE 4 |
Assert the CE pad of the last selected device. | |
#define | NFC_EXT_CELOW 1 |
#define | NFC_EXT_NOP 0 |
#define | NFC_ACT_STOP 5 |
Stop the NFC, or the DFC flow. | |
#define | NFC_ACT_ADC_EXT 6 |
Column address extension. | |
#define | NF_ADD_LATCH_ENABLE_ADD 0x3A00 |
#define | NF_CMD_LATCH_ENABLE_ADD 0x3900 |
#define | NF_ADDRESS_CMD_DATA 0x3800 |
#define | Nf_rd_byte() (nf_data) |
#define | Nf_wr_byte(b) (nf_data = b) |
#define | Nf_send_command(command) {Nandflash_CLE_select(); nf_send_cmd = command; Nandflash_CLE_unselect(); } |
#define | Nf_send_address(address) {Nandflash_ALE_select(); nf_send_add = address; Nandflash_ALE_unselect(); } |
#define | Mcu_set_sfr_page_nfc() |
#define | Nfc_set_cmd(command) Nf_send_command(command) |
#define | Nfc_rd_status() Nf_rd_byte() |
#define | Nfc_rd_data() Nf_rd_byte() |
#define | Nfc_rd_data_fetch_next() Nf_rd_byte() |
#define | Nfc_wr_data(dat) Nf_wr_byte(dat) |
#define | Nfc_set_adc(adr) Nf_send_address(adr) |
#define | Nfc_set_adr(adr) Nf_send_address(adr) |
#define | Nfc_unprotect_all_flash() |
#define | Nfc_action(a, b) { if( a == NFC_ACT_DEV_SELECT ) nfc_select_dev(b); } |
#define | nfc_init(a, b) nf_XMCR_enable() |
#define | Nfc_get_ecc() (0xFF) |
#define | Nfc_init_ecc() |
#define | Nfc_open_page_read(page_addr, byte_addr) |
Opens a page for read. | |
#define | Nfc_open_page_write(page_addr, byte_addr) |
Opens a page for write. | |
#define | NF_MAX_DEVICES 2 |
#define | NF_MAX_RB_TIMEOUT 0xFF |
Define here the number of NF connected to the microcontroller For AVR8 the number must be 1. | |
#define | NF_READ_A_AREA_CMD 0x00 |
Read Command of zone A (512B). | |
#define | NF_READ_B_AREA_CMD 0x01 |
Read Command of zone B (512B). | |
#define | NF_READ_C_AREA_CMD 0x50 |
Read Command of zone C (spare) (512B). | |
#define | NF_READ_CMD 0x00 |
Read Command (2KB). | |
#define | NF_READ_CMD2 0x30 |
Confirm read Command (2KB). | |
#define | NF_RANDOM_READ_CMD_C1 0x05 |
Random read Command (2KB). | |
#define | NF_RANDOM_READ_CMD_C2 0xE0 |
Confirm random read Command (2KB). | |
#define | NF_READ_ID_CMD 0x90 |
Read ID Command. | |
#define | NF_READ_ID2_CMD 0x91 |
Read ID 2 Command. | |
#define | NF_RESET_CMD 0xff |
Reset command. | |
#define | NF_SEQUENTIAL_DATA_INPUT_CMD 0x80 |
Sequential data input command. | |
#define | NF_PAGE_PROGRAM_CMD 0x10 |
Page Program command. | |
#define | NF_RANDOM_DATA_INPUT_CMD 0x85 |
Random data input command (2KB). | |
#define | NF_COPY_BACK_CMD 0x35 |
Copy-back command (2KB). | |
#define | NF_CACHE_PROGRAM_CMD 0x15 |
Cache program (fast) command (2KB). | |
#define | NF_BLOCK_ERASE_CMD 0x60 |
Erase command. | |
#define | NF_BLOCK_ERASE_CONFIRM_CMD 0xD0 |
Confirm erase command. | |
#define | NF_READ_STATUS_CMD 0x70 |
Read Status command. | |
#define | NF_MASK_STATUS_FAIL (1<<0) |
Fail. | |
#define | NF_MASK_STATUS_READY (1<<6) |
Ready. | |
#define | NF_MASK_STATUS_T_RDY_2KB (1<<5) |
True Ready. | |
#define | NF_MASK_STATUS_T_RDY_512B (1<<6) |
True Ready. | |
#define | Nfc_wait_cache_busy() |
Macro that tests the cache busy. | |
#define | SIZE_PAGE_BYTE ((U16)1<<G_SHIFT_PAGE_BYTE) |
#define | SIZE_SECTOR_BYTE ((U16)1<<S_SHIFT_SECTOR_BYTE) |
#define | SIZE_BLOCK_PAGE ((U8)1<<G_SHIFT_BLOCK_PAGE) |
#define | SIZE_PAGE_SECTOR ((U8)1<<(G_SHIFT_PAGE_BYTE - S_SHIFT_SECTOR_BYTE)) |
#define | NFC_SPARE_OFST_1_BLK_ID 1 |
#define | NFC_BLK_ID_SYSTEM 0x39 |
#define | NFC_BLK_ID_SUBLUT 0xE8 |
#define | NFC_BLK_ID_RCV 0x72 |
#define | NFC_BLK_ID_FBB 0xB4 |
#define | NFC_BLK_ID_DATA 0xFF |
#define | NFC_BLK_ID_QUARANTINE 0x8D |
#define | NFC_SPARE_OFST_2_BYTE_2 2 |
#define | NFC_SPARE_OFST_3_BYTE_3 3 |
#define | NFC_OFST_3_DATA_SRC 0x00 |
#define | NFC_OFST_3_DATA_DST 0xFF |
#define | NFC_SPARE_OFST_4_BYTE_4 4 |
#define | NFC_OFST_4_FBB_DRIVER_RELEASE 0x01 |
#define | NFC_SPARE_DATA_VALID 0xFF |
#define | NFC_SPARE_DATA_INVALID 0 |
#define | NFC_SPARE_OFST_EXPORT 11 |
#define | NFC_SPARE_OFST_6_LBA 6 |
#define | NFC_OFST_6_FBB_VALID 0xFF |
#define | NFC_OFST_6_FBB_INVALID 0 |
#define | NFC_SPARE_OFST_ECC2 8 |
#define | NFC_SPARE_OFST_ECC1 13 |
#define | G_N_ZONES g_n_zones |
#define | G_N_BLOCKS g_n_blocks |
#define | G_N_ROW_CYCLES g_n_row_cycles |
#define | G_COPY_BACK_CONT g_copy_back_cont |
#define | G_COPY_BACK_DISCONT g_copy_back_discont |
#define | G_CACHE_PROG g_cache_program |
#define | G_CE_TOGGLE g_ce_toggle |
#define | G_CLK_DFC_NFC g_clock_dfc_nfc |
#define | G_DEV_MAKER g_dev_maker |
#define | G_DEV_ID g_dev_id |
#define | Is_nf_2k() (11==g_shift_page_byte ) |
#define | Is_not_nf_2k() (11!=g_shift_page_byte ) |
#define | Is_nf_512() ( 9==g_shift_page_byte ) |
#define | Is_not_nf_512() ( 9!=g_shift_page_byte ) |
#define | G_SHIFT_BLOCK_PAGE g_shift_block_page |
#define | G_SHIFT_PAGE_BYTE g_shift_page_byte |
#define | G_OFST_BLK_STATUS g_ofst_blk_status |
#define | NF_SPARE_POS ( Is_nf_2k() ? 2048 : 512 ) |
#define | NF_N_GOOD_STATIC_BLOCK ( Is_nf_2k() ? 32 : 256 ) |
#define | NO_NF_CONNECTED 0xFF |
#define | NF_UNKNOW 0xFE |
Functions | |
void | nf_XMCR_enable (void) |
Enable the XMCR (Extending Memory Module) of the AVR to drive the NAND Flash. | |
void | nf_XMCR_disable (void) |
Disable the XMCR module of the AVR, to allow access to others peripherals that may be connected on this same bus. | |
void | nfc_select_dev (U8 dev) |
Status_bool | nfc_check_status (void) |
Check the status of the selected device. | |
U8 | nfc_check_type (U8 nb_dev) |
Tests the Nand Flash configuration. | |
void | nfc_reset_nands (U8 nb_dev) |
Reset all the NF devices. | |
void | nfc_open_page_read (U32 page_addr, U16 byte_addr) |
Opens a page for read. | |
void | nfc_open_page_write (U32 page_addr, U16 byte_addr) |
Opens a page for write. | |
void | nfc_mark_bad_block (U32 page_addr) |
Mark a block as 'invalid' by clearing it entirely. | |
void | nfc_erase_block (U32 page_addr, U8 force_erase) |
Erases a block. | |
void | nfc_copy_back_init (U32 page_addr) |
Prepare a copy-back session. | |
void | nfc_copy_back_conf (U32 page_addr) |
U32 | nfc_read_id (U8 read_id_cmd, U8 nf_num) |
Read the ID of the Nand-Flash. | |
U8 | nfc_detect (void) |
Read the ID of the Nand-Flash and update the global variable. | |
void | nfc_wait_busy (void) |
Tests the true busy. | |
void | nfc_read_spare_byte (U8 _MEM_TYPE_SLOW_ *p_byte, U8 n_byte, U32 page_addr) |
Reads the number spare bytes specified and stores them in a array. | |
void | nfc_print_block (U16 block_addr, U8 dev_id) |
Variables | |
_MEM_TYPE_SLOW_ U8 | g_n_zones |
_MEM_TYPE_SLOW_ U16 | g_n_blocks |
_MEM_TYPE_FAST_ U8 | g_n_row_cycles |
_MEM_TYPE_SLOW_ U8 | g_copy_back_cont |
_MEM_TYPE_SLOW_ U8 | g_copy_back_discont |
Bool | g_cache_program |
Bool | g_ce_toggle |
_MEM_TYPE_SLOW_ U8 | g_clock_dfc_nfc |
_MEM_TYPE_SLOW_ U8 | g_dev_maker |
_MEM_TYPE_SLOW_ U8 | g_dev_id |
_MEM_TYPE_FAST_ U8 | g_shift_page_byte |
_MEM_TYPE_FAST_ U8 | g_shift_block_page |
_MEM_TYPE_SLOW_ U8 | g_ofst_blk_status |
Definition in file nf_drv.h.
#define Nf_rd_byte | ( | ) | (nf_data) |
Definition at line 95 of file nf_drv.h.
Referenced by nf_nf_2_ram(), nf_read_sector_to_usb(), and nf_upload().
#define Nf_wr_byte | ( | b | ) | (nf_data = b) |
Definition at line 96 of file nf_drv.h.
Referenced by nf_download(), nf_ram_2_nf(), and nf_write_sector_from_usb().
#define Nf_send_command | ( | command | ) | {Nandflash_CLE_select(); nf_send_cmd = command; Nandflash_CLE_unselect(); } |
#define Nf_send_address | ( | address | ) | {Nandflash_ALE_select(); nf_send_add = address; Nandflash_ALE_unselect(); } |
#define Mcu_set_sfr_page_nfc | ( | ) |
Definition at line 106 of file nf_drv.h.
Referenced by nfc_check_status(), nfc_copy_back_init(), nfc_erase_block(), nfc_mark_bad_block(), nfc_open_page_read(), nfc_open_page_write(), nfc_read_id(), nfc_read_spare_byte(), and nfc_reset_nands().
#define Nfc_set_cmd | ( | command | ) | Nf_send_command(command) |
Definition at line 107 of file nf_drv.h.
Referenced by nf_copy(), nf_copy_tail(), nf_dfc_write_stop(), nf_open_write(), nf_update_spare_zone(), nf_write_10(), nf_write_fbb(), nf_write_lut(), nfc_check_type(), nfc_copy_back_init(), nfc_erase_block(), nfc_mark_bad_block(), nfc_nf_is_ready(), nfc_read_id(), nfc_reset_nands(), and nfc_wait_busy().
#define Nfc_rd_status | ( | ) | Nf_rd_byte() |
#define Nfc_rd_data | ( | ) | Nf_rd_byte() |
Definition at line 109 of file nf_drv.h.
Referenced by nf_cleanup_memory(), nf_refine_index(), nfc_check_status(), and nfc_erase_block().
#define Nfc_rd_data_fetch_next | ( | ) | Nf_rd_byte() |
Definition at line 110 of file nf_drv.h.
Referenced by nf_cache_fbb_flush(), nf_cache_fbb_refill(), nf_cache_lut_flush(), nf_cache_lut_refill(), nf_check_fbb(), nf_check_lut(), nf_cleanup_memory(), nf_rebuild(), nfc_check_type(), nfc_read_id(), and nfc_read_spare_byte().
#define Nfc_wr_data | ( | dat | ) | Nf_wr_byte(dat) |
Definition at line 111 of file nf_drv.h.
Referenced by nf_copy(), nf_open_write(), nf_update_spare_zone(), nf_write_fbb(), nf_write_lut(), and nfc_mark_bad_block().
#define Nfc_set_adc | ( | adr | ) | Nf_send_address(adr) |
Definition at line 112 of file nf_drv.h.
Referenced by nf_copy(), nf_copy_tail(), nf_update_spare_zone(), nfc_check_type(), nfc_copy_back_init(), and nfc_read_id().
#define Nfc_set_adr | ( | adr | ) | Nf_send_address(adr) |
Definition at line 113 of file nf_drv.h.
Referenced by nf_copy(), nfc_copy_back_init(), and nfc_erase_block().
#define Nfc_unprotect_all_flash | ( | ) |
Definition at line 114 of file nf_drv.h.
Referenced by nf_copy(), nfc_copy_back_init(), and nfc_erase_block().
#define Nfc_action | ( | a, | |||
b | ) | { if( a == NFC_ACT_DEV_SELECT ) nfc_select_dev(b); } |
Definition at line 116 of file nf_drv.h.
Referenced by nf_cache_fbb_flush(), nf_cache_fbb_refill(), nf_cache_lut_flush(), nf_cache_lut_refill(), nf_check_fbb(), nf_check_lut(), nf_cleanup_memory(), nf_copy_tail(), nf_erase_old_blocks(), nf_nf_2_ram(), nf_open_write(), nf_ram_2_nf(), nf_read_10(), nf_rebuild(), nf_scan(), nf_write_10(), nf_write_fbb(), nf_write_lut(), nfc_check_type(), nfc_read_id(), nfc_reset_nands(), and ut_nfc_erase_all().
#define nfc_init | ( | a, | |||
b | ) | nf_XMCR_enable() |
#define Nfc_open_page_read | ( | page_addr, | |||
byte_addr | ) |
Opens a page for read.
The macro will adapt the commands according to the type of flash memory. The busy is polled at the end of the function.
page_addr | absolute page address of the block | |
byte_addr | relative byte address inside the page. |
nf_init()
should have been called before. The NF device should have been selected before with Nfc_action(NFC_ACT_DEV_SELECT, id)
. Definition at line 132 of file nf_drv.h.
Referenced by nf_read_10(), and nfc_open_page_read().
#define Nfc_open_page_write | ( | page_addr, | |||
byte_addr | ) |
Opens a page for write.
The macro will adapt the commands according to the type of flash memory.
page_addr | absolute page address of the block | |
byte_addr | relative byte address inside the page. |
nf_init()
should have been called before. The NF device should have been selected before with Nfc_action(NFC_ACT_DEV_SELECT, id)
. Definition at line 211 of file nf_drv.h.
Referenced by nf_write_10(), and nfc_open_page_write().
#define NF_MAX_DEVICES 2 |
#define NF_MAX_RB_TIMEOUT 0xFF |
Define here the number of NF connected to the microcontroller For AVR8 the number must be 1.
Definition at line 278 of file nf_drv.h.
Referenced by nfc_nf_is_ready().
#define Nfc_wait_cache_busy | ( | ) |
Value:
{ \ register int Reg; \ Nfc_set_cmd(NF_READ_STATUS_CMD); \ Reg = Nfc_rd_status(); \ while( (Nfc_rd_status() & NF_MASK_STATUS_READY)==0 /*busy*/ ); \ while( (Nfc_rd_status() & NF_MASK_STATUS_READY)==0 /*busy*/ ); \ }
#define SIZE_PAGE_BYTE ((U16)1<<G_SHIFT_PAGE_BYTE) |
Definition at line 335 of file nf_drv.h.
Referenced by nf_cache_fbb_flush(), nf_cache_fbb_refill(), and nf_cache_lut_refill().
#define SIZE_SECTOR_BYTE ((U16)1<<S_SHIFT_SECTOR_BYTE) |
#define SIZE_BLOCK_PAGE ((U8)1<<G_SHIFT_BLOCK_PAGE) |
Definition at line 337 of file nf_drv.h.
Referenced by nf_copy_tail(), nf_dfc_write_stop(), nf_open_write(), nf_read_10(), nf_rebuild(), nf_refine_index(), nf_translate(), and nf_write_10().
#define SIZE_PAGE_SECTOR ((U8)1<<(G_SHIFT_PAGE_BYTE - S_SHIFT_SECTOR_BYTE)) |
Definition at line 338 of file nf_drv.h.
Referenced by nf_copy_tail(), nf_open_write(), nf_rebuild(), nf_translate(), and nf_xfer_update_vars().
#define NFC_SPARE_OFST_1_BLK_ID 1 |
Definition at line 344 of file nf_drv.h.
Referenced by nf_fetch_free_block(), nf_rebuild(), nf_refine_index(), and nf_scan().
#define NFC_BLK_ID_SUBLUT 0xE8 |
Definition at line 346 of file nf_drv.h.
Referenced by nf_cleanup_memory(), nf_fetch_free_block(), nf_scan(), and nf_write_lut().
#define NFC_BLK_ID_FBB 0xB4 |
Definition at line 348 of file nf_drv.h.
Referenced by nf_cleanup_memory(), nf_fetch_free_block(), nf_scan(), and nf_write_fbb().
#define NFC_BLK_ID_DATA 0xFF |
Definition at line 349 of file nf_drv.h.
Referenced by nf_fetch_free_block(), nf_rebuild(), nf_scan(), and nf_update_spare_zone().
#define NFC_BLK_ID_QUARANTINE 0x8D |
#define NFC_SPARE_OFST_3_BYTE_3 3 |
Definition at line 353 of file nf_drv.h.
Referenced by nf_copy(), nf_open_write(), nf_rebuild(), and nf_scan().
#define NFC_OFST_3_DATA_SRC 0x00 |
#define NFC_OFST_3_DATA_DST 0xFF |
Definition at line 355 of file nf_drv.h.
Referenced by nf_copy(), nf_rebuild(), and nf_update_spare_zone().
#define NFC_OFST_4_FBB_DRIVER_RELEASE 0x01 |
#define NFC_SPARE_DATA_VALID 0xFF |
#define NFC_SPARE_OFST_6_LBA 6 |
Definition at line 363 of file nf_drv.h.
Referenced by nf_copy(), nf_fetch_free_block(), nf_open_write(), nf_rebuild(), and nf_scan().
#define NFC_OFST_6_FBB_VALID 0xFF |
#define NFC_OFST_6_FBB_INVALID 0 |
#define G_N_BLOCKS g_n_blocks |
Definition at line 383 of file nf_drv.h.
Referenced by nf_cache_fbb_flush(), nf_cache_fbb_refill(), nf_cache_lut_flush(), nf_cache_lut_refill(), nf_check_fbb(), nf_check_lut(), nf_cleanup_memory(), nf_erase_all_blocks(), nf_rebuild(), nf_scan(), nf_swap(), nf_write_lut(), and ut_nfc_erase_all().
#define G_N_ROW_CYCLES g_n_row_cycles |
Definition at line 384 of file nf_drv.h.
Referenced by nf_copy(), nfc_copy_back_init(), and nfc_erase_block().
#define G_COPY_BACK_CONT g_copy_back_cont |
#define G_COPY_BACK_DISCONT g_copy_back_discont |
#define G_CACHE_PROG g_cache_program |
#define G_CE_TOGGLE g_ce_toggle |
#define G_CLK_DFC_NFC g_clock_dfc_nfc |
#define G_DEV_MAKER g_dev_maker |
#define G_DEV_ID g_dev_id |
#define Is_nf_2k | ( | ) | (11==g_shift_page_byte ) |
Definition at line 409 of file nf_drv.h.
Referenced by nf_copy(), nf_init(), nf_ram_2_nf(), nf_update_spare_zone(), nf_write_10(), and nfc_wait_busy().
#define Is_not_nf_2k | ( | ) | (11!=g_shift_page_byte ) |
#define Is_nf_512 | ( | ) | ( 9==g_shift_page_byte ) |
Definition at line 411 of file nf_drv.h.
Referenced by nf_init(), nfc_mark_bad_block(), and nfc_wait_busy().
#define Is_not_nf_512 | ( | ) | ( 9!=g_shift_page_byte ) |
#define G_SHIFT_BLOCK_PAGE g_shift_block_page |
Definition at line 413 of file nf_drv.h.
Referenced by nf_block_2_page(), nf_cache_fbb_flush(), nf_cache_lut_flush(), nf_copy(), nf_get_sectors_number(), nf_init(), nf_refine_index(), and nfc_mark_bad_block().
#define G_SHIFT_PAGE_BYTE g_shift_page_byte |
Definition at line 414 of file nf_drv.h.
Referenced by nf_copy(), nf_get_sectors_number(), nf_init(), nf_nf_2_ram(), nf_ram_2_nf(), nf_translate(), nf_write_10(), nf_write_fbb(), and nf_write_lut().
#define G_OFST_BLK_STATUS g_ofst_blk_status |
Definition at line 415 of file nf_drv.h.
Referenced by nf_fetch_free_block(), nf_rebuild(), nf_scan(), and nfc_erase_block().
#define NF_SPARE_POS ( Is_nf_2k() ? 2048 : 512 ) |
Definition at line 416 of file nf_drv.h.
Referenced by nf_cleanup_memory(), nf_copy(), nf_copy_tail(), nf_open_write(), nf_rebuild(), nf_refine_index(), nf_update_spare_zone(), nfc_erase_block(), nfc_mark_bad_block(), and nfc_read_spare_byte().
#define NO_NF_CONNECTED 0xFF |
#define NF_UNKNOW 0xFE |
void nf_XMCR_enable | ( | void | ) |
Enable the XMCR (Extending Memory Module) of the AVR to drive the NAND Flash.
Definition at line 172 of file nf_drv.c.
00173 { 00174 #if (NF_CLE_ALE_MANUAL == ENABLED) 00175 XMCRB |= ((1<<XMM2) | (1<<XMM1) | (1<<XMM0)); // limit XRAM interface to A7 (release PC0..7) 00176 #else 00177 XMCRB |= ((1<<XMM2) | (1<<XMM1)); // limit XRAM interface to A9 (release PC2..7) 00178 #endif 00179 XMCRA |= (1<<SRE); // enable the external memory 00180 }
void nf_XMCR_disable | ( | void | ) |
Disable the XMCR module of the AVR, to allow access to others peripherals that may be connected on this same bus.
Definition at line 185 of file nf_drv.c.
References Nandflash0_unselect, and Nandflash1_unselect.
00186 { 00187 Nandflash0_unselect(); 00188 Nandflash1_unselect(); 00189 XMCRA &= ~(1<<SRE); // disable the external memory 00190 }
void nfc_select_dev | ( | U8 | dev | ) |
Definition at line 83 of file nf_drv.c.
References Nandflash0_select, Nandflash0_unselect, Nandflash1_select, and Nandflash1_unselect.
00084 { 00085 if(0==dev) 00086 { 00087 Nandflash1_unselect(); 00088 Nandflash0_select(); 00089 }else{ 00090 Nandflash0_unselect(); 00091 Nandflash1_select(); 00092 } 00093 }
Status_bool nfc_check_status | ( | void | ) |
Check the status of the selected device.
Definition at line 203 of file nf_drv.c.
References FAIL, Mcu_set_sfr_page_nfc, NF_MASK_STATUS_FAIL, Nfc_rd_data, nfc_wait_busy(), and PASS.
00204 { 00205 Mcu_set_sfr_page_nfc(); 00206 nfc_wait_busy(); // Send a status command and wait the completion of the last command 00207 if ( (Nfc_rd_data()&NF_MASK_STATUS_FAIL)==0 ) { return PASS; } // I/O 0 Pass:0 Fail:1 00208 else { return FAIL; } 00209 }
Tests the Nand Flash configuration.
The function verifies that the NF connected to device are properly declared in conf_nf.h.
none |
Definition at line 107 of file nf_drv.c.
References G_CE_TOGGLE, G_DEV_ID, G_DEV_MAKER, NF_READ_ID_CMD, nf_XMCR_disable(), nf_XMCR_enable(), NFC_ACT_ASSERT_CE, NFC_ACT_DEV_SELECT, Nfc_action, NFC_EXT_CELOW, NFC_EXT_NOP, nfc_init, Nfc_rd_data_fetch_next, nfc_reset_nands(), Nfc_set_adc, Nfc_set_cmd, and nfc_wait_busy().
00108 { 00109 U8 i_dev; 00110 if( 2 < nb_dev ) 00111 nb_dev = 2; // Only 1 or 2 for this driver 00112 00113 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00114 nf_XMCR_enable(); 00115 #endif 00116 nfc_init( nb_dev, 0 ); 00117 nfc_reset_nands( nb_dev ); // Reset all the NF devices 00118 00119 // Test NF configuration 00120 // 00121 for( i_dev=0 ; i_dev<nb_dev ; i_dev++ ) 00122 { 00123 Nfc_action( NFC_ACT_DEV_SELECT, i_dev); 00124 nfc_wait_busy(); 00125 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_CELOW); 00126 Nfc_set_cmd(NF_READ_ID_CMD); 00127 Nfc_set_adc( 0 ); 00128 if(( Nfc_rd_data_fetch_next()!=G_DEV_MAKER ) 00129 || ( Nfc_rd_data_fetch_next()!=G_DEV_ID )) 00130 { 00131 return i_dev; 00132 } 00133 if( G_CE_TOGGLE ) 00134 { 00135 // disable CE Low 00136 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_NOP); 00137 } 00138 } 00139 00140 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00141 nf_XMCR_disable(); 00142 #endif 00143 return nb_dev; 00144 }
void nfc_reset_nands | ( | U8 | nb_dev | ) |
Reset all the NF devices.
none |
Definition at line 152 of file nf_drv.c.
References Mcu_set_sfr_page_nfc, NF_RESET_CMD, NFC_ACT_DEV_SELECT, Nfc_action, Nfc_set_cmd, and nfc_wait_busy().
00153 { 00154 U8 i_dev; 00155 Mcu_set_sfr_page_nfc(); 00156 for( i_dev=0 ; i_dev<nb_dev ; i_dev++ ) 00157 { 00158 Nfc_action(NFC_ACT_DEV_SELECT, i_dev); 00159 // The wait is mandatory here since the function is used to wait any 00160 // pending internal programmation (Cache Program cmd). 00161 nfc_wait_busy(); 00162 Nfc_set_cmd(NF_RESET_CMD); 00163 nfc_wait_busy(); 00164 } 00165 }
Opens a page for read.
The function will adapt the commands according to the type of flash memory. The busy is polled at the end of the function.
page_addr | absolute page address of the block | |
byte_addr | relative byte address inside the page. |
nf_init()
should have been called before. The NF device should have been selected before with Nfc_action(NFC_ACT_DEV_SELECT, id)
. Definition at line 221 of file nf_drv.c.
References Mcu_set_sfr_page_nfc, Nfc_open_page_read, and nfc_wait_busy().
00222 { 00223 Mcu_set_sfr_page_nfc(); 00224 nfc_wait_busy(); 00225 Nfc_open_page_read( page_addr, byte_addr); 00226 }
Opens a page for write.
The function will adapt the commands according to the type of flash memory.
page_addr | absolute page address of the block | |
byte_addr | relative byte address inside the page. |
nf_init()
should have been called before. The NF device should have been selected before with Nfc_action(NFC_ACT_DEV_SELECT, id)
. Definition at line 239 of file nf_drv.c.
References Mcu_set_sfr_page_nfc, and Nfc_open_page_write.
00240 { 00241 Mcu_set_sfr_page_nfc(); 00242 Nfc_open_page_write( page_addr, byte_addr); 00243 }
void nfc_mark_bad_block | ( | U32 | page_addr | ) |
Mark a block as 'invalid' by clearing it entirely.
page_addr | absolute page address of the block |
nf_init()
should have been called before. The device which holds this bad block should have been selected before with Nfc_action(NFC_ACT_DEV_SELECT, id)
. Definition at line 255 of file nf_drv.c.
References G_SHIFT_BLOCK_PAGE, Is_nf_512, Mcu_set_sfr_page_nfc, NF_PAGE_PROGRAM_CMD, NF_SPARE_POS, nfc_erase_block(), nfc_open_page_write(), Nfc_set_cmd, Nfc_wr_data, and TRUE.
00256 { 00257 U8 n_bytes; 00258 U8 i_byte; 00259 U8 i_page; 00260 00261 Mcu_set_sfr_page_nfc(); 00262 00263 n_bytes= ( Is_nf_512() ) 00264 ? 16 // 512B page access 00265 : 64 // 2KB page access 00266 ; 00267 00268 // Erasing the block is mandatory to prevent partial programming 00269 // (some 512B NF does support partial prog, but not after a copy back command). 00270 nfc_erase_block( page_addr, TRUE ); 00271 for ( i_page=(U8)1<<G_SHIFT_BLOCK_PAGE ; i_page!=0 ; i_page--, page_addr++ ) 00272 { 00273 nfc_open_page_write( page_addr, NF_SPARE_POS-8 ); 00274 Nfc_wr_data('A'); Nfc_wr_data('t'); 00275 Nfc_wr_data('m'); Nfc_wr_data('e'); 00276 Nfc_wr_data('l'); Nfc_wr_data(' '); 00277 Nfc_wr_data(' '); Nfc_wr_data(' '); 00278 for ( i_byte=n_bytes ; i_byte!=0 ; i_byte-=4 ) 00279 { 00280 Nfc_wr_data(0); 00281 Nfc_wr_data(0); 00282 Nfc_wr_data(0); 00283 Nfc_wr_data(0); 00284 } 00285 Nfc_set_cmd(NF_PAGE_PROGRAM_CMD); // Confirm programmation 00286 } 00287 }
Erases a block.
The erase will be done only if the block is not bad
page_addr | absolute page address of the block | |
force_erase | TRUE forces erasing, FALSE erases the block (if not bad) |
nf_init()
should have been called before. The device which holds the block to delete should have been selected before with Nfc_action(NFC_ACT_DEV_SELECT, id)
. Definition at line 302 of file nf_drv.c.
References FALSE, G_N_ROW_CYCLES, G_OFST_BLK_STATUS, LSB0, LSB1, Mcu_set_sfr_page_nfc, MSB1, NF_BLOCK_ERASE_CMD, NF_BLOCK_ERASE_CONFIRM_CMD, NF_SPARE_POS, nfc_open_page_read(), Nfc_rd_data, Nfc_set_adr, Nfc_set_cmd, Nfc_unprotect_all_flash, and nfc_wait_busy().
00303 { 00304 Mcu_set_sfr_page_nfc(); 00305 if (FALSE == force_erase) 00306 { 00307 nfc_open_page_read( page_addr, NF_SPARE_POS + G_OFST_BLK_STATUS ); 00308 if( (Nfc_rd_data() != 0xFF) ) return; // The block is bad. We can not erase it 00309 } 00310 nfc_wait_busy(); 00311 Nfc_unprotect_all_flash(); // WP may be actif due to block protection 00312 Nfc_set_cmd (NF_BLOCK_ERASE_CMD); // Auto Block Erase Setup 00313 Nfc_set_adr( LSB0(page_addr) ); 00314 Nfc_set_adr( LSB1(page_addr) ); 00315 if (3 == G_N_ROW_CYCLES) 00316 { 00317 Nfc_set_adr( MSB1(page_addr) ); 00318 } 00319 Nfc_set_cmd(NF_BLOCK_ERASE_CONFIRM_CMD); // Erase command 00320 }
void nfc_copy_back_init | ( | U32 | page_addr | ) |
Prepare a copy-back session.
page_addr | absolute source page address of the block |
nf_init()
should have been called before. Definition at line 558 of file nf_drv.c.
References G_N_ROW_CYCLES, LSB0, LSB1, Mcu_set_sfr_page_nfc, MSB1, NF_COPY_BACK_CMD, NF_READ_CMD, Nfc_set_adc, Nfc_set_adr, Nfc_set_cmd, Nfc_unprotect_all_flash, and nfc_wait_busy().
00559 { 00560 Mcu_set_sfr_page_nfc(); 00561 nfc_wait_busy(); 00562 Nfc_unprotect_all_flash(); // WP may be actif due to block protection 00563 Nfc_set_cmd(NF_READ_CMD); 00564 Nfc_set_adc( 0 ); 00565 Nfc_set_adc( 0 ); 00566 Nfc_set_adr( LSB0(page_addr) ); 00567 Nfc_set_adr( LSB1(page_addr) ); 00568 if ( 3==G_N_ROW_CYCLES ) 00569 { 00570 Nfc_set_adr( MSB1(page_addr) ); 00571 } 00572 Nfc_set_cmd(NF_COPY_BACK_CMD); 00573 nfc_wait_busy(); 00574 }
void nfc_copy_back_conf | ( | U32 | page_addr | ) |
Read the ID of the Nand-Flash.
read_id_cmd | Read_id command (NF_READ_ID_CMD, NF_READ_ID2_CMD) | |
nf_num | Nand Flash number |
nf_init()
should have been called before. Definition at line 397 of file nf_drv.c.
References Mcu_set_sfr_page_nfc, MSB0, MSB1, MSB2, MSB3, NFC_ACT_ASSERT_CE, NFC_ACT_DEV_SELECT, Nfc_action, NFC_EXT_CELOW, NFC_EXT_NOP, Nfc_rd_data_fetch_next, Nfc_set_adc, Nfc_set_cmd, and nfc_wait_busy().
00398 { 00399 U32 ret; 00400 00401 Mcu_set_sfr_page_nfc(); 00402 Nfc_action(NFC_ACT_DEV_SELECT, nf_num); 00403 nfc_wait_busy(); 00404 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_CELOW); 00405 Nfc_set_cmd (read_id_cmd); 00406 Nfc_set_adc( 0 ); 00407 00408 MSB0(ret)= Nfc_rd_data_fetch_next(); // Maker Code 00409 MSB1(ret)= Nfc_rd_data_fetch_next(); // Device Id 00410 MSB2(ret)= Nfc_rd_data_fetch_next(); // extra 00411 MSB3(ret)= Nfc_rd_data_fetch_next(); // extra (Multi Plane Support) 00412 00413 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_NOP); 00414 return ret; 00415 }
U8 nfc_detect | ( | void | ) |
Read the ID of the Nand-Flash and update the global variable.
Definition at line 449 of file nf_drv.c.
References St_nf_conf::cache_program, St_nf_conf::ce_toggle, St_nf_id::conf, St_nf_conf::copy_back_cont, St_nf_conf::copy_back_discont, FALSE, g_cache_program, g_ce_toggle, g_copy_back_cont, g_copy_back_discont, g_dev_id, g_dev_maker, g_n_blocks, g_n_row_cycles, g_n_zones, g_shift_block_page, g_shift_page_byte, MSB0, MSB1, St_nf_link_id_block::nb_zones, nf_list_conf, nf_list_id, nf_list_link_id_block, NF_MAX_DEVICES, NF_READ_ID_CMD, NF_UNKNOW, nf_XMCR_disable(), nf_XMCR_enable(), nfc_init, nfc_nf_is_ready(), nfc_read_id(), nfc_reset_nands(), and NO_NF_CONNECTED.
00450 { 00451 U32 u32_nf_ids; 00452 U8 u8_i, u8_conf; 00453 00454 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00455 nf_XMCR_enable(); 00456 #endif 00457 00458 // Init the Nand Flash Controller 00459 nfc_init( NF_MAX_DEVICES, 0 ); 00460 nfc_reset_nands( NF_MAX_DEVICES ); // Reset all the NF devices 00461 00462 // Check the presence of device 0 00463 if ( FALSE == nfc_nf_is_ready() ) 00464 { 00465 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00466 nf_XMCR_disable(); 00467 #endif 00468 return NO_NF_CONNECTED; 00469 } 00470 00471 // Read the Nand Flash IDs of device 0 00472 u32_nf_ids = nfc_read_id( NF_READ_ID_CMD, 0 ); 00473 00474 // Identify the Nand Flash (device 0) 00475 for( u8_i=0 ; u8_i < (sizeof(nf_list_id)/sizeof(St_nf_id)) ; u8_i++) 00476 { 00477 if((nf_list_id[u8_i].manuf == MSB0(u32_nf_ids)) 00478 && (nf_list_id[u8_i].dev == MSB1(u32_nf_ids))) 00479 break; // here, ID is know 00480 } 00481 if( u8_i == (sizeof(nf_list_id)/sizeof(St_nf_id)) ) 00482 { 00483 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00484 nf_XMCR_disable(); 00485 #endif 00486 return NF_UNKNOW; 00487 } 00488 00489 // Set NF configuration parameters for initialisation and access 00490 #if (NF_GENERIC_DRIVER==TRUE) 00491 # error Test me... 00492 g_shift_page_byte =; 00493 g_shift_block_page =; 00494 #endif 00495 00496 #if (NF_GENERIC_DRIVER==TRUE) || (NF_AUTO_DETECT_2KB==TRUE) ||(NF_AUTO_DETECT_512B==TRUE) 00497 00498 // Record info 00499 u8_conf = nf_list_id[u8_i].conf; 00500 g_dev_maker = MSB0(u32_nf_ids); // Device maker 00501 g_dev_id = MSB1(u32_nf_ids); // Device ID 00502 00503 // Search the number of block of device 00504 for( u8_i=0 ; u8_i < (sizeof(nf_list_link_id_block)/sizeof(St_nf_link_id_block)) ; u8_i++) 00505 { 00506 if( nf_list_link_id_block[u8_i].dev_id == g_dev_id ) 00507 break; // ID found 00508 } 00509 if( u8_i == (sizeof(nf_list_link_id_block)/sizeof(St_nf_link_id_block)) ) 00510 while(1); // Error in NF definition 00511 00512 g_n_zones = nf_list_link_id_block[u8_i].nb_zones; 00513 #if (NF_AUTO_DETECT_2KB==TRUE) 00514 if( 1 == g_n_zones ) 00515 g_n_row_cycles = 2; 00516 else 00517 g_n_row_cycles = 3; 00518 #endif 00519 #if (NF_AUTO_DETECT_512B==TRUE) 00520 if( 2 >= g_n_zones ) 00521 g_n_row_cycles = 2; 00522 else 00523 g_n_row_cycles = 3; 00524 #endif 00525 g_n_blocks = g_n_zones*1024L; 00526 00527 g_copy_back_cont = nf_list_conf[u8_conf].copy_back_cont ; 00528 g_copy_back_discont = nf_list_conf[u8_conf].copy_back_discont; 00529 g_cache_program = nf_list_conf[u8_conf].cache_program ; 00530 g_ce_toggle = nf_list_conf[u8_conf].ce_toggle; 00531 /* 00532 g_clock_dfc_nfc = (nf_list_conf[u8_conf].dfc_nfc_clock<<5) & MSK_DNFCKS; 00533 00534 Mcu_set_sfr_page_nfc(); 00535 Nfc_set_read_timing((U8)nf_list_conf[u8_conf].timing_read ); 00536 if( !g_ce_toggle ) 00537 { 00538 // Enable CE low 00539 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_CELOW); 00540 } 00541 */ 00542 #endif 00543 00544 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00545 nf_XMCR_disable(); 00546 #endif 00547 return u8_i; 00548 }
void nfc_wait_busy | ( | void | ) |
Tests the true busy.
Note that we test twice the ready, since there is an hardware minimum requirement between the end of the busy and the first read cycle. Since the busy is not wired, the ready is tested twice.
Definition at line 353 of file nf_drv.c.
References G_CACHE_PROG, Is_nf_2k, Is_nf_512, NF_MASK_STATUS_READY, NF_MASK_STATUS_T_RDY_2KB, NF_MASK_STATUS_T_RDY_512B, NF_READ_STATUS_CMD, Nfc_rd_status, and Nfc_set_cmd.
00354 { 00355 register int Reg; 00356 Nfc_set_cmd(NF_READ_STATUS_CMD); 00357 Reg = Nfc_rd_status(); 00358 if( Is_nf_2k() ) 00359 { 00360 if( G_CACHE_PROG ) 00361 { 00362 while( (Nfc_rd_status() & NF_MASK_STATUS_T_RDY_2KB )==0 ); 00363 while( (Nfc_rd_status() & NF_MASK_STATUS_T_RDY_2KB )==0 ); 00364 } 00365 else 00366 { 00367 while( (Nfc_rd_status() & NF_MASK_STATUS_READY )==0 ); 00368 while( (Nfc_rd_status() & NF_MASK_STATUS_READY )==0 ); 00369 } 00370 } 00371 if( Is_nf_512() ) 00372 { 00373 while( (Nfc_rd_status() & NF_MASK_STATUS_T_RDY_512B )==0 ); 00374 while( (Nfc_rd_status() & NF_MASK_STATUS_T_RDY_512B )==0 ); 00375 } 00376 }
Reads the number spare bytes specified and stores them in a array.
p_byte | pointer on the array in which are stored the spare bytes. | |
n_byte | number of spare bytes to read. | |
page_addr | absolute page address of the block. |
nf_init()
should have been called before. The NF device should have been selected before with Nfc_action(NFC_ACT_DEV_SELECT, id)
. Definition at line 333 of file nf_drv.c.
References i, Mcu_set_sfr_page_nfc, NF_SPARE_POS, nfc_open_page_read(), and Nfc_rd_data_fetch_next.
00337 { 00338 U8 i; 00339 00340 Mcu_set_sfr_page_nfc(); 00341 nfc_open_page_read( page_addr, NF_SPARE_POS); 00342 00343 for ( i=0 ; i!=n_byte ; i++ ) 00344 { 00345 p_byte[i] = Nfc_rd_data_fetch_next(); 00346 } 00347 }
Referenced by nfc_detect().
_MEM_TYPE_SLOW_ U16 g_n_blocks |
Referenced by nfc_detect().
_MEM_TYPE_FAST_ U8 g_n_row_cycles |
Referenced by nf_init(), and nfc_detect().
_MEM_TYPE_SLOW_ U8 g_copy_back_cont |
Referenced by nfc_detect().
_MEM_TYPE_SLOW_ U8 g_copy_back_discont |
Referenced by nfc_detect().
Referenced by nfc_detect().
Referenced by nfc_detect().
_MEM_TYPE_SLOW_ U8 g_clock_dfc_nfc |
_MEM_TYPE_SLOW_ U8 g_dev_maker |
Referenced by nfc_detect().
Referenced by nfc_detect().
_MEM_TYPE_FAST_ U8 g_shift_page_byte |
_MEM_TYPE_FAST_ U8 g_shift_block_page |
_MEM_TYPE_SLOW_ U8 g_ofst_blk_status |