Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SDFileSystem.h@0:050fdb1efb7a, 2011-02-10 (annotated)
- Committer:
 - moon_light
 - Date:
 - Thu Feb 10 12:21:50 2011 +0000
 - Revision:
 - 0:050fdb1efb7a
 
ver 0.1
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| moon_light | 0:050fdb1efb7a | 1 | /* mbed Microcontroller Library - SDFileSystem | 
| moon_light | 0:050fdb1efb7a | 2 | * Copyright (c) 2008-2009, sford | 
| moon_light | 0:050fdb1efb7a | 3 | */ | 
| moon_light | 0:050fdb1efb7a | 4 | |
| moon_light | 0:050fdb1efb7a | 5 | // VERY DRAFT CODE!!! | 
| moon_light | 0:050fdb1efb7a | 6 | |
| moon_light | 0:050fdb1efb7a | 7 | #ifndef SDFILESYSTEM_H | 
| moon_light | 0:050fdb1efb7a | 8 | #define SDFILESYSTEM_H | 
| moon_light | 0:050fdb1efb7a | 9 | |
| moon_light | 0:050fdb1efb7a | 10 | #include "mbed.h" | 
| moon_light | 0:050fdb1efb7a | 11 | #include "FATFileSystem.h" | 
| moon_light | 0:050fdb1efb7a | 12 | |
| moon_light | 0:050fdb1efb7a | 13 | /* Class: SDFileSystem | 
| moon_light | 0:050fdb1efb7a | 14 | * Access the filesystem on an SD Card using SPI | 
| moon_light | 0:050fdb1efb7a | 15 | * | 
| moon_light | 0:050fdb1efb7a | 16 | * Example: | 
| moon_light | 0:050fdb1efb7a | 17 | * > SDFileSystem sd(p5, p6, p7, p12, "sd"); | 
| moon_light | 0:050fdb1efb7a | 18 | * > | 
| moon_light | 0:050fdb1efb7a | 19 | * > int main() { | 
| moon_light | 0:050fdb1efb7a | 20 | * > FILE *fp = fopen("/sd/myfile.txt", "w"); | 
| moon_light | 0:050fdb1efb7a | 21 | * > fprintf(fp, "Hello World!\n"); | 
| moon_light | 0:050fdb1efb7a | 22 | * > fclose(fp); | 
| moon_light | 0:050fdb1efb7a | 23 | * > } | 
| moon_light | 0:050fdb1efb7a | 24 | */ | 
| moon_light | 0:050fdb1efb7a | 25 | class SDFileSystem : public FATFileSystem { | 
| moon_light | 0:050fdb1efb7a | 26 | public: | 
| moon_light | 0:050fdb1efb7a | 27 | |
| moon_light | 0:050fdb1efb7a | 28 | /* Constructor: SDFileSystem | 
| moon_light | 0:050fdb1efb7a | 29 | * Create the File System for accessing an SD Card using SPI | 
| moon_light | 0:050fdb1efb7a | 30 | * | 
| moon_light | 0:050fdb1efb7a | 31 | * Variables: | 
| moon_light | 0:050fdb1efb7a | 32 | * mosi - SPI mosi pin connected to SD Card | 
| moon_light | 0:050fdb1efb7a | 33 | * miso - SPI miso pin conencted to SD Card | 
| moon_light | 0:050fdb1efb7a | 34 | * sclk - SPI sclk pin connected to SD Card | 
| moon_light | 0:050fdb1efb7a | 35 | * cs - DigitalOut pin used as SD Card chip select | 
| moon_light | 0:050fdb1efb7a | 36 | * name - The name used to access the filesystem | 
| moon_light | 0:050fdb1efb7a | 37 | */ | 
| moon_light | 0:050fdb1efb7a | 38 | SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); | 
| moon_light | 0:050fdb1efb7a | 39 | virtual int disk_initialize(); | 
| moon_light | 0:050fdb1efb7a | 40 | virtual int disk_write(const char *buffer, int block_number); | 
| moon_light | 0:050fdb1efb7a | 41 | virtual int disk_read(char *buffer, int block_number); | 
| moon_light | 0:050fdb1efb7a | 42 | virtual int disk_status(); | 
| moon_light | 0:050fdb1efb7a | 43 | virtual int disk_sync(); | 
| moon_light | 0:050fdb1efb7a | 44 | virtual int disk_sectors(); | 
| moon_light | 0:050fdb1efb7a | 45 | |
| moon_light | 0:050fdb1efb7a | 46 | protected: | 
| moon_light | 0:050fdb1efb7a | 47 | |
| moon_light | 0:050fdb1efb7a | 48 | int _cmd(int cmd, int arg); | 
| moon_light | 0:050fdb1efb7a | 49 | int _cmdx(int cmd, int arg); | 
| moon_light | 0:050fdb1efb7a | 50 | int _cmd8(); | 
| moon_light | 0:050fdb1efb7a | 51 | int _cmd58(); | 
| moon_light | 0:050fdb1efb7a | 52 | int initialise_card(); | 
| moon_light | 0:050fdb1efb7a | 53 | int initialise_card_v1(); | 
| moon_light | 0:050fdb1efb7a | 54 | int initialise_card_v2(); | 
| moon_light | 0:050fdb1efb7a | 55 | |
| moon_light | 0:050fdb1efb7a | 56 | |
| moon_light | 0:050fdb1efb7a | 57 | int _read(char *buffer, int length); | 
| moon_light | 0:050fdb1efb7a | 58 | int _write(const char *buffer, int length); | 
| moon_light | 0:050fdb1efb7a | 59 | int _sd_sectors(); | 
| moon_light | 0:050fdb1efb7a | 60 | int _sectors; | 
| moon_light | 0:050fdb1efb7a | 61 | |
| moon_light | 0:050fdb1efb7a | 62 | SPI _spi; | 
| moon_light | 0:050fdb1efb7a | 63 | DigitalOut _cs; | 
| moon_light | 0:050fdb1efb7a | 64 | }; | 
| moon_light | 0:050fdb1efb7a | 65 | |
| moon_light | 0:050fdb1efb7a | 66 | #endif |