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 92 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 93 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 103 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 104 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 106 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 107 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 108 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 109 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 110 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 111 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 113 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 129 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 208 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 275 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 332 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 334 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 335 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 341 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 343 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 345 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 346 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 350 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 352 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 360 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 380 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 381 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 406 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 408 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 410 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 411 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 412 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 413 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 171 of file nf_drv.c.
00172 { 00173 #if (NF_CLE_ALE_MANUAL == ENABLED) 00174 XMCRB |= ((1<<XMM2) | (1<<XMM1) | (1<<XMM0)); // limit XRAM interface to A7 (release PC0..7) 00175 #else 00176 XMCRB |= ((1<<XMM2) | (1<<XMM1)); // limit XRAM interface to A9 (release PC2..7) 00177 #endif 00178 XMCRA |= (1<<SRE); // enable the external memory 00179 }
| 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 184 of file nf_drv.c.
References Nandflash0_unselect, and Nandflash1_unselect.
00185 { 00186 Nandflash0_unselect(); 00187 Nandflash1_unselect(); 00188 XMCRA &= ~(1<<SRE); // disable the external memory 00189 }
| void nfc_select_dev | ( | U8 | dev | ) |
Definition at line 82 of file nf_drv.c.
References Nandflash0_select, Nandflash0_unselect, Nandflash1_select, and Nandflash1_unselect.
00083 { 00084 if(0==dev) 00085 { 00086 Nandflash1_unselect(); 00087 Nandflash0_select(); 00088 }else{ 00089 Nandflash0_unselect(); 00090 Nandflash1_select(); 00091 } 00092 }
| Status_bool nfc_check_status | ( | void | ) |
Check the status of the selected device.
Definition at line 202 of file nf_drv.c.
References FAIL, Mcu_set_sfr_page_nfc, NF_MASK_STATUS_FAIL, Nfc_rd_data, nfc_wait_busy(), and PASS.
00203 { 00204 Mcu_set_sfr_page_nfc(); 00205 nfc_wait_busy(); // Send a status command and wait the completion of the last command 00206 if ( (Nfc_rd_data()&NF_MASK_STATUS_FAIL)==0 ) { return PASS; } // I/O 0 Pass:0 Fail:1 00207 else { return FAIL; } 00208 }
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 106 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().
00107 { 00108 U8 i_dev; 00109 if( 2 < nb_dev ) 00110 nb_dev = 2; // Only 1 or 2 for this driver 00111 00112 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00113 nf_XMCR_enable(); 00114 #endif 00115 nfc_init( nb_dev, 0 ); 00116 nfc_reset_nands( nb_dev ); // Reset all the NF devices 00117 00118 // Test NF configuration 00119 // 00120 for( i_dev=0 ; i_dev<nb_dev ; i_dev++ ) 00121 { 00122 Nfc_action( NFC_ACT_DEV_SELECT, i_dev); 00123 nfc_wait_busy(); 00124 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_CELOW); 00125 Nfc_set_cmd(NF_READ_ID_CMD); 00126 Nfc_set_adc( 0 ); 00127 if(( Nfc_rd_data_fetch_next()!=G_DEV_MAKER ) 00128 || ( Nfc_rd_data_fetch_next()!=G_DEV_ID )) 00129 { 00130 return i_dev; 00131 } 00132 if( G_CE_TOGGLE ) 00133 { 00134 // disable CE Low 00135 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_NOP); 00136 } 00137 } 00138 00139 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00140 nf_XMCR_disable(); 00141 #endif 00142 return nb_dev; 00143 }
| void nfc_reset_nands | ( | U8 | nb_dev | ) |
Reset all the NF devices.
| none |
Definition at line 151 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().
00152 { 00153 U8 i_dev; 00154 Mcu_set_sfr_page_nfc(); 00155 for( i_dev=0 ; i_dev<nb_dev ; i_dev++ ) 00156 { 00157 Nfc_action(NFC_ACT_DEV_SELECT, i_dev); 00158 // The wait is mandatory here since the function is used to wait any 00159 // pending internal programmation (Cache Program cmd). 00160 nfc_wait_busy(); 00161 Nfc_set_cmd(NF_RESET_CMD); 00162 nfc_wait_busy(); 00163 } 00164 }
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 220 of file nf_drv.c.
References Mcu_set_sfr_page_nfc, Nfc_open_page_read, and nfc_wait_busy().
00221 { 00222 Mcu_set_sfr_page_nfc(); 00223 nfc_wait_busy(); 00224 Nfc_open_page_read( page_addr, byte_addr); 00225 }
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 238 of file nf_drv.c.
References Mcu_set_sfr_page_nfc, and Nfc_open_page_write.
00239 { 00240 Mcu_set_sfr_page_nfc(); 00241 Nfc_open_page_write( page_addr, byte_addr); 00242 }
| 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 254 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.
00255 { 00256 U8 n_bytes; 00257 U8 i_byte; 00258 U8 i_page; 00259 00260 Mcu_set_sfr_page_nfc(); 00261 00262 n_bytes= ( Is_nf_512() ) 00263 ? 16 // 512B page access 00264 : 64 // 2KB page access 00265 ; 00266 00267 // Erasing the block is mandatory to prevent partial programming 00268 // (some 512B NF does support partial prog, but not after a copy back command). 00269 nfc_erase_block( page_addr, TRUE ); 00270 for ( i_page=(U8)1<<G_SHIFT_BLOCK_PAGE ; i_page!=0 ; i_page--, page_addr++ ) 00271 { 00272 nfc_open_page_write( page_addr, NF_SPARE_POS-8 ); 00273 Nfc_wr_data('A'); Nfc_wr_data('t'); 00274 Nfc_wr_data('m'); Nfc_wr_data('e'); 00275 Nfc_wr_data('l'); Nfc_wr_data(' '); 00276 Nfc_wr_data(' '); Nfc_wr_data(' '); 00277 for ( i_byte=n_bytes ; i_byte!=0 ; i_byte-=4 ) 00278 { 00279 Nfc_wr_data(0); 00280 Nfc_wr_data(0); 00281 Nfc_wr_data(0); 00282 Nfc_wr_data(0); 00283 } 00284 Nfc_set_cmd(NF_PAGE_PROGRAM_CMD); // Confirm programmation 00285 } 00286 }
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 301 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().
00302 { 00303 Mcu_set_sfr_page_nfc(); 00304 if (FALSE == force_erase) 00305 { 00306 nfc_open_page_read( page_addr, NF_SPARE_POS + G_OFST_BLK_STATUS ); 00307 if( (Nfc_rd_data() != 0xFF) ) return; // The block is bad. We can not erase it 00308 } 00309 nfc_wait_busy(); 00310 Nfc_unprotect_all_flash(); // WP may be actif due to block protection 00311 Nfc_set_cmd (NF_BLOCK_ERASE_CMD); // Auto Block Erase Setup 00312 Nfc_set_adr( LSB0(page_addr) ); 00313 Nfc_set_adr( LSB1(page_addr) ); 00314 if (3 == G_N_ROW_CYCLES) 00315 { 00316 Nfc_set_adr( MSB1(page_addr) ); 00317 } 00318 Nfc_set_cmd(NF_BLOCK_ERASE_CONFIRM_CMD); // Erase command 00319 }
| 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 557 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().
00558 { 00559 Mcu_set_sfr_page_nfc(); 00560 nfc_wait_busy(); 00561 Nfc_unprotect_all_flash(); // WP may be actif due to block protection 00562 Nfc_set_cmd(NF_READ_CMD); 00563 Nfc_set_adc( 0 ); 00564 Nfc_set_adc( 0 ); 00565 Nfc_set_adr( LSB0(page_addr) ); 00566 Nfc_set_adr( LSB1(page_addr) ); 00567 if ( 3==G_N_ROW_CYCLES ) 00568 { 00569 Nfc_set_adr( MSB1(page_addr) ); 00570 } 00571 Nfc_set_cmd(NF_COPY_BACK_CMD); 00572 nfc_wait_busy(); 00573 }
| 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 396 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().
00397 { 00398 U32 ret; 00399 00400 Mcu_set_sfr_page_nfc(); 00401 Nfc_action(NFC_ACT_DEV_SELECT, nf_num); 00402 nfc_wait_busy(); 00403 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_CELOW); 00404 Nfc_set_cmd (read_id_cmd); 00405 Nfc_set_adc( 0 ); 00406 00407 MSB0(ret)= Nfc_rd_data_fetch_next(); // Maker Code 00408 MSB1(ret)= Nfc_rd_data_fetch_next(); // Device Id 00409 MSB2(ret)= Nfc_rd_data_fetch_next(); // extra 00410 MSB3(ret)= Nfc_rd_data_fetch_next(); // extra (Multi Plane Support) 00411 00412 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_NOP); 00413 return ret; 00414 }
| U8 nfc_detect | ( | void | ) |
Read the ID of the Nand-Flash and update the global variable.
Definition at line 448 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.
00449 { 00450 U32 u32_nf_ids; 00451 U8 u8_i, u8_conf; 00452 00453 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00454 nf_XMCR_enable(); 00455 #endif 00456 00457 // Init the Nand Flash Controller 00458 nfc_init( NF_MAX_DEVICES, 0 ); 00459 nfc_reset_nands( NF_MAX_DEVICES ); // Reset all the NF devices 00460 00461 // Check the presence of device 0 00462 if ( FALSE == nfc_nf_is_ready() ) 00463 { 00464 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00465 nf_XMCR_disable(); 00466 #endif 00467 return NO_NF_CONNECTED; 00468 } 00469 00470 // Read the Nand Flash IDs of device 0 00471 u32_nf_ids = nfc_read_id( NF_READ_ID_CMD, 0 ); 00472 00473 // Identify the Nand Flash (device 0) 00474 for( u8_i=0 ; u8_i < (sizeof(nf_list_id)/sizeof(St_nf_id)) ; u8_i++) 00475 { 00476 if((nf_list_id[u8_i].manuf == MSB0(u32_nf_ids)) 00477 && (nf_list_id[u8_i].dev == MSB1(u32_nf_ids))) 00478 break; // here, ID is know 00479 } 00480 if( u8_i == (sizeof(nf_list_id)/sizeof(St_nf_id)) ) 00481 { 00482 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00483 nf_XMCR_disable(); 00484 #endif 00485 return NF_UNKNOW; 00486 } 00487 00488 // Set NF configuration parameters for initialisation and access 00489 #if (NF_GENERIC_DRIVER==TRUE) 00490 # error Test me... 00491 g_shift_page_byte =; 00492 g_shift_block_page =; 00493 #endif 00494 00495 #if (NF_GENERIC_DRIVER==TRUE) || (NF_AUTO_DETECT_2KB==TRUE) ||(NF_AUTO_DETECT_512B==TRUE) 00496 00497 // Record info 00498 u8_conf = nf_list_id[u8_i].conf; 00499 g_dev_maker = MSB0(u32_nf_ids); // Device maker 00500 g_dev_id = MSB1(u32_nf_ids); // Device ID 00501 00502 // Search the number of block of device 00503 for( u8_i=0 ; u8_i < (sizeof(nf_list_link_id_block)/sizeof(St_nf_link_id_block)) ; u8_i++) 00504 { 00505 if( nf_list_link_id_block[u8_i].dev_id == g_dev_id ) 00506 break; // ID found 00507 } 00508 if( u8_i == (sizeof(nf_list_link_id_block)/sizeof(St_nf_link_id_block)) ) 00509 while(1); // Error in NF definition 00510 00511 g_n_zones = nf_list_link_id_block[u8_i].nb_zones; 00512 #if (NF_AUTO_DETECT_2KB==TRUE) 00513 if( 1 == g_n_zones ) 00514 g_n_row_cycles = 2; 00515 else 00516 g_n_row_cycles = 3; 00517 #endif 00518 #if (NF_AUTO_DETECT_512B==TRUE) 00519 if( 2 >= g_n_zones ) 00520 g_n_row_cycles = 2; 00521 else 00522 g_n_row_cycles = 3; 00523 #endif 00524 g_n_blocks = g_n_zones*1024L; 00525 00526 g_copy_back_cont = nf_list_conf[u8_conf].copy_back_cont ; 00527 g_copy_back_discont = nf_list_conf[u8_conf].copy_back_discont; 00528 g_cache_program = nf_list_conf[u8_conf].cache_program ; 00529 g_ce_toggle = nf_list_conf[u8_conf].ce_toggle; 00530 /* 00531 g_clock_dfc_nfc = (nf_list_conf[u8_conf].dfc_nfc_clock<<5) & MSK_DNFCKS; 00532 00533 Mcu_set_sfr_page_nfc(); 00534 Nfc_set_read_timing((U8)nf_list_conf[u8_conf].timing_read ); 00535 if( !g_ce_toggle ) 00536 { 00537 // Enable CE low 00538 Nfc_action( NFC_ACT_ASSERT_CE, NFC_EXT_CELOW); 00539 } 00540 */ 00541 #endif 00542 00543 #if (NF_XMCR_MODULE_SHARED == ENABLED) 00544 nf_XMCR_disable(); 00545 #endif 00546 return u8_i; 00547 }
| 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 352 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.
00353 { 00354 register int Reg; 00355 Nfc_set_cmd(NF_READ_STATUS_CMD); 00356 Reg = Nfc_rd_status(); 00357 if( Is_nf_2k() ) 00358 { 00359 if( G_CACHE_PROG ) 00360 { 00361 while( (Nfc_rd_status() & NF_MASK_STATUS_T_RDY_2KB )==0 ); 00362 while( (Nfc_rd_status() & NF_MASK_STATUS_T_RDY_2KB )==0 ); 00363 } 00364 else 00365 { 00366 while( (Nfc_rd_status() & NF_MASK_STATUS_READY )==0 ); 00367 while( (Nfc_rd_status() & NF_MASK_STATUS_READY )==0 ); 00368 } 00369 } 00370 if( Is_nf_512() ) 00371 { 00372 while( (Nfc_rd_status() & NF_MASK_STATUS_T_RDY_512B )==0 ); 00373 while( (Nfc_rd_status() & NF_MASK_STATUS_T_RDY_512B )==0 ); 00374 } 00375 }
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 332 of file nf_drv.c.
References Mcu_set_sfr_page_nfc, NF_SPARE_POS, nfc_open_page_read(), and Nfc_rd_data_fetch_next.
00336 { 00337 U8 i; 00338 00339 Mcu_set_sfr_page_nfc(); 00340 nfc_open_page_read( page_addr, NF_SPARE_POS); 00341 00342 for ( i=0 ; i!=n_byte ; i++ ) 00343 { 00344 p_byte[i] = Nfc_rd_data_fetch_next(); 00345 } 00346 }
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 |
1.5.3