Added blocking receive function and peek function
This commit is contained in:
parent
7fd6d8ddec
commit
88eb11cc02
33
usart.cpp
33
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" */ )
|
||||
{
|
||||
|
6
usart.h
6
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();
|
||||
|
Loading…
Reference in New Issue
Block a user