WIP - SerialX(__UART__) tx speedup and fixes #59
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Should address: #44
@facchinm, and others, would be good to get your feedback on this.
Short version:
The current released code, outputs one character at at time and waits for the first callback, which could be because of TDRE or transfer complete, before returning. It makes no use of the txBuffer which is defined to use 512 bytes. If you call Serial.print/write from ISR today it hangs.
First attempts where to continue using R_SCI_UART_Write, but there were/are difficulties in getting this to work, as it simply wants to output a buffer of size N. Once that is done, it calls the callback to the UART code. If I then try to start up a new transfer, in the callback, you will often lose one character. As they will notify you of the TDRE like condition as they have already output the last character in your buffer, and if you call the R_SCI_UART_Write, it will blindly write one character out into the transfer register, but the TDRE condition is not true, so you overwrite the last character of previous buffer....
So this version does not call their write, but instead handles the TDRE like code itself...
Longer version below:
This is a WIP.
The released code does not use the write(buf, cnt) code, but instead unrolls it to use the one byte at a time, as the method signature did not match that in print (missing const)
Fixing this uncovered lots of issues where data would be lost as, you would typically call to output again while the last one was still putting and could lose one or two bytes.
This code bypasses the R_SCI_UART_Write(&uart_ctrl, c, len); functions and instead I do my own code wheich utilizes the txBuffer that was already part of the class. The code both fills the buffer and if the hardware buffer has room, it takes characters from the txBuffer to fill it.
I also implemented my own version of the TDRE interrupt, to again simply take data from our txBuffer.
But to do this without changing the underlying layers, I implemented a version of attachInterruptVector, that plugs in the location of my ISR handler into the interrupt vector.
Probably could/should overwrite some of the others as well.
the SerialX.flush() code was completely busted. But you hardly noticed it before as you were only outputting one character at a time and then waiting for an interrupt before returning.
I have some debug code still in here, hopefully disabled by a #define.