Paul Griffith
/
BoB3Test
Test program for BoB3 breakout board. Refer to my Notebook page for further details and contact info.
SDFileSystem.h@0:788d8ebe64b5, 2010-04-06 (annotated)
- Committer:
- paulg
- Date:
- Tue Apr 06 17:08:41 2010 +0000
- Revision:
- 0:788d8ebe64b5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
paulg | 0:788d8ebe64b5 | 1 | /* mbed Microcontroller Library - SDFileSystem |
paulg | 0:788d8ebe64b5 | 2 | * Copyright (c) 2008-2009, sford |
paulg | 0:788d8ebe64b5 | 3 | */ |
paulg | 0:788d8ebe64b5 | 4 | |
paulg | 0:788d8ebe64b5 | 5 | // VERY DRAFT CODE!!! |
paulg | 0:788d8ebe64b5 | 6 | |
paulg | 0:788d8ebe64b5 | 7 | #ifndef SDFILESYSTEM_H |
paulg | 0:788d8ebe64b5 | 8 | #define SDFILESYSTEM_H |
paulg | 0:788d8ebe64b5 | 9 | |
paulg | 0:788d8ebe64b5 | 10 | #include "mbed.h" |
paulg | 0:788d8ebe64b5 | 11 | #include "FATFileSystem.h" |
paulg | 0:788d8ebe64b5 | 12 | |
paulg | 0:788d8ebe64b5 | 13 | /* Class: SDFileSystem |
paulg | 0:788d8ebe64b5 | 14 | * Access the filesystem on an SD Card using SPI |
paulg | 0:788d8ebe64b5 | 15 | * |
paulg | 0:788d8ebe64b5 | 16 | * Example: |
paulg | 0:788d8ebe64b5 | 17 | * > SDFileSystem sd(p5, p6, p7, p12, "sd"); |
paulg | 0:788d8ebe64b5 | 18 | * > |
paulg | 0:788d8ebe64b5 | 19 | * > int main() { |
paulg | 0:788d8ebe64b5 | 20 | * > FILE *fp = fopen("/sd/myfile.txt", "w"); |
paulg | 0:788d8ebe64b5 | 21 | * > fprintf(fp, "Hello World!\n"); |
paulg | 0:788d8ebe64b5 | 22 | * > fclose(fp); |
paulg | 0:788d8ebe64b5 | 23 | * > } |
paulg | 0:788d8ebe64b5 | 24 | */ |
paulg | 0:788d8ebe64b5 | 25 | class SDFileSystem : public FATFileSystem { |
paulg | 0:788d8ebe64b5 | 26 | public: |
paulg | 0:788d8ebe64b5 | 27 | |
paulg | 0:788d8ebe64b5 | 28 | /* Constructor: SDFileSystem |
paulg | 0:788d8ebe64b5 | 29 | * Create the File System for accessing an SD Card using SPI |
paulg | 0:788d8ebe64b5 | 30 | * |
paulg | 0:788d8ebe64b5 | 31 | * Variables: |
paulg | 0:788d8ebe64b5 | 32 | * mosi - SPI mosi pin connected to SD Card |
paulg | 0:788d8ebe64b5 | 33 | * miso - SPI miso pin conencted to SD Card |
paulg | 0:788d8ebe64b5 | 34 | * sclk - SPI sclk pin connected to SD Card |
paulg | 0:788d8ebe64b5 | 35 | * cs - DigitalOut pin used as SD Card chip select |
paulg | 0:788d8ebe64b5 | 36 | * name - The name used to access the filesystem |
paulg | 0:788d8ebe64b5 | 37 | */ |
paulg | 0:788d8ebe64b5 | 38 | SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); |
paulg | 0:788d8ebe64b5 | 39 | virtual int disk_initialize(); |
paulg | 0:788d8ebe64b5 | 40 | virtual int disk_write(const char *buffer, int block_number); |
paulg | 0:788d8ebe64b5 | 41 | virtual int disk_read(char *buffer, int block_number); |
paulg | 0:788d8ebe64b5 | 42 | virtual int disk_status(); |
paulg | 0:788d8ebe64b5 | 43 | virtual int disk_sync(); |
paulg | 0:788d8ebe64b5 | 44 | virtual int disk_sectors(); |
paulg | 0:788d8ebe64b5 | 45 | |
paulg | 0:788d8ebe64b5 | 46 | protected: |
paulg | 0:788d8ebe64b5 | 47 | |
paulg | 0:788d8ebe64b5 | 48 | int _cmd(int cmd, int arg); |
paulg | 0:788d8ebe64b5 | 49 | int _cmdx(int cmd, int arg); |
paulg | 0:788d8ebe64b5 | 50 | int _cmd8(); |
paulg | 0:788d8ebe64b5 | 51 | int _cmd58(); |
paulg | 0:788d8ebe64b5 | 52 | int initialise_card(); |
paulg | 0:788d8ebe64b5 | 53 | int initialise_card_v1(); |
paulg | 0:788d8ebe64b5 | 54 | int initialise_card_v2(); |
paulg | 0:788d8ebe64b5 | 55 | |
paulg | 0:788d8ebe64b5 | 56 | |
paulg | 0:788d8ebe64b5 | 57 | int _read(char *buffer, int length); |
paulg | 0:788d8ebe64b5 | 58 | int _write(const char *buffer, int length); |
paulg | 0:788d8ebe64b5 | 59 | int _sd_sectors(); |
paulg | 0:788d8ebe64b5 | 60 | int _sectors; |
paulg | 0:788d8ebe64b5 | 61 | |
paulg | 0:788d8ebe64b5 | 62 | SPI _spi; |
paulg | 0:788d8ebe64b5 | 63 | DigitalOut _cs; |
paulg | 0:788d8ebe64b5 | 64 | }; |
paulg | 0:788d8ebe64b5 | 65 | |
paulg | 0:788d8ebe64b5 | 66 | #endif |