Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.os.linux.development.system > #522

Multi threaded embedded linux application state machine design

Newsgroups comp.os.linux.development.system
Date 2013-08-21 05:19 -0700
Message-ID <a21b4286-0096-4c4f-ba11-be40c0e5440a@googlegroups.com> (permalink)
Subject Multi threaded embedded linux application state machine design
From Hari Prasath <gehariprasath@gmail.com>

Show all headers | View raw


Problem definition:

We are designing an application for an industrial embedded system running Linux.

The system is driven by events from the outside world. The inputs to the system could be any of the following:

    Few inputs to the system in the form of Digital IO lines(connected to the GPIOs of the processor like e-stop)
    The system runs a web-server which allows for the system to be controlled via the web browser.
    The system runs a TCP server. Any PC or HMI device could send commands over TCP/IP.

The system needs to drive or control RS485 slave devices over UART using Modbus. The system also need to control few IO lines like Cooler ON/OFF etc.We believe that a state machine is essential to define this application. The core application shall be a multi threaded application which shall have the following threads...

    Main thread
    Thread to control the RS485 slaves.
    Thread to handle events from the Web interface.
    Thread to handle digital I/O events.
    Thread to handle commands over TCP/IP(Sockets)

For inter-thread communication, we are using Pthread condition signal & wait.  As per our initial design approach(one state machine in main thread), any input event to the system(web or tcp/ip or digital I/O) shall be relayed to the main thread and it shall communicate to the appropriate thread for which the event is destined. A typical scenario would be to get the status of the RS485 slave through the web interface. In this case, the web interface thread shall relay the event to the main thread which shall change the state and then communicate the event to the thread that control's the RS485 slaves & respond back. The main thread shall send the response back to the web interface thread.

Questions:

    Should each thread have its own state machine thereby reducing the complexity of the main thread ? In such a case, should we still need to have a state machine in main thread ?
    Any thread processing input event can communicate directly to the thread that handles the event bypassing the main thread ? For e.g web interface thread could communicate directly with the thread controlling the RS485 slaves ?
    Is it fine to use pthread condition signals & wait for inter thread communication or is there a better approach ?
    How can we have one thread wait for event from outside & response from other threads ? For e.g. the web interface thread usually waits for events on a POSIX message queue for Inter process communication from web server CGI bins. The CGI bin's send events to the web interface thread through this message queue. When processing this event, the web interface thread would wait for response from other threads. In such a situation, it couldn't process any new event from the web interface until it has completed processing the previous event and gets back to the wait on the POSIX message queues.

sorry for the too big explanation...I hope I have put forward my explanation in the best possible way for others to understand and help me.

I could give more inputs if needed.

Back to comp.os.linux.development.system | Previous | NextNext in thread | Find similar


Thread

Multi threaded embedded linux application state machine design Hari Prasath <gehariprasath@gmail.com> - 2013-08-21 05:19 -0700
  Re: Multi threaded embedded linux application state machine design Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-08-21 14:54 +0000

csiph-web