SD card data log
FATFileSystem/FATFileSystem.h@0:18d80d7403d3, 2019-11-03 (annotated)
- Committer:
- kotachi
- Date:
- Sun Nov 03 07:28:09 2019 +0000
- Revision:
- 0:18d80d7403d3
SD card logging system
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kotachi | 0:18d80d7403d3 | 1 | /* mbed Microcontroller Library |
kotachi | 0:18d80d7403d3 | 2 | * Copyright (c) 2006-2012 ARM Limited |
kotachi | 0:18d80d7403d3 | 3 | * |
kotachi | 0:18d80d7403d3 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
kotachi | 0:18d80d7403d3 | 5 | * of this software and associated documentation files (the "Software"), to deal |
kotachi | 0:18d80d7403d3 | 6 | * in the Software without restriction, including without limitation the rights |
kotachi | 0:18d80d7403d3 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
kotachi | 0:18d80d7403d3 | 8 | * copies of the Software, and to permit persons to whom the Software is |
kotachi | 0:18d80d7403d3 | 9 | * furnished to do so, subject to the following conditions: |
kotachi | 0:18d80d7403d3 | 10 | * |
kotachi | 0:18d80d7403d3 | 11 | * The above copyright notice and this permission notice shall be included in |
kotachi | 0:18d80d7403d3 | 12 | * all copies or substantial portions of the Software. |
kotachi | 0:18d80d7403d3 | 13 | * |
kotachi | 0:18d80d7403d3 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
kotachi | 0:18d80d7403d3 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
kotachi | 0:18d80d7403d3 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
kotachi | 0:18d80d7403d3 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
kotachi | 0:18d80d7403d3 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kotachi | 0:18d80d7403d3 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
kotachi | 0:18d80d7403d3 | 20 | * SOFTWARE. |
kotachi | 0:18d80d7403d3 | 21 | */ |
kotachi | 0:18d80d7403d3 | 22 | #ifndef MBED_FATFILESYSTEM_H |
kotachi | 0:18d80d7403d3 | 23 | #define MBED_FATFILESYSTEM_H |
kotachi | 0:18d80d7403d3 | 24 | |
kotachi | 0:18d80d7403d3 | 25 | #include "FileSystemLike.h" |
kotachi | 0:18d80d7403d3 | 26 | #include "FileHandle.h" |
kotachi | 0:18d80d7403d3 | 27 | #include "ff.h" |
kotachi | 0:18d80d7403d3 | 28 | #include <stdint.h> |
kotachi | 0:18d80d7403d3 | 29 | |
kotachi | 0:18d80d7403d3 | 30 | using namespace mbed; |
kotachi | 0:18d80d7403d3 | 31 | |
kotachi | 0:18d80d7403d3 | 32 | /** |
kotachi | 0:18d80d7403d3 | 33 | * FATFileSystem based on ChaN's Fat Filesystem library v0.8 |
kotachi | 0:18d80d7403d3 | 34 | */ |
kotachi | 0:18d80d7403d3 | 35 | class FATFileSystem : public FileSystemLike { |
kotachi | 0:18d80d7403d3 | 36 | public: |
kotachi | 0:18d80d7403d3 | 37 | |
kotachi | 0:18d80d7403d3 | 38 | FATFileSystem(const char* n); |
kotachi | 0:18d80d7403d3 | 39 | virtual ~FATFileSystem(); |
kotachi | 0:18d80d7403d3 | 40 | |
kotachi | 0:18d80d7403d3 | 41 | static FATFileSystem * _ffs[_VOLUMES]; // FATFileSystem objects, as parallel to FatFs drives array |
kotachi | 0:18d80d7403d3 | 42 | FATFS _fs; // Work area (file system object) for logical drive |
kotachi | 0:18d80d7403d3 | 43 | char _fsid[2]; |
kotachi | 0:18d80d7403d3 | 44 | |
kotachi | 0:18d80d7403d3 | 45 | /** |
kotachi | 0:18d80d7403d3 | 46 | * Opens a file on the filesystem |
kotachi | 0:18d80d7403d3 | 47 | */ |
kotachi | 0:18d80d7403d3 | 48 | virtual FileHandle *open(const char* name, int flags); |
kotachi | 0:18d80d7403d3 | 49 | virtual int open(FileHandle **file, const char *name, int flags); |
kotachi | 0:18d80d7403d3 | 50 | |
kotachi | 0:18d80d7403d3 | 51 | /** |
kotachi | 0:18d80d7403d3 | 52 | * Removes a file path |
kotachi | 0:18d80d7403d3 | 53 | */ |
kotachi | 0:18d80d7403d3 | 54 | virtual int remove(const char *filename); |
kotachi | 0:18d80d7403d3 | 55 | |
kotachi | 0:18d80d7403d3 | 56 | /** |
kotachi | 0:18d80d7403d3 | 57 | * Renames a file |
kotachi | 0:18d80d7403d3 | 58 | */ |
kotachi | 0:18d80d7403d3 | 59 | virtual int rename(const char *oldname, const char *newname); |
kotachi | 0:18d80d7403d3 | 60 | |
kotachi | 0:18d80d7403d3 | 61 | /** |
kotachi | 0:18d80d7403d3 | 62 | * Formats a logical drive, FDISK artitioning rule, 512 bytes per cluster |
kotachi | 0:18d80d7403d3 | 63 | */ |
kotachi | 0:18d80d7403d3 | 64 | virtual int format(); |
kotachi | 0:18d80d7403d3 | 65 | |
kotachi | 0:18d80d7403d3 | 66 | /** |
kotachi | 0:18d80d7403d3 | 67 | * Opens a directory on the filesystem |
kotachi | 0:18d80d7403d3 | 68 | */ |
kotachi | 0:18d80d7403d3 | 69 | virtual DirHandle *opendir(const char *name); |
kotachi | 0:18d80d7403d3 | 70 | virtual int open(DirHandle **dir, const char *name); |
kotachi | 0:18d80d7403d3 | 71 | |
kotachi | 0:18d80d7403d3 | 72 | /** |
kotachi | 0:18d80d7403d3 | 73 | * Creates a directory path |
kotachi | 0:18d80d7403d3 | 74 | */ |
kotachi | 0:18d80d7403d3 | 75 | virtual int mkdir(const char *name, mode_t mode); |
kotachi | 0:18d80d7403d3 | 76 | |
kotachi | 0:18d80d7403d3 | 77 | /** |
kotachi | 0:18d80d7403d3 | 78 | * Mounts the filesystem |
kotachi | 0:18d80d7403d3 | 79 | */ |
kotachi | 0:18d80d7403d3 | 80 | virtual int mount(); |
kotachi | 0:18d80d7403d3 | 81 | |
kotachi | 0:18d80d7403d3 | 82 | /** |
kotachi | 0:18d80d7403d3 | 83 | * Unmounts the filesystem |
kotachi | 0:18d80d7403d3 | 84 | */ |
kotachi | 0:18d80d7403d3 | 85 | virtual int unmount(); |
kotachi | 0:18d80d7403d3 | 86 | |
kotachi | 0:18d80d7403d3 | 87 | virtual int disk_initialize() { return 0; } |
kotachi | 0:18d80d7403d3 | 88 | virtual int disk_status() { return 0; } |
kotachi | 0:18d80d7403d3 | 89 | virtual int disk_read(uint8_t *buffer, uint32_t sector, uint32_t count) = 0; |
kotachi | 0:18d80d7403d3 | 90 | virtual int disk_write(const uint8_t *buffer, uint32_t sector, uint32_t count) = 0; |
kotachi | 0:18d80d7403d3 | 91 | virtual int disk_sync() { return 0; } |
kotachi | 0:18d80d7403d3 | 92 | virtual uint32_t disk_sectors() = 0; |
kotachi | 0:18d80d7403d3 | 93 | |
kotachi | 0:18d80d7403d3 | 94 | }; |
kotachi | 0:18d80d7403d3 | 95 | |
kotachi | 0:18d80d7403d3 | 96 | #endif |