diff --git a/usart.cpp b/usart.cpp index 9711f5a..016ead4 100644 --- a/usart.cpp +++ b/usart.cpp @@ -369,6 +369,39 @@ bool USART0::receiveByte( uint8_t &ui8Data, uint16_t ui16TimeoutMS ) return true; } +////////////////////////////////////////////////////////////////////////// +uint8_t USART0::receiveByteBlocked() +{ + uint8_t ui8Received; + while( !receiveByte( ui8Received ) ); + return ui8Received; +} + +////////////////////////////////////////////////////////////////////////// +uint8_t USART0::receivePeek() +{ + uint8_t ui8Received; + + if( !( SREG & ( 1 << SREG_I ) && m_vsizeRXBufferHead == m_vsizeRXBufferTail ) ) + { + while( !( *m_vui8pUCSRA & ( 1 << RXC_D ) ) ); + ui8Received = *m_vui8pUDR; + + size_t sizeIndex = ( m_vsizeRXBufferHead + 1 ) % sm_sizeRXBUFFER_SIZE; + + if( sizeIndex != m_vsizeRXBufferTail ) + { + m_vui8aRXBuffer[m_vsizeRXBufferHead] = ui8Received; + m_vsizeRXBufferHead = sizeIndex; + } + + return ui8Received; + } + + while( m_vsizeRXBufferHead == m_vsizeRXBufferTail ); + return m_vui8aRXBuffer[m_vsizeRXBufferTail]; +} + ////////////////////////////////////////////////////////////////////////// bool USART0::receiveLine( char *szBuffer, size_t sizeBufferLength, const char *szLineTerminator /* = "\r\n" */ ) { diff --git a/usart.h b/usart.h index dfa6f31..61ed803 100644 --- a/usart.h +++ b/usart.h @@ -1,7 +1,7 @@ /* * Copyright (c) by BlackMark 2015-2016 -* Date 25/05/2016 -* Version 3.2 +* Date 26/05/2016 +* Version 3.3 */ #ifndef USART_H @@ -144,6 +144,8 @@ public: bool receiveByte( uint8_t &ui8Data ); bool receiveByte( uint8_t &ui8Data, uint16_t ui16TimeoutMS ); + uint8_t receiveByteBlocked(); + uint8_t receivePeek(); bool receiveLine( char *szBuffer, size_t sizeBufferLength, const char *szLineTerminator = "\r\n" ); bool receiveLine( char *szBuffer, size_t sizeBufferLength, uint16_t ui16TimeoutMS, const char *szLineTerminator = "\r\n" ); void flushReceive();