Added blocking receive function and peek function

This commit is contained in:
BlackMark 2016-05-26 20:15:21 +02:00
parent 7fd6d8ddec
commit 88eb11cc02
2 changed files with 37 additions and 2 deletions

View File

@ -369,6 +369,39 @@ bool USART0::receiveByte( uint8_t &ui8Data, uint16_t ui16TimeoutMS )
return true; 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" */ ) bool USART0::receiveLine( char *szBuffer, size_t sizeBufferLength, const char *szLineTerminator /* = "\r\n" */ )
{ {

View File

@ -1,7 +1,7 @@
/* /*
* Copyright (c) by BlackMark 2015-2016 * Copyright (c) by BlackMark 2015-2016
* Date 25/05/2016 * Date 26/05/2016
* Version 3.2 * Version 3.3
*/ */
#ifndef USART_H #ifndef USART_H
@ -144,6 +144,8 @@ public:
bool receiveByte( uint8_t &ui8Data ); bool receiveByte( uint8_t &ui8Data );
bool receiveByte( uint8_t &ui8Data, uint16_t ui16TimeoutMS ); 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, const char *szLineTerminator = "\r\n" );
bool receiveLine( char *szBuffer, size_t sizeBufferLength, uint16_t ui16TimeoutMS, const char *szLineTerminator = "\r\n" ); bool receiveLine( char *szBuffer, size_t sizeBufferLength, uint16_t ui16TimeoutMS, const char *szLineTerminator = "\r\n" );
void flushReceive(); void flushReceive();