DMA library for the KL25Z

Dependents:   SimpleDMA_HelloWorld RTOS_SPI spiDMAtest Pinscape_Controller_v1 ... more

Introduction

SimpleDMA is a standard library for different DMA peripherals. Currently the LPC1768, KL46Z and KL25Z are supported. It provided one set of functions for different peripherals. It does not allow for usage of all the advanced functions, partially because the goal was to provide a simple interface, and partially because they are different for different microcontrollers.

Examples

Helloworld: http://mbed.org/users/Sissors/code/SimpleDMA_HelloWorld/

Example in a library (SPI): http://mbed.org/users/Sissors/code/RTOS_SPI/

Revision:
1:0b73b00bcee8
Parent:
0:d77ea45fa625
Child:
2:fe2fcaa72434
--- a/SimpleDMA.h	Fri Oct 18 07:44:42 2013 +0000
+++ b/SimpleDMA.h	Fri Dec 20 20:48:17 2013 +0000
@@ -2,6 +2,7 @@
 #define SIMPLEDMA_H
 
 #include "mbed.h"
+#include "rtos.h"
 #include "SimpleDMA_KL25.h"
 
 
@@ -79,28 +80,78 @@
 int start(int length);
 
 /**
-* Set the DMA channel
-*
-* @param chan - DMA channel to use
-*/
-void channel(int chan);
-
-/**
 * Is the DMA channel busy
 *
 * @return - true if it is busy
 */
 bool isBusy( void );
 
+/**
+* Attach an interrupt upon completion of DMA transfer or error
+*
+* @param function - function to call upon completion (may be a member function)
+*/
+void attach(void (*function)(void)) {
+    irq_en = function;
+    _callback.attach(function);
+    }
+    
+template<typename T>
+    void attach(T *object, void (T::*member)(void)) {
+        irq_en = object;
+        _callback.attach(object, member);
+    }
 
-
+void wait(void) {
+    id = Thread::gettid();
+    this->attach(this, &SimpleDMA::waitCallback);
+    this->start(8);
+    Thread::signal_wait(0x1);
+}
 
 
 protected:
+/**
+* Set the DMA channel
+*
+* @param chan - DMA channel to use
+*/
+void channel(int chan);
+
 int setMemory(uint32_t address, int wordsize, bool source, bool autoinc);
 int _channel;
+FunctionPointer _callback;
+bool irq_en;
+void irq_handler(void);
 
+//IRQ handlers
 
+static SimpleDMA *irq_owner[4];
+
+static void irq_handler0( void ) {
+    if (irq_owner[0]!=NULL)
+        irq_owner[0]->irq_handler();
+}
+static void irq_handler1( void ) {
+    if (irq_owner[1]!=NULL)
+        irq_owner[1]->irq_handler();
+}
+static void irq_handler2( void ) {
+    if (irq_owner[2]!=NULL)
+        irq_owner[2]->irq_handler();
+}
+static void irq_handler3( void ) {
+    if (irq_owner[3]!=NULL)
+        irq_owner[3]->irq_handler();
+}
+public:
+osThreadId id;
+void waitCallback(void) {
+
+    //id = Thread::gettid();
+    osSignalSet(id, 0x1);
+    
+}
 
 };
 #endif
\ No newline at end of file