Event-driven applications for embedded systems: Summary of PDF

C code is provided and explained for creating event-driven applications for embedded systems, and simulating a task-manager application.

By Peter Galan November 30, 2021
Courtesy: Peter Galan, retired control software engineer


Learning Objectives

  • Learn how to do task management using C in embedded systems.
  • Examine an event-driven task management implementation.
  • Compile and run the program.

When opening any PC program, it’s obvious it is an event-driven application. Users need to click at a specific button/gadget to prompt the application to execute a desired action; otherwise, nothing happens. And if you are familiar with the C# programming language, which is probably the most important language for writing such PC applications (at least those running under Microsoft Windows), very likely you will use such code constructions.

The Control Engineering 14-page downloadable Adobe PDF contains code examples for using C for an event-driven task-management embedded system example, a diagram and screenshot, covering:

Task management using C in embedded systems

Galan provides an extended example to aid understanding: Imagine a medium-size embedded system requiring a group of designers working on the firmware. One designer is dealing with the signals sampling/processing; another designer is responsible for the communication with other systems, etc. There has to be one designer who is responsible for coordinating all actions (let’s call them tasks) required by the system. C-code examples follow.

An event-driven task management embedded system implementation

In the embedded systems, there might occur dozens and dozens of events. They may indicate some external signal level changes, real time clock “ticks” indicating certain time period elapsing, completion of A/D converting procedures, and many other “events.” It is very convenient to group events of a similar nature into one, let’s call it an event register.

Galan continues, providing and explaining C code.

Compile and run the embedded system program

When you compile and run the program above, he concludes, your PC should launch a following Debug Console window as it is shown in the screenshot, as provided in the PDF download. And everything can be nicely written in C, which is still an optimal programming language for many embedded systems.

Figure: Publisher object: Array of linked lists and event register Courtesy: Peter Galan, retired control software engineer

Figure: Publisher object: Array of linked lists and event register Courtesy: Peter Galan, retired control software engineer

A little history about C programming

C programming language was developed in 1972 by Dennis Ritchie at Bell Laboratories. C language was initially developed for use with the UNIX operating system. Today, it is still widely used for embedded systems (autonomous, processor/computer-based systems not running under common and huge operating systems like MS Windows). C language is considered to be a low-level language, because it can very easily access and use H/W elements of a used (micro)processor.

C++ was developed at Bell Laboratories over a period starting in 1979 and commercially released at 1985. Since C++ is an attempt to add object-oriented features (plus other improvements) to C, earlier it was called as “C with Objects” and later renamed to C++. C++ can be used in embedded systems, though usually only its “C features” are mainly used, as all those “object-oriented” features can rapidly increase the size of executable files and slow down their performance. C++ was initially used by Microsoft for writing Windows-based applications, which used graphical user interfaces (GUI), not like the original MS DOS.

C# was designed by Anders Hejlsberg from Microsoft in 2000 and Microsoft introduced C# along with .NET Framework and Visual Studio. All modern MS Windows applications are recommended to write in C#, as they can be very small (in size) as they can heavily use very rich .NET Framework libraries. There are still many (older) applications written in C++ and running on the latest Windows versions. However, they can’t use anything from .NET Framework libraries, so they need to contain (their own) code for everything, which means the executable files tend to be very large.

Peter Galan is a retired control software engineer; Edited by Mark T. Hoske, content manager, Control Engineering, CFE Media and Technology, mhoske@cfemedia.com.

KEYWORDS: C programming, embedded systems, event-driven systems


Do you know how to use C to program event-driven applications for embedded systems?


Other Control Engineering articles by Peter Galan, retired control software engineer highlighted below.

Author Bio: Peter Galan is a (retired) control system designer with extensive experience in electronics, control systems and software design. He worked for many companies like ZTS, GE, Husky, Nortel, JDSU, Emerson (in Canada and the U.S.A.) and previously at the Technical University in Kosice (former Czechoslovakia). He holds a Ph.D. degree in Automated Control Systems and M.Eng degree in Applied Cybernetics from Czech Technical University in Prague.