Could there be something like an ISR template function?

Ah, that case was actually easy to find. DMAChannel.cpp, lines 17...23:
Code:
if (++ch >= DMA_NUM_CHANNELS) {
  __enable_irq();
  TCD = (TCD_t *)0;
  channel = 16;
  return; // no more channels available
  // attempts to use this object will hardfault
}
So the only way of reporting this before getting a hardfault is to check for channel < 16 in any routine that allocates a DMA channel. The DMAChannel class could provide an allocated() (or similarly named) method for that, in case people don't want to go into the chip details. Why:

The hardcoded 16 should be defined in the kinetis header because the next teensy might have even more channels, and the Teensy 3.0 has only 4.
 
Yup, you'll get a memory fault when trying to write and of the settings. Of course, that only happens if all 16 channels are already in use.

I could be talked into adding (or accepting a pull request for) a bool operator, similar to how "while(!Serial)" tells you if the Arduino Serial Monitor has opened. By really, what are you going to do if it's false?
 
By really, what are you going to do if it's false?
In case a someDriver.begin() tries to allocate a channel that can't be allocated and then fails by returning false, I can emit a message over Serial (or some other method) that points to a possible cause for the problem. A hardfault is less comfortable to debug.
 
Yup, you'll get a memory fault when trying to write and of the settings. Of course, that only happens if all 16 channels are already in use.

I could be talked into adding (or accepting a pull request for) a bool operator, similar to how "while(!Serial)" tells you if the Arduino Serial Monitor has opened. By really, what are you going to do if it's false?

Do something else perhaps?

In the I2C I'm approaching it this way, is there a simpler method of detecting allocation fail?
Code:
        if(opMode == I2C_OP_MODE_DMA)
        {
            // attempt to get a DMA Channel
            i2c->DMA = new DMAChannel();
            // check if object created but no available channel
            if(i2c->DMA != nullptr && i2c->DMA->channel == DMA_NUM_CHANNELS)
            {
                // revert to ISR mode if no DMA channels avail
                delete i2c->DMA;
                i2c->opMode = I2C_OP_MODE_ISR;
            }
            ...
            ...
 
is there a simple example of how to use the DMAchannel library?
I really want to try adding DMA in my screen driver, but I need a simple example of where to start.

I have been looking at the Ornament and Crime module code on github:
https://github.com/mxmxmx/O_C/tree/master/software/o_c_REV/src/drivers
he does a great job of using it, and he helped me a fair bit, I
just wanted to have something stripped down and simple to know how to configure and use the DMA channel on SPI to do transfers

maybe someone has already done this? SSD1306 & teensy 3.1, Ive got a few library variations of the adafruit code with DMA,
but if I recall they don't allow other use of the SPI port/library.
 
Been getting my hands dirty configuring DMA for USART and I2C on ST Micro (STM32F3 in this case) and I have to say, I really wish ST would adopt a DMAMUX approach similar to Kinetis. STM has fixed mappings between peripherals and DMA channels (with one or two alternates) and the mapping varies from part to part. Reading through Paul's code for the Teensy DMAChannel where you can simply pick an available channel for any peripheral with DMA support makes me wonder what other cruelties STM is inflicting upon developers that could be avoided by switching to Kinetis.
 
Back
Top