An I/O controller for virtual pinball machines: accelerometer nudge sensing, analog plunger input, button input encoding, LedWiz compatible output controls, and more.

Dependencies:   mbed FastIO FastPWM USBDevice

Fork of Pinscape_Controller by Mike R

Embed: (wiki syntax)

« Back to documentation index

SimpleDMA Class Reference

SimpleDMA Class Reference

SimpleDMA, DMA made simple! (Okay that was bad) More...

#include <SimpleDMA.h>

Public Member Functions

 SimpleDMA (int channel=-1)
 Constructor.
template<typename Type >
void source (Type *pointer, bool autoinc, int size=sizeof(Type)*8)
 Set the source of the DMA transfer.
template<typename Type >
void destination (Type *pointer, bool autoinc, int size=sizeof(Type)*8)
 Set the destination of the DMA transfer.
void trigger (SimpleDMA_Trigger trig)
 Set the trigger for the DMA operation.
void channel (int chan)
 Set the DMA channel.
int start (uint32_t length, bool wait)
 Start the transfer.
volatile uint8_t * prepare (uint32_t length, bool wait)
 Prepare a transfer.
bool isBusy (int channel=-1)
 Is the DMA channel busy.
uint32_t remaining (int channel=-1)
 Number of bytes remaining in running transfer.
void attach (void(*function)(void))
 Attach an interrupt upon completion of DMA transfer or error.
void link (SimpleDMA &dest, bool all=false)
 Link to another channel.
void link (SimpleDMA &dest1, SimpleDMA &dest2)
 Link to two other channels.
void wait (int length)
 Start a DMA transfer similar to start, however block current Thread until the transfer is finished.

Detailed Description

SimpleDMA, DMA made simple! (Okay that was bad)

A class to easily make basic DMA operations happen. Not all features of the DMA peripherals are used, but the main ones are: From and to memory and peripherals, either continiously or triggered

Definition at line 21 of file SimpleDMA.h.


Constructor & Destructor Documentation

SimpleDMA ( int  channel = -1 )

Constructor.

Parameters:
channel- optional parameter which channel should be used, default is automatic channel selection

Definition at line 47 of file SimpleDMA_KL25_46.cpp.


Member Function Documentation

void attach ( void(*)(void)  function )

Attach an interrupt upon completion of DMA transfer or error.

Parameters:
function- function to call upon completion (may be a member function)

Definition at line 139 of file SimpleDMA.h.

void channel ( int  chan )

Set the DMA channel.

Generally you will not need to call this function, the constructor does so for you

Parameters:
chan- DMA channel to use, -1 = variable channel (highest priority channel which is available)

Definition at line 3 of file SimpleDMA_common.cpp.

void destination ( Type *  pointer,
bool  autoinc,
int  size = sizeof(Type) * 8 
)

Set the destination of the DMA transfer.

Autoincrement increments the pointer after each transfer. If the source is an array this should be true, if it is a peripheral or a single memory location it should be false.

The destination can be any pointer to any memory location. Automatically the wordsize is calculated depending on the type, if required you can also override this.

Parameters:
pointer- pointer to the memory location
autoinc- should the pointer be incremented by the DMA module
size- wordsize in bits (optional, generally can be omitted)
Returns:
- 0 on success

Definition at line 70 of file SimpleDMA.h.

bool isBusy ( int  channel = -1 )

Is the DMA channel busy.

Parameters:
channel- channel to check, -1 = current channel
Returns:
- true if it is busy

Definition at line 166 of file SimpleDMA_KL25_46.cpp.

void link ( SimpleDMA dest1,
SimpleDMA dest2 
)

Link to two other channels.

This triggers the 'dest1' channel once for each transfer on this channel, and then triggers the 'dest2' channel once when the entire transfer has been completed (i.e., the byte count register on this channel reaches zero).

Definition at line 158 of file SimpleDMA_KL25_46.cpp.

void link ( SimpleDMA dest,
bool  all = false 
)

Link to another channel.

This triggers the given destination channel when a transfer on this channel is completed. If 'all' is true, the link occurs after the entire transfer is complete (i.e., the byte count register in this channel reaches zero). Otherwise, the link is triggered once for each transfer on this channel.

Definition at line 151 of file SimpleDMA_KL25_46.cpp.

volatile uint8_t * prepare ( uint32_t  length,
bool  wait 
)

Prepare a transfer.

This sets everything up for a transfer, but leaves it up to the caller to trigger the start of the transfer. This gives the caller precise control over the timing of the transfer, for transfers that must be synchronized with other functions. To start the DMA transfer, the caller must simply "OR" DMAMUX_CHCFG_ENBL_MASK into the byte at the returned address.

Definition at line 84 of file SimpleDMA_KL25_46.cpp.

uint32_t remaining ( int  channel = -1 )

Number of bytes remaining in running transfer.

This reads the controller register with the remaining byte count, which the hardware updates each time it completes a destination transfer.

Definition at line 178 of file SimpleDMA_KL25_46.cpp.

void source ( Type *  pointer,
bool  autoinc,
int  size = sizeof(Type) * 8 
)

Set the source of the DMA transfer.

Autoincrement increments the pointer after each transfer. If the source is an array this should be true, if it is a peripheral or a single memory location it should be false.

The source can be any pointer to any memory location. Automatically the wordsize is calculated depending on the type, if required you can also override this.

Parameters:
pointer- pointer to the memory location
autoinc- should the pointer be incremented by the DMA module
size- wordsize in bits (optional, generally can be omitted)
Returns:
- 0 on success

Definition at line 47 of file SimpleDMA.h.

int start ( uint32_t  length,
bool  wait 
)

Start the transfer.

Parameters:
length- number of BYTES to be moved by the DMA

Definition at line 67 of file SimpleDMA_KL25_46.cpp.

void trigger ( SimpleDMA_Trigger  trig )

Set the trigger for the DMA operation.

In SimpleDMA_[yourdevice].h you can find the names of the different triggers. Trigger_ALWAYS is defined for all devices, it will simply move the data as fast as possible. Used for memory-memory transfers. If nothing else is set that will be used by default.

Parameters:
trig- trigger to use
return- 0 on success

Definition at line 88 of file SimpleDMA.h.

void wait ( int  length )

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.

Parameters:
length- number of BYTES to be moved by the DMA

Definition at line 181 of file SimpleDMA.h.