ADC  8.0
Analog to Digital Conversor library for the Teensy 3.6 microprocessor
RingBufferDMA.h
1 /* Teensy 4, 3.x, LC ADC library
2  * https://github.com/pedvide/ADC
3  * Copyright (c) 2019 Pedro Villanueva
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #ifndef RINGBUFFERDMA_H
27 #define RINGBUFFERDMA_H
28 
29 #include <Arduino.h> // for digitalWrite
30 #include "DMAChannel.h"
31 
32 
36 {
37  public:
39  RingBufferDMA(volatile int16_t* elems, uint32_t len, uint8_t ADC_num = 0);
40 
43 
45  bool isFull();
46 
48  bool isEmpty();
49 
51  int16_t read();
52 
54  void start(void (*call_dma_isr)(void));
55 
57 
59  void write();
60 
62  uint16_t size() {return b_size; }
63 
65  volatile int16_t* const buffer() {return p_elems;}
66 
68  DMAChannel* dmaChannel;
69 
70 
71  // the buffer needs to be aligned, so use malloc instead of new
72  // see http://stackoverflow.com/questions/227897/solve-the-memory-alignment-in-c-interview-question-that-stumped-me/
73  //uint8_t alignment;
74  //void *p_mem;
75 
77  uint16_t b_start;
79  uint16_t b_end;
80 
82  volatile int16_t* const p_elems;
83 
84  protected:
85  private:
86 
87 
88 
90  uint16_t b_size;
91 
93  uint8_t ADC_number;
94 
96  uint16_t increase(uint16_t p);
97 
98  volatile uint32_t* const ADC_RA;
99 
100 
101 
102 
103 };
104 
105 
106 #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.