1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-04 18:03:20 +03:00

improve os_printf handling when buffer full.

- wait for free buffer in hw fifo
This commit is contained in:
Markus Sattler 2015-05-17 13:43:49 +02:00
parent e0f9a4173e
commit 5b5deb5a77

View File

@ -42,12 +42,12 @@ extern "C" {
#define UART_TX_FIFO_SIZE 0x80
struct uart_ {
int uart_nr;
int uart_nr;
int baud_rate;
bool rxEnabled;
bool txEnabled;
uint8_t rxPin;
uint8_t txPin;
uint8_t rxPin;
uint8_t txPin;
};
static const int UART0 = 0;
@ -120,7 +120,7 @@ void ICACHE_RAM_ATTR uart_interrupt_handler(uart_t* uart) {
// -------------- UART 0 --------------
if(Serial.isRxEnabled()) {
while(U0IS & (1 << UIFF)) {
Serial._rx_complete_irq((char)(U0F & 0xff));
Serial._rx_complete_irq((char) (U0F & 0xff));
U0IC = (1 << UIFF);
}
}
@ -135,7 +135,7 @@ void ICACHE_RAM_ATTR uart_interrupt_handler(uart_t* uart) {
if(Serial1.isRxEnabled()) {
while(U1IS & (1 << UIFF)) {
Serial1._rx_complete_irq((char)(U1F & 0xff));
Serial1._rx_complete_irq((char) (U1F & 0xff));
U1IC = (1 << UIFF);
}
}
@ -357,19 +357,19 @@ void uart_swap(uart_t* uart) {
switch(uart->uart_nr) {
case UART0:
if(uart->txPin == 1 && uart->rxPin == 3) {
pinMode(15, FUNCTION_4);//TX
pinMode(13, FUNCTION_4);//RX
pinMode(15, FUNCTION_4); //TX
pinMode(13, FUNCTION_4); //RX
USWAP |= (1 << USWAP0);
pinMode(1, INPUT);//TX
pinMode(3, INPUT);//RX
pinMode(1, INPUT); //TX
pinMode(3, INPUT); //RX
uart->rxPin = 13;
uart->txPin = 15;
} else {
pinMode(1, SPECIAL);//TX
pinMode(3, SPECIAL);//RX
pinMode(1, SPECIAL); //TX
pinMode(3, SPECIAL); //RX
USWAP &= ~(1 << USWAP0);
pinMode(15, INPUT);//TX
pinMode(13, INPUT);//RX
pinMode(15, INPUT); //TX
pinMode(13, INPUT); //RX
uart->rxPin = 3;
uart->txPin = 1;
}
@ -400,6 +400,14 @@ void uart0_write_char(char c) {
return;
}
}
// wait for the Hardware FIFO
while(true) {
if(((USS(0) >> USTXC) & 0xff) <= (UART_TX_FIFO_SIZE - 2)) {
break;
}
}
if(c == '\n') {
USF(0) = '\r';
}
@ -416,6 +424,14 @@ void uart1_write_char(char c) {
return;
}
}
// wait for the Hardware FIFO
while(true) {
if(((USS(1) >> USTXC) & 0xff) <= (UART_TX_FIFO_SIZE - 2)) {
break;
}
}
if(c == '\n') {
USF(1) = '\r';
}
@ -469,11 +485,11 @@ void HardwareSerial::begin(unsigned long baud, byte config) {
}
if(_uart->rxEnabled) {
if (!_rx_buffer)
if(!_rx_buffer)
_rx_buffer = new cbuf(SERIAL_RX_BUFFER_SIZE);
}
if(_uart->txEnabled) {
if (!_tx_buffer)
if(!_tx_buffer)
_tx_buffer = new cbuf(SERIAL_TX_BUFFER_SIZE);
}
_written = false;