Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify UART Class to Use the txBuffer #303

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions cores/arduino/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ void UART::WrapperCallback(uart_callback_args_t *p_args) {
case UART_EVENT_TX_COMPLETE:
case UART_EVENT_TX_DATA_EMPTY:
{
//uint8_t to_enqueue = uart_ptr->txBuffer.available() < uart_ptr->uart_ctrl.fifo_depth ? uart_ptr->txBuffer.available() : uart_ptr->uart_ctrl.fifo_depth;
//while (to_enqueue) {
uart_ptr->tx_done = true;
if(uart_ptr->txBuffer.available()){
static char txc;
txc = uart_ptr->txBuffer.read_char();
R_SCI_UART_Write(&(uart_ptr->uart_ctrl), (uint8_t*)&txc , 1);
} else {
uart_ptr->tx_done = true;
}
break;
}
case UART_EVENT_RX_CHAR:
Expand Down Expand Up @@ -108,27 +112,31 @@ bool UART::setUpUartIrqs(uart_cfg_t &cfg) {
/* -------------------------------------------------------------------------- */
size_t UART::write(uint8_t c) {
/* -------------------------------------------------------------------------- */
if(init_ok) {
tx_done = false;
R_SCI_UART_Write(&uart_ctrl, &c, 1);
while (!tx_done) {}
return 1;
}
else {
return 0;
}
if(init_ok) {
while(txBuffer.isFull()){;}
txBuffer.store_char(c);
if(tx_done){
tx_done = false;
txc = txBuffer.read_char(); // clear out the char we just added and send it to start transmission.
R_SCI_UART_Write(&uart_ctrl, (uint8_t*)&txc , 1);
}
return 1;
}
else {
return 0;
}
}

size_t UART::write(uint8_t* c, size_t len) {
if(init_ok) {
tx_done = false;
R_SCI_UART_Write(&uart_ctrl, c, len);
while (!tx_done) {}
return len;
}
else {
return 0;
}
if(init_ok) {
for(int i = 0; i<len; i++){
write(c[i]);
}
return len;
}
else {
return 0;
}
}

/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -328,11 +336,5 @@ void UART::flush() {
/* -------------------------------------------------------------------------- */
size_t UART::write_raw(uint8_t* c, size_t len) {
/* -------------------------------------------------------------------------- */
size_t i = 0;
while (i < len) {
uart_ctrl.p_reg->TDR = *(c+i);
while (uart_ctrl.p_reg->SSR_b.TEND == 0) {}
i++;
}
return len;
return write(c, len);
}
3 changes: 2 additions & 1 deletion cores/arduino/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class UART : public arduino::HardwareSerial {
arduino::SafeRingBufferN<SERIAL_BUFFER_SIZE> rxBuffer;
arduino::SafeRingBufferN<SERIAL_BUFFER_SIZE> txBuffer;

volatile bool tx_done;
volatile bool tx_done = true;
char txc;

sci_uart_instance_ctrl_t uart_ctrl;
uart_cfg_t uart_cfg;
Expand Down
2 changes: 1 addition & 1 deletion extras/fsp
Submodule fsp updated 1218 files
2 changes: 1 addition & 1 deletion extras/net/lwip
Submodule lwip updated from d8d1e4 to 1cc153
2 changes: 1 addition & 1 deletion extras/tinyusb
2 changes: 1 addition & 1 deletion extras/tls/mbedtls
2 changes: 1 addition & 1 deletion libraries/WiFi/extra/esptool
Submodule esptool updated 235 files
Loading