updated serial system

This commit is contained in:
IMback
2018-11-14 11:29:12 +01:00
parent 18dc36e928
commit b72ec4ba8a
3 changed files with 42 additions and 28 deletions

View File

@ -1,19 +1,19 @@
#include "serial.h"
#include "ringbuffer.h"
RingBuffer<SERIAL_BUFFER_SIZE> rxBuffer;
volatile RingBuffer<SERIAL_BUFFER_SIZE, volatile uint8_t> rxBuffer;
bool stopped = false;
ISR (USART_RX_vect) //I have seen worse interrupt sintax
ISR(USART_RX_vect) //I have seen worse interrupt sintax
{
rxBuffer.write(UDR0);
if(serialFlowControl && !stopped && rxBuffer.isOverun(32))
{
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = 0x13;
stopped = true;
}
if(serialFlowControl && !stopped && rxBuffer.remainingCapacity() < 32)
{
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = 0x13;
stopped = true;
}
}
Serial::Serial()
@ -23,6 +23,7 @@ Serial::Serial()
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
UCSR0B = _BV(RXEN0) | _BV(TXEN0); //Enable RX and TX
UCSR0B |= (1 << RXCIE0); //Enable Rx interuppt
sei();
}
void Serial::putChar(const char c)
@ -98,7 +99,7 @@ char Serial::getChar()
{
if(!rxBuffer.isEmpty())
{
if(serialFlowControl && stopped && !rxBuffer.isOverun(32))
if(serialFlowControl && stopped && rxBuffer.remainingCapacity() > 32 )
{
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = 0x11;
@ -111,7 +112,7 @@ char Serial::getChar()
unsigned int Serial::getString(char* buffer, const int bufferLength)
{
return rxBuffer.getString(_terminator, buffer, bufferLength);
return rxBuffer.getString(_terminator, (uint8_t*)buffer, bufferLength);
}
unsigned int Serial::read(char* buffer, const unsigned int length )