optimized Serial.PutChar ?

General discussions about working with the Astrobe IDE and programming ARM Cortex-M0, M3, M4 and M7 microcontrollers.
Post Reply
abaumann
Posts: 11
Joined: Wed Sep 25, 2013 9:07 pm

optimized Serial.PutChar ?

Post by abaumann » Thu Jan 16, 2014 4:47 pm

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

cfbsoftware
Site Admin
Posts: 525
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: optimized Serial.PutChar ?

Post by cfbsoftware » Fri Jan 17, 2014 12:22 pm

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.
Attachments
VariableBlinker.zip
Variable speed Blinker
(778 Bytes) Downloaded 1885 times

abaumann
Posts: 11
Joined: Wed Sep 25, 2013 9:07 pm

Re: optimized Serial.PutChar ?

Post by abaumann » Mon Jan 20, 2014 8:30 am

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

Post Reply