Round Robin Scheduler and Serial Tx

I have ported my simple Round Robin Scheduler into mbed, being a cooperative scheduler the rule is 'dont wait but sleep()', to give the other tasks a slice of the cpu time (none stick code I call it).

Testing the timings out I see that doing a printf("Hello World") hangs that task thread by 15ms, a sprintf() followed by a series of putc(), followed by a sleep(), hang the thread by 1ms for each character. Understandably at 9600 baud 1 character takes about 1ms to transmit so I'm assuming that the Serial library code waits for transmitter empty, sort of understandable.

What I need is a sleepy putc(), has anyone any idea how to do this?




09 Jul 2010

Serial has a function called 'writeable' which allows you to check if there is space to write a character before you call putc.

18 Jul 2010
user avatar Tim Exton-McGuinness wrote:
I have ported my simple Round Robin Scheduler into mbed

Hi Tim

I'm interested in the theory of this, are there any code samples?


Tim is on holiday I'll get back to you. Remind me.

I have simplified and published the code now.

09 Sep 2010

Hi Tim,

I was trying to look at your scheduler but apparently there's no such page...

I also looked on your  Profile page & that says that you haven't published any programs yet.

Is it possible for you to post/re-post this please? It sonds extremely useful.



Ok there again now.

09 Sep 2010

That's great - and very speedy service!

Many thanks,


09 Sep 2010

I recently found that I was spending the majority of the time in my little app attempting to print to my serial LCD.

And so I wrote a buffered writer, it uses a ring buffer and the Serial TXIrq to that it ought not block.

I've written the code but not actually tested it yet, so I'm not ready to publish it.


I'm not actually 100% sure that it'll do for what I require now. I want the Data that's sent to be the most recent update rather that just to send it async in order, so I might create a double or possibly triple buffered serial writer that uses the TXIrq to flip between the buffers. I'll probably publish all the bits once I get them written :)

09 Sep 2010

I found and ported a small RTOS called scmRTOS to mbed. Details here. It offers something called "channels" which might be what you need.

09 Sep 2010

Oh, interesting, I'll have a look.