I am looking for tips on how best to implement thread-safe I / O (for example, for printf going to the debug serial port) in an environment in which the operating system scheduler can still start, run, pause, or may stop or crash. I use Newlib and FreeRTOS.
I am currently doing a (apparently standard) FreeRTOS approach that queues _write (Newlib) queues of a queue into a FreeRTOS queue, which is then freed from the interrupt service routine (filling out the serial port hardware FIFO and then waiting for an empty FIFO interrupt) .
This has the disadvantage that (at least on FreeRTOS), the queue can only be used safely when the scheduler starts, and the debug output cannot be printed when interrupts are disabled (as during loading before the scheduler started, or after a fatal error condition (namely where printf debugging output would be most useful :-).
Would it be better if the _write system call requested the status of the scheduler and / or interrupt and used the queues if the scheduler is running and use locking / polling serial I / O when interrupts are disabled? Is there an even more elegant idea that I haven't thought about?
thank
hugov source
share