A simple library to access the DMA functionality.
Fork of SimpleDMA by
Diff: SimpleDMA.h
- Revision:
- 5:d9f46ef80e20
- Parent:
- 4:c3a84c6c432c
diff -r c3a84c6c432c -r d9f46ef80e20 SimpleDMA.h --- a/SimpleDMA.h Thu Dec 26 16:31:54 2013 +0000 +++ b/SimpleDMA.h Sat Jan 04 14:42:33 2014 +0000 @@ -7,6 +7,7 @@ #include "mbed.h" #include "SimpleDMA_KL25.h" +#include "SimpleDMA_LPC1768.h" /** @@ -42,8 +43,10 @@ * @return - 0 on success */ template<typename Type> -int source(Type* pointer, bool autoinc, int size = sizeof(Type) * 8) { - return setAddress((uint32_t)pointer, size, true, autoinc); +void source(Type* pointer, bool autoinc, int size = sizeof(Type) * 8) { + _source = (uint32_t)pointer; + source_inc = autoinc; + source_size = size; } /** @@ -63,8 +66,10 @@ * @return - 0 on success */ template<typename Type> -int destination(Type* pointer, bool autoinc, int size = sizeof(Type) * 8) { - return setAddress((uint32_t)pointer, size, false, autoinc); +void destination(Type* pointer, bool autoinc, int size = sizeof(Type) * 8) { + _destination = (uint32_t)pointer; + destination_inc = autoinc; + destination_size = size; } /** @@ -78,7 +83,9 @@ * @param trig - trigger to use * @param return - 0 on success */ -int trigger(SimpleDMA_Trigger trig); +void trigger(SimpleDMA_Trigger trig) { + _trigger = trig; +} /** * Set the DMA channel @@ -141,36 +148,33 @@ #endif protected: -int setAddress(uint32_t address, int wordsize, bool source, bool autoinc); +int _channel; +SimpleDMA_Trigger _trigger; +uint32_t _source; +uint32_t _destination; +bool source_inc; +bool destination_inc; +uint8_t source_size; +uint8_t destination_size; -int _channel; bool auto_channel; -uint32_t SAR, DAR, DSR, DCR; -uint8_t CHCFG; //IRQ handlers FunctionPointer _callback; void irq_handler(void); -static SimpleDMA *irq_owner[4]; +static SimpleDMA *irq_owner[DMA_CHANNELS]; + +static void irq_handler0( void ); -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(); -} +#if DMA_IRQS > 1 +static void irq_handler1( void ); +static void irq_handler2( void ); +static void irq_handler3( void ); +#endif +//Keep searching until we find a non-busy channel, start with lowest channel number +int getFreeChannel(void); #ifdef RTOS_H osThreadId id; @@ -178,17 +182,5 @@ osSignalSet(id, 0x1); } #endif - -//Keep searching until we find a non-busy channel, start with lowest channel number -int getFreeChannel(void) { - int retval = 0; - while(1) { - if (!isBusy(retval)) - return retval; - retval++; - if (retval >= DMA_CHANNELS) - retval = 0; - } -} }; #endif \ No newline at end of file