A simple library to access the DMA functionality.
Fork of SimpleDMA by
SimpleDMA.h@0:d77ea45fa625, 2013-10-18 (annotated)
- Committer:
- Sissors
- Date:
- Fri Oct 18 07:44:42 2013 +0000
- Revision:
- 0:d77ea45fa625
- Child:
- 1:0b73b00bcee8
v0.1, KL25, no interrupt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 0:d77ea45fa625 | 1 | #ifndef SIMPLEDMA_H |
Sissors | 0:d77ea45fa625 | 2 | #define SIMPLEDMA_H |
Sissors | 0:d77ea45fa625 | 3 | |
Sissors | 0:d77ea45fa625 | 4 | #include "mbed.h" |
Sissors | 0:d77ea45fa625 | 5 | #include "SimpleDMA_KL25.h" |
Sissors | 0:d77ea45fa625 | 6 | |
Sissors | 0:d77ea45fa625 | 7 | |
Sissors | 0:d77ea45fa625 | 8 | /** |
Sissors | 0:d77ea45fa625 | 9 | * SimpleDMA, DMA made simple! (Okay that was bad) |
Sissors | 0:d77ea45fa625 | 10 | * |
Sissors | 0:d77ea45fa625 | 11 | * A class to easily make basic DMA operations happen. Not all features |
Sissors | 0:d77ea45fa625 | 12 | * of the DMA peripherals are used, but the main ones are: From and to memory |
Sissors | 0:d77ea45fa625 | 13 | * and peripherals, either continiously or triggered |
Sissors | 0:d77ea45fa625 | 14 | */ |
Sissors | 0:d77ea45fa625 | 15 | class SimpleDMA { |
Sissors | 0:d77ea45fa625 | 16 | public: |
Sissors | 0:d77ea45fa625 | 17 | SimpleDMA(int channel = 0); |
Sissors | 0:d77ea45fa625 | 18 | |
Sissors | 0:d77ea45fa625 | 19 | /** |
Sissors | 0:d77ea45fa625 | 20 | * Set the source of the DMA transfer |
Sissors | 0:d77ea45fa625 | 21 | * |
Sissors | 0:d77ea45fa625 | 22 | * Autoincrement increments the pointer after each transfer. If the source |
Sissors | 0:d77ea45fa625 | 23 | * is an array this should be true, if it is a peripheral or a single memory |
Sissors | 0:d77ea45fa625 | 24 | * location it should be false. |
Sissors | 0:d77ea45fa625 | 25 | * |
Sissors | 0:d77ea45fa625 | 26 | * The source can be any pointer to any memory location. Automatically |
Sissors | 0:d77ea45fa625 | 27 | * the wordsize is calculated depending on the type, if required you can |
Sissors | 0:d77ea45fa625 | 28 | * also override this. |
Sissors | 0:d77ea45fa625 | 29 | * |
Sissors | 0:d77ea45fa625 | 30 | * @param pointer - pointer to the memory location |
Sissors | 0:d77ea45fa625 | 31 | * @param autoinc - should the pointer be incremented by the DMA module |
Sissors | 0:d77ea45fa625 | 32 | * @param size - size of the transfer (optional, generally can be omitted) |
Sissors | 0:d77ea45fa625 | 33 | * @return - 0 on success |
Sissors | 0:d77ea45fa625 | 34 | */ |
Sissors | 0:d77ea45fa625 | 35 | template<typename Type> |
Sissors | 0:d77ea45fa625 | 36 | int source(Type* pointer, bool autoinc, int size = sizeof(Type*)) { |
Sissors | 0:d77ea45fa625 | 37 | return setMemory((uint32_t)pointer, size, true, autoinc); |
Sissors | 0:d77ea45fa625 | 38 | } |
Sissors | 0:d77ea45fa625 | 39 | |
Sissors | 0:d77ea45fa625 | 40 | /** |
Sissors | 0:d77ea45fa625 | 41 | * Set the destination of the DMA transfer |
Sissors | 0:d77ea45fa625 | 42 | * |
Sissors | 0:d77ea45fa625 | 43 | * Autoincrement increments the pointer after each transfer. If the source |
Sissors | 0:d77ea45fa625 | 44 | * is an array this should be true, if it is a peripheral or a single memory |
Sissors | 0:d77ea45fa625 | 45 | * location it should be false. |
Sissors | 0:d77ea45fa625 | 46 | * |
Sissors | 0:d77ea45fa625 | 47 | * The destination can be any pointer to any memory location. Automatically |
Sissors | 0:d77ea45fa625 | 48 | * the wordsize is calculated depending on the type, if required you can |
Sissors | 0:d77ea45fa625 | 49 | * also override this. |
Sissors | 0:d77ea45fa625 | 50 | * |
Sissors | 0:d77ea45fa625 | 51 | * @param pointer - pointer to the memory location |
Sissors | 0:d77ea45fa625 | 52 | * @param autoinc - should the pointer be incremented by the DMA module |
Sissors | 0:d77ea45fa625 | 53 | * @param size - size of the transfer (optional, generally can be omitted) |
Sissors | 0:d77ea45fa625 | 54 | * @return - 0 on success |
Sissors | 0:d77ea45fa625 | 55 | */ |
Sissors | 0:d77ea45fa625 | 56 | template<typename Type> |
Sissors | 0:d77ea45fa625 | 57 | int destination(Type* pointer, bool autoinc, int size = sizeof(Type*)) { |
Sissors | 0:d77ea45fa625 | 58 | return setMemory((uint32_t)pointer, size, false, autoinc); |
Sissors | 0:d77ea45fa625 | 59 | } |
Sissors | 0:d77ea45fa625 | 60 | |
Sissors | 0:d77ea45fa625 | 61 | /** |
Sissors | 0:d77ea45fa625 | 62 | * Set the trigger for the DMA operation |
Sissors | 0:d77ea45fa625 | 63 | * |
Sissors | 0:d77ea45fa625 | 64 | * In SimpleDMA_[yourdevice].h you can find the names of the different triggers. |
Sissors | 0:d77ea45fa625 | 65 | * Trigger_ALWAYS is defined for all devices, it will simply move the data |
Sissors | 0:d77ea45fa625 | 66 | * as fast as possible. Used for memory-memory transfers. If nothing else is set |
Sissors | 0:d77ea45fa625 | 67 | * that will be used by default. |
Sissors | 0:d77ea45fa625 | 68 | * |
Sissors | 0:d77ea45fa625 | 69 | * @param trig - trigger to use |
Sissors | 0:d77ea45fa625 | 70 | * @param return - 0 on success |
Sissors | 0:d77ea45fa625 | 71 | */ |
Sissors | 0:d77ea45fa625 | 72 | int trigger(SimpleDMA_Trigger trig); |
Sissors | 0:d77ea45fa625 | 73 | |
Sissors | 0:d77ea45fa625 | 74 | /** |
Sissors | 0:d77ea45fa625 | 75 | * Start the transfer |
Sissors | 0:d77ea45fa625 | 76 | * |
Sissors | 0:d77ea45fa625 | 77 | * @param length - number of BYTES to be moved by the DMA |
Sissors | 0:d77ea45fa625 | 78 | */ |
Sissors | 0:d77ea45fa625 | 79 | int start(int length); |
Sissors | 0:d77ea45fa625 | 80 | |
Sissors | 0:d77ea45fa625 | 81 | /** |
Sissors | 0:d77ea45fa625 | 82 | * Set the DMA channel |
Sissors | 0:d77ea45fa625 | 83 | * |
Sissors | 0:d77ea45fa625 | 84 | * @param chan - DMA channel to use |
Sissors | 0:d77ea45fa625 | 85 | */ |
Sissors | 0:d77ea45fa625 | 86 | void channel(int chan); |
Sissors | 0:d77ea45fa625 | 87 | |
Sissors | 0:d77ea45fa625 | 88 | /** |
Sissors | 0:d77ea45fa625 | 89 | * Is the DMA channel busy |
Sissors | 0:d77ea45fa625 | 90 | * |
Sissors | 0:d77ea45fa625 | 91 | * @return - true if it is busy |
Sissors | 0:d77ea45fa625 | 92 | */ |
Sissors | 0:d77ea45fa625 | 93 | bool isBusy( void ); |
Sissors | 0:d77ea45fa625 | 94 | |
Sissors | 0:d77ea45fa625 | 95 | |
Sissors | 0:d77ea45fa625 | 96 | |
Sissors | 0:d77ea45fa625 | 97 | |
Sissors | 0:d77ea45fa625 | 98 | |
Sissors | 0:d77ea45fa625 | 99 | protected: |
Sissors | 0:d77ea45fa625 | 100 | int setMemory(uint32_t address, int wordsize, bool source, bool autoinc); |
Sissors | 0:d77ea45fa625 | 101 | int _channel; |
Sissors | 0:d77ea45fa625 | 102 | |
Sissors | 0:d77ea45fa625 | 103 | |
Sissors | 0:d77ea45fa625 | 104 | |
Sissors | 0:d77ea45fa625 | 105 | }; |
Sissors | 0:d77ea45fa625 | 106 | #endif |