Commit 39312f32 authored by Martin Vítek's avatar Martin Vítek

Finaly upgraded fifo class, supressed unused variables

parent 115754ef
......@@ -145,7 +145,7 @@ class adc_class
//Trash first conversion after change of reference
start_conversion();
uint16_t dummy = get();
__attribute__((__unused__)) uint16_t dummy = get();
//Enable Result Ready Interrupt
ADC->INTENSET.reg = ADC_INTENSET_RESRDY;
......
......@@ -77,7 +77,7 @@ class SPI
while (!spi.INTFLAG.bit.RXC) ;;
uint8_t dummy = spi.DATA.reg;
__attribute__((__unused__)) uint8_t dummy = spi.DATA.reg;
}
uint8_t read()
......
......@@ -25,7 +25,7 @@ class USART
private:
volatile SercomUsart& usart;
const uint32_t baudrate;
fifo<volatile uint8_t> tx_buffer;
fifo<volatile uint8_t, 500> tx_buffer;
volatile bool DRE_enabled;
public:
......
......@@ -3,53 +3,44 @@
#include <cstdint>
template <typename A_type> class fifo
template <typename A_type, int SIZE> class fifo
{
private:
enum settings
{
QUEUE_LENGHT = 500
};
//Pole a další
A_type queue[QUEUE_LENGHT];
A_type queue[SIZE];
uint16_t read_position;
uint16_t write_position;
public:
//Konstruktor, destruktor
fifo();
//Metody pro operace s polem dat
void add(A_type data);
A_type read();
uint8_t check();
};
template <typename A_type> fifo<A_type>::fifo():read_position(0),write_position(0)
template <typename A_type, int SIZE> fifo<A_type, SIZE>::fifo():read_position(0),write_position(0)
{
}
template <typename A_type> void fifo<A_type>::add(A_type data)
template <typename A_type, int SIZE> void fifo<A_type, SIZE>::add(A_type data)
{
queue[write_position++] = data;
if (write_position > QUEUE_LENGHT-1) write_position = 0;
if (write_position > SIZE-1) write_position = 0;
}
template <typename A_type> A_type fifo<A_type>::read()
template <typename A_type, int SIZE> A_type fifo<A_type, SIZE>::read()
{
A_type value = queue[read_position++];
if (read_position > QUEUE_LENGHT-1) read_position = 0;
if (read_position > SIZE-1) read_position = 0;
return value;
}
template <typename A_type> uint8_t fifo<A_type>::check()
template <typename A_type, int SIZE> uint8_t fifo<A_type, SIZE>::check()
{
if (write_position < read_position) return (QUEUE_LENGHT + write_position - read_position);
if (write_position < read_position) return (SIZE + write_position - read_position);
else return (write_position - read_position);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment