Serial RAM (SPI SRAM) library 23K256, 23LC1024 (Microchip) see: http://mbed.org/users/okini3939/notebook/extend-memory/

Dependents:   SPIRAM_23LC1024_FIFO

Revision:
1:5a261b6a88af
Parent:
0:69ea2af1d9af
--- a/SerRAM.h	Mon Jan 07 14:30:06 2013 +0000
+++ b/SerRAM.h	Fri Mar 08 14:00:38 2013 +0000
@@ -8,20 +8,17 @@
  * @brief Serial RAM (SPI SRAM) library
  *   23K256, 23LC1024 (Microchip)
  *   support FIFO
- *   support DMA http://mbed.org/users/AjK/code/MODDMA/
+ *   support DMA need http://mbed.org/users/AjK/code/MODDMA/
  */
 
 #ifndef __SerRAM_h__
 #define __SerRAM_h__
 
 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
-//#define RAM_USE_DMA
+#define RAM_USE_DMA
 #define RAM_DMA_SIZE 64
 #endif
 
-#define RAM_USE_FIFO
-#define RAM_FIFO_NUM 20
-
 #include "mbed.h"
 
 #ifdef RAM_USE_DMA
@@ -53,7 +50,7 @@
      * @param async block (DMA)
      * @return >=0:success, -1:failure
      */
-    int write (int addr, char *buf, int len, int async = 0);
+    int write (int addr, char *buf, int len, bool async = false);
     /**
      * @param addr address
      * @return data
@@ -66,20 +63,19 @@
      * @param async block (DMA)
      * @return 0:success, -1:failure
      */
-    int read (int addr, char *buf, int len, int async = 0);
+    int read (int addr, char *buf, int len, bool async = false);
 
     int setStatus (int status);
     int getStatus ();
 
-#ifdef RAM_USE_FIFO
-    int fifoAlloc (int size);
-    int fifoPut (int n, char dat);
-    int fifoPut (int n, char *buf, int len);
-    int fifoGet (int n, char *dat);
-    int fifoGet (int n, char *buf, int len);
-    int fifoAvailable (int n);
-    int fifoUse (int n);
-    void fifoClear (int n);
+    static SerRAM * getInstance() {
+        return _inst;
+    };
+
+#ifdef RAM_USE_DMA
+    bool isBusy () {
+        return dmabusy;
+    };
 #endif
 
 private:
@@ -87,29 +83,18 @@
     DigitalOut _cs;
     int _size;
     int _alloc;
+    static SerRAM * _inst;
 
 #ifdef RAM_USE_DMA
     void tc0_callback ();
     void tc1_callback ();
     void err_callback ();
 
-    __IO uint32_t *ssp_dmacr;
+    LPC_SSP_TypeDef *_ssp;
     MODDMA dma;
     MODDMA_Config *dmacfg0, *dmacfg1;
     MODDMA::GPDMA_CONNECTION dmacon0, dmacon1;
-    volatile int dmaexit;
-#endif
-
-#ifdef RAM_USE_FIFO
-    int fifo_num;
-    struct {
-        char *buf_w, *buf_r;
-        int size;
-        int addr_w, addr_r;
-        int addr2_w, addr2_r;
-        int ram;
-        int ram_w, ram_r;
-    } fifo[RAM_FIFO_NUM];
+    volatile bool dmabusy;
 #endif
 };