Andrew Lindsay / Mbed 2 deprecated IoTGateway_Basic

Dependencies:   NetServices FatFileSystem csv_parser mbed MQTTClient RF12B DNSResolver SDFileSystem

Committer:
SomeRandomBloke
Date:
Mon Apr 02 22:05:20 2012 +0000
Revision:
0:a29a0225f203
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SomeRandomBloke 0:a29a0225f203 1 /*-----------------------------------------------------------------------*/
SomeRandomBloke 0:a29a0225f203 2 /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
SomeRandomBloke 0:a29a0225f203 3 /*-----------------------------------------------------------------------*/
SomeRandomBloke 0:a29a0225f203 4 /* This is a stub disk I/O module that acts as front end of the existing */
SomeRandomBloke 0:a29a0225f203 5 /* disk I/O modules and attach it to FatFs module with common interface. */
SomeRandomBloke 0:a29a0225f203 6 /*-----------------------------------------------------------------------*/
SomeRandomBloke 0:a29a0225f203 7
SomeRandomBloke 0:a29a0225f203 8 #include "diskio.h"
SomeRandomBloke 0:a29a0225f203 9 #include <stdio.h>
SomeRandomBloke 0:a29a0225f203 10 #include <string.h>
SomeRandomBloke 0:a29a0225f203 11 #include "FATFileSystem.h"
SomeRandomBloke 0:a29a0225f203 12
SomeRandomBloke 0:a29a0225f203 13 #include "mbed.h"
SomeRandomBloke 0:a29a0225f203 14
SomeRandomBloke 0:a29a0225f203 15 DSTATUS disk_initialize (
SomeRandomBloke 0:a29a0225f203 16 BYTE drv /* Physical drive nmuber (0..) */
SomeRandomBloke 0:a29a0225f203 17 )
SomeRandomBloke 0:a29a0225f203 18 {
SomeRandomBloke 0:a29a0225f203 19 FFSDEBUG("disk_initialize on drv [%d]\n", drv);
SomeRandomBloke 0:a29a0225f203 20 return (DSTATUS)FATFileSystem::_ffs[drv]->disk_initialize();
SomeRandomBloke 0:a29a0225f203 21 }
SomeRandomBloke 0:a29a0225f203 22
SomeRandomBloke 0:a29a0225f203 23 DSTATUS disk_status (
SomeRandomBloke 0:a29a0225f203 24 BYTE drv /* Physical drive nmuber (0..) */
SomeRandomBloke 0:a29a0225f203 25 )
SomeRandomBloke 0:a29a0225f203 26 {
SomeRandomBloke 0:a29a0225f203 27 FFSDEBUG("disk_status on drv [%d]\n", drv);
SomeRandomBloke 0:a29a0225f203 28 return (DSTATUS)FATFileSystem::_ffs[drv]->disk_status();
SomeRandomBloke 0:a29a0225f203 29 }
SomeRandomBloke 0:a29a0225f203 30
SomeRandomBloke 0:a29a0225f203 31 DRESULT disk_read (
SomeRandomBloke 0:a29a0225f203 32 BYTE drv, /* Physical drive nmuber (0..) */
SomeRandomBloke 0:a29a0225f203 33 BYTE *buff, /* Data buffer to store read data */
SomeRandomBloke 0:a29a0225f203 34 DWORD sector, /* Sector address (LBA) */
SomeRandomBloke 0:a29a0225f203 35 BYTE count /* Number of sectors to read (1..255) */
SomeRandomBloke 0:a29a0225f203 36 )
SomeRandomBloke 0:a29a0225f203 37 {
SomeRandomBloke 0:a29a0225f203 38 FFSDEBUG("disk_read(sector %d, count %d) on drv [%d]\n", sector, count, drv);
SomeRandomBloke 0:a29a0225f203 39 for(DWORD s=sector; s<sector+count; s++) {
SomeRandomBloke 0:a29a0225f203 40 FFSDEBUG(" disk_read(sector %d)\n", s);
SomeRandomBloke 0:a29a0225f203 41 int res = FATFileSystem::_ffs[drv]->disk_read((char*)buff, s);
SomeRandomBloke 0:a29a0225f203 42 if(res) {
SomeRandomBloke 0:a29a0225f203 43 return RES_PARERR;
SomeRandomBloke 0:a29a0225f203 44 }
SomeRandomBloke 0:a29a0225f203 45 buff += 512;
SomeRandomBloke 0:a29a0225f203 46 }
SomeRandomBloke 0:a29a0225f203 47 return RES_OK;
SomeRandomBloke 0:a29a0225f203 48 }
SomeRandomBloke 0:a29a0225f203 49
SomeRandomBloke 0:a29a0225f203 50 #if _READONLY == 0
SomeRandomBloke 0:a29a0225f203 51 DRESULT disk_write (
SomeRandomBloke 0:a29a0225f203 52 BYTE drv, /* Physical drive nmuber (0..) */
SomeRandomBloke 0:a29a0225f203 53 const BYTE *buff, /* Data to be written */
SomeRandomBloke 0:a29a0225f203 54 DWORD sector, /* Sector address (LBA) */
SomeRandomBloke 0:a29a0225f203 55 BYTE count /* Number of sectors to write (1..255) */
SomeRandomBloke 0:a29a0225f203 56 )
SomeRandomBloke 0:a29a0225f203 57 {
SomeRandomBloke 0:a29a0225f203 58 FFSDEBUG("disk_write(sector %d, count %d) on drv [%d]\n", sector, count, drv);
SomeRandomBloke 0:a29a0225f203 59 for(DWORD s=sector; s<sector+count; s++) {
SomeRandomBloke 0:a29a0225f203 60 FFSDEBUG(" disk_write(sector %d)\n", s);
SomeRandomBloke 0:a29a0225f203 61 int res = FATFileSystem::_ffs[drv]->disk_write((char*)buff, s);
SomeRandomBloke 0:a29a0225f203 62 if(res) {
SomeRandomBloke 0:a29a0225f203 63 return RES_PARERR;
SomeRandomBloke 0:a29a0225f203 64 }
SomeRandomBloke 0:a29a0225f203 65 buff += 512;
SomeRandomBloke 0:a29a0225f203 66 }
SomeRandomBloke 0:a29a0225f203 67 return RES_OK;
SomeRandomBloke 0:a29a0225f203 68 }
SomeRandomBloke 0:a29a0225f203 69 #endif /* _READONLY */
SomeRandomBloke 0:a29a0225f203 70
SomeRandomBloke 0:a29a0225f203 71 DRESULT disk_ioctl (
SomeRandomBloke 0:a29a0225f203 72 BYTE drv, /* Physical drive nmuber (0..) */
SomeRandomBloke 0:a29a0225f203 73 BYTE ctrl, /* Control code */
SomeRandomBloke 0:a29a0225f203 74 void *buff /* Buffer to send/receive control data */
SomeRandomBloke 0:a29a0225f203 75 )
SomeRandomBloke 0:a29a0225f203 76 {
SomeRandomBloke 0:a29a0225f203 77 FFSDEBUG("disk_ioctl(%d)\n", ctrl);
SomeRandomBloke 0:a29a0225f203 78 switch(ctrl) {
SomeRandomBloke 0:a29a0225f203 79 case CTRL_SYNC:
SomeRandomBloke 0:a29a0225f203 80 if(FATFileSystem::_ffs[drv] == NULL) {
SomeRandomBloke 0:a29a0225f203 81 return RES_NOTRDY;
SomeRandomBloke 0:a29a0225f203 82 } else if(FATFileSystem::_ffs[drv]->disk_sync()) {
SomeRandomBloke 0:a29a0225f203 83 return RES_ERROR;
SomeRandomBloke 0:a29a0225f203 84 }
SomeRandomBloke 0:a29a0225f203 85 return RES_OK;
SomeRandomBloke 0:a29a0225f203 86 case GET_SECTOR_COUNT:
SomeRandomBloke 0:a29a0225f203 87 if(FATFileSystem::_ffs[drv] == NULL) {
SomeRandomBloke 0:a29a0225f203 88 return RES_NOTRDY;
SomeRandomBloke 0:a29a0225f203 89 } else {
SomeRandomBloke 0:a29a0225f203 90 int res = FATFileSystem::_ffs[drv]->disk_sectors();
SomeRandomBloke 0:a29a0225f203 91 if(res > 0) {
SomeRandomBloke 0:a29a0225f203 92 *((DWORD*)buff) = res; // minimum allowed
SomeRandomBloke 0:a29a0225f203 93 return RES_OK;
SomeRandomBloke 0:a29a0225f203 94 } else {
SomeRandomBloke 0:a29a0225f203 95 return RES_ERROR;
SomeRandomBloke 0:a29a0225f203 96 }
SomeRandomBloke 0:a29a0225f203 97 }
SomeRandomBloke 0:a29a0225f203 98 case GET_BLOCK_SIZE:
SomeRandomBloke 0:a29a0225f203 99 *((DWORD*)buff) = 1; // default when not known
SomeRandomBloke 0:a29a0225f203 100 return RES_OK;
SomeRandomBloke 0:a29a0225f203 101
SomeRandomBloke 0:a29a0225f203 102 }
SomeRandomBloke 0:a29a0225f203 103 return RES_PARERR;
SomeRandomBloke 0:a29a0225f203 104 }
SomeRandomBloke 0:a29a0225f203 105