mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-06 05:21:22 +03:00
improve os_printf handling when buffer full.
- wait for free buffer in hw fifo
This commit is contained in:
parent
e0f9a4173e
commit
5b5deb5a77
@ -42,12 +42,12 @@ extern "C" {
|
|||||||
#define UART_TX_FIFO_SIZE 0x80
|
#define UART_TX_FIFO_SIZE 0x80
|
||||||
|
|
||||||
struct uart_ {
|
struct uart_ {
|
||||||
int uart_nr;
|
int uart_nr;
|
||||||
int baud_rate;
|
int baud_rate;
|
||||||
bool rxEnabled;
|
bool rxEnabled;
|
||||||
bool txEnabled;
|
bool txEnabled;
|
||||||
uint8_t rxPin;
|
uint8_t rxPin;
|
||||||
uint8_t txPin;
|
uint8_t txPin;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int UART0 = 0;
|
static const int UART0 = 0;
|
||||||
@ -120,7 +120,7 @@ void ICACHE_RAM_ATTR uart_interrupt_handler(uart_t* uart) {
|
|||||||
// -------------- UART 0 --------------
|
// -------------- UART 0 --------------
|
||||||
if(Serial.isRxEnabled()) {
|
if(Serial.isRxEnabled()) {
|
||||||
while(U0IS & (1 << UIFF)) {
|
while(U0IS & (1 << UIFF)) {
|
||||||
Serial._rx_complete_irq((char)(U0F & 0xff));
|
Serial._rx_complete_irq((char) (U0F & 0xff));
|
||||||
U0IC = (1 << UIFF);
|
U0IC = (1 << UIFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ void ICACHE_RAM_ATTR uart_interrupt_handler(uart_t* uart) {
|
|||||||
|
|
||||||
if(Serial1.isRxEnabled()) {
|
if(Serial1.isRxEnabled()) {
|
||||||
while(U1IS & (1 << UIFF)) {
|
while(U1IS & (1 << UIFF)) {
|
||||||
Serial1._rx_complete_irq((char)(U1F & 0xff));
|
Serial1._rx_complete_irq((char) (U1F & 0xff));
|
||||||
U1IC = (1 << UIFF);
|
U1IC = (1 << UIFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,19 +357,19 @@ void uart_swap(uart_t* uart) {
|
|||||||
switch(uart->uart_nr) {
|
switch(uart->uart_nr) {
|
||||||
case UART0:
|
case UART0:
|
||||||
if(uart->txPin == 1 && uart->rxPin == 3) {
|
if(uart->txPin == 1 && uart->rxPin == 3) {
|
||||||
pinMode(15, FUNCTION_4);//TX
|
pinMode(15, FUNCTION_4); //TX
|
||||||
pinMode(13, FUNCTION_4);//RX
|
pinMode(13, FUNCTION_4); //RX
|
||||||
USWAP |= (1 << USWAP0);
|
USWAP |= (1 << USWAP0);
|
||||||
pinMode(1, INPUT);//TX
|
pinMode(1, INPUT); //TX
|
||||||
pinMode(3, INPUT);//RX
|
pinMode(3, INPUT); //RX
|
||||||
uart->rxPin = 13;
|
uart->rxPin = 13;
|
||||||
uart->txPin = 15;
|
uart->txPin = 15;
|
||||||
} else {
|
} else {
|
||||||
pinMode(1, SPECIAL);//TX
|
pinMode(1, SPECIAL); //TX
|
||||||
pinMode(3, SPECIAL);//RX
|
pinMode(3, SPECIAL); //RX
|
||||||
USWAP &= ~(1 << USWAP0);
|
USWAP &= ~(1 << USWAP0);
|
||||||
pinMode(15, INPUT);//TX
|
pinMode(15, INPUT); //TX
|
||||||
pinMode(13, INPUT);//RX
|
pinMode(13, INPUT); //RX
|
||||||
uart->rxPin = 3;
|
uart->rxPin = 3;
|
||||||
uart->txPin = 1;
|
uart->txPin = 1;
|
||||||
}
|
}
|
||||||
@ -400,6 +400,14 @@ void uart0_write_char(char c) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wait for the Hardware FIFO
|
||||||
|
while(true) {
|
||||||
|
if(((USS(0) >> USTXC) & 0xff) <= (UART_TX_FIFO_SIZE - 2)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(c == '\n') {
|
if(c == '\n') {
|
||||||
USF(0) = '\r';
|
USF(0) = '\r';
|
||||||
}
|
}
|
||||||
@ -416,6 +424,14 @@ void uart1_write_char(char c) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wait for the Hardware FIFO
|
||||||
|
while(true) {
|
||||||
|
if(((USS(1) >> USTXC) & 0xff) <= (UART_TX_FIFO_SIZE - 2)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(c == '\n') {
|
if(c == '\n') {
|
||||||
USF(1) = '\r';
|
USF(1) = '\r';
|
||||||
}
|
}
|
||||||
@ -469,11 +485,11 @@ void HardwareSerial::begin(unsigned long baud, byte config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(_uart->rxEnabled) {
|
if(_uart->rxEnabled) {
|
||||||
if (!_rx_buffer)
|
if(!_rx_buffer)
|
||||||
_rx_buffer = new cbuf(SERIAL_RX_BUFFER_SIZE);
|
_rx_buffer = new cbuf(SERIAL_RX_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
if(_uart->txEnabled) {
|
if(_uart->txEnabled) {
|
||||||
if (!_tx_buffer)
|
if(!_tx_buffer)
|
||||||
_tx_buffer = new cbuf(SERIAL_TX_BUFFER_SIZE);
|
_tx_buffer = new cbuf(SERIAL_TX_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
_written = false;
|
_written = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user