1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

sam: fix code format and indent in UART/USART class

This commit is contained in:
Cristian Maglie
2014-12-29 17:27:43 +01:00
parent cabfd8ed21
commit 16d836108f
4 changed files with 94 additions and 91 deletions

View File

@ -35,8 +35,6 @@ UARTClass::UARTClass( Uart *pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer *p
// Public Methods //////////////////////////////////////////////////////////////
void UARTClass::begin( const uint32_t dwBaudRate )
{
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
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;
_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 )
{
// clear any received data
// Clear any received data
_rx_buffer->_iHead = _rx_buffer->_iTail;
// 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 )
{
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;
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->_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
{
// Send character
// Bypass buffering and send character directly
_pUart->UART_THR = uc_data;
}
return 1;
@ -169,19 +171,19 @@ void UARTClass::IrqHandler( void )
// Do we need to keep sending data?
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];
_tx_buffer->_iTail = (unsigned int)(_tx_buffer->_iTail + 1) % SERIAL_BUFFER_SIZE;
}
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
if ((status & UART_SR_OVRE) == UART_SR_OVRE ||
(status & UART_SR_FRAME) == UART_SR_FRAME)
if ((status & UART_SR_OVRE) == UART_SR_OVRE || (status & UART_SR_FRAME) == UART_SR_FRAME)
{
// TODO: error reporting outside ISR
_pUart->UART_CR |= UART_CR_RSTSTA;

View File

@ -23,10 +23,11 @@
// 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)
{
_pUsart=pUsart ; //In case anyone needs USART specific functionality in the future
// In case anyone needs USART specific functionality in the future
_pUsart=pUsart;
}
// Public Methods //////////////////////////////////////////////////////////////