ADC  7.0
 All Classes Functions Variables Pages
RingBufferDMA.h
1 /* Teensy 3.x, LC ADC library
2  * https://github.com/pedvide/ADC
3  * Copyright (c) 2015 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 //#include <stdlib.h> // malloc
32 
33 
38 {
39  public:
41  RingBufferDMA(volatile int16_t* elems, uint32_t len, uint8_t ADC_num = 0);
42 
45 
47  bool isFull();
48 
50  bool isEmpty();
51 
53  int16_t read();
54 
56  void start();
57 
59  void void_isr();
60 
62  DMAChannel* dmaChannel;
63 
65  volatile int16_t* const p_elems;
66 
68  uint16_t b_size;
69 
71  uint8_t ADC_number;
72 
73  // the buffer needs to be aligned, so use malloc instead of new
74  // see http://stackoverflow.com/questions/227897/solve-the-memory-alignment-in-c-interview-question-that-stumped-me/
75  //uint8_t alignment;
76  //void *p_mem;
77 
78  // this static pointer is set to point to this object and
79  // call_dma_isr calls the void_isr()
80  static RingBufferDMA *static_ringbuffer_dma;
81  static void call_dma_isr(void);
82 
83  protected:
84  private:
85 
87 
90  void write();
91 
93  uint16_t increase(uint16_t p);
94 
95  volatile uint32_t* const ADC_RA;
96 
98  uint16_t b_start;
100  uint16_t b_end;
101 
102 
103 };
104 
105 
106 #endif // RINGBUFFERDMA_H
Definition: RingBufferDMA.h:37
bool isEmpty()
Returns true if the buffer is empty.
Definition: RingBufferDMA.cpp:140
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.
Definition: RingBufferDMA.cpp:35
uint8_t ADC_number
ADC module of the instance.
Definition: RingBufferDMA.h:71
DMAChannel * dmaChannel
DMAChannel to handle all low level DMA code.
Definition: RingBufferDMA.h:62
uint16_t b_size
Size of buffer.
Definition: RingBufferDMA.h:68
bool isFull()
Returns true if the buffer is full.
Definition: RingBufferDMA.cpp:136
void void_isr()
This function will be called when a DMA transfer finishes.
Definition: RingBufferDMA.cpp:129
~RingBufferDMA()
Destructor.
Definition: RingBufferDMA.cpp:122
volatile int16_t *const p_elems
Pointer to the elements of the buffer.
Definition: RingBufferDMA.h:65
void start()
Start DMA operation.
Definition: RingBufferDMA.cpp:71
int16_t read()
Read a value from the buffer, make sure it&#39;s not emtpy by calling isEmpty() first.
Definition: RingBufferDMA.cpp:155