diff options
| author | Uladzimir Pylinski <barthess@yandex.ru> | 2016-02-17 21:18:15 +0300 |
|---|---|---|
| committer | Uladzimir Pylinski <barthess@yandex.ru> | 2016-02-17 21:18:15 +0300 |
| commit | 31066ddfbffd2ee801e63c090e30929bae5b0e43 (patch) | |
| tree | b165f84bc96d0dc961d4e570d1520dde06e5c70b /testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c | |
| parent | d51d9c799f4ed64398f47945329b3138f44c8a37 (diff) | |
| parent | 771feb098db86458340ab2665dfb23bef970ace6 (diff) | |
| download | ChibiOS-Contrib-31066ddfbffd2ee801e63c090e30929bae5b0e43.tar.gz ChibiOS-Contrib-31066ddfbffd2ee801e63c090e30929bae5b0e43.tar.bz2 ChibiOS-Contrib-31066ddfbffd2ee801e63c090e30929bae5b0e43.zip | |
Merge pull request #40 from fpoussin/usb-host-pull
USB-Host Driver
Merged pull request #40 from fpoussin/usb-host-pull
Diffstat (limited to 'testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c')
| -rw-r--r-- | testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c b/testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c new file mode 100644 index 0000000..98a7edf --- /dev/null +++ b/testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c @@ -0,0 +1,144 @@ +/*-----------------------------------------------------------------------*/
+/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
+/*-----------------------------------------------------------------------*/
+/* This is a stub disk I/O module that acts as front end of the existing */
+/* disk I/O modules and attach it to FatFs module with common interface. */
+/*-----------------------------------------------------------------------*/
+
+#include "hal.h"
+#include "ffconf.h"
+#include "diskio.h"
+
+#include "usbh.h"
+#include "usbh/dev/msd.h"
+
+/*-----------------------------------------------------------------------*/
+/* Correspondence between physical drive number and physical drive. */
+#define MSDLUN0 0
+
+/*-----------------------------------------------------------------------*/
+/* Inidialize a Drive */
+
+DSTATUS disk_initialize (
+ BYTE pdrv /* Physical drive nmuber (0..) */
+)
+{
+ DSTATUS stat;
+
+ switch (pdrv) {
+ case MSDLUN0:
+ stat = 0;
+ /* It is initialized externally, just reads the status.*/
+ if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
+ stat |= STA_NOINIT;
+ return stat;
+ }
+ return STA_NOINIT;
+}
+
+
+
+/*-----------------------------------------------------------------------*/
+/* Return Disk Status */
+
+DSTATUS disk_status (
+ BYTE pdrv /* Physical drive nmuber (0..) */
+)
+{
+ DSTATUS stat;
+
+ switch (pdrv) {
+ case MSDLUN0:
+ stat = 0;
+ /* It is initialized externally, just reads the status.*/
+ if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
+ stat |= STA_NOINIT;
+ return stat;
+ }
+ return STA_NOINIT;
+}
+
+
+
+/*-----------------------------------------------------------------------*/
+/* Read Sector(s) */
+
+DRESULT disk_read (
+ BYTE pdrv, /* Physical drive nmuber (0..) */
+ BYTE *buff, /* Data buffer to store read data */
+ DWORD sector, /* Sector address (LBA) */
+ UINT count /* Number of sectors to read (1..255) */
+)
+{
+ switch (pdrv) {
+ case MSDLUN0:
+ /* It is initialized externally, just reads the status.*/
+ if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
+ return RES_NOTRDY;
+ if (usbhmsdLUNRead(&MSBLKD[0], sector, buff, count))
+ return RES_ERROR;
+ return RES_OK;
+ }
+ return RES_PARERR;
+}
+
+
+
+/*-----------------------------------------------------------------------*/
+/* Write Sector(s) */
+
+#if _USE_WRITE
+DRESULT disk_write (
+ BYTE pdrv, /* Physical drive nmuber (0..) */
+ const BYTE *buff, /* Data to be written */
+ DWORD sector, /* Sector address (LBA) */
+ UINT count /* Number of sectors to write (1..255) */
+)
+{
+ switch (pdrv) {
+ case MSDLUN0:
+ /* It is initialized externally, just reads the status.*/
+ if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
+ return RES_NOTRDY;
+ if (usbhmsdLUNWrite(&MSBLKD[0], sector, buff, count))
+ return RES_ERROR;
+ return RES_OK;
+ }
+ return RES_PARERR;
+}
+#endif /* _USE_WRITE */
+
+
+
+/*-----------------------------------------------------------------------*/
+/* Miscellaneous Functions */
+
+#if _USE_IOCTL
+DRESULT disk_ioctl (
+ BYTE pdrv, /* Physical drive nmuber (0..) */
+ BYTE cmd, /* Control code */
+ void *buff /* Buffer to send/receive control data */
+)
+{
+ switch (pdrv) {
+ case MSDLUN0:
+ switch (cmd) {
+ case CTRL_SYNC:
+ return RES_OK;
+ case GET_SECTOR_COUNT:
+ *((DWORD *)buff) = MSBLKD[0].info.blk_num;
+ return RES_OK;
+ case GET_SECTOR_SIZE:
+ *((WORD *)buff) = MSBLKD[0].info.blk_size;
+ return RES_OK;
+ default:
+ return RES_PARERR;
+ }
+ }
+ return RES_PARERR;
+}
+#endif /* _USE_IOCTL */
+
+DWORD get_fattime(void) {
+ return ((uint32_t)0 | (1 << 16)) | (1 << 21); /* wrong but valid time */
+}
|
