ok

Dependents:   USB-MSD_SD_HelloWorld_Mbed-RAMVersion

Fork of USBMSD_SD by Samuel Mokrani

Files at this revision

API Documentation at this revision

Comitter:
avnisha
Date:
Mon Aug 19 04:35:39 2013 +0000
Parent:
2:055119ccf5a7
Commit message:
ok

Changed in this revision

USBMSD_SD.cpp Show annotated file Show diff for this revision Revisions of this file
USBMSD_SD.h Show annotated file Show diff for this revision Revisions of this file
--- a/USBMSD_SD.cpp	Mon Jan 21 10:40:05 2013 +0000
+++ b/USBMSD_SD.cpp	Mon Aug 19 04:35:39 2013 +0000
@@ -1,3 +1,5 @@
+
+#ifdef OLD
 /* mbed Microcontroller Library
  * Copyright (c) 2006-2012 ARM Limited
  *
@@ -471,3 +473,94 @@
     };
     return blocks;
 }
+
+#endif
+
+
+#define NEW
+#ifdef NEW
+
+#ifdef FOO
+You have to inherit from USBMSD and define ALL the following pure virtual functions:
+virtual int disk_read(uint8_t * data, uint64_t block): function to read a block
+virtual int disk_write(const uint8_t * data, uint64_t block): function to write a block
+virtual int disk_initialize(): function to initialize the memory
+virtual uint64_t disk_sectors(): return the number of blocks
+virtual uint64_t disk_size(): return the memory size
+virtual int disk_status(): return the status of the storage chip (0: OK, 1: not initialized, 2: no medium in the drive, 4: write protection)
+All functions names are compatible with the fat filesystem library. So you can imagine using your own class with USBMSD and the fat filesystem library in the same program. Just be careful because there are two different parts which will access the sd card. You can do a master/slave system using disk_status().
+Once these functions defined, you can call connect() (at the end of the constructor of your class for instance) of USBMSD to connect your mass storage device. connect() will first call disk_status() to test the status of the disk. If disk_status() returns 1 (disk not initialized), then disk_initialize() is called. After this step, connect() will collect information such as the number of blocks and the memory size.
+#endif
+
+#include "USBMSD_SD.h"
+#include "mbed_debug.h"
+
+#define SD_COMMAND_TIMEOUT 5000
+#define SD_DBG             0
+#define BLOCKS  16
+#define FS  BLOCKS*512
+
+LocalFileSystem local("local"); 
+
+char    s[FS];
+int     status = 1;
+
+USBMSD_SD::USBMSD_SD(PinName mosi, PinName miso, PinName sclk, PinName cs) :
+    _spi(mosi, miso, sclk), _cs(cs) {
+    _cs = 1;
+    
+    printf("cons\n");
+    connect();
+}
+
+int USBMSD_SD::disk_initialize() { 
+
+    printf("ini\n");
+    status--;
+    return 0;
+}
+
+int USBMSD_SD::disk_write(const uint8_t *buffer, uint64_t block_number) {
+
+//
+// find the correct block and write
+//
+    int offset;
+    int i;
+    
+    //printf("write\n");
+    if (block_number > (BLOCKS -1)) return 1;
+    offset = 512 * block_number;   
+    for (i = 0; i < 512; i++) {
+        s[offset + i] = buffer[i];  
+    }
+    return 0;
+}
+
+int USBMSD_SD::disk_read(uint8_t *buffer, uint64_t block_number) {
+
+    int offset;
+    int i;
+    
+    //printf("read\n");
+    if (block_number > (BLOCKS -1)) return 1;
+    offset = 512 * block_number;   
+    for (i = 0; i < 512; i++) {
+        buffer[i] = s[offset + i];  
+    }
+    return 0;
+}
+
+int USBMSD_SD::disk_status() { 
+    printf("status\n");
+    return status; 
+}
+
+
+int USBMSD_SD::disk_sync() { printf("sync\n"); return 0; }
+uint64_t USBMSD_SD::disk_size() { printf("size\n"); return FS;}
+uint64_t USBMSD_SD::disk_sectors() { printf("sectors\n"); return BLOCKS; }
+
+
+
+#endif
\ No newline at end of file
--- a/USBMSD_SD.h	Mon Jan 21 10:40:05 2013 +0000
+++ b/USBMSD_SD.h	Mon Aug 19 04:35:39 2013 +0000
@@ -59,7 +59,8 @@
     virtual int disk_sync();
     virtual uint64_t disk_sectors();
     
-    virtual uint64_t disk_size(){return _sectors*512;};
+//virtual uint64_t disk_size(){return _sectors*512;};
+    virtual uint64_t disk_size();
 
 protected: