mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-05 13:16:13 +03:00
sam: fix code format and indent in UART/USART class
This commit is contained in:
@@ -35,8 +35,6 @@ UARTClass::UARTClass( Uart *pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer *p
|
|||||||
|
|
||||||
// Public Methods //////////////////////////////////////////////////////////////
|
// Public Methods //////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void UARTClass::begin( const uint32_t dwBaudRate )
|
void UARTClass::begin( const uint32_t dwBaudRate )
|
||||||
{
|
{
|
||||||
begin( dwBaudRate, UART_MR_PAR_NO | UART_MR_CHMODE_NORMAL );
|
begin( dwBaudRate, UART_MR_PAR_NO | UART_MR_CHMODE_NORMAL );
|
||||||
@@ -66,7 +64,7 @@ void UARTClass::begin( const uint32_t dwBaudRate, const uint32_t config )
|
|||||||
// Enable UART interrupt in NVIC
|
// Enable UART interrupt in NVIC
|
||||||
NVIC_EnableIRQ(_dwIrq);
|
NVIC_EnableIRQ(_dwIrq);
|
||||||
|
|
||||||
//make sure both ring buffers are initialized back to empty.
|
// Make sure both ring buffers are initialized back to empty.
|
||||||
_rx_buffer->_iHead = _rx_buffer->_iTail = 0;
|
_rx_buffer->_iHead = _rx_buffer->_iTail = 0;
|
||||||
_tx_buffer->_iHead = _tx_buffer->_iTail = 0;
|
_tx_buffer->_iHead = _tx_buffer->_iTail = 0;
|
||||||
|
|
||||||
@@ -76,7 +74,7 @@ void UARTClass::begin( const uint32_t dwBaudRate, const uint32_t config )
|
|||||||
|
|
||||||
void UARTClass::end( void )
|
void UARTClass::end( void )
|
||||||
{
|
{
|
||||||
// clear any received data
|
// Clear any received data
|
||||||
_rx_buffer->_iHead = _rx_buffer->_iTail;
|
_rx_buffer->_iHead = _rx_buffer->_iTail;
|
||||||
|
|
||||||
// Wait for any outstanding data to be sent
|
// Wait for any outstanding data to be sent
|
||||||
@@ -140,19 +138,23 @@ void UARTClass::flush( void )
|
|||||||
|
|
||||||
size_t UARTClass::write( const uint8_t uc_data )
|
size_t UARTClass::write( const uint8_t uc_data )
|
||||||
{
|
{
|
||||||
if (((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) | (_tx_buffer->_iTail != _tx_buffer->_iHead)) //is the hardware currently busy?
|
// Is the hardware currently busy?
|
||||||
|
if (((_pUart->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY) |
|
||||||
|
(_tx_buffer->_iTail != _tx_buffer->_iHead))
|
||||||
{
|
{
|
||||||
//if busy we buffer
|
// If busy we buffer
|
||||||
unsigned int l = (_tx_buffer->_iHead + 1) % SERIAL_BUFFER_SIZE;
|
unsigned int l = (_tx_buffer->_iHead + 1) % SERIAL_BUFFER_SIZE;
|
||||||
while (_tx_buffer->_iTail == l); //spin locks if we're about to overwrite the buffer. This continues once the data is sent
|
while (_tx_buffer->_iTail == l)
|
||||||
|
; // Spin locks if we're about to overwrite the buffer. This continues once the data is sent
|
||||||
|
|
||||||
_tx_buffer->_aucBuffer[_tx_buffer->_iHead] = uc_data;
|
_tx_buffer->_aucBuffer[_tx_buffer->_iHead] = uc_data;
|
||||||
_tx_buffer->_iHead = l;
|
_tx_buffer->_iHead = l;
|
||||||
_pUart->UART_IER = UART_IER_TXRDY; //make sure TX interrupt is enabled
|
// Make sure TX interrupt is enabled
|
||||||
|
_pUart->UART_IER = UART_IER_TXRDY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Send character
|
// Bypass buffering and send character directly
|
||||||
_pUart->UART_THR = uc_data;
|
_pUart->UART_THR = uc_data;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@@ -169,19 +171,19 @@ void UARTClass::IrqHandler( void )
|
|||||||
// Do we need to keep sending data?
|
// Do we need to keep sending data?
|
||||||
if ((status & UART_SR_TXRDY) == UART_SR_TXRDY)
|
if ((status & UART_SR_TXRDY) == UART_SR_TXRDY)
|
||||||
{
|
{
|
||||||
if (_tx_buffer->_iTail != _tx_buffer->_iHead) { //just in case
|
if (_tx_buffer->_iTail != _tx_buffer->_iHead) {
|
||||||
_pUart->UART_THR = _tx_buffer->_aucBuffer[_tx_buffer->_iTail];
|
_pUart->UART_THR = _tx_buffer->_aucBuffer[_tx_buffer->_iTail];
|
||||||
_tx_buffer->_iTail = (unsigned int)(_tx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE;
|
_tx_buffer->_iTail = (unsigned int)(_tx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_pUart->UART_IDR = UART_IDR_TXRDY; //mask off transmit interrupt so we don't get it anymore
|
// Mask off transmit interrupt so we don't get it anymore
|
||||||
|
_pUart->UART_IDR = UART_IDR_TXRDY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Acknowledge errors
|
// Acknowledge errors
|
||||||
if ((status & UART_SR_OVRE) == UART_SR_OVRE ||
|
if ((status & UART_SR_OVRE) == UART_SR_OVRE || (status & UART_SR_FRAME) == UART_SR_FRAME)
|
||||||
(status & UART_SR_FRAME) == UART_SR_FRAME)
|
|
||||||
{
|
{
|
||||||
// TODO: error reporting outside ISR
|
// TODO: error reporting outside ISR
|
||||||
_pUart->UART_CR |= UART_CR_RSTSTA;
|
_pUart->UART_CR |= UART_CR_RSTSTA;
|
||||||
|
@@ -23,10 +23,11 @@
|
|||||||
|
|
||||||
// Constructors ////////////////////////////////////////////////////////////////
|
// Constructors ////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
USARTClass::USARTClass( Usart* pUsart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer, RingBuffer* pTx_buffer ) : UARTClass((Uart*)pUsart, dwIrq, dwId, pRx_buffer, pTx_buffer)
|
USARTClass::USARTClass( Usart* pUsart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* pRx_buffer, RingBuffer* pTx_buffer )
|
||||||
|
: UARTClass((Uart*)pUsart, dwIrq, dwId, pRx_buffer, pTx_buffer)
|
||||||
{
|
{
|
||||||
|
// In case anyone needs USART specific functionality in the future
|
||||||
_pUsart=pUsart ; //In case anyone needs USART specific functionality in the future
|
_pUsart=pUsart;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public Methods //////////////////////////////////////////////////////////////
|
// Public Methods //////////////////////////////////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user