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

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

?? serialflashdriver.c

?? 文件系統轅馬,想要的258031823大幅度反對反對法
?? C
字號:
/*
**********************************************************************
*                          Micrium, Inc.
*                      949 Crestview Circle
*                     Weston,  FL 33327-1848
*
*                            uC/FS
*
*             (c) Copyright 2001 - 2003, Micrium, Inc.
*                      All rights reserved.
*
***********************************************************************

----------------------------------------------------------------------
File        : mmc_drv.c
Purpose     : File system generic MMC/SD driver
---------------------------END-OF-HEADER------------------------------
*/

/*********************************************************************
*
*             #include Section
*
**********************************************************************
*/

#include "FS_ConfDefaults.h"        /* FS Configuration */
#include "fs_api.h"
#include "FS_Debug.h"
#include "fs_clib.h"
#if FS_USE_SFLASH_DRIVER
#include "SerialFlash_X_HW.h"

/*********************************************************************
*
*       Configuration check
*
**********************************************************************
*/
#if (FS_USE_SFLASH_DRIVER != 45)
  #error "Please define FS_USE_SFLASH_DRIVER to 45. The driver currently supports ATMEL's DataFlash only."
#endif

/*********************************************************************
*
*       defines non configurable
*
**********************************************************************
*/

/*******     Commands    *********************************************/
#define  READ_STATUS      0xd7
#define  READ_PAGE        0xd2
#define  WRITE2BUFFER     0x84
#define  PAGE_PROGRAM     0x82

/*******     Serial Flash Types      ********************************/
#define  FLASH_1MBIT      0x03
#define  FLASH_2MBIT      0x05
#define  FLASH_4MBIT      0x07
#define  FLASH_8MBIT      0x09
#define  FLASH_16MBIT     0x0b
#define  FLASH_32MBIT     0x0d


/*******     Serial Flash specific data    **************************/
#define MAX_EXTRABYTES    0x10
#define COMMAND_LENGTH    0x04
#define DUMMY_DATA        0xff

/*******     Serial Flash size definitions      *********************/
#define PAGE_SIZE_256      256
#define PAGE_SIZE_512      512
#define EXTRABYTES_08        8
#define EXTRABYTES_16       16


#define SF_SECTOR_SIZE     FS_SEC_SIZE

/*********************************************************************
*
*             Local data types
*
**********************************************************************
*/
typedef struct {
  FS_U16  BytesPerPage;
  FS_U16  ldBytesPerPage;
  FS_U8   ExtraBytes;
  FS_U32  MaxNumSectors;
}  SFLASH_PARATYPE;

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
static int              _IsInited;
static SFLASH_PARATYPE  _aSerialFlashPara[FS_SFLASH_MAXUNIT];

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/


/*********************************************************************
*
*       _ld
*/
static FS_U16 _ld(FS_U32 Value) {
  FS_U16 i;
  for (i = 0; i < 16; i++) {
    if ((1UL << i) == Value) {
      break;
    }
  }
  return i;
}



/*********************************************************************
*
*       _SendDummyClocks
*/
static void _SendDummyClocks(FS_U8 Unit, int NumClocks) {
  int NumBytes;
  FS_U8 DummyData;
  DummyData = 0xff;
  NumBytes = NumClocks >> 3;
  do {
    FS_SF_HW_X_Write(Unit, &DummyData, 1);
  } while(--NumBytes);
}

/*********************************************************************
*
*       _SendCommandPara
*/
static void _SendCommandPara(FS_U8 Unit, FS_U8 Command, FS_U32 Para, int CSHandling) {
  FS_U8 aData[COMMAND_LENGTH];
  aData[0] = Command;
  aData[1] = (FS_U8)((Para >> 16) & 0xff);
  aData[2] = (FS_U8)((Para >>  8) & 0xff);
  aData[3] = (FS_U8)( Para        & 0xff);
  if (CSHandling) {
    FS_SF_HW_X_EnableCS(Unit);
  }
  FS_SF_HW_X_Write(Unit, aData, COMMAND_LENGTH);
  if (CSHandling) {
    FS_SF_HW_X_DisableCS(Unit);
  }
}

/*********************************************************************
*
*       _GetNumSectors
*/
static FS_U8 _SendCommand(FS_U8 Unit, FS_U8 Command, int CSHandling) {
  FS_U8 r;
  if (CSHandling) {
    FS_SF_HW_X_EnableCS(Unit);
  }
  FS_SF_HW_X_Write(Unit, &Command, 1);
  FS_SF_HW_X_Read(Unit,  &r,       1);
  if (CSHandling) {
    FS_SF_HW_X_DisableCS(Unit);
  }
  return r;
}

/*********************************************************************
*
*       _WaitUntilReady
*/
static void _WaitUntilReady(FS_U8 Unit) {
  FS_U8 Status;
  do {
    Status = _SendCommand(Unit, READ_STATUS, 1);
    if ((Status & (1 << 7)) == (1 << 7)) {
      break;
    }
  } while(1);
}

/*********************************************************************
*
*       _GetNumSectors
*/
static FS_U32 _GetNumSectors(FS_U8 Unit) {
  FS_U32 r;
  SFLASH_PARATYPE * pCardPara;
  pCardPara = &_aSerialFlashPara[Unit];
  r = pCardPara->MaxNumSectors;
  if (pCardPara->BytesPerPage == PAGE_SIZE_256) {
    r >>= 1;
  }
  return r;
}


/*********************************************************************
*
*       _Write
*/
static void _Write(FS_U8 Unit, FS_U32 PageAddr, FS_U8 * pBuffer, FS_U16 BytesPerPage, FS_U8 NumExtraBytes) {
  FS_U8 acDummyData[MAX_EXTRABYTES];

  FS_MEMSET(acDummyData, 0xff, sizeof(acDummyData));
  FS_SF_HW_X_EnableCS(Unit);
  _SendCommandPara(Unit, PAGE_PROGRAM, PageAddr, 0);
  FS_SF_HW_X_Write(Unit, pBuffer, BytesPerPage);
  FS_SF_HW_X_Write(Unit, acDummyData, NumExtraBytes);
  FS_SF_HW_X_DisableCS(Unit);
  _WaitUntilReady(Unit);
}

/*********************************************************************
*
*       _Read
*/
static void _Read(FS_U8 Unit, FS_U32 PageAddr, FS_U8 * pBuffer, FS_U16 BytesPerPage, FS_U8 NumExtraBytes) {
  FS_U8 acDummyData[MAX_EXTRABYTES];

  FS_SF_HW_X_EnableCS(Unit);
  _SendCommandPara(Unit, READ_PAGE, PageAddr , 0);
  _SendDummyClocks(Unit, 32);
  FS_SF_HW_X_Read(Unit, pBuffer,     BytesPerPage);
  FS_SF_HW_X_Read(Unit, acDummyData, NumExtraBytes);
  FS_SF_HW_X_DisableCS(Unit);
  _WaitUntilReady(Unit);
}


/*********************************************************************
*
*       _WritePage
*/
static int _WritePage(FS_U8 Unit, FS_U32 Sector, FS_U8 * pBuffer) {
  FS_U8                  ExtraBytes;
  FS_U16                 BytesPerPage;
  FS_U16                 ShiftCount;
  int                    NumLoops;
  SFLASH_PARATYPE * pCardPara;

  pCardPara    = &_aSerialFlashPara[Unit];
  BytesPerPage = pCardPara->BytesPerPage;
  ExtraBytes   = pCardPara->ExtraBytes;
  ShiftCount   = pCardPara->ldBytesPerPage + 1;
  NumLoops     = SF_SECTOR_SIZE / BytesPerPage;
  if (BytesPerPage == PAGE_SIZE_256) {
    Sector <<= 1;
  }
  do {
    _Write(Unit, Sector++ << ShiftCount, pBuffer, BytesPerPage, ExtraBytes);
    pBuffer += BytesPerPage;
  } while(--NumLoops);
  return 0;
}

/*********************************************************************
*
*       _ReadPage
*/
static int _ReadPage(FS_U8 Unit, FS_U32 Sector, FS_U8 * pBuffer) {
  FS_U8                  ExtraBytes;
  FS_U16                 BytesPerPage;
  FS_U16                 ShiftCount;
  int                    NumLoops;
  SFLASH_PARATYPE * pCardPara;

  pCardPara    = &_aSerialFlashPara[Unit];
  BytesPerPage = pCardPara->BytesPerPage;
  ExtraBytes   = pCardPara->ExtraBytes;
  ShiftCount   = pCardPara->ldBytesPerPage + 1;
  NumLoops     = SF_SECTOR_SIZE / BytesPerPage;
  if (BytesPerPage == PAGE_SIZE_256) {
    Sector <<= 1;
  }
  do {
    _Read(Unit, Sector++ << ShiftCount, pBuffer, BytesPerPage, ExtraBytes);
    pBuffer += BytesPerPage;
  } while(--NumLoops);
  return 0;
}


/*********************************************************************
*
*       _InitFlashPara
*/
static int _InitFlashPara(FS_U8 Unit, FS_U8 Id) {
  FS_U16                 BytesPerPage;
  FS_U8                  ExtraBytes;
  FS_U32                 MaxNumSectors;
  SFLASH_PARATYPE * pCardPara;

  pCardPara = &_aSerialFlashPara[Unit];
  switch (Id) {
  case FLASH_1MBIT:
    BytesPerPage  = PAGE_SIZE_256;
    ExtraBytes    = EXTRABYTES_08;
    MaxNumSectors = 512;
    break;
  case FLASH_2MBIT:
    BytesPerPage  = PAGE_SIZE_256;
    ExtraBytes    = EXTRABYTES_08;
    MaxNumSectors = 1024;
    break;
  case FLASH_4MBIT:
    BytesPerPage  = PAGE_SIZE_256;
    ExtraBytes    = EXTRABYTES_08;
    MaxNumSectors = 2048;
    break;
  case FLASH_8MBIT:
    BytesPerPage  = PAGE_SIZE_256;
    ExtraBytes    = EXTRABYTES_08;
    MaxNumSectors = 4096;
    break;
  case FLASH_16MBIT:
    BytesPerPage  = PAGE_SIZE_512;
    ExtraBytes    = EXTRABYTES_16;
    MaxNumSectors = 4096;
    break;
  case FLASH_32MBIT:
    BytesPerPage  = PAGE_SIZE_512;
    ExtraBytes    = EXTRABYTES_16;
    MaxNumSectors = 8192;
    break;
  default:
    return 1;
  }
  pCardPara->BytesPerPage  = BytesPerPage;
  pCardPara->ExtraBytes    = ExtraBytes;
  pCardPara->MaxNumSectors = MaxNumSectors;
  pCardPara->ldBytesPerPage = _ld(BytesPerPage);
  return 0;
}


/*********************************************************************
*
*             _SF_GetStatus
*
*  Description:
*    FS driver function. Get status of the media,
*    Initialize the card if necassary.
*
*  Parameters:
*    Unit        - Unit number.
*
*  Return value:
*    FS_MEDIA_STATEUNKNOWN if the state of the media is unknown.
*    FS_MEDIA_ISNOTPRESENT if no card is present.
*    FS_MEDIA_ISPRESENT if a card is present.
*/
static int _SF_GetStatus(FS_U8 Unit) {
  int r;
  if (_IsInited) {
    r = FS_MEDIA_ISPRESENT;
  } else {
    r = FS_MEDIA_ISNOTPRESENT;
  }
  return r;
}

/*********************************************************************
*
*             _FS_MMC_ReadBurst
*
*  Description:
*  FS driver function. Read a sector from the media.
*
*  Parameters:
*    Unit      - Device index number
*    Sector        - Sector to be read from the device.
*    pBuffer       - Pointer to buffer for storing the data.
*
*  Return value:
*    ==0           - Sector has been read and copied to pBuffer.
*    <0            - An error has occured.
*/
#if SUPPORT_BURST
static int _SF_ReadBurst(FS_U8 Unit, FS_U32 SectorNo, FS_U32 NumSectors, void *pBuffer) {
  return 0;
}
#endif

/*********************************************************************
*
*             _SF_ReadSector
*
*  Description:
*    Read a sector from the Serial flash.
*
*  Parameters:
*    Unit        - Unit number.
*    Sector      - Sector to be read from the device.
*    pBuffer     - Pointer to buffer for storing the data.
*
*  Return value:
*    ==0         - Sector has been read and copied to pBuffer.
*    <0          - An error has occured.
*/
static int _SF_ReadSector(FS_U8 Unit, FS_U32 Sector, void *pBuffer) {
  SFLASH_PARATYPE * pCardPara;
  FS_U8 * p;
  pCardPara = &_aSerialFlashPara[Unit];
  p = (FS_U8 *)pBuffer;
  if (Sector > pCardPara->MaxNumSectors) {
    return -1;
  }
  return _ReadPage(Unit, Sector, p);
}

/*********************************************************************
*
*             _SF_WriteSector
*
*  Description:
*    Write sector to the serial flash.
*
*  Parameters:
*    Unit        - Unit number.
*    Sector      - Sector to be written to the device.
*    pBuffer     - Pointer to data to be stored.
*
*  Return value:
*    ==0         - Sector has been written to the device.
*    <0          - An error has occured.
*/

static int _SF_WriteSector(FS_U8 Unit, FS_U32 Sector, void *pBuffer) {
  SFLASH_PARATYPE * pCardPara;
  FS_U8 * p;
  pCardPara = &_aSerialFlashPara[Unit];
  p = (FS_U8 *)pBuffer;
  if (Sector > pCardPara->MaxNumSectors) {
    return -1;
  }
  return _WritePage(Unit, Sector, p);
}
/*********************************************************************
*
*             _FS_MMC_IoCtl
*
*  Description:
*    FS driver function. Execute device command.
*
*  Parameters:
*    Unit      - Device Index.
*    Cmd         - Command to be executed.
*    Aux         - Parameter depending on command.
*    pBuffer     - Pointer to a buffer used for the command.
*
*  Return value:
*    Command specific. In general a negative value means an error.
*/
static int _SF_IoCtl(FS_U8 Unit, FS_I32 Cmd, FS_I32 Aux, void *pBuffer) {
  FS_DEV_INFO *      pDevInfo;
  FS_USE_PARA(Aux);
  switch (Cmd) {
  case FS_CMD_INC_BUSYCNT: /* enter busy state */
    FS_SF_HW_X_BusyLedOn(Unit);
    break;
  case FS_CMD_DEC_BUSYCNT: /* leave busy state */
    FS_SF_HW_X_BusyLedOff(Unit);
    break;
  case FS_CMD_CHK_DSKCHANGE: /* check for disk change */
    return 0;
  case FS_CMD_GET_DEVINFO: /* Get general device information */
    pDevInfo = (FS_DEV_INFO *)pBuffer;
    pDevInfo->BytesPerSector = 512;
    pDevInfo->NumSectors     = _GetNumSectors(Unit);
    break;
  default:
    break;
  }
  return 0;
}



/*********************************************************************
*
*             _FS_MMC_InitMedium
*
*  Description:
*    FS driver function.
*    Initialize the card.
*
*  Parameters:
*    Unit        - Unit number.
*/
static void _SF_InitMedium(FS_U8 Unit) {
  if (_IsInited == 0) {
    if (FS_SF_HW_X_Init(Unit) == 0) {
      FS_U8 Id;
      /*
       * Read Status Byte to get the ID of device
       */
      Id = _SendCommand(Unit, READ_STATUS, 1);
      Id = (Id >> 2) & 0x0f;
      if (_InitFlashPara(Unit, Id) == 0) {
        _IsInited = 1;
      }
    } else {
      /* init failed */
      FS_DEBUG_WARN("SerialFlash: Init failure.");
    }
  }
}

/*********************************************************************
*
*             _FS_MMC_InitMedium
*
*  Description:
*    FS driver function.
*    Initialize the card.
*
*  Parameters:
*    Unit        - Unit number.
*/
static int _SF_InitDevice(FS_U8 Unit) {
  _SF_InitMedium(Unit);
  return 1;
}

/*********************************************************************
*
*             Global variables
*
**********************************************************************
*/

const FS_DEVICE_TYPE FS__SFlash_Driver = {
  "sflash",
  FS_SFLASH_MAXUNIT,
  _SF_GetStatus,
  _SF_ReadSector,
  _SF_WriteSector,
  _SF_IoCtl,
#if 0 /* not yet released FS_SUPPORT_BURST for SerialFlash */
  _SF_ReadBurst,
  _SF_WriteBurst,
#else
  NULL,
  NULL,
#endif
  _SF_InitDevice,
  _SF_InitMedium
};

#endif /* FS_USE_SFLASH_DRIVER */

/*************************** End of file ****************************/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品一区二区在线观看网站| 亚洲女女做受ⅹxx高潮| 奇米影视一区二区三区小说| 欧美日韩免费视频| 日本特黄久久久高潮| 日韩视频一区二区| 国产一区二区三区美女| 欧美国产日本韩| 色香蕉成人二区免费| 亚洲国产精品一区二区久久| 欧美精品一二三| 国产福利精品一区| 亚洲天堂福利av| 在线不卡中文字幕| 国产成人在线视频网站| 亚洲男人的天堂av| 日韩欧美中文一区二区| 粉嫩一区二区三区性色av| 亚洲欧洲中文日韩久久av乱码| 欧美日韩免费观看一区二区三区| 久久99久久99精品免视看婷婷| 国产日韩精品视频一区| 在线免费一区三区| 国产一区二区三区国产| 亚洲精品成人精品456| 日韩欧美www| 91久久香蕉国产日韩欧美9色| 日本不卡123| 综合av第一页| 精品1区2区在线观看| 在线视频欧美精品| 国产乱理伦片在线观看夜一区| 日韩伦理免费电影| 欧美一级理论性理论a| 99九九99九九九视频精品| 秋霞电影一区二区| 中文字幕日本不卡| 欧美大片在线观看一区| 在线免费亚洲电影| 国产v日产∨综合v精品视频| 亚洲.国产.中文慕字在线| 亚洲国产高清在线| 日韩欧美中文字幕精品| 91久久精品日日躁夜夜躁欧美| 狠狠色丁香久久婷婷综| 亚洲国产一区二区在线播放| 中文字幕精品综合| 日韩精品一区二| 欧美精品乱人伦久久久久久| 色综合天天天天做夜夜夜夜做| 精品一区二区免费在线观看| 亚洲成人免费观看| 亚洲精品成人a在线观看| 国产精品免费视频观看| 国产亚洲欧美激情| 日韩欧美精品在线| 欧美日韩的一区二区| 在线欧美日韩国产| 色菇凉天天综合网| 99久久精品费精品国产一区二区| 国产精品66部| 韩国av一区二区三区在线观看| 免费欧美高清视频| 丝袜诱惑制服诱惑色一区在线观看| 亚洲色图在线视频| 国产精品久线观看视频| 日本一区二区不卡视频| 国产午夜精品一区二区| 久久久久久9999| 26uuu色噜噜精品一区二区| 日韩欧美中文字幕精品| 91精品国产色综合久久不卡蜜臀 | 久久麻豆一区二区| 夜夜嗨av一区二区三区| 国产精品美女久久久久av爽李琼| 欧美精品一区二区三区很污很色的 | 热久久国产精品| 午夜精品一区二区三区免费视频| 国内不卡的二区三区中文字幕| 亚洲第一主播视频| 天天综合天天综合色| 日本在线不卡视频一二三区| 日韩国产欧美视频| 热久久免费视频| 韩国理伦片一区二区三区在线播放| 精品制服美女久久| 国产高清亚洲一区| 91亚洲精品一区二区乱码| 91视频免费看| 欧美中文字幕亚洲一区二区va在线| 91黄色激情网站| 91精品国产综合久久久蜜臀图片| 日韩一区二区三区av| 欧美va在线播放| 国产女人18毛片水真多成人如厕| 国产精品成人在线观看| 亚洲成人免费在线观看| 久久66热偷产精品| 国产mv日韩mv欧美| 在线亚洲一区观看| 欧美一区二区国产| 中文字幕欧美激情| 亚洲一区二区五区| 理论电影国产精品| 成人av资源下载| 欧美日韩亚洲丝袜制服| 欧美成人激情免费网| 日本一区二区三区dvd视频在线| 亚洲天堂福利av| 蜜臀久久99精品久久久久久9| 国产精品一品二品| 在线观看av不卡| 精品国产乱码久久久久久久 | 免费观看一级特黄欧美大片| 久久电影网站中文字幕| 99在线热播精品免费| 欧美一区二区三区思思人| 国产精品视频一二三| 亚洲成人自拍偷拍| 成人一区二区三区在线观看| 精品视频全国免费看| 中文字幕免费不卡在线| 午夜激情久久久| 成人av电影在线观看| 69成人精品免费视频| 久久国产成人午夜av影院| 不卡视频在线观看| 欧美成人a∨高清免费观看| 亚洲色图制服丝袜| 国产91丝袜在线播放0| 欧美三级乱人伦电影| 1024成人网色www| 国产一区二区三区四区五区美女 | 91麻豆精品国产91久久久更新时间 | 日韩高清一级片| 色婷婷综合久久久久中文一区二区| 日韩精品综合一本久道在线视频| 亚洲猫色日本管| 国产成人一级电影| 日韩欧美色电影| 香蕉加勒比综合久久| 91在线小视频| 国产欧美一区二区三区在线看蜜臀| 亚洲va国产va欧美va观看| 99久久久精品| 国产精品日韩成人| 国产一区二区视频在线播放| 7878成人国产在线观看| 亚洲午夜久久久久久久久电影院 | 色噜噜狠狠成人中文综合| 久久久久久久久久久久久久久99 | 国产成人精品三级麻豆| 日韩一区二区视频| 亚洲va欧美va人人爽| 欧美亚洲国产一卡| 一区二区三区日本| 99久精品国产| 综合欧美一区二区三区| 99久久综合国产精品| 国产亚洲短视频| 国产精品亚洲第一区在线暖暖韩国| 精品福利一二区| 国内精品嫩模私拍在线| 日韩精品在线一区二区| 另类欧美日韩国产在线| 日韩美女主播在线视频一区二区三区| 日韩专区在线视频| 日韩欧美一区二区免费| 久久99精品国产.久久久久久| 精品福利二区三区| 国产剧情一区在线| 国产欧美综合在线| www.日韩精品| 亚洲欧美日韩国产中文在线| 色美美综合视频| 午夜日韩在线观看| 日韩一区二区三区在线| 日本中文字幕一区二区视频| 精品日韩在线观看| 成人免费精品视频| 亚洲伦理在线精品| 欧美伦理影视网| 美女爽到高潮91| 日本一区二区视频在线观看| 99精品欧美一区二区三区综合在线| 亚洲欧美日本在线| 欧美少妇xxx| 精品影视av免费| 日本一区二区高清| 欧美日韩在线一区二区| 久久精品国产精品亚洲综合| 国产三级一区二区三区| 91无套直看片红桃| 日韩成人精品在线| 欧美激情中文字幕一区二区| 色噜噜偷拍精品综合在线| 日韩电影在线看| 国产精品久久毛片| 51精品视频一区二区三区| 国产不卡视频在线观看|