RingBufferDMA.h
/* Teensy 4, 3.x, LC ADC library
* https://github.com/pedvide/ADC
* Copyright (c) 2019 Pedro Villanueva
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef RINGBUFFERDMA_H
#define RINGBUFFERDMA_H
#include <Arduino.h> // for digitalWrite
#include "DMAChannel.h"
class RingBufferDMA
{
public:
RingBufferDMA(volatile int16_t* elems, uint32_t len, uint8_t ADC_num = 0);
~RingBufferDMA();
bool isFull();
bool isEmpty();
int16_t read();
void start(void (*call_dma_isr)(void));
void write();
uint16_t size() {return b_size; }
volatile int16_t* const buffer() {return p_elems;}
DMAChannel* dmaChannel;
// the buffer needs to be aligned, so use malloc instead of new
// see http://stackoverflow.com/questions/227897/solve-the-memory-alignment-in-c-interview-question-that-stumped-me/
//uint8_t alignment;
//void *p_mem;
uint16_t b_start;
uint16_t b_end;
volatile int16_t* const p_elems;
protected:
private:
uint16_t b_size;
uint8_t ADC_number;
uint16_t increase(uint16_t p);
volatile uint32_t* const ADC_RA;
};
#endif // RINGBUFFERDMA_H
RingBufferDMA::b_end
uint16_t b_end
End pointer: Write here.
Definition: RingBufferDMA.h:79
RingBufferDMA::write
void write()
Write a value into the buffer.
RingBufferDMA::isFull
bool isFull()
Returns true if the buffer is full.
RingBufferDMA::b_start
uint16_t b_start
Start pointer: Read here.
Definition: RingBufferDMA.h:77
RingBufferDMA::size
uint16_t size()
Length of the buffer.
Definition: RingBufferDMA.h:62
RingBufferDMA::RingBufferDMA
RingBufferDMA(volatile int16_t *elems, uint32_t len, uint8_t ADC_num=0)
Constructor, buffer has a size len and stores the conversions of ADC number ADC_num.
RingBufferDMA::start
void start(void(*call_dma_isr)(void))
Start DMA operation.
RingBufferDMA::~RingBufferDMA
~RingBufferDMA()
Destructor.
RingBufferDMA::p_elems
volatile int16_t *const p_elems
Pointer to the elements of the buffer.
Definition: RingBufferDMA.h:82
RingBufferDMA::dmaChannel
DMAChannel * dmaChannel
DMAChannel to handle all low level DMA code.
Definition: RingBufferDMA.h:68
RingBufferDMA::buffer
volatile int16_t *const buffer()
Pointer to the data.
Definition: RingBufferDMA.h:65
RingBufferDMA
Definition: RingBufferDMA.h:35
RingBufferDMA::isEmpty
bool isEmpty()
Returns true if the buffer is empty.
RingBufferDMA::read
int16_t read()
Read a value from the buffer, make sure it's not emtpy by calling isEmpty() first.