zoukankan      html  css  js  c++  java
  • FATFS 初学之 磁盘 I/O接口

    详见:嵌入式大讲堂

    由于FatFs模块完全与磁盘I/O层分开,因此底层磁盘I/O需要下列函数去读/写物理磁盘以及获取当前时间。由于底层磁盘I/O模块并不是FatFs的一部分,因此它必须由用户提供。

    disk_initialize:

     1 /*-----------------------------------------------------------------------*/
     2 /* Inidialize a Drive                                                    */
     3 
     4 DSTATUS disk_initialize (
     5     BYTE drv                /* Physical drive nmuber (0..) */
     6 )
     7 {
     8     SD_Error  Status;
     9     /* Supports only single drive */
    10     if (drv)
    11     {
    12         return STA_NOINIT;
    13     }
    14 /*-------------------------- SD Init ----------------------------- */
    15   Status = SD_Init();
    16     if (Status!=SD_OK )
    17     {
    18         return STA_NOINIT;
    19     }
    20     else
    21     {
    22         return RES_OK;
    23     }
    24 
    25 }
    View Code

    函数功能:初始化磁盘驱动器

    描述:

    disk_initialize函数初始化一个物理驱动器。函数成功后,返回值中的STA_NOINIT标志被清除。

    disk_initialize函数被FatFs模块在卷挂载过程中调用,去管理存储介质的改变。当FatFs模块起作用时,或卷上的FAT结构可以被瓦解时,应用程序不能调用该函数。可以使用f_mount函数去重新初始化文件系统。

    disk_status:

    1 /*-----------------------------------------------------------------------*/
    2 /* Return Disk Status                                                    */
    3 
    4 DSTATUS disk_status (
    5     BYTE drv        /* Physical drive nmuber (0..) */
    6 )
    7 {
    8     return RES_OK;
    9 }
    View Code

    函数功能:获取当前磁盘的状态

    disk_read:

     1 /*-----------------------------------------------------------------------*/
     2 /* Read Sector(s)                                                        */
     3 
     4 DRESULT disk_read (
     5     BYTE drv,        /* Physical drive nmuber (0..) */
     6     BYTE *buff,        /* Data buffer to store read data */
     7     DWORD sector,    /* Sector address (LBA) */
     8     BYTE count        /* Number of sectors to read (1..255) */
     9 )
    10 {
    11     return RES_OK;
    12 }
    View Code

    函数功能:从磁盘驱动器中读取扇区

    disk_write:

     1 /*-----------------------------------------------------------------------*/
     2 /* Write Sector(s)                                                       */
     3 
     4 #if _READONLY == 0
     5 DRESULT disk_write (
     6     BYTE drv,            /* Physical drive nmuber (0..) */
     7     const BYTE *buff,    /* Data to be written */
     8     DWORD sector,        /* Sector address (LBA) */
     9     BYTE count            /* Number of sectors to write (1..255) */
    10 )
    11 {
    12     return RES_OK;
    13 }
    14 #endif /* _READONLY */
    View Code

    函数功能:向磁盘驱动器中写入扇区

    disk_ioctl:

     1 /*-----------------------------------------------------------------------*/
     2 /* Miscellaneous Functions                                               */
     3 
     4 DRESULT disk_ioctl (
     5     BYTE drv,        /* Physical drive nmuber (0..) */
     6     BYTE ctrl,        /* Control code */
     7     void *buff        /* Buffer to send/receive control data */
     8 )
     9 {
    10     return RES_OK;
    11 }
    View Code

    get_fattime:

    1 /*-----------------------------------------------------------------------*/
    2 /* Get current time                                                      */
    3 /*-----------------------------------------------------------------------*/ 
    4 DWORD get_fattime(void)
    5 {
    6 
    7      return 0;
    8 
    9 } 
    View Code

    函数功能:获取当前时间

    描述:get_fattime函数必须返回任何有效的时间,即使系统不支持实时时钟。如果返回一个0,则文件将没有一个有效的时间。在只读配置中,不需要此函数。

  • 相关阅读:
    c# 图文添加文字斜水印 优化
    c# 图文添加文字斜水印
    c# bool类型和int类型的互转
    在xcode中新建项目使用Image.xcassets时不显示自定义图片
    修改SearchBar的取消按钮Cancel为中文
    生成新订单号
    java LineNumberReader的使用
    深入浅出多线程——ReentrantLock (二)
    深入浅出多线程——ReentrantLock (一)
    深入浅出多线程——线程基础篇
  • 原文地址:https://www.cnblogs.com/Danhuise/p/3912313.html
Copyright © 2011-2022 走看看