SD Card test
Embed:
(wiki syntax)
Show/hide line numbers
SDFileSystem.h
00001 /* mbed Microcontroller Library - SDFileSystem 00002 * Copyright (c) 2008-2009, sford 00003 */ 00004 00005 // VERY DRAFT CODE!!! 00006 00007 #ifndef SDFILESYSTEM_H 00008 #define SDFILESYSTEM_H 00009 00010 #include "mbed.h" 00011 #include "FATFileSystem.h" 00012 00013 /* Class: SDFileSystem 00014 * Access the filesystem on an SD Card using SPI 00015 * 00016 * Example: 00017 * > SDFileSystem sd(p5, p6, p7, p12, "sd"); 00018 * > 00019 * > int main() { 00020 * > FILE *fp = fopen("/sd/myfile.txt", "w"); 00021 * > fprintf(fp, "Hello World!\n"); 00022 * > fclose(fp); 00023 * > } 00024 */ 00025 class SDFileSystem : public FATFileSystem { 00026 public: 00027 00028 /* Constructor: SDFileSystem 00029 * Create the File System for accessing an SD Card using SPI 00030 * 00031 * Variables: 00032 * mosi - SPI mosi pin connected to SD Card 00033 * miso - SPI miso pin conencted to SD Card 00034 * sclk - SPI sclk pin connected to SD Card 00035 * cs - DigitalOut pin used as SD Card chip select 00036 * name - The name used to access the filesystem 00037 */ 00038 SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); 00039 virtual int disk_initialize(); 00040 virtual int disk_write(const char *buffer, int block_number); 00041 virtual int disk_read(char *buffer, int block_number); 00042 virtual int disk_status(); 00043 virtual int disk_sync(); 00044 virtual int disk_sectors(); 00045 00046 protected: 00047 00048 int _cmd(int cmd, int arg); 00049 int _cmdx(int cmd, int arg); 00050 int _cmd41(); 00051 int _cmd8(); 00052 int _cmd58(); 00053 int initialise_card(); 00054 int initialise_card_v1(); 00055 int initialise_card_v2(); 00056 00057 00058 int _read(char *buffer, int length); 00059 int _write(const char *buffer, int length); 00060 int _sd_sectors(); 00061 int _sectors; 00062 00063 SPI _spi; 00064 DigitalOut _cs; 00065 00066 struct CSD_REGISTER { 00067 unsigned reserved1:4; 00068 unsigned reserved2:3; 00069 unsigned low_voltage:1; 00070 unsigned reserved3:7; 00071 unsigned volt_27_28:1; 00072 unsigned volt_28_29:1; 00073 unsigned volt_29_30:1; 00074 unsigned volt_30_31:1; 00075 unsigned volt_31_32:1; 00076 unsigned volt_32_33:1; 00077 unsigned volt_33_34:1; 00078 unsigned volt_34_35:1; 00079 unsigned volt_35_36:1; 00080 unsigned reserved:6; 00081 unsigned card_capacity_status:1; 00082 unsigned card_power_up_status:1; 00083 }; 00084 }; 00085 00086 #endif
Generated on Wed Jul 13 2022 03:35:30 by
1.7.2