<p>ChibiOS/RT offers a variety of mechanisms and primitives, often it is better to focus on a single approach for the system design and use only part of the available subsystems.<br/>
<p>Correct, single thread, it is not mandatory to use the multithreading features of the OS. You may choose to implements everything as a complex state machine handled in the main thread alone. In this scenario the OS still offers a variety of useful mechanisms:</p>
<ul>
<li>Interrupt handling.</li>
<li>Virtual Timers, very useful in state machines in order to handle time triggered state transitions.</li>
<li>Power management.</li>
<li>Event Flags and/or Semaphores as communication mechanism between interrupt handlers and the main.</li>
<li>I/O queues.</li>
<li>Memory allocation.</li>
<li>System time.</li>
</ul>
<p>In this configuration the kernel size is really minimal, everything else is disabled and takes no space. You always have the option to use more threads at a later time in order to perform separate tasks.</p>
<p>In this scenario there are multiple threads in the system that never share data, everything is done by exchanging messages. Each thread represents a service, the other threads can request the service by sending a message.<br/>
In this scenario the following subsystems can be used:</p>
<ul>
<li>Synchronous Messages.</li>
<li>Mailboxes (asynchronous message queues).</li>
</ul>
<p>The advantage of this approach is to not have to deal with mutual exclusion, each functionality is encapsulated into a server thread that sequentially serves all the requests. As example, you can have the following scenario:</p>
Note that the threads should not exchange complex messages but just pointers to data structures in order to optimize the performance. Also note that a thread can be both client and server at the same time, the FS service in the previous scenario as example.</p>
<p>This is the most common scenario, several threads have access to both their private data and shared data. Synchronization happens with one of the mechanisms described in the <aclass="el"href="article_mutual_exclusion.html">Mutual Exclusion guide</a> article.<br/>
<p>All the above approaches can be freely mixed in a single application but usually I prefer to choose a way and consistently design the system around it. The OS is a toolbox that offers a lot of tools but you don't have to use them all necessarily. </p>
Generated on Sun Nov 28 2010 14:09:55 for ChibiOS/RT by <ahref="http://www.doxygen.org/index.html"><imgsrc="doxygen.png"alt="doxygen"align="middle"border="0"></a> 1.7.1</small></address>