Counter

Dependencies:   EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem

Committer:
Tuxitheone
Date:
Mon Feb 29 18:59:15 2016 +0000
Revision:
0:ecaf3e593122
TankCounter

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Tuxitheone 0:ecaf3e593122 1 /* mbed Microcontroller Library
Tuxitheone 0:ecaf3e593122 2 * Copyright (c) 2006-2012 ARM Limited
Tuxitheone 0:ecaf3e593122 3 *
Tuxitheone 0:ecaf3e593122 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
Tuxitheone 0:ecaf3e593122 5 * of this software and associated documentation files (the "Software"), to deal
Tuxitheone 0:ecaf3e593122 6 * in the Software without restriction, including without limitation the rights
Tuxitheone 0:ecaf3e593122 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Tuxitheone 0:ecaf3e593122 8 * copies of the Software, and to permit persons to whom the Software is
Tuxitheone 0:ecaf3e593122 9 * furnished to do so, subject to the following conditions:
Tuxitheone 0:ecaf3e593122 10 *
Tuxitheone 0:ecaf3e593122 11 * The above copyright notice and this permission notice shall be included in
Tuxitheone 0:ecaf3e593122 12 * all copies or substantial portions of the Software.
Tuxitheone 0:ecaf3e593122 13 *
Tuxitheone 0:ecaf3e593122 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Tuxitheone 0:ecaf3e593122 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Tuxitheone 0:ecaf3e593122 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Tuxitheone 0:ecaf3e593122 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Tuxitheone 0:ecaf3e593122 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Tuxitheone 0:ecaf3e593122 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Tuxitheone 0:ecaf3e593122 20 * SOFTWARE.
Tuxitheone 0:ecaf3e593122 21 */
Tuxitheone 0:ecaf3e593122 22 #ifndef MBED_SDFILESYSTEM_H
Tuxitheone 0:ecaf3e593122 23 #define MBED_SDFILESYSTEM_H
Tuxitheone 0:ecaf3e593122 24
Tuxitheone 0:ecaf3e593122 25 #include "mbed.h"
Tuxitheone 0:ecaf3e593122 26 #include "FATFileSystem.h"
Tuxitheone 0:ecaf3e593122 27 #include <stdint.h>
Tuxitheone 0:ecaf3e593122 28
Tuxitheone 0:ecaf3e593122 29 /** Access the filesystem on an SD Card using SPI
Tuxitheone 0:ecaf3e593122 30 *
Tuxitheone 0:ecaf3e593122 31 * @code
Tuxitheone 0:ecaf3e593122 32 * #include "mbed.h"
Tuxitheone 0:ecaf3e593122 33 * #include "SDFileSystem.h"
Tuxitheone 0:ecaf3e593122 34 *
Tuxitheone 0:ecaf3e593122 35 * SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs
Tuxitheone 0:ecaf3e593122 36 *
Tuxitheone 0:ecaf3e593122 37 * int main() {
Tuxitheone 0:ecaf3e593122 38 * FILE *fp = fopen("/sd/myfile.txt", "w");
Tuxitheone 0:ecaf3e593122 39 * fprintf(fp, "Hello World!\n");
Tuxitheone 0:ecaf3e593122 40 * fclose(fp);
Tuxitheone 0:ecaf3e593122 41 * }
Tuxitheone 0:ecaf3e593122 42 */
Tuxitheone 0:ecaf3e593122 43 class SDFileSystem : public FATFileSystem {
Tuxitheone 0:ecaf3e593122 44 public:
Tuxitheone 0:ecaf3e593122 45
Tuxitheone 0:ecaf3e593122 46 /** Create the File System for accessing an SD Card using SPI
Tuxitheone 0:ecaf3e593122 47 *
Tuxitheone 0:ecaf3e593122 48 * @param mosi SPI mosi pin connected to SD Card
Tuxitheone 0:ecaf3e593122 49 * @param miso SPI miso pin conencted to SD Card
Tuxitheone 0:ecaf3e593122 50 * @param sclk SPI sclk pin connected to SD Card
Tuxitheone 0:ecaf3e593122 51 * @param cs DigitalOut pin used as SD Card chip select
Tuxitheone 0:ecaf3e593122 52 * @param name The name used to access the virtual filesystem
Tuxitheone 0:ecaf3e593122 53 */
Tuxitheone 0:ecaf3e593122 54 SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
Tuxitheone 0:ecaf3e593122 55 virtual int disk_initialize();
Tuxitheone 0:ecaf3e593122 56 virtual int disk_status();
Tuxitheone 0:ecaf3e593122 57 virtual int disk_read(uint8_t * buffer, uint64_t block_number);
Tuxitheone 0:ecaf3e593122 58 virtual int disk_write(const uint8_t * buffer, uint64_t block_number);
Tuxitheone 0:ecaf3e593122 59 virtual int disk_sync();
Tuxitheone 0:ecaf3e593122 60 virtual uint64_t disk_sectors();
Tuxitheone 0:ecaf3e593122 61
Tuxitheone 0:ecaf3e593122 62 protected:
Tuxitheone 0:ecaf3e593122 63
Tuxitheone 0:ecaf3e593122 64 int _cmd(int cmd, int arg);
Tuxitheone 0:ecaf3e593122 65 int _cmdx(int cmd, int arg);
Tuxitheone 0:ecaf3e593122 66 int _cmd8();
Tuxitheone 0:ecaf3e593122 67 int _cmd58();
Tuxitheone 0:ecaf3e593122 68 int initialise_card();
Tuxitheone 0:ecaf3e593122 69 int initialise_card_v1();
Tuxitheone 0:ecaf3e593122 70 int initialise_card_v2();
Tuxitheone 0:ecaf3e593122 71
Tuxitheone 0:ecaf3e593122 72 int _read(uint8_t * buffer, uint32_t length);
Tuxitheone 0:ecaf3e593122 73 int _write(const uint8_t *buffer, uint32_t length);
Tuxitheone 0:ecaf3e593122 74 uint64_t _sd_sectors();
Tuxitheone 0:ecaf3e593122 75 uint64_t _sectors;
Tuxitheone 0:ecaf3e593122 76
Tuxitheone 0:ecaf3e593122 77 SPI _spi;
Tuxitheone 0:ecaf3e593122 78 DigitalOut _cs;
Tuxitheone 0:ecaf3e593122 79 int cdv;
Tuxitheone 0:ecaf3e593122 80 };
Tuxitheone 0:ecaf3e593122 81
Tuxitheone 0:ecaf3e593122 82 #endif