Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Committer:
gert_lauritsen
Date:
Thu Jun 20 07:13:18 2019 +0000
Revision:
56:df9052e3808c
change date stamp from gps, reads serialnumb from file.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gert_lauritsen 56:df9052e3808c 1 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 2 /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
gert_lauritsen 56:df9052e3808c 3 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 4 /* If a working storage control module is available, it should be */
gert_lauritsen 56:df9052e3808c 5 /* attached to the FatFs via a glue function rather than modifying it. */
gert_lauritsen 56:df9052e3808c 6 /* This is an example of glue functions to attach various exsisting */
gert_lauritsen 56:df9052e3808c 7 /* storage control modules to the FatFs module with a defined API. */
gert_lauritsen 56:df9052e3808c 8 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 9
gert_lauritsen 56:df9052e3808c 10 #include "diskio.h"
gert_lauritsen 56:df9052e3808c 11 #include "mbed_debug.h"
gert_lauritsen 56:df9052e3808c 12 #include "FATFileSystem.h"
gert_lauritsen 56:df9052e3808c 13
gert_lauritsen 56:df9052e3808c 14 using namespace mbed;
gert_lauritsen 56:df9052e3808c 15
gert_lauritsen 56:df9052e3808c 16 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 17 /* Get Drive Status */
gert_lauritsen 56:df9052e3808c 18 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 19
gert_lauritsen 56:df9052e3808c 20 DSTATUS disk_status (
gert_lauritsen 56:df9052e3808c 21 BYTE pdrv /* Physical drive nmuber to identify the drive */
gert_lauritsen 56:df9052e3808c 22 )
gert_lauritsen 56:df9052e3808c 23 {
gert_lauritsen 56:df9052e3808c 24 debug_if(FFS_DBG, "disk_status on pdrv [%d]\n", pdrv);
gert_lauritsen 56:df9052e3808c 25 return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_status();
gert_lauritsen 56:df9052e3808c 26 }
gert_lauritsen 56:df9052e3808c 27
gert_lauritsen 56:df9052e3808c 28 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 29 /* Inidialize a Drive */
gert_lauritsen 56:df9052e3808c 30 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 31
gert_lauritsen 56:df9052e3808c 32 DSTATUS disk_initialize (
gert_lauritsen 56:df9052e3808c 33 BYTE pdrv /* Physical drive nmuber to identify the drive */
gert_lauritsen 56:df9052e3808c 34 )
gert_lauritsen 56:df9052e3808c 35 {
gert_lauritsen 56:df9052e3808c 36 debug_if(FFS_DBG, "disk_initialize on pdrv [%d]\n", pdrv);
gert_lauritsen 56:df9052e3808c 37 return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_initialize();
gert_lauritsen 56:df9052e3808c 38 }
gert_lauritsen 56:df9052e3808c 39
gert_lauritsen 56:df9052e3808c 40 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 41 /* Read Sector(s) */
gert_lauritsen 56:df9052e3808c 42 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 43
gert_lauritsen 56:df9052e3808c 44 DRESULT disk_read (
gert_lauritsen 56:df9052e3808c 45 BYTE pdrv, /* Physical drive nmuber to identify the drive */
gert_lauritsen 56:df9052e3808c 46 BYTE* buff, /* Data buffer to store read data */
gert_lauritsen 56:df9052e3808c 47 DWORD sector, /* Sector address in LBA */
gert_lauritsen 56:df9052e3808c 48 UINT count /* Number of sectors to read */
gert_lauritsen 56:df9052e3808c 49 )
gert_lauritsen 56:df9052e3808c 50 {
gert_lauritsen 56:df9052e3808c 51 debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
gert_lauritsen 56:df9052e3808c 52 if (FATFileSystem::_ffs[pdrv]->disk_read((uint8_t*)buff, sector, count))
gert_lauritsen 56:df9052e3808c 53 return RES_PARERR;
gert_lauritsen 56:df9052e3808c 54 else
gert_lauritsen 56:df9052e3808c 55 return RES_OK;
gert_lauritsen 56:df9052e3808c 56 }
gert_lauritsen 56:df9052e3808c 57
gert_lauritsen 56:df9052e3808c 58 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 59 /* Write Sector(s) */
gert_lauritsen 56:df9052e3808c 60 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 61
gert_lauritsen 56:df9052e3808c 62 #if _USE_WRITE
gert_lauritsen 56:df9052e3808c 63 DRESULT disk_write (
gert_lauritsen 56:df9052e3808c 64 BYTE pdrv, /* Physical drive nmuber to identify the drive */
gert_lauritsen 56:df9052e3808c 65 const BYTE* buff, /* Data to be written */
gert_lauritsen 56:df9052e3808c 66 DWORD sector, /* Sector address in LBA */
gert_lauritsen 56:df9052e3808c 67 UINT count /* Number of sectors to write */
gert_lauritsen 56:df9052e3808c 68 )
gert_lauritsen 56:df9052e3808c 69 {
gert_lauritsen 56:df9052e3808c 70 debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
gert_lauritsen 56:df9052e3808c 71 if (FATFileSystem::_ffs[pdrv]->disk_write((uint8_t*)buff, sector, count))
gert_lauritsen 56:df9052e3808c 72 return RES_PARERR;
gert_lauritsen 56:df9052e3808c 73 else
gert_lauritsen 56:df9052e3808c 74 return RES_OK;
gert_lauritsen 56:df9052e3808c 75 }
gert_lauritsen 56:df9052e3808c 76 #endif
gert_lauritsen 56:df9052e3808c 77
gert_lauritsen 56:df9052e3808c 78 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 79 /* Miscellaneous Functions */
gert_lauritsen 56:df9052e3808c 80 /*-----------------------------------------------------------------------*/
gert_lauritsen 56:df9052e3808c 81
gert_lauritsen 56:df9052e3808c 82 #if _USE_IOCTL
gert_lauritsen 56:df9052e3808c 83 DRESULT disk_ioctl (
gert_lauritsen 56:df9052e3808c 84 BYTE pdrv, /* Physical drive nmuber (0..) */
gert_lauritsen 56:df9052e3808c 85 BYTE cmd, /* Control code */
gert_lauritsen 56:df9052e3808c 86 void* buff /* Buffer to send/receive control data */
gert_lauritsen 56:df9052e3808c 87 )
gert_lauritsen 56:df9052e3808c 88 {
gert_lauritsen 56:df9052e3808c 89 debug_if(FFS_DBG, "disk_ioctl(%d)\n", cmd);
gert_lauritsen 56:df9052e3808c 90 switch(cmd) {
gert_lauritsen 56:df9052e3808c 91 case CTRL_SYNC:
gert_lauritsen 56:df9052e3808c 92 if(FATFileSystem::_ffs[pdrv] == NULL) {
gert_lauritsen 56:df9052e3808c 93 return RES_NOTRDY;
gert_lauritsen 56:df9052e3808c 94 } else if(FATFileSystem::_ffs[pdrv]->disk_sync()) {
gert_lauritsen 56:df9052e3808c 95 return RES_ERROR;
gert_lauritsen 56:df9052e3808c 96 }
gert_lauritsen 56:df9052e3808c 97 return RES_OK;
gert_lauritsen 56:df9052e3808c 98 case GET_SECTOR_COUNT:
gert_lauritsen 56:df9052e3808c 99 if(FATFileSystem::_ffs[pdrv] == NULL) {
gert_lauritsen 56:df9052e3808c 100 return RES_NOTRDY;
gert_lauritsen 56:df9052e3808c 101 } else {
gert_lauritsen 56:df9052e3808c 102 DWORD res = FATFileSystem::_ffs[pdrv]->disk_sectors();
gert_lauritsen 56:df9052e3808c 103 if(res > 0) {
gert_lauritsen 56:df9052e3808c 104 *((DWORD*)buff) = res; // minimum allowed
gert_lauritsen 56:df9052e3808c 105 return RES_OK;
gert_lauritsen 56:df9052e3808c 106 } else {
gert_lauritsen 56:df9052e3808c 107 return RES_ERROR;
gert_lauritsen 56:df9052e3808c 108 }
gert_lauritsen 56:df9052e3808c 109 }
gert_lauritsen 56:df9052e3808c 110 case GET_BLOCK_SIZE:
gert_lauritsen 56:df9052e3808c 111 *((DWORD*)buff) = 1; // default when not known
gert_lauritsen 56:df9052e3808c 112 return RES_OK;
gert_lauritsen 56:df9052e3808c 113
gert_lauritsen 56:df9052e3808c 114 }
gert_lauritsen 56:df9052e3808c 115 return RES_PARERR;
gert_lauritsen 56:df9052e3808c 116 }
gert_lauritsen 56:df9052e3808c 117 #endif