Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed formatting
  • Loading branch information
delta-G committed Jun 30, 2024
commit b4a4e37c59f2d3ceff941a654992e3135dacd9e8
56 changes: 28 additions & 28 deletions cores/arduino/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ void UART::WrapperCallback(uart_callback_args_t *p_args) {
case UART_EVENT_TX_COMPLETE:
case UART_EVENT_TX_DATA_EMPTY:
{
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;
}
if(uart_ptr->txBuffer.available()){
static char txc;
txc = uart_ptr->txBuffer.read_char();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it OK to use a static variable here instead of uart_ptr->txc? Would this work correctly if there are multiple uarts working simultaneously?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question. I made it static because it was being passed as a pointer on the next line but I didn't really think about it being there in multiple instances.

I think that it will be OK because R_SCI_UART_Write is going to use that data one line later and then we're done with it. I think it would be OK to make it not static.

I wish I could grab a whole chunk of the tx_buffer there so the code in r_sci_uart.c could make effective use of the FIFO. The problem is that I would need to know where the data in the tx_buffer wraps around or I could run off the end.

I have a separate branch that uses DMA and it doesn't have this problem because I set the DMA extended repeat area to match the tx_buffer and the DMA controller will automatically wrap back around. But that code seems to be broken in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at it now, I don't see why I don't just use uart_ptr->txc instead. Maybe I thought because it was an interrupt handler that I wouldn't have access but I do.

I'll update the branch tonight and retest a little.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code to use the member variable instead. It tests ok. I did a lot of printing without any failures. Unfortunately I seem to have messed up my branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated once more to load characters 16 at a time in the interrupt callback. This takes advantage of the FIFO to reduce the number of interrupts.

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 @@ -112,31 +112,31 @@ bool UART::setUpUartIrqs(uart_cfg_t &cfg) {
/* -------------------------------------------------------------------------- */
size_t UART::write(uint8_t c) {
/* -------------------------------------------------------------------------- */
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;
}
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) {
for(int i = 0; i<len; i++){
if(init_ok) {
for(int i = 0; i<len; i++){
write(c[i]);
}
return len;
}
else {
return 0;
}
}
return len;
}
else {
return 0;
}
}

/* -------------------------------------------------------------------------- */
Expand Down