Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SimpleDMA_HelloWorld RTOS_SPI spiDMAtest Pinscape_Controller_v1 ... more
Revision 9:f7345d41b076, committed 2017-05-12
- 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 |
--- 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
--- 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 ) {
