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

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

?? upsd3400_usb_app.c

?? uPSD34xx Disk driver
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*------------------------------------------------------------------------------
upsd3400_usb_app.c

Version:
September 13, 2005 Ver 1.1 - Updated disclaimer, renamed file.
March 22, 2005 - Version 1.0 - Initial Release.

Description:  USB Mass Storage Class application module. 

Compilers:
Raisonance, Keil

THIS INFORMATION (or THIS SOFTWARE or THIS DOCUMENT) IS FOR GUIDANCE ONLY. ST 
MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS 
SOFTWARE nor for any infringement of patents or other rights of third parties 
which may result from its use. ST MICROELECTRONICS SHALL NOT BE HELD LIABLE FOR 
ANY DIRECT, INDIRECT INCIDENTAL OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY 
CLAIMS ARISING IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, 
OR USE OF THIS SOFTWARE. Specifications mentioned in this publication are 
subject to change without notice. This publication supersedes and replaces all 
information previously supplied. STMicroelectronics products are not authorized 
for use as critical components in life support devices or systems without the 
express written approval of STMicroelectronics.
------------------------------------------------------------------------------*/

#pragma NOAREGS

#include "upsd3400.h"
#include "upsd3400_hardware.h"
#include "upsd3400_usb.h"
#include "upsd3400_upsd_usb.h"
#include "upsd3400_usb_app.h"

#define USB_MS_SectorSize 512
#define USB_MS_UnitSize   (USB_MS_SectorSize*9*64)

extern xdata PSD_REGS UPSD_xreg;

data unsigned      char gbCBWCB[16];
data unsigned long  int gdwCBWTag;
data unsigned long  int gdwCBWDataTransferLength;
data unsigned      char gbCBWFlags;
data unsigned      char gbCBWLUN;
data unsigned      char gbCBWCBLength;
data unsigned      char gbCSWStatus;
data unsigned      char gbBulkPipeStage;

static data unsigned int TransferLength;
static data unsigned int PhysicalDataAddr;

extern unsigned char data usbState, ep0state, ep1state;
extern setup_buffer setupPacket;

#define USB_FIFO ((unsigned char volatile xdata *) USB_BASE_ADDR)

#define UMSC_IN_ENDPOINT SELEP1
#define UMSC_OUT_ENDPOINT SELEP1

#define UMSC_MASK_IN_ENDPOINT IN1F
#define UMSC_MASK_OUT_ENDPOINT OUT1F


void ReturnCSW(void)
/******************************************************************************
  Function   : void ReturnCSW(void)
  Parameters : none
  Description: Handle CSW package.
               Command Status Wrapper (CSW) shall start on a packet boundary
               and shall end as a short packet with exactly 13 (0Dh) bytes
               transferred. Fields appear aligned to byte offsets equal to
               a multiple of their byte size. All CSW transfers shall
               be ordered with the LSB (byte 0) first (little endian).
   ******************************************************************************/
 {
  USEL  = INDIR | UMSC_IN_ENDPOINT;          //Select EP1 IN

/*dCSWSignature:
  Signature that helps identify this data packet as a CSW. The signature field
  shall contain the value 53425355h (little endian), indicating CSW. */
  USB_FIFO[ 0] = 0x55;                       // dCSWSignature
  USB_FIFO[ 1] = 0x53;
  USB_FIFO[ 2] = 0x42;
  USB_FIFO[ 3] = 0x53;
/*dCSWTag:
  The device shall set this field to the value received in the dCBWTag
  of the associated CBW.*/
  USB_FIFO[ 4] = *((uchar *)&gdwCBWTag+3);   // dCSWTag, LSB read first
  USB_FIFO[ 5] = *((uchar *)&gdwCBWTag+2);
  USB_FIFO[ 6] = *((uchar *)&gdwCBWTag+1);
  USB_FIFO[ 7] = *((uchar *)&gdwCBWTag+0);
/*dCSWDataResidue:
  For Data-Out the device shall report in the dCSWDataResidue the difference
  between
  the amount of data expected as stated in the dCBWDataTransferLength,
  and the actual amount of data processed by the device.
  For Data-In the device shall report in the dCSWDataResidue the difference
  between the amount of data expected as stated in the dCBWDataTransferLength
  and the actual amount of relevant data sent by the device.
  The dCSWDataResidue shall not exceed the value sent in the dCBWDataTransferLength.
  We return always zero, it is simple.
  */
  USB_FIFO[ 8] = 0x00;                       // dCSWDataResidue
  USB_FIFO[ 9] = 0x00;
  USB_FIFO[10] = 0x00;
  USB_FIFO[11] = 0x00;
/*bCSWStatus:
  bCSWStatus indicates the success or failure of the command.
  The device shall set this byte to zero if the command completed successfully.
  A non-zero value shall indicate a failure during command execution according
  to the following table:
  00h Command Passed ("good status")
  01h Command Failed
  02h Phase Error
  03h and 04h Reserved (Obsolete)
  05h to FFh Reserved
  */
  USB_FIFO[12] = gbCSWStatus;                // bCSWStatus

  USIZE = 0x0D;                              // fire !

  gbBulkPipeStage = BS_CSW_DONE_PHASE;
 }

void SpecificIncrementSectorAddress(void)
/******************************************************************************
 Function   : void SpecificIncrementSectorAddress(void)
 Parameters : none
 Description: Increments PhysicalDataAddr of 512b (1 sector),
              adjust PAGE and TransferLength.
              Used in Read and Write Commands
 ******************************************************************************/
 {
  PhysicalDataAddr   += 64;                  // next sector physical address
  if (PhysicalDataAddr < 0x8000)
   {
    PhysicalDataAddr += 0x8000;        // adjust address to the top half of memory
    UPSD_xreg.PAGE   += 1;                   // adjust PAGE
   }
  TransferLength--;                          // decrement sector counter
 }

// Flash parameters
#define NVM_DATA_POLL     0x80              // flash status "data poll" bit at DQ7
#define NVM_DATA_TOGGLE   0x40            // flash status "toggle poll" bit at DQ6
#define NVM_ERROR         0x20               // flash status "error" bit at DQ5


BOOL EraseMainFlashSector(void)
/******************************************************************************
 Function   : BOOL EraseMainFlashSector()
 Parameters : (unsigned int addr,unsigned char wbyte)
 Description: Erases Main Flash Sector
 ******************************************************************************/
 {
  data unsigned char err,error,done;
  data unsigned char poll;

  done = FALSE;
  err = FALSE;

  ((unsigned char volatile xdata *) 0x8000)[0x0555] = 0xAA;
                                 // unlock main flash, write 0xAA to addess 0xX555
  ((unsigned char volatile xdata *) 0x8000)[0x0AAA] = 0x55;
                                 // unlock main flash, write 0x55 to addess 0xXAAA
  ((unsigned char volatile xdata *) 0x8000)[0x0555] = 0x80;
                                             // write 0x80 command to erase sector
  ((unsigned char volatile xdata *) 0x8000)[0x0555] = 0xAA;
                                             // continue unlock sequence
  ((unsigned char volatile xdata *) 0x8000)[0x0AAA] = 0x55;
                                             // continue unlock sequence
  ((unsigned char volatile xdata *) 0x8000)[0x0000] = 0x30;
                                          // write 0x30 to sector address to erase

  do                      // now use dat polling method to verify successful erase
   {
    poll = ((unsigned char volatile xdata *) 0x8000)[0x0000];
                                             // read flash status from any address
                                         // within the defined flash address space
    error = poll & NVM_ERROR;                // save timeout error bit at DQ5
    poll = poll & NVM_DATA_POLL;             // look at D7
    if (poll == NVM_DATA_POLL)               // compare DQ7
     {
      done = TRUE;             // bulk erase OK, indicate successful exit criteria
     }
    else if (error == NVM_ERROR)             // check for timeout error
     {
      err = TRUE;                            // indicate timeout error occurred
     }

   }
  while((done == FALSE) && (err == FALSE));


  if (err == TRUE)                  // make sure timeout error and dat poll didn't
                                             // occur simultaneously
   {
    poll = ((unsigned char volatile xdata *) 0x8000)[0x000];
                                             // Read flash status again
    poll = poll & NVM_DATA_POLL;           // get DQ7 of poll byte read from flash
    if (poll == NVM_DATA_POLL)               // compare DQ7
     {
      done = TRUE;                           // the flash erased OK at the same
                   // time timout error occured, indicate successful exit criteria
      err  = FALSE;
     }
    else
     {
      ((unsigned char volatile xdata *) 0x8000)[0x0555] = 0xF0;
                                // reset the flash array (short reset instruction)
     }
   }

  return err;
 }







BOOL WriteToMainFlash(unsigned int addr,unsigned char wdat)
/******************************************************************************
 Function   : BOOL WriteToMainFlash()
 Parameters : (unsigned int addr,unsigned char wbyte)
 Description: Writes 1 byte to Main Flash
 ******************************************************************************/
 {
  data unsigned char err,error,done;
  data unsigned char poll,dat;

  err = FALSE;

  if ( ((unsigned char volatile xdata *) 0)[addr] != wdat)
   {
    done = FALSE;
    ((unsigned char volatile xdata *) 0)[0x8555] = 0xAA;
                                 // unlock main flash, write 0xAA to addess 0xX555
    ((unsigned char volatile xdata *) 0)[0x8AAA] = 0x55;
                                 // unlock main flash, write 0x55 to addess 0xXAAA
    ((unsigned char volatile xdata *) 0)[0x8555] = 0xA0;
                                             // write 0xA0 command to program
    ((unsigned char volatile xdata *) 0)[addr] = wdat;
                                             // write byte to flash
    dat = wdat & NVM_DATA_POLL;              // get bit DQ7 of the original dat

    do                    // now use dat polling method to verify successful write
     {
      poll = ((unsigned char volatile xdata *) 0)[addr];
                                     // Read the location that was just programmed
      error = poll & NVM_ERROR;              // save timeout error bit at DQ5
      poll = poll & NVM_DATA_POLL;         // get DQ7 of poll byte read from flash

      if (dat == poll)                       // compare DQ7
       {
        done = TRUE;                         // dat byte programmed into flash OK,
                                             // indicate successful exit criteria
       }
      else if (error ==  NVM_ERROR )         // check for timeout error
       {
        err = TRUE;                          // indicate timeout error occurred
       }

     }
    while((done == FALSE) && (err == FALSE));

    if (err == TRUE)                // make sure timeout error and dat poll didn't
                                             // occur simultaneously
     {
      poll = ((unsigned char volatile xdata *) 0)[addr];
                                             // Read location in flash again
      poll = poll & NVM_DATA_POLL;         // get DQ7 of poll byte read from flash
      if (dat == poll)                       // compare DQ7
       {
        done = TRUE;             // data byte programmed into flash OK at the same
                   // time timout error occured, indicate successful exit criteria
        err  = FALSE;
       }
      else
       {
        ((unsigned char volatile xdata *) 0)[0x8555] = 0xF0;
                                // reset the flash array (short reset instruction)
       }
     }
   }
  return err;
 }







void WriteBufferToFlash(void)
/******************************************************************************
 Function   : void WriteBufferToFlash()
 Parameters : (none)
 Description: Receives (writes) TransferLength sectors with length of 512 Bytes

 How it works:
 This SW burns data into internal uPSD NOR FLASH. To save FLASH RW cycles,
 it is looking for empty sector part you are burning in.
 If the area is filled by 0xFF only, the sector part is assumed
 to be erased before, so only data are written directly to the selected flash
 sector.
 If not, the sector is copied to the last flash sector #8,
 erased afterwards and written back (with the updated data block).
 ******************************************************************************/
 {
  data unsigned char j,page;
  data unsigned int i,SectorEndPhysicalDataAddr;


  UPSD_xreg.DATAOUT_D = 0;                   // WRITE, RED LED ON !

  if (TransferLength != 0)
   {
                                             // Test the block (following 64B).
    USEL  = OUTDIR | UMSC_OUT_ENDPOINT;      // Select EP3 OUT

    i = PhysicalDataAddr;
    j = 0;
// now check whether is necessary to erase the block or not; it saves Flash RW cycles
    while (j<64)
     {
      if (( ( ((unsigned char volatile xdata *) 0)[i]) | USB_FIFO[j]) != 0xFF)
       {
        j = 255;
       }
      else
       {
        i++;
        j++;
       }
     }


    if (j == 255)             //check whether the sector needs to be erased or not
     {
      page = UPSD_xreg.PAGE;
      UPSD_xreg.PAGE = 7;

      EraseMainFlashSector();                //erase sector #8;
                                  //now calculate the max. FLASH area to be erased
           //TransferLength holds number of 64B packets to be received and written
      if ((TransferLength>=512) || ((PhysicalDataAddr+(TransferLength<<6))<0x8000))
       {
        SectorEndPhysicalDataAddr = 0xFFFF;  //the top of memory
       }
      else
       {
        SectorEndPhysicalDataAddr = PhysicalDataAddr+(((unsigned int)TransferLength)<<6)-1;
       }


      UPSD_xreg.PAGE = page;                 // the sector part needs to be erased
      i = 0x8000;               //now copy the FLASH sector to the flash sector #8
      while (i != 0)   //  copy only the area without the part we are updating now
       {
        if ((i<PhysicalDataAddr) || (i>SectorEndPhysicalDataAddr))    //write back
         {
          j = ((unsigned char volatile xdata *) 0)[i];
          if (j != 0xFF)                     // do not write 0xFF
           {
            UPSD_xreg.PAGE = 7;
            if (WriteToMainFlash(i,j) == TRUE)
             {
              gbCSWStatus = FAIL;          //error during write operation occured!
              i = 0xFFFF;
             }
            UPSD_xreg.PAGE = page;
           }
         }
        i++;                           // this area will be replaced by a new data
       }

      EraseMainFlashSector();                // erase sector


// now we have a copy of data in the sector #8 with the erase area we need to update

      i = 0x8000;
      while (i != 0)              //copy the rest of data back to the orig. sector
       {
        UPSD_xreg.PAGE = 7;
        j = ((unsigned char volatile xdata *) 0)[i];
        if (j != 0xFF)                       // do not write 0xFF, already present
         {
          UPSD_xreg.PAGE = page;
          if (WriteToMainFlash(i,j) == TRUE)
           {
            gbCSWStatus = FAIL;            //error during write operation occured!
            i = 0xFFFF;                      //end loop
           }
         }
        i++;
       }

      UPSD_xreg.PAGE = page;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕一区二区在线播放| 久久精品亚洲麻豆av一区二区| 成人丝袜18视频在线观看| 国产一区二区三区四| 国产一区二区三区免费| 国产又粗又猛又爽又黄91精品| 国产一区二区导航在线播放| 国产成人在线观看| 91免费在线视频观看| 一本一道综合狠狠老| 欧美日韩一区小说| 欧美一区二区女人| 久久九九久久九九| 中文字幕一区在线观看| 一区二区久久久| 日本不卡123| 国产大陆a不卡| 色噜噜狠狠色综合中国| 91精品久久久久久蜜臀| 久久夜色精品国产欧美乱极品| 国产视频在线观看一区二区三区| 国产精品久久久久久久久果冻传媒 | 在线观看91视频| 日韩欧美一级在线播放| 欧美国产视频在线| 亚洲国产精品一区二区www在线| 日本不卡中文字幕| 波多野结衣精品在线| 欧美精品自拍偷拍| 欧美高清在线一区二区| 午夜日韩在线电影| av在线不卡免费看| 日韩一区二区三区电影在线观看| 国产偷国产偷精品高清尤物| 伊人夜夜躁av伊人久久| 久久99精品国产91久久来源| 色偷偷一区二区三区| 欧美大黄免费观看| 一区二区三区鲁丝不卡| 国产一区二区美女诱惑| 91精品国产91久久综合桃花| 综合激情网...| 国产九九视频一区二区三区| 欧美日韩国产高清一区二区三区| 久久精品网站免费观看| 日韩av成人高清| 在线日韩国产精品| 欧美国产一区在线| 国产一区在线精品| 欧美一区二区三区四区五区| 亚洲国产精品天堂| 91热门视频在线观看| 久久久午夜电影| 久久精品国产秦先生| 欧美久久久久中文字幕| 一区二区三区日韩精品| 99免费精品视频| 国产午夜亚洲精品羞羞网站| 久久成人av少妇免费| 欧美三级视频在线观看| 中文字幕五月欧美| 成人avav在线| 成人欧美一区二区三区| 成人免费视频一区二区| 国产农村妇女精品| 成人免费的视频| 中国av一区二区三区| 成人动漫在线一区| 国产精品全国免费观看高清 | 一本大道av伊人久久综合| 国产性色一区二区| 国产精品一区二区黑丝| 久久久久久日产精品| 精品亚洲欧美一区| 26uuu成人网一区二区三区| 精品亚洲国产成人av制服丝袜| 欧美va亚洲va香蕉在线| 激情综合一区二区三区| 国产欧美一区二区三区网站| 懂色av一区二区夜夜嗨| 国产精品免费观看视频| 99精品视频在线免费观看| 亚洲精品写真福利| 欧美精品在线一区二区| 久久福利视频一区二区| 国产亚洲一区二区在线观看| 国产91精品露脸国语对白| 成人免费在线播放视频| 色88888久久久久久影院按摩| 亚洲网友自拍偷拍| 日韩免费观看2025年上映的电影| 免费成人你懂的| 国产精品色在线观看| 色婷婷综合激情| 久久不见久久见免费视频7| 国产人久久人人人人爽| 日本精品免费观看高清观看| 亚洲18色成人| 久久久www免费人成精品| av电影一区二区| 首页国产欧美久久| 国产调教视频一区| 欧美日韩中文另类| 狠狠色综合播放一区二区| 日韩一区日韩二区| 日韩丝袜情趣美女图片| 成人黄色国产精品网站大全在线免费观看 | 国产精品免费看片| 欧美日韩aaaaaa| 成人精品在线视频观看| 亚洲无人区一区| 中文在线免费一区三区高中清不卡| 91麻豆福利精品推荐| 麻豆精品精品国产自在97香蕉| 亚洲国产精品99久久久久久久久| 欧美在线视频全部完| 国产伦精品一区二区三区在线观看 | 欧美久久久影院| 成人毛片视频在线观看| 老司机午夜精品| 亚洲一区电影777| 久久网站最新地址| 3d成人动漫网站| 97se亚洲国产综合在线| 久久er99热精品一区二区| 亚洲国产精品视频| 亚洲色图欧美激情| 欧美经典一区二区三区| 欧美一区二区女人| 欧美日韩国产首页在线观看| 91伊人久久大香线蕉| 国产成人精品亚洲日本在线桃色| 欧美a级理论片| 亚洲成人免费视| 亚洲综合色噜噜狠狠| 亚洲日本青草视频在线怡红院 | 国产a精品视频| 国产一区二区免费看| 精品一区二区三区免费视频| 日日夜夜免费精品视频| 亚洲不卡在线观看| 亚洲午夜在线视频| 亚洲一区二区不卡免费| 一区二区三区国产精华| 亚洲婷婷综合久久一本伊一区 | 日韩一区二区在线观看| 欧美高清hd18日本| 91精品国产综合久久婷婷香蕉| 色综合久久久久综合体桃花网| 97精品久久久午夜一区二区三区| 国产麻豆视频一区二区| 韩日精品视频一区| 国产成人免费在线观看不卡| 国产精品99久久久久久久vr| 国产成人免费高清| 99久久99久久精品国产片果冻 | 国产尤物一区二区| 国产黄色精品网站| 99久久免费精品高清特色大片| 不卡一区中文字幕| 欧美性受极品xxxx喷水| 欧美丝袜第三区| 91麻豆精品国产91久久久资源速度 | 午夜免费欧美电影| 奇米精品一区二区三区四区| 蜜桃av一区二区| 国产一区二区三区日韩| va亚洲va日韩不卡在线观看| 在线欧美小视频| 欧美一区二视频| 久久伊人蜜桃av一区二区| 国产精品日韩成人| 偷偷要91色婷婷| 狠狠v欧美v日韩v亚洲ⅴ| 99久久er热在这里只有精品66| 在线亚洲一区二区| 欧美大片免费久久精品三p| 中文无字幕一区二区三区| 亚洲一区二三区| 精彩视频一区二区| 91久久精品一区二区二区| 日韩丝袜美女视频| 亚洲女人****多毛耸耸8| 日韩不卡一区二区三区| 成人午夜免费视频| 日韩一区二区免费视频| 欧美激情综合五月色丁香小说| 一区二区三区四区不卡视频| 国内久久精品视频| 精品污污网站免费看| 久久精子c满五个校花| 丝袜亚洲另类欧美| gogogo免费视频观看亚洲一| 6080国产精品一区二区| 国产精品初高中害羞小美女文| 老色鬼精品视频在线观看播放| 91麻豆国产在线观看| 国产亚洲欧美在线| 日韩成人午夜精品| 欧美偷拍一区二区|