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/

Files at this revision

API Documentation at this revision

Comitter:
wkleunen
Date:
Fri May 12 10:26:15 2017 +0000
Parent:
8:876f3b55e6f5
Commit message:
Use callback template class to integrate library with mbed os 5.

Changed in this revision

SimpleDMA.h Show annotated file Show diff for this revision Revisions of this file
SimpleDMA_KL25_46.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 876f3b55e6f5 -r f7345d41b076 SimpleDMA.h
--- a/SimpleDMA.h	Tue Jan 27 14:30:18 2015 +0000
+++ b/SimpleDMA.h	Fri May 12 10:26:15 2017 +0000
@@ -117,36 +117,10 @@
 *
 * @param function - function to call upon completion (may be a member function)
 */
-void attach(void (*function)(void)) {
-    _callback.attach(function);
+void attach(Callback<void(int)> func) {
+    _callback = func;
     }
     
-template<typename T>
-    void attach(T *object, void (T::*member)(void)) {
-        _callback.attach(object, member);
-    }
-
-#ifdef RTOS_H
-/**
-* Start a DMA transfer similar to start, however block current Thread
-* until the transfer is finished
-*
-* When using this function only the current Thread is halted.
-* The Thread is moved to Waiting state: other Threads will continue
-* to run normally. 
-*
-* This function is only available if you included rtos.h before 
-* including SimpleDMA.h.
-*
-* @param length - number of BYTES to be moved by the DMA
-*/
-void wait(int length) {
-    id = Thread::gettid();
-    this->attach(this, &SimpleDMA::waitCallback);
-    this->start(length);
-    Thread::signal_wait(0x1);
-}
-#endif
 
 protected:
 int _channel;
@@ -161,7 +135,7 @@
 bool auto_channel;
 
 //IRQ handlers
-FunctionPointer _callback;
+Callback<void(int)> _callback;
 void irq_handler(void);
 
 static SimpleDMA *irq_owner[DMA_CHANNELS];
@@ -177,11 +151,6 @@
 //Keep searching until we find a non-busy channel, start with lowest channel number
 int getFreeChannel(void);
 
-#ifdef RTOS_H
-osThreadId id;
-void waitCallback(void) {
-    osSignalSet(id, 0x1);    
-}
-#endif
+
 };
 #endif
\ No newline at end of file
diff -r 876f3b55e6f5 -r f7345d41b076 SimpleDMA_KL25_46.cpp
--- a/SimpleDMA_KL25_46.cpp	Tue Jan 27 14:30:18 2015 +0000
+++ b/SimpleDMA_KL25_46.cpp	Fri May 12 10:26:15 2017 +0000
@@ -1,11 +1,12 @@
 #if defined TARGET_KL25Z || defined TARGET_KL46Z
 #include "SimpleDMA.h"
 
-
+static void donothing(int) { }
 
 SimpleDMA *SimpleDMA::irq_owner[4] = {NULL};
 
 SimpleDMA::SimpleDMA(int channel) {
+    _callback = donothing;
     this->channel(channel);
        
     //Enable DMA
@@ -76,12 +77,15 @@
     return (DMA0->DMA[channel].DSR_BCR & 0xFFFFFF);
 }
 
-
 /*****************************************************************/
 void SimpleDMA::irq_handler(void) {
+    Callback<void(int)> func = _callback;
+    _callback = donothing;
+    
     DMAMUX0->CHCFG[_channel] = 0;
     DMA0->DMA[_channel].DSR_BCR |= DMA_DSR_BCR_DONE_MASK ; 
-    _callback.call();
+    
+    func(_channel);    
 }
 
 void SimpleDMA::irq_handler0( void ) {