[1] | 1 | /*-----------------------------------------------------------------------*/
|
---|
| 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2017 */
|
---|
| 3 | /* */
|
---|
| 4 | /* Portions COPYRIGHT 2017 STMicroelectronics */
|
---|
| 5 | /* Portions Copyright (C) 2017, ChaN, all right reserved */
|
---|
| 6 | /*-----------------------------------------------------------------------*/
|
---|
| 7 | /* If a working storage control module is available, it should be */
|
---|
| 8 | /* attached to the FatFs via a glue function rather than modifying it. */
|
---|
| 9 | /* This is an example of glue functions to attach various existing */
|
---|
| 10 | /* storage control modules to the FatFs module with a defined API. */
|
---|
| 11 | /*-----------------------------------------------------------------------*/
|
---|
| 12 |
|
---|
| 13 | /* Includes ------------------------------------------------------------------*/
|
---|
| 14 | #include "diskio.h"
|
---|
| 15 | #include "ff_gen_drv.h"
|
---|
| 16 |
|
---|
| 17 | #if defined ( __GNUC__ )
|
---|
| 18 | #ifndef __weak
|
---|
| 19 | #define __weak __attribute__((weak))
|
---|
| 20 | #endif
|
---|
| 21 | #endif
|
---|
| 22 |
|
---|
| 23 | /* Private typedef -----------------------------------------------------------*/
|
---|
| 24 | /* Private define ------------------------------------------------------------*/
|
---|
| 25 | /* Private variables ---------------------------------------------------------*/
|
---|
| 26 | extern Disk_drvTypeDef disk;
|
---|
| 27 |
|
---|
| 28 | /* Private function prototypes -----------------------------------------------*/
|
---|
| 29 | /* Private functions ---------------------------------------------------------*/
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
| 32 | * @brief Gets Disk Status
|
---|
| 33 | * @param pdrv: Physical drive number (0..)
|
---|
| 34 | * @retval DSTATUS: Operation status
|
---|
| 35 | */
|
---|
| 36 | DSTATUS disk_status (
|
---|
| 37 | BYTE pdrv /* Physical drive number to identify the drive */
|
---|
| 38 | )
|
---|
| 39 | {
|
---|
| 40 | DSTATUS stat;
|
---|
| 41 |
|
---|
| 42 | stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]);
|
---|
| 43 | return stat;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | /**
|
---|
| 47 | * @brief Initializes a Drive
|
---|
| 48 | * @param pdrv: Physical drive number (0..)
|
---|
| 49 | * @retval DSTATUS: Operation status
|
---|
| 50 | */
|
---|
| 51 | DSTATUS disk_initialize (
|
---|
| 52 | BYTE pdrv /* Physical drive nmuber to identify the drive */
|
---|
| 53 | )
|
---|
| 54 | {
|
---|
| 55 | DSTATUS stat = RES_OK;
|
---|
| 56 |
|
---|
| 57 | if(disk.is_initialized[pdrv] == 0)
|
---|
| 58 | {
|
---|
| 59 | disk.is_initialized[pdrv] = 1;
|
---|
| 60 | stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
|
---|
| 61 | }
|
---|
| 62 | return stat;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | /**
|
---|
| 66 | * @brief Reads Sector(s)
|
---|
| 67 | * @param pdrv: Physical drive number (0..)
|
---|
| 68 | * @param *buff: Data buffer to store read data
|
---|
| 69 | * @param sector: Sector address (LBA)
|
---|
| 70 | * @param count: Number of sectors to read (1..128)
|
---|
| 71 | * @retval DRESULT: Operation result
|
---|
| 72 | */
|
---|
| 73 | DRESULT disk_read (
|
---|
| 74 | BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
---|
| 75 | BYTE *buff, /* Data buffer to store read data */
|
---|
| 76 | DWORD sector, /* Sector address in LBA */
|
---|
| 77 | UINT count /* Number of sectors to read */
|
---|
| 78 | )
|
---|
| 79 | {
|
---|
| 80 | DRESULT res;
|
---|
| 81 |
|
---|
| 82 | res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count);
|
---|
| 83 | return res;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /**
|
---|
| 87 | * @brief Writes Sector(s)
|
---|
| 88 | * @param pdrv: Physical drive number (0..)
|
---|
| 89 | * @param *buff: Data to be written
|
---|
| 90 | * @param sector: Sector address (LBA)
|
---|
| 91 | * @param count: Number of sectors to write (1..128)
|
---|
| 92 | * @retval DRESULT: Operation result
|
---|
| 93 | */
|
---|
| 94 | #if _USE_WRITE == 1
|
---|
| 95 | DRESULT disk_write (
|
---|
| 96 | BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
---|
| 97 | const BYTE *buff, /* Data to be written */
|
---|
| 98 | DWORD sector, /* Sector address in LBA */
|
---|
| 99 | UINT count /* Number of sectors to write */
|
---|
| 100 | )
|
---|
| 101 | {
|
---|
| 102 | DRESULT res;
|
---|
| 103 |
|
---|
| 104 | res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count);
|
---|
| 105 | return res;
|
---|
| 106 | }
|
---|
| 107 | #endif /* _USE_WRITE == 1 */
|
---|
| 108 |
|
---|
| 109 | /**
|
---|
| 110 | * @brief I/O control operation
|
---|
| 111 | * @param pdrv: Physical drive number (0..)
|
---|
| 112 | * @param cmd: Control code
|
---|
| 113 | * @param *buff: Buffer to send/receive control data
|
---|
| 114 | * @retval DRESULT: Operation result
|
---|
| 115 | */
|
---|
| 116 | #if _USE_IOCTL == 1
|
---|
| 117 | DRESULT disk_ioctl (
|
---|
| 118 | BYTE pdrv, /* Physical drive nmuber (0..) */
|
---|
| 119 | BYTE cmd, /* Control code */
|
---|
| 120 | void *buff /* Buffer to send/receive control data */
|
---|
| 121 | )
|
---|
| 122 | {
|
---|
| 123 | DRESULT res;
|
---|
| 124 |
|
---|
| 125 | res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff);
|
---|
| 126 | return res;
|
---|
| 127 | }
|
---|
| 128 | #endif /* _USE_IOCTL == 1 */
|
---|
| 129 |
|
---|
| 130 | /**
|
---|
| 131 | * @brief Gets Time from RTC
|
---|
| 132 | * @param None
|
---|
| 133 | * @retval Time in DWORD
|
---|
| 134 | */
|
---|
| 135 | __weak DWORD get_fattime (void)
|
---|
| 136 | {
|
---|
| 137 | return 0;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|
| 141 |
|
---|