亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? at25f1024.c

?? EP9315的wince下載程序。download.exe
?? C
字號:
//****************************************************************************
//
// at25f1024.c - Routines for erasing and programing the at25f1024
//               eeprom.
//
// Copyright (c) 2006 Cirrus Logic, Inc.
//
//****************************************************************************

#include "ep93xx.h"
#include "timer.h"
#include "spi.h"
#include "at25f1024.h"

//-----------------------------------------------------------------------------
// at25f1024 write status
//-----------------------------------------------------------------------------
static void at25f1024_write_status(unsigned char value)
{
    int temp,i;
    //
    // Clear out the EEPROM status register in case there are bit left set.
    //
    while(SSP1->SSPSR.Field.TFE == 0);
    SSP1->SSPDR.Value = AT25F1024_WRITE_STATUS_REGISTER;
    SSP1->SSPDR.Value = 0;

    //
    // Get these useless bytes out of the FIFO.
    //
    while (SSP1->SSPSR.Field.RNE == 0);
    temp = SSP1->SSPDR.Value;
    while (SSP1->SSPSR.Field.RNE == 0);
    temp = SSP1->SSPDR.Value;

    //
    // Do some dummy reads to delay long enough for the Frame signal to be
    // deasserted.
    //
    for (i=0;i<100;i++)
    {
        temp = SSP1->SSPDR.Value;
    }
}

static unsigned char at25f1024_clear_receivefifo()
{
    int temp, i;
    unsigned char Status;

    //
    // Wait for the Transmit FIFO to empty
    //
    while(SSP1->SSPSR.Field.TFE == 0);

    while(SSP1->SSPSR.Field.BSY == 1);

     delay_usec(200);
    //
    // Empty the Recieve FIFO
    //
    while(SSP1->SSPSR.Field.RNE == 1)
    {
        temp = SSP1->SSPDR.Value;
    }
    
    return 0;
}
//-----------------------------------------------------------------------------
// at25f1024 get status
//-----------------------------------------------------------------------------
static unsigned char at25f1024_get_status()
{
    int temp, i;
    unsigned char Status;

    //
    // Wait for the Transmit FIFO to empty
    //
    while(SSP1->SSPSR.Field.TFE == 0);

    //
    // Empty the Recieve FIFO
    //
    while(SSP1->SSPSR.Field.RNE == 1)
    {
        temp = SSP1->SSPDR.Value;
    }

    //
    // Issues a Read Status Register command to the at25f1024
    //
    SSP1->SSPDR.Value = AT25F1024_READ_STATUS_REGISTER;

    //
    // Clock back in the status from the
    //
    SSP1->SSPDR.Value = 0x00;

    //
    // Wait for the Transmit FIFO to empty
    //
    while(SSP1->SSPSR.Field.TFE == 0);

    //
    // Throw away of this byte
    //
    while(SSP1->SSPSR.Field.RNE == 0);
    temp = SSP1->SSPDR.Value;

    //
    // Get the status of status register
    //
    while(SSP1->SSPSR.Field.RNE == 0);
    Status = (unsigned char)SSP1->SSPDR.Value;

    //
    // Do some dummy reads to delay long enough for
    // the Frame signal to be deasserted.
    //
    for (i=0;i<100;i++)
    {
        temp = SSP1->SSPDR.Value;
    }

    return(Status);
}

//-----------------------------------------------------------------------------
// at25f1024 enable writing
//-----------------------------------------------------------------------------
static int at25f1024_write_enable()
{
    int temp, i;

    //
    // Send the write enable latch command
    //
    while(SSP1->SSPSR.Field.TFE == 0);
    SSP1->SSPDR.Value = AT25F1024_SET_WRITE_ENABLE;

    while(SSP1->SSPSR.Field.TFE == 0);

    //
    // Empty out the read FIFO entry that was created by the write..
    //
    while (SSP1->SSPSR.Field.RNE == 0);
    temp = SSP1->SSPDR.Value;

    //
    // Do some dummy reads to delay long enough for the Frame signal to be
    // deasserted.
    //
    for (i=0;i<100;i++)
    {
        temp = SSP1->SSPDR.Value;
    }

    //
    // Gives the time to let Frame going high again!
    //
    delay_usec(500);

    //
    // Check that the write enable is indicated in the EEPROM status
    // register.
    do
    {
    //
    // Get the ready status of status register
    //
    temp = at25f1024_get_status();
    if( (temp & (AT25F1024_STATUS_READY | AT25F1024_STATUS_WRITE) ) == AT25F1024_STATUS_WRITE)
    {
        break;
    }
    } while (temp & AT25F1024_STATUS_READY);

    delay_usec(500);

    return 0;
}

//-----------------------------------------------------------------------------
// init_at25f1024 chip init
//-----------------------------------------------------------------------------
void init_at25f1024(void)
{
    unsigned long ulChipID=0;
    //
    // Disable the ssp, disable interrupts
    //
    SSP1->SSPCR1.Value = 0;

    //
    // Set GPIO pins 12 and 14 as outputs.
    //
    *((volatile unsigned int *)(PBDDR)) = (0x50);

    //
    // Set GPIO pins 12 and 14 high to disable the keyboard.
    //
    *((volatile unsigned int *)(PBDR)) = (0x50);

    //
    // Set GPIO pin 6 and 7 as an outputs.
    //
    *((volatile unsigned int *)(PADDR)) = (0xc0);

    //
    // Clear GPIO pin 7 to enable the frame line.
    // Set GPIO pin 6 to disable the CS4271.
    //
    *((volatile unsigned int *)(PADR)) = (0x00);
    *((volatile unsigned int *)(PADR)) = (0x40);

    //
    // Set FGPIO pin 0 as an output.
    //
    *((volatile unsigned int *)(PFDDR)) = (0x01);

    //
    // Set FGPIO pin 0 to disable the TLV2542.
    //
    *((volatile unsigned int *)(PFDR)) = (0x01);

    //
    // Set the enable bit(SSE) in SSP1CR1
    //
      SSP1->SSPCR1.Value = 0x10;

    //
    //program the SSP1CRO register
    //
    ulChipID = *((volatile unsigned int *)(SDRAMDEVCFG0));
    if((ulChipID&0x4)==4)
    {
    	SSP1->SSPCR0.Value = 0x000002c7;
    }
    else
    {
    	SSP1->SSPCR0.Value = 0x000001c7;
    }

    //
    //Read the chip id
    //
    ulChipID = *((volatile unsigned int *)(CHIPID));
    
    //
    // Program the predivisor register.
    //
    //if(((ulChipID&0xf0000000)>>28)>=0x0111)
    if(((ulChipID&0xf0000000)>>28)>=0x07)
    {   
    	//
    	//if Chip REV >=E2,the diver =4;
    	//
    	SSP1->SSPCPSR.Value = 4;
    }
    else
    {
    	//
    	//if Chip REV <=E1,(E0)the diver =2;
    	//
    	SSP1->SSPCPSR.Value = 2;
    }
    //
    // Clear the enable bit(SSE) in SSP1CR1
    //
    SSP1->SSPCR1.Value = 0;

    //
    // Set the enable bit(SSE) in SSP1CR1
    //
    SSP1->SSPCR1.Value = 0x10;
}

//-----------------------------------------------------------------------------
// query_at25f1024 chip query
//-----------------------------------------------------------------------------
int query_at25f1024(unsigned int manu_id,unsigned int device_id)
{
    int delay;
    int atmelcode;
    int devicecode;
    int temp, temp2;

    //
    // Make sure fifo is empty.
    //
    while(SSP1->SSPSR.Field.TFE == 0 || SSP1->SSPSR.Field.BSY == 1);

    //
    // Wait for any data to get out of the transmit fifo.
    //
    for(delay=64;delay >0; delay--);

    while(SSP1->SSPSR.Field.RNE == 1)
    {
        temp = SSP1->SSPDR.Value;
    }

    //
    // Clock in four bytes of data.
    //
    SSP1->SSPDR.Value = AT25F1024_READ_MANUFACTURER_PRODUCT_ID;
    SSP1->SSPDR.Value = 0x00;
    SSP1->SSPDR.Value = 0x00;

    while(!SSP1->SSPSR.Field.TFE || SSP1->SSPSR.Field.BSY || !SSP1->SSPSR.Field.RNE);

    //
    // throw away the 2 first data
    //
    temp2 = (unsigned char)SSP1->SSPDR.Value;

    //
    // Get the bytes of data that are actually read back from the device.
    //
    while(!SSP1->SSPSR.Field.RNE);
    atmelcode = (unsigned char)SSP1->SSPDR.Value;

    while(!SSP1->SSPSR.Field.RNE);
    devicecode = (unsigned char)SSP1->SSPDR.Value;

    //
    // Compare the ID got from eeprom with at25f1024's ID
    //
    if ((manu_id ==(unsigned int)atmelcode)&(device_id==(unsigned int)devicecode))
        return 1;
    else
        return 0;
}



//-----------------------------------------------------------------------------
// erase_at25f1024 chip erase
//-----------------------------------------------------------------------------
int erase_at25f1024(unsigned int addrOffset, int length)
{
    int temp;
    unsigned int addrBase=0,addr;

    if(addrOffset>1*1024*1024/8)
    	return 2;
    else if(addrOffset+length>1*1024*1024/8)
    	return 0;	
   
   //each sector 32k bytes
   for(addrBase=0; addrBase<length; addrBase+=0x8000)
    {
    addr =  addrBase+addrOffset; 	    	
    //
    // Send the write command to status register
    //
    at25f1024_write_status(0);

    delay_usec(50);

    //
    // Send the enable_write command to status register
    //
    at25f1024_write_enable();

    delay_usec(50);

    //
    // Send the chip erase command to eeprom
    //
    SSP1->SSPDR.Value = AT25F1024_SECTOR_ERASE;//AT25F1024_CHIP_ERASE;
    
    SSP1->SSPDR.Value = (addr>>16) & 0xFF;//0;
    SSP1->SSPDR.Value = (addr>>8)  & 0xFF;
    SSP1->SSPDR.Value = (addr)	   & 0xFF;

    delay_usec(50);

    //
    // Check that the write enable is indicated in the EEPROM status
    // register.
    //
    do
    {
        delay_usec(100/2);
        temp = at25f1024_get_status();
    } while (temp & AT25F1024_STATUS_READY);


    }
    
    delay_usec(500);
    return(1);
}

//-----------------------------------------------------------------------------
// program_at25f1024 chip write
//-----------------------------------------------------------------------------
int program_at25f1024(unsigned int addr, unsigned char *pBuffer, int length)
{
    unsigned int  count = 0;
    volatile unsigned char * pData;
    unsigned long * pLongData,pulTest[4];
    addr &= 0x1ffff;
    pData = pBuffer;
    pLongData = (unsigned long *)pBuffer;
    
    do
    {
    //
    // Send the enable_write command to status register
    //
    at25f1024_write_enable();

    //
    // Send byte_program command and the address to eeprom
    //
    SSP1->SSPDR.Value = AT25F1024_PROGRAM_DATA;
    SSP1->SSPDR.Value = (addr>>16) & 0xFF;//0;
    SSP1->SSPDR.Value = (addr>>8)  & 0xFF;
    SSP1->SSPDR.Value = (addr)	   & 0xFF;

    //
    // Write the word to eeprom and add the length of the buffer
    //
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];

    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];
    
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];
    
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];
    SSP1->SSPDR.Value = pData[count++];            
    
    //while(SSP1->SSPSR.Field.TFE == 0);

    //
    // Increase the address of the eeprom
    //
    addr +=16;//4
    delay_usec(100);

    //
    // Get the ready status of status register
    //
    while(at25f1024_get_status() & (AT25F1024_STATUS_READY | AT25F1024_STATUS_WRITE));

    delay_usec(50);
    
    //
    //Read-back verification
    // 
    pulTest[0] = read_at25f1024(addr-16,(unsigned char *)(pulTest),4);
    pulTest[1] = read_at25f1024(addr-12,(unsigned char *)(pulTest),4);
    pulTest[2] = read_at25f1024(addr-8,(unsigned char *)(pulTest),4);
    pulTest[3] = read_at25f1024(addr-4,(unsigned char *)(pulTest),4);
    
    if( 
      (((pulTest[0])&0xff)!=pData[count-16])||(((pulTest[0]>>8)&0xff)!=pData[count-15])||
      (((pulTest[0]>>16)&0xff)!=pData[count-14])||(((pulTest[0]>>24)&0xff)!=pData[count-13])||
      (((pulTest[1])&0xff)!=pData[count-12])||(((pulTest[1]>>8)&0xff)!=pData[count-11])||
      (((pulTest[1]>>16)&0xff)!=pData[count-10])||(((pulTest[1]>>24)&0xff)!=pData[count-9])||
      (((pulTest[2])&0xff)!=pData[count-8])||(((pulTest[2]>>8)&0xff)!=pData[count-7])||
      (((pulTest[2]>>16)&0xff)!=pData[count-6])||(((pulTest[2]>>24)&0xff)!=pData[count-5])||
      (((pulTest[3])&0xff)!=pData[count-4])||(((pulTest[3]>>8)&0xff)!=pData[count-3])||
      (((pulTest[3]>>16)&0xff)!=pData[count-2])||(((pulTest[3]>>24)&0xff)!=pData[count-1])            
      )
    {
    	return 0;//-1;	
    }

    }while (count < length);
    
    return length;
}



unsigned long read_at25f1024(unsigned int start, unsigned char *pBuffer, int numBytes)
{
	
    unsigned long ulRet, ulTemp;
    //unsigned long count=0;
  
    unsigned long ulOffset = start;
  
    at25f1024_clear_receivefifo();
  
    //
    //
    //
    out(SSP1DR,0x03);
    out(SSP1DR, (ulOffset >>16) & 255);
    out(SSP1DR, (ulOffset >>8) & 255);
    out(SSP1DR,  ulOffset & 255);
    
    do{
      ulTemp = in(SSP1SR);
    } while(!(ulTemp & 0x04));
     ulTemp = in(SSP1DR);
     
     out(SSP1DR,0x00);
     out(SSP1DR,0x00);
     out(SSP1DR,0x00);
     out(SSP1DR,0x00);
     
     do{ 
     	 ulTemp = in(SSP1SR);
     } while(!(ulTemp & 0x04));
       ulTemp = in(SSP1DR);
     //out(SSP1DR,0x00);
     
     do{ 
     	ulTemp = in(SSP1SR);
     } while(!(ulTemp & 0x04));
       ulTemp = in(SSP1DR);
     //out(SSP1DR,0x00);
     
     do{ 
     	 ulTemp =in(SSP1SR);
     }while (!(ulTemp & 0x04));
      ulTemp = in(SSP1DR);
     //out(SSP1DR,0x00);
     
      do{
     	ulTemp =in(SSP1SR);
     } while(!(ulTemp & 0x04));
       ulRet = in(SSP1DR);
     
     do{
        ulTemp = in(SSP1SR);
      } while(!(ulTemp & 0x04));
       ulTemp = in(SSP1DR);
       ulRet |= ulTemp<<8;
       
      do{
         ulTemp = in(SSP1SR);
        } while(!(ulTemp & 0x04));
          ulTemp = in(SSP1DR);
          ulRet |= ulTemp<<16;
      
      do{
         ulTemp = in(SSP1SR);
        } while(!(ulTemp & 0x04));
          ulTemp = in(SSP1DR);
          ulRet |= ulTemp <<24;
          
       do{ 
          ulTemp = in(SSP1SR);
        } while(!(ulTemp & 0x01));
        
        
        do{ 
           ulTemp = in(SSP1SR);
           if(ulTemp & 0x04)
             ulTemp = in(SSP1DR);
        } while (ulTemp & 0x04);
        
        return ulRet;
 
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品精品国产高清一毛片一天堂| 成人免费福利片| 欧美日韩五月天| 亚洲一区二区高清| 欧美三级视频在线播放| 亚洲动漫第一页| 91精品国产综合久久久久| 蜜桃视频一区二区三区在线观看| 精品欧美一区二区在线观看| 国产乱人伦偷精品视频免下载 | 香蕉影视欧美成人| 欧美妇女性影城| 国模套图日韩精品一区二区| 欧美激情中文不卡| 日本乱人伦一区| 蜜臀av性久久久久av蜜臀妖精| 精品国产一区二区精华| 成人黄色av网站在线| 亚洲综合免费观看高清在线观看| 91麻豆精品国产91久久久久| 国产另类ts人妖一区二区| 日韩美女视频一区二区| 欧美精品日日鲁夜夜添| 国产激情视频一区二区三区欧美| 玉足女爽爽91| 日韩欧美中文一区| av中文一区二区三区| 日韩高清在线一区| 中文一区在线播放| 正在播放一区二区| 成人av电影免费观看| 蜜臀91精品一区二区三区| 国产精品卡一卡二| 日韩一区二区三区精品视频| 北条麻妃一区二区三区| 日本麻豆一区二区三区视频| 国产精品久99| 日韩欧美黄色影院| 色婷婷av一区二区三区之一色屋| 久久99国产精品久久99 | 在线视频综合导航| 国产美女精品一区二区三区| 亚洲一区在线电影| 欧美国产欧美综合| 日韩欧美你懂的| 在线亚洲精品福利网址导航| 成人午夜私人影院| 蜜桃一区二区三区在线| 偷拍一区二区三区四区| 成人欧美一区二区三区小说 | 大白屁股一区二区视频| 午夜日韩在线电影| 一区二区三区四区在线| 欧美高清在线精品一区| 久久综合九色综合欧美亚洲| 欧美丰满一区二区免费视频| 色婷婷精品久久二区二区蜜臂av| 国产99久久精品| 国产美女在线观看一区| 久久99国产精品久久| 麻豆精品一区二区三区| 五月婷婷激情综合| 亚洲福中文字幕伊人影院| 91美女在线视频| 色8久久精品久久久久久蜜| 精品影视av免费| 亚洲成人免费视频| 亚洲一区二区三区三| 亚洲欧洲精品一区二区精品久久久| 26uuu成人网一区二区三区| 欧美一区日韩一区| 欧美日本国产视频| 欧美日本一区二区| 精品视频1区2区| 欧美四级电影网| 欧美日本一道本| 日韩欧美亚洲国产另类| 精品国产乱码久久久久久久久| 日韩三区在线观看| 日韩美女在线视频| 久久色在线视频| 欧美国产一区在线| 亚洲日本一区二区| 一个色在线综合| 婷婷开心激情综合| 免费成人深夜小野草| 久久国产福利国产秒拍| 国产在线看一区| 国产精品一级片| 成人动漫视频在线| 色婷婷综合久久久久中文| 欧日韩精品视频| 欧美日韩色综合| 欧美成人a在线| 国产日本欧洲亚洲| 亚洲人123区| 日韩精品国产精品| 国内精品伊人久久久久av影院| 国产一区 二区 三区一级| www.亚洲色图.com| 欧美日精品一区视频| 精品久久久三级丝袜| 国产午夜精品福利| 一区二区三区小说| 韩国一区二区三区| 91免费观看国产| 日韩一区二区麻豆国产| 久久久噜噜噜久久人人看| 亚洲欧美自拍偷拍色图| 亚洲福利视频导航| 国产麻豆一精品一av一免费| 色哟哟一区二区在线观看| 欧美理论在线播放| 国产亚洲短视频| 亚洲成人av一区二区| 国内精品自线一区二区三区视频| 91色在线porny| 欧美精品一区二区三区视频| 亚洲免费在线电影| 日本午夜一本久久久综合| 99久久精品免费精品国产| 69av一区二区三区| 中文字幕一区免费在线观看| 日韩黄色片在线观看| 成人sese在线| 日韩精品一区二区三区三区免费| 亚洲免费大片在线观看| 激情亚洲综合在线| 欧美乱熟臀69xxxxxx| 国产精品久久国产精麻豆99网站| 免费观看日韩av| 欧美在线观看视频在线| 国产精品毛片大码女人| 美腿丝袜一区二区三区| 在线日韩国产精品| 国产精品国产a| 激情六月婷婷久久| 3d成人动漫网站| 亚洲人xxxx| 99视频有精品| 久久免费看少妇高潮| 日韩精品一二三| 欧美日韩国产首页| 一区二区三区在线观看国产| 国产成人免费视频一区| 精品国产一区二区三区久久久蜜月| 亚洲永久免费av| 91麻豆福利精品推荐| 国产精品乱人伦| 国产成人自拍网| 久久在线免费观看| 久久疯狂做爰流白浆xx| 91精品国产综合久久福利软件| 亚洲精品日产精品乱码不卡| 成人午夜免费电影| 久久久噜噜噜久久人人看| 激情文学综合网| 欧美xxxxxxxx| 精品一区二区三区在线播放| 日韩一区二区影院| 免费人成精品欧美精品| 欧美一区二区精品在线| 日本伊人精品一区二区三区观看方式| 欧洲色大大久久| 一区二区三区不卡视频| 欧美亚洲禁片免费| 亚洲午夜私人影院| 91精品一区二区三区久久久久久 | 免费一级片91| 91精品国产综合久久精品性色| 午夜精品123| 欧美精品久久99久久在免费线| 亚洲国产欧美日韩另类综合| 91国产成人在线| 亚洲高清在线精品| 日韩情涩欧美日韩视频| 激情综合色综合久久综合| 久久精品这里都是精品| 国产精品一二三四五| 国产精品久久久久桃色tv| 91丝袜美女网| 亚洲一二三四在线| 欧美高清视频不卡网| 麻豆专区一区二区三区四区五区| 欧美成人精品3d动漫h| 国产乱码字幕精品高清av| 国产精品对白交换视频| 欧美在线看片a免费观看| 五月激情六月综合| 久久一夜天堂av一区二区三区| 国产福利一区二区三区视频在线| 中文字幕+乱码+中文字幕一区| 日本道在线观看一区二区| 午夜精品aaa| 欧美激情一区二区三区全黄| 一本大道综合伊人精品热热| 日本不卡一区二区| 国产亚洲精品久| 欧美性生交片4| 久久99精品国产麻豆婷婷|