Browse Source

Add DMAChannel begin()

teensy4-core
PaulStoffregen 10 years ago
parent
commit
a15be57b1d
2 changed files with 13 additions and 5 deletions
  1. +9
    -1
      teensy3/DMAChannel.cpp
  2. +4
    -4
      teensy3/DMAChannel.h

+ 9
- 1
teensy3/DMAChannel.cpp View File

// so C-only code can reserve DMA channels // so C-only code can reserve DMA channels
uint16_t dma_channel_allocated_mask = 0; uint16_t dma_channel_allocated_mask = 0;


void DMAChannel::init(void)
void DMAChannel::begin(void)
{ {
uint32_t ch = 0; uint32_t ch = 0;

__disable_irq(); __disable_irq();
if (TCD && ch < DMA_NUM_CHANNELS
&& (dma_channel_allocated_mask & (1 << ch))
&& (uint32_t)TCD == (0x40009000 + ch * 32)) {
// DMA channel already allocated
__enable_irq();
return;
}
while (1) { while (1) {
if (!(dma_channel_allocated_mask & (1 << ch))) { if (!(dma_channel_allocated_mask & (1 << ch))) {
dma_channel_allocated_mask |= (1 << ch); dma_channel_allocated_mask |= (1 << ch);

+ 4
- 4
teensy3/DMAChannel.h View File

// https://github.com/pixelmatix/SmartMatrix // https://github.com/pixelmatix/SmartMatrix
// https://github.com/crteensy/DmaSpi // https://github.com/crteensy/DmaSpi



#ifdef __cplusplus #ifdef __cplusplus


#define DMACHANNEL_HAS_BEGIN


class DMABaseClass { class DMABaseClass {
public: public:
/*************************************************/ /*************************************************/


DMAChannel() { DMAChannel() {
init();
begin();
} }
DMAChannel(const DMAChannel &c) { DMAChannel(const DMAChannel &c) {
TCD = c.TCD; TCD = c.TCD;
channel = c.channel; channel = c.channel;
} }
DMAChannel(const DMASetting &c) { DMAChannel(const DMASetting &c) {
init();
begin();
copy_tcd(TCD, c.TCD); copy_tcd(TCD, c.TCD);
} }
DMAChannel & operator = (const DMAChannel &rhs) { DMAChannel & operator = (const DMAChannel &rhs) {
~DMAChannel() { ~DMAChannel() {
release(); release();
} }
void begin(void);
private: private:
void init(void);
void release(void); void release(void);


public: public:

Loading…
Cancel
Save