Page 1 of 1

optimized Serial.PutChar ?

Posted: Thu Jan 16, 2014 4:47 pm
by abaumann
Hi,

I'm thinking about a simple background communication.
In this scenario one character per main loop cycle should be send if a char is in the background send buffer ( the scenario is not the same as a buffered UART).
I have implemented one version with the standard implementation of the MODULE Serial.
Now, I'm thinking about if a interrupt controlled send of a character could avoid the blocking behavior.

Code: Select all

 ..
 REPEAT UNTIL SYSTEM.BIT(MCU.U0LSR, 5);
..
I'm not sure if this make sense.
Could I really save time ?
==> this depend of the amount of time of waiting in the REPEAT loop.

Before I start to implement that I want to ask if somebody can give me a hint


best regards

Andreas

Re: optimized Serial.PutChar ?

Posted: Fri Jan 17, 2014 12:22 pm
by cfbsoftware
The attached example program for the LPCXpresso LPC1769 shows how you can use the Serial functions RxReady and TxReady to avoid blocking.

After you have uploaded the program the led will start flashing once per second (500ms on and 500ms off).

Open the Astrobe Terminal window and click on the Reset button. If you enter a digit between 1 and 9 in the Input area of the terminal window, the number will be echoed in the Output area and the delay is changed to a value between 100ms and 900ms. The blinker will speed up or slow down accordingly.

You will notice that it is more responsive to your keystrokes when the delay between flashes is less. If you enter 9 for the longest delay it is fairly easy to then type enough characters to exceed the UART Receive FIFO limit and you will start to see characters being lost. It would be in situations like this that you would need to implement an interrupt / buffer scheme - not for better performance but to avoid losing data.

Re: optimized Serial.PutChar ?

Posted: Mon Jan 20, 2014 8:30 am
by abaumann
Thank you for this hint. I'm using TxReady in combination with a Ring buffer based Fifo to implement my background communication. It works very well.


Best regards


Andreas