Professional Documents
Culture Documents
00.Real-time Systems Study Guide
00.Real-time Systems Study Guide
STUDY GUIDE
P a g e 1 | 66
Table of contents
P a g e 2 | 66
P a g e 3 | 66
Learning unit 01: The real-time environment
Before class activities
Reading: Preface (Kopetz, 2023)
• System Workbench for STM32 (SW4STM32) is an Eclipse integrated IDE for STM32
microcontrollers. Download and install SW4STM321.
In class activities
Warming up: discussion of prior knowledge
Lab exercise
• CMSIS-Core is a vendor-independent hardware abstraction layer for the Cortex-M processor
series. The CMSIS-Core enables consistent and simple software interfaces to the processor
and the peripherals, simplifying software re-use, reducing the learning curve for new
microcontroller developers and reducing the time to market for new devices (CMSIS, 2018).
This website2 provides an overview of how CMSIS is used in embedded applications.
1 http://www.openstm32.org
2 http://arm-software.github.io/CMSIS_5/Core/html/using_pg.html
P a g e 4 | 66
Learning unit 02: Simplicity
Before class activities
Reading: Chapter 2 Simplicity (Kopetz, 2023)
• Tera Term is a terminal emulator for Microsoft Windows, that supports serial port, telnet and
SSH connections. Install Tera Term3.
In class activities
Lab exercise
• Run Learning unit 02 and verify that data is received and transmitted by using Tera Term.
• Study the source code. Refer to the following sections of the
STM32F0x1/STM32F0x2/STM32F0x8 microcontroller reference manual (RM0091, 2017) for
a detailed explanation of the peripherals that are used in the project:
o General-purpose I/Os (GPIO)
o Interrupts and events
o Universal synchronous asynchronous receiver transmitter (USART)
o General-purpose timers (TIM2 and TIM3)
• Extend the project with one or more of the following functionality:
o The time between two blinks of the green LED can be adjusted in steps of 100 ms,
with a maximum of 1000 ms and a minimum of 100 ms. Make the blink rate of the
green LED adjustable in 20 ms steps (without changing the maximum and minimum
value).
o When an ‘r’ is received by the microcontroller, the blink rate is reset to 1000 ms
between two blinks of the green LED. The string ‘reset’ is displayed in Tera Term.
o After the string ‘fastest’ has been received by the microcontroller, the blink rate is set
to its maximum.
After the string ‘slowest’ has been received by the microcontroller, the blink rate is set
to its minimum.
Tip: use the strcmp() function.
o When button B1 is clicked, blinking stops. When B1 is clicked again, blinking
resumes.
Tip: introduce a global variable that is set in the external interrupt handler and read in
the main loop.
3 https://ttssh2.osdn.jp/index.html.en
P a g e 5 | 66
Learning unit 03: Global time
Before class activities
Reading: Chapter 3 Global Time (Kopetz, 2023)
In class activities
Warming up: discussion of prior knowledge
Lab exercise
• Lookup the drift rate of the microcontroller’s system core clock in the datasheet. What is used
as the reference clock?
• You will measure the microcontroller’s drift for the period of (approximately) one hour. Your
laptop’s system clock will be used as the reference clock 𝑧.
Setup the microcontroller’s system tick timer to generated a system tick interrupt every
minute. Use the system tick’s interrupt handler to trigger the transmission of the number of
minutes that have past via the UART. Repeat this for sixty minutes. TeraTerm should show the
following output:
00
01
02
..
..
..
13
14
15
Enable the logging option in TeraTerm (File → Log…). Make sure to enable timestamps.
TeraTerm provides timestamps with millisecond granularity. What is the expected number of
microticks for the duration of one minute (𝑛𝑘)?
Copy-and-paste the log data into the Excel sheet. Repeat the measurement on three different
physical locations. Discuss the results. Also discuss the latency jitter in this measurement and
how it influences the measured results.
P a g e 6 | 66
Learning unit 04: Temporal relations
Before class activities
Reading: Chapter 5 Temporal relations (Kopetz, 2023)
In class activities
Warming up: discussion of prior knowledge
Lab exercise
P a g e 7 | 66
o In main.c: Transmit the value of the fake sensor in an observation message from the
master to the node.
o In cni.c: Receive the value of the fake sensor in the node and write it to the
fake_sensor RT image. On correct reception by the node, a message is printed in
TeraTerm as long as the value of the fake sensor is equal to 1.
o Why is state estimation not possible for this fake sensor?
P a g e 8 | 66
Learning unit 05: Dependability
Before class activities
Reading: Chapter 6 Dependability (Kopetz, 2023)
In class activities
Warming up: discussion of prior knowledge
Lab exercise
• In this example project: what is the fault, what is the error, and what is the failure?
• Give the specification of the g-state. Does this specification adhere to the description in
paragraph 6.6.2?
• Describe the structure of a message (header, data, trailer).
• Describe the messages that are being transmitted in a scenario without a fault.
• When faking a transient error by pressing the blue button of the operational component, the
user still sees an erroneous ‘3’ being displayed. The operational component, however,
continues counting after the erroneous ‘3’ was displayed. Explain how this is possible by
describing the program flow and the sequence of messages.
• Why is such behaviour, an erroneous ‘3’ still being displayed, not a major problem in most
control applications?
P a g e 9 | 66
• The example project does not implement a self-test. Where in the code should a self-test be
implemented?
• Paragraph 6.4.3 describes two sorts of architectures. Which one is implemented in the
example project?
• What are pros and cons of using the AES256 library in the transmit and receive functions of
the CNI?
• What is the content and meaning of the following message:
header 0x01
Data 0xDC, 0xFA, 0xF1, 0xF1, 0xA6, 0x35, 0x89, 0x2D, 0x4C, 0x4B, 0xC9, 0x23,
0xC5, 0xA3, 0xCB, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
trailer
0x3A, 0xBA, 0x59, 0xB0, 0x39, 0x85, 0x7F, 0x52, 0x07, 0x87, 0x89, 0x9A, 0x76, 0x4A,
0x05, 0x44, 0x53, 0x94, 0x84, 0xC9, 0xF7, 0xC5, 0xD1, 0x48, 0x68, 0x76, 0x96, 0x33,
0x6E, 0x6E, 0xCE, 0x13,
Extra (hard)
The monitoring component implements value verification and does not implement temporal
verification. Implement temporal verification with a window of 0.2 seconds. In order to do so, you
should:
P a g e 10 | 66
Learning unit 06: Real-time communication
Before class activities
Reading: Chapter 7 Real-time communication (Kopetz, 2023)
In class activities
Warming up: discussion of prior knowledge
Lab exercise
• Attach an RS485 CAN shield to each board. Connect the three boards as depicted in the
image below. Refer to the board’s User Manual (UM1724, 2017) to find the pin locations of
PC6, PC8, 3V3 and GND on connectors CN7 and CN10.
CANH
CANL
3V3
GND
This hardware setup allows us to connect a single board via USB to the computer and power
all the boards. Programming the boards must be done by connecting each board separately to
the computer. By connecting PC6 or PC8 to GND, the board knows its role in the ensemble.
• Test the project. The green LED on Node B will be lit as long as the blue button on Node A is
pressed. By connecting the Monitor to a terminal program, messages on the CAN bus can be
observed.
• Study section Controller Area Network (bxCAN) in the reference manual (RM0091, 2017).
Answer the following questions.
o What BaudRate is implemented?
P a g e 11 | 66
o What is the size of the sender queue? What happens if the queue is full?
o What is the size of the receiver queue? What happens if the queue is full?
o What is the content of a mailbox?
o What are acceptance filters used for?
o What is the difference between loopback mode and silent mode?
• Explain why/how this project implements event-triggered communication.
• Explain how CAN implements back-pressure flow control. Why can this not be used in a real-
time communication system?
• Why is the latency jitter for media access higher for messages with lower priority?
• What is (approximately) the limit of the data efficiency that can be achieved?
• In event-triggered communication, it is impossible to provide temporal guarantees. Implement
a scenario that shows this. Test the implementation and prove your scenario by analysing the
observed CAN messages from the Monitor.
• Reflect on the project by discussing the following architectural requirements of a
communication infrastructure: timeliness, dependability, flexibility, and physical structure.
Extra
P a g e 12 | 66
Learning unit 0 7: Real-time operating systems
Before class activities
Reading: Chapter 9 Real-Time Operating Systems (Kopetz, 2011)
In class activities
Warming up: discussion of prior knowledge
Lab exercise
• This project runs on a single NUCLEO-F072RB board without an RS485 CAN shield mounted.
• The project shows how the FreeRTOS real-time operating system is ported to the NUCLEO-
F072RB board and how three tasks interact.
• The scheduler follows the following scheme:
𝑻𝒂𝒔𝒌 𝟏
𝑻𝒂𝒔𝒌 𝟐
𝑻𝒂𝒔𝒌 𝟑
𝑰𝒅𝒍𝒆
𝑡2 𝑡5 𝑡6 𝑡𝑖𝑚𝑒
𝑡1 = 0 𝑚𝑠: Start of task 1. The maximum duration of this task is 100 ms. If the task finishes
earlier, the idle task is executed.
𝑡2 = 100 𝑚𝑠: Start of task 2. The maximum duration of this task is 40 ms. The example
shows that this time is not needed, so the idle task is executed.
𝑡3 = 140 𝑚𝑠: Start of task 3. The maximum duration of this task is 860 ms. The example
shows that this time is not needed, so the idle task is executed.
𝑡4 = 1000 𝑚𝑠: The cycle repeats by the execution of task 1.
P a g e 13 | 66
• The project shows two means of inter-task interaction. The first is exchange of messages by
means of a queue:
𝑄𝑢𝑒𝑢𝑒
𝑆𝑒𝑛𝑑 𝑅𝑒𝑐𝑒𝑖𝑣𝑒
𝑻𝒂𝒔𝒌 𝟏 𝑂𝑏𝑠𝑒𝑟𝑣𝑎𝑡𝑖𝑜𝑛_𝑡 𝑻𝒂𝒔𝒌 𝟐
𝑻𝒂𝒔𝒌 𝟐
𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡 𝑏𝑦𝑡𝑒
Notice that task 2 is writing to a shared data structure, but in the example project, this shared
data structure is never read.
• Study the source code of the project. Documentation related to the FreeRTOS functions is
provided in (Barry, 2016) and on the FreeRTOS website5.
o For each of the three tasks: is it an S-task or a C-task?
o What mechanism is used to ensure data integrity for the shared data structures?
o What is the role of time in this project?
o Does the project implement any interrupts?
5 https://www.freertos.org
P a g e 14 | 66
• Update the project and implement a component. The component must realize the following
high-level software structure and tasks:
𝑻𝒂𝒔𝒌 𝟓
𝐴𝑝𝑝𝑙𝑖𝑐𝑎𝑡𝑖𝑜𝑛 𝑠𝑜𝑓𝑡𝑤𝑎𝑟𝑒
𝐴𝑃𝐼
𝑻𝒂𝒔𝒌 𝟒𝒂 𝑻𝒂𝒔𝒌 𝟑𝒂
𝑀𝑖𝑑𝑑𝑙𝑒𝑤𝑎𝑟𝑒
𝐿𝐼𝐹 𝑇𝐼𝐼
𝑻𝒂𝒔𝒌 𝟒𝒃 𝑻𝒂𝒔𝒌 𝟑𝒃
𝐿𝑜𝑐𝑎𝑙 𝑂𝑆
𝑻𝒂𝒔𝒌 𝟐 𝑻𝒂𝒔𝒌 𝟏
𝐿𝐸𝐷 𝐵𝑢𝑡𝑡𝑜𝑛
P a g e 15 | 66
• Give a description and rationale for the duration of each task.
• Give a description and rationale for the inter-task interactions.
P a g e 16 | 66
Learning unit 08: Digital Twinning
Before class activities
Reading: Chapter 14 Cloud and Fog Computing (Kopetz, 2023)
In class activities
Warming up: discussion of prior knowledge
Lab exercise
P a g e 17 | 66
Learning unit 09: System design
Before class activities
Reading: Chapter 11 System Design (Kopetz, 2023)
In class activities
Warming up: discussion of prior knowledge
Lab exercise
• Attach an RS485 CAN shield to each of the three boards. Connect the three boards as
depicted in the image below. Refer to the board’s User Manual (UM1724, 2017) to find the
pin locations of PC6, PC8, 3V3 and GND on connectors CN7 and CN10.
RS485A
RS485B
CANH
CANL
FTU
3V3
GND
This hardware setup allows us to connect a single board via USB to the computer and power
all the boards. Programming the boards must be done by connecting each board separately to
the computer. By connecting PC6 or PC8 to GND, the board knows its role in the ensemble.
P a g e 18 | 66
The jumpers of the RS485 CAN shield should be set
to their default positions as depicted in the adjacent
image.
It is very important that safety-critical functions do not use a single channel system. An example of
a safety-critical function is the synchronisation message of the global clock.
The goal of this assignment is to implement a fail-silent architecture (refer to paragraph 6.4.2 in
(Kopetz, 2023)) for two types of functions:
1. Transmitting global clock synchronisation messages from the monitoring node to nodes A and
node B.
2. Transmitting blue button pressed messages from nodes A and B to the monitoring node.
Nodes A and B are a single FTU: as long as one or both blue buttons are pressed, the
monitoring node turns on the green LED.
10 https://www.ixxat.com/technologies/all4can/can-news-blog/can-news-blog/2017/09/22/rs485-vs.-can
P a g e 19 | 66
o Receives messages via CAN indicating the state of a blue button. The green LED is set
according to this state. Redundant incoming messages are removed. For each node
that has not produced a message, an appropriate message is displayed via the TII
interface.
• Node A
o Receives global clock synchronisation messages and synchronises its local clock to the
content of this message. Redundant incoming messages are removed.
For each interface that has not produced a message, an appropriate message is
displayed via the TII interface.
o Transmits a message via CAN indicating the state of the blue user button.
• Node B
Identical to node A.
Test your implementation by removing the jumper wires from the CAN and/or RS485 interface and
show by utilizing several different scenarios that it is fail-silent.
• Make you’re implementation more diverse, by implementing an RTOS in node A and by not
implementing an RTOS in node B.
P a g e 20 | 66
Learning unit 10: Validation
Before class activities
Reading: Chapter 12 Validation (Kopetz, 2023)
In class activities
Warming up: discussion of selected assignments
Lab exercise
• Attach an RS485 CAN shield to each of the three boards. Connect the three boards as
depicted in the image below. Refer to the board’s User Manual (UM1724, 2017) to find the
pin locations of PC6, PC8, 3V3 and GND on connectors CN7 and CN10.
CANH
CANL
3V3
GND
This hardware setup allows us to connect a single board via USB to the computer and power
all the boards. Programming the boards must be done by connecting each board separately to
the computer. By connecting PC6 or PC8 to GND, the board knows its role in the ensemble.
• The implementation of the Monitor and Node A is given and tested by the supplier. It is your
task to test node A as a component provider and as a component user.
P a g e 21 | 66
The given specification of node A is as follows:
7 The node establishes a static temporal control structure, as described in section 3.3.4
(Kopetz, 2011):
7.1 The duration of one cycle is 200 ms
7.1.1 The duration of phase A is 30 ms
7.1.2 The duration of phase B is 20 ms
7.1.3 The duration of phase C is 30 ms
7.1.4 The duration of phase D is 20 ms
7.1.5 The duration of phase E is 30 ms
7.2 The cycle is phase aligned with all other nodes
7.3 At the start of the cycle, the green LED toggles
7.4 The control structure is independent of the input data (blue button clicks)
P a g e 22 | 66
The implementation of the node does not comply to all specifications. It is your task to find out
what specifications are not met by testing the component (and not by reviewing the code in
node_a.c). Use the following approach:
P a g e 23 | 66
References
Barry, R. (2016). Mastering the FreeRTOS ™ Real Time Kernel - A Hands-On Tutorial Guide. Retrieved
from FreeRTOS Documentation:
https://www.freertos.org/Documentation/161204_Mastering_the_FreeRTOS_Real_Time_Ker
nel-A_Hands-On_Tutorial_Guide.pdf
Kopetz, H. (2023, September). Real-time systems: design principles for distributed embedded applications.
Springer Cham.
P a g e 24 | 66