Controlling the threading behaviour of the stack

As of version 0.8 of the library in addition to the default multi-threaded operation, also a single-threaded operation mode has been introduced. The new single-threaded mode helps to prevent stack space and other thread related resources without compromising the ease of use of the library. It is also possible to use the stack without using threading at all.

Select between multi-threaded and single-threaded operation

You can select single-threaded operation mode at compile time by enabling CONFIG_MMS_SINGLE_THREADED in the stack_config.h file. If this is not set to 1 the operation mode is multi-threaded.

In multi-threaded and single-threaded operation mode the stack is used in the same way as in previous versions of the library. After calling IedServer_start a background thread is started that listens for incoming client connections.

In the multi-threaded version in addition to this background thread also a new thread is started for each client connection. In the single-threaded operation mode the single background thread handles all client connections.

Operation without threads

The “thread-less” operation mode has the following advantages:

  • The platform doesn’t require support for pre-emptive multi-threading
  • No semaphore and thread HAL implementations are required
  • memory is preserved because there is only a single stack to maintain
  • does better fit to the requirements and coding styles for small embedded systems

To use the server stack in this operation mode the following new functions were added to the API:

void
IedServer_startThreadless(IedServer self, int tcpPort);

void
IedServer_processIncomingData(IedServer self);

void
IedServer_performPeriodicTasks(IedServer self);

void
IedServer_stopThreadless(IedServer self);

These functions have to be called at proper places of your server application. The IedServer_processIncomingData has to be called whenever data is available at the TCP layer. For convenience you can also call this function periodically. If no new data is available the function will simply return. The IedServer_performPeriodicTasks function has to be called periodically. As more often the function is called the better is the timing behavior of the stack.

You can optimize the behavior of the stack by enabling the CONFIG_MMS_THREADLESS_STACK option in the stack_config.h file. This will deactivate any stack internal synchronization mechanisms (semaphores). Because of this you have to make sure that not any two functions of the stack are executed in parallel! With this option enable single- and multi-threaded operation modes are no longer available.

One thought on “Controlling the threading behaviour of the stack

  1. Abdelbacet

    hi sir ,
    I am a student in software engineering at the National School of Computer Science.
    It’s my first project with IEC61850 and would porting this library to STM32F4 microcontroller .

    Can any one help me or give me some tutorial please

Comments are closed.