⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mx51_nfc.h

📁 freescale atk source code
💻 H
📖 第 1 页 / 共 2 页
字号:

/*!
 * Function to input address
 */
static void nfc_address_input(u32 address)
{	
	raw_write(address, NFC_NAND_ADD_0);
	raw_write(LAUNCH_ADDRESS_INPUT, NFC_LAUNCH_NFC);
	
	 /* Wait for Basic Operation Complete */
        nfc_wait();
}

/*!
 * Function to write flash address cycle
 */
static void nfc_address_cycle(u32 Address, u8 NumOfCycle)
{
	if(back_cmd == NAND_CMD_ERASE) {
                raw_write(Address, NFC_NAND_ADD_0);
	   	
	} else {
		/* for other than erase */
		raw_write(0x00000000, NFC_NAND_ADD_0);	
		raw_write((raw_read(NFC_NAND_ADD_0) | ( (Address & 0x0000ffff) << 16)), NFC_NAND_ADD_0);
		raw_write(((raw_read(NFC_NAND_ADD_8) & 0xffff0000) | ((Address & 0xffff0000) >> 16)), NFC_NAND_ADD_8);
	}
}

/*!
 * Function to input command
 */
static void nfc_command_input(u32 command)
{
	//back up the cmd
	back_cmd = command;
		
	switch ((u8)command)
	{
                case NAND_CMD_READ:	
                        raw_write(command, NFC_NAND_CMD);
                        break;	
                case NAND_CMD_RESET:
                        raw_write(command, NFC_NAND_CMD);
                        raw_write(LAUNCH_COMMAND_INPUT,NFC_LAUNCH_NFC);
                        nfc_wait();
                        break;
                case NAND_CMD_ERASE:
                        break;
                case NAND_CMD_READID:
                        raw_write(command, NFC_NAND_CMD);
                        raw_write(0x1,NFC_LAUNCH_NFC);
                        nfc_wait();
                        break;
                case NAND_CMD_PAGE_PROG:
                        raw_write(command, NFC_NAND_CMD);
                        raw_write(raw_read(NFC_NAND_CMD) | (NAND_CMD_PAGE_PROG_CONFIRM << 8), NFC_NAND_CMD);
                        break;	
                case NAND_CMD_READ_CONFIRM:
                        raw_write(raw_read(NFC_NAND_CMD) | (command << 8), NFC_NAND_CMD);
                        break;
                case NAND_CMD_PAGE_PROG_CONFIRM:
                        break;
                case NAND_CMD_ERASE_CONFIRM:	
                        raw_write(NAND_CMD_ERASE, NFC_NAND_CMD);
                        raw_write(raw_read(NFC_NAND_CMD) | (NAND_CMD_ERASE_CONFIRM << 8), NFC_NAND_CMD);
                        /* launch auto erase operation */
                        raw_write(LAUNCH_AUTO_ERASE, NFC_LAUNCH_NFC);
                        nfc_wait();
                        break;
                default:
                        break;
			
       }	 
}


static void nfc_block_unlock(void)
{
        raw_write(0x0, NFC_UNLOCK_BLK_ADD0);
        raw_write(0xffff<<16, NFC_UNLOCK_BLK_ADD0);
}

static void nfc_unlock_cs(u32 cs)
{
        /*Flash UN-Lock Setting*/
        u32 data2write;
        u32 new_cs;

        new_cs = (0x7 & cs)<<3;
        data2write = 0x00000084 | new_cs;
        raw_write(data2write, NFC_WR_PROTECT);
} 


/*!
  * Automation operations
  */

/*!
 * Function to send command to read page
 */
void send_read_page(void)
{	
        NFC_SEL_RAM_BUFFER(RBA_BUFFER0);
        /* lauch auto read operation */
        raw_write(LAUNCH_AUTO_READ, NFC_LAUNCH_NFC);
        nfc_wait();
        nand_wait();
}

/*!
 * Function to send command to write page
 */
void send_prog_page(void)
{
        NFC_SEL_RAM_BUFFER(RBA_BUFFER0);
        /* launch auto programming operation */
        raw_write(LAUNCH_AUTO_PRO, NFC_LAUNCH_NFC); 
        nfc_wait();
}

/*!
 * Function to check ecc status
 */
u8 nfc_ecc_uncorrectable_error(u32 page_size)
{
        u32 ecc_stat, err;
        int no_subpages = 1;
        int ret = 0;
        u8 ecc_bit_mask, err_limit;

        ecc_bit_mask = (IS_4BIT_ECC ? 0x7 : 0xf);
	err_limit = (IS_4BIT_ECC ? 0x4 : 0x8);

	no_subpages = page_size>>9;

        ecc_stat = raw_read(NFC_ECC_STATUS_RESULT);
	
	do {
		err = ecc_stat & ecc_bit_mask;
		if (err > err_limit) {
			ret = 1;
			break;
		}
		ecc_stat >>= 4;
	} while (--no_subpages);

	return ret;
}

/*!
 * Function to set nfc spare data
 */
void  set_nfc_spare(FLASH_FILE_FORMAT file_format )
{
        u32 i,j;
	/*this is for wince spare setting */
	if (FILE_FORMAT_NB0 == file_format) {
		/* fill internal RAM buffer */
        for(j=0;j<NFC_SAB_COUNT;j++) {
  		    for(i=0; i<NFC_SAB_LEN; i+=2){
   			    if((j== ((NAND_MAIN_BYTESIZE >> 9) - 1)) && (i==0))
				    *(volatile u16 *)(NFC_SAB0_BASE+i+j*NFC_SAB_LEN) = 0xFF00;
			    else
      			    *(volatile u16 *)(NFC_SAB0_BASE+i+j*NFC_SAB_LEN) = 0xFFFF;
		    }
        }
	} else if (FILE_FORMAT_NORMAL == file_format) {
  	    /* fill internal RAM buffer */
        for(j=0;j<NFC_SAB_COUNT;j++) {
  	        for(i=0; i<NFC_SAB_LEN; i+=2) {
		        *(volatile u16 *)(NFC_SAB0_BASE+i+j*NFC_SAB_LEN) = 0xFFFF;
  	        }
        }
	}
}

/*!
 * Function to init nfc
 */
void nfc_init(void)
{
        /* unlock blocks */
        nfc_block_unlock();

        /* unlock cs0 */
        nfc_unlock_cs(0);    

	
	/* NFC_CONFIGURATION2
		ST_CMD 				- 	8'b01110000   
		SPAS				-	8'b00100000   should be 8'b01000000 64K??
		INT_MSK				-	1'b1   disable interrupt
		AUTO_PROG_DONE_MSK 	-	1'b0
		NUM_ADR_PHASE1		-	2'b10  5 address phase read/program operations  // here could be more flexible
		EDC					-	3'b000
		PPB					-	2'b10
		ECC_MODE			-	1'b1   4bit error correction(16 spare)
		NUM_ADR_PHASE0		-	1'b1   (5-2 = 3) address phase erase operation // here could be moe flexible
		NUM_CMD_PHASES		-	1'b1   2 pahses (read command & read-confirm command)
		ECC_EN				-	1'b1   Ecc enable
		SYM					-	1'b0   asymmetric RE
		PS					-	2'b01   2kb page
	*/
	
	raw_write(0x7020A179,NFC_CONFIGURATION2);
	
	/* NO_SDMA,FMP=6,SBB=6,little Endian,Flash Width=x8*/
	raw_write(0x00160608, NFC_CONFIGURATION3);

        NFC_SEL_RAM_BUFFER(RBA_BUFFER0);
}

/*!
 * Function to set FMS
 */
void set_fms(u8 bus_width, u32 page_size,u16 oob_size)
{
        if(bus_width == 16)
                raw_write(raw_read(NFC_CONFIGURATION3) & NF_16BIT, NFC_CONFIGURATION3);  /* Set to 16-bit NAND */
        if(page_size == 4096) {
                /* Set to 4K Page Size */
                raw_write(raw_read(NFC_CONFIGURATION2) & ~3, NFC_CONFIGURATION2);
                raw_write(raw_read(NFC_CONFIGURATION2) | 2, NFC_CONFIGURATION2);
        }	
        if (page_size <= 512)
        {
                /*  NFC_CONFIGURATION2
                NUM_ADR_PHASE1		-	2'b01  4 address phase read/program operations 
                NUM_ADR_PHASE0		-	1'b0   (4-1 = 3) address phase erase operation
                NUM_CMD_PHASES		-	1'b0   1 pahses (read command & read-confirm command)
                PS					-	2'b00   1/2kb page   
                */
                raw_write(raw_read(NFC_CONFIGURATION2) & ~0x3033, NFC_CONFIGURATION2);
                raw_write(raw_read(NFC_CONFIGURATION2) | 0x1000, NFC_CONFIGURATION2);	
        }
	/* set the spas size */
	SET_SPAS(oob_size >>1);  
}

/*!
 * Function to read id
 */
void send_read_id(u32* tmp)
{
        NFC_SEL_RAM_BUFFER(RBA_BUFFER0);
        nfc_command_input(NAND_CMD_READID);
        nfc_address_input(0);
        raw_write(LAUNCH_READ_ID, NFC_LAUNCH_NFC);
        /* Wait for Basic Operation Complete */
        nfc_wait();
        *tmp  = *(volatile u32 *)(NFC_MAB0_BASE);
}
 
#endif /* __MX51_NFC_H__ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -