Page 1 of 1

Serial write from multiple threads

Posted: Mon Apr 07, 2014 4:20 pm
by jackt
Hi,

I would like to make multiple write calls to the serial port from different threads. I want to make sure that all of the calls in a given portion of a thread are performed sequentially and not interrupted by another thread. What is the best mechanism to do this?

My hunch is that this is a fairly straightforward issue that shows my ignorance of general RTOS principals. Can anybody recommend a resource to learn general best practices when dealing with RTOS threads and interrupts?

Thanks!

Re: Serial write from multiple threads

Posted: Mon Apr 07, 2014 8:06 pm
by Giovanni
Hi,

This is a common problem, you need to do mutual exclusion using a mutex or a semaphore. The threads would take the mutex/semaphore, perform their I/O and finally release the mutex/semaphore. The I/O operation will be atomically performed.

I think this can help: http://www.chibios.org/dokuwiki/doku.ph ... sion_guide

Giovanni