Tutorial: Building a Mainloop Application

This tutorial shows how easy it is to develop an application that uses the redBlocks Mainloop Scheduler for timing services and events. In the course of this tutorial we develop an application that allows to control a flashing LED via a serial connection. The next tutorial demonstrates how this application can be integrated on an XMC2Go board.

Even though this sample application is very trivial, it shows the concepts of the redBlocks Mainloop Scheduler, so you are able to develop much more sophisticated functionality with these concepts.

This is a short description of the mechanisms that are implemented in the sample application:

  • The application uses a periodically running ISR (interrupt service routine) timer for flashing the LED with a constant time interval.
  • Whenever a byte is received via the serial interface, it is immediately read from the receive FIFO in interrupt context and an event is generated.
  • This event is handled from the mainloop context. This is done for demonstration purposes, i. e. in order to show how the redBlocks Mainloop Scheduler can be used to process interrupts as synchronous events, if the corresponding actions are not time critical. This approach relieves the programmer from concurrency issues, that arise when multiple actions interrupt each other. In the event handler method, the LED is switched and some logging output is generated.
  • When the LED is switched to constant on or off, the ISR timer is stopped, so the redBlocks Mainloop Scheduler enters the tickless mode, i. e. the system tick is switched off. Then, the CPU stays in sleep mode until another character is sent via the serial connection.

The complete code of the example that is built during this tutorial can be downloaded here. This archive also includes the target project for an XMC2Go board.

Before starting this tutorial you should have installed and tested the redBlocks evaluation package (instructions can be found here). You should also have a look at the "Hello World" tutorial first.