0% found this document useful (0 votes)
6 views38 pages

Lect 6

The document is a lecture presentation on Real-time Operating Systems (RTOS) by Dr. Mateusz Cholewiński, covering topics such as RTOS services, timers, memory management, and various RTOS architectures including QNX, Xenomai, FreeRTOS, NuttX, and ChibiOS/RT. It discusses key concepts like kernel and user space, scheduling methods, and inter-process communication mechanisms such as mutexes, semaphores, and pipes. The presentation also includes code snippets and examples related to thread management and synchronization in Xenomai.

Uploaded by

Moji Bake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views38 pages

Lect 6

The document is a lecture presentation on Real-time Operating Systems (RTOS) by Dr. Mateusz Cholewiński, covering topics such as RTOS services, timers, memory management, and various RTOS architectures including QNX, Xenomai, FreeRTOS, NuttX, and ChibiOS/RT. It discusses key concepts like kernel and user space, scheduling methods, and inter-process communication mechanisms such as mutexes, semaphores, and pipes. The presentation also includes code snippets and examples related to thread management and synchronization in Xenomai.

Uploaded by

Moji Bake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Last week

RTOS services
Timers

Real-time Operating Systems


Lecture 6

dr inż. Mateusz Cholewiński

Chair of Cybernetics and Robotics


Faculty of Electronics, Photonics and Microsystems
Wrocław University of Science and Technology

8.05.2025
rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week
RTOS services
Timers

Scope of presentation

1 Last week

2 RTOS services

3 Timers

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

Memory management

Virtual memory
memory management technique that provides an idealized
abstraction of the storage resources that are actually available on a
given machine.

Can be divided into 2 space:


kernel space – lowest abstraction layer directly communicating
with hardware (process scheduling, IPC, device drivers,
providing system calls and services),
user space – dedicated for running user applications and more
sophisticated software. rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

Monolithic vs Microkernel

Figure 1: https://en.wikipedia.org/wiki/Microkernel rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

Scheduling

Priority based,
FCFS,
SRTF,
Round-Robin,

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

Architecture

Architecture
It ia a high level structure of a software system. Such structure
comprises software elements, relations among them and properties
of both elements and relations.

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

Architecture

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

QNX
QNX
Rigorous RT system, created in the beginning of 80’s of century by
the Quantum Software System company for PC.
multiple tasks,
added support for networking after some time,
conformity with POSIX standard,
rapid development,
expansion to other architectures in 90’s,
microkernel (scheduling, IPC, interrupts, timers),
device drivers,
fast context switching,
rys/CyRobekow
scheduling based on priorities with preemptive feature.
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

Xenomai
Xenomai
Hard RT cooperating with Linux kernel providing RT support to
user space applications.

project started in 2001


multiple tasks,
different platforms,
installed next to linux kernel,
has own API in order to provide RT functions,
scheduling based on preemtive priority or round-robin,
two possible ways to integrate with linux ecosystem: Cobaltrys/CyRobekow
and Mercury.
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

Xenomai – Cobalt
”It is dealing with all time-critical activities, such as handling
interrupts, and scheduling real-time threads. The Cobalt core has
higher priority over the native kernel activities.”

rys/CyRobekow
https://gitlab.denx.de/Xenomai/xenomai/wikis/Start_Here

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

Xenomai – Mercury
”(...)relying on the real-time capabilities of the native Linux
kernel.(...) Often, applications will require the PREEMPT-RT
extension to be enabled in the target kernel, for delivering real-time
services”

rys/CyRobekow

https://gitlab.denx.de/Xenomai/xenomai/wikis/Start_Here
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

FreeRTOS
FreeRTOS
RTOS kernel for embedded devices, ported to 35 microcontroller
platforms.

designed to be small, simple and based on C (portability),


kernel consist of three C files,
provides threads, tasks, mutexes, semaphores, software timers,
supporting low power applications,
FreeRTOS can be completely statically allocated (q: why?),
there is no device drivers, sophisticated memory management,
user accounts, networking,
uses round-robin for scheduling (time based on hardware rys/CyRobekow
timer).
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

Informations

rys/CyRobekow

Figure 3: https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

NuttX
NuttX
RTOS for microcontroller platforms (from 8 to 32 bits).

standards compliant,
modular design,
fully preemptible,
naturally scalable,
highly configurable,
realtime, deterministic, with support for priority inheritance,
optional tasks with address environments (Processes).
loadable kernel modules; lightweight, embedded shared
libraries,
rys/CyRobekow
FIFO and RR scheduling available.
http://nuttx.org/
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures

ChibiOS/RT
ChibiOS/RT
compact and fast RTOS.

preemptive multithreading,
128 priority levels,
round-robin scheduling for threads at the same priority level,
synchronous and asynchronous I/O with timeout capability,
thread-safe memory heap and memory pool allocators,
Hardware Abstraction Layer with support for ADC, CAN, GPT
(general-purpose timer), EXT, I²C, ICU, MAC, MMC/SD,
PAL, PWM, RTC, SDC, Serial, SPI, and USB drivers,
support for the LwIP and uIP TCP/IP stacks,
rys/CyRobekow
support for the FatFs file system library.
http://www.chibios.org/dokuwiki/doku.php
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Thread creation – Xenomai

1 RT TASK r e a d e r , w r i t e r ;
2
3 r t t a s k s p a w n (& r e a d e r , ” r e a d e r ” , 0 , 0 , T JOINABLE , &
r e a d e r f u n c , NULL) ;
4 r t t a s k s p a w n (& w r i t e r , ” w r i t e r ” , 0 , 0 , T JOINABLE , &
w r i t e r f u n c , NULL) ;
5
6 r t t a s k j o i n (& r e a d e r ) ;
7 r t t a s k j o i n (& w r i t e r ) ;

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Mutex – Xenomai

Mutex
A mutex is a MUTual EXclusion object, and is useful for protecting
shared data structures from concurrent modifications, and
implementing critical sections and monitors.
A mutex has two possible states: unlocked (not owned by any
task), and locked (owned by one task). A mutex can never be
owned by two different tasks simultaneously. A task attempting to
lock a mutex that is already locked by another task is blocked until
the latter unlocks the mutex first.

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Mutex – Xenomai

1
2 i n t r t m u t e x c r e a t e ( RT MUTEX * mutex ,
3 c o n s t c h a r * name
4
5 int rt mutex acquire ( RT MUTEX * mutex ,
6 RTIME timeout )
7
8 int rt mutex release ( RT MUTEX * mutex )

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Semaphore – Xenomai
Semaphore
A counting semaphore is a synchronization object for controlling
the concurrency level allowed in accessing a resource from multiple
real-time tasks, based on the value of a count variable accessed
atomically. The semaphore is used through the P (”Proberen”,
from the Dutch ”test and decrement”) and V (”Verhogen”,
increment) operations. The P operation decrements the semaphore
count by one if non-zero, or waits until a V operation is issued by
another task. Conversely, the V operation releases a resource by
incrementing the count by one, unblocking the heading task
waiting on the P operation if any. Waiting on a semaphore may
cause a priority inversion. rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Semaphore – Xenomai

1 i n t r t s e m c r e a t e ( RT SEM * sem ,
2 c o n s t c h a r * name ,
3 unsigned long icount ,
4 int mode )
5
6 i n t r t s e m p ( RT SEM * sem ,
7 RTIME timeout )
8
9 int rt sem v ( RT SEM * sem )

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Pipe

Figure :)

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Pipe – Xenomai

A message pipe is a two-way communication channel between


Xenomai threads and normal Linux threads using regular file I/O
operations on a pseudo-device.
Xenomai – rt pipe create(),
Linux – /dev/rtpN.

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Named pipes – FIFO

ready in filesystem,
needs to be opened with RDONLY or WRONLY,
request for opening pipe not already opened in complementary
mode suspends and waits for other opening in second mode.
Figure :)

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Named pipes – Buffers Xenomai

A buffer is a lightweight IPC mechanism, implementing a fast,


one-way producer-consumer data path. All messages written are
buffered in a single memory area in strict FIFO order, until read
either in blocking or non-blocking mode.
atomic handling on write side i.e. no interleave, no short
writes

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Shared memory

1 opening or creating shared memory file with shm_open,


2 setting the size of shared memory ftruncate(),
3 system call for maping files in memory mmap(),
4 using shared memory read()/write
5 deleting mapping munmap()
Figure :)

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Shared memory – Xenomai


Heap services
Heaps are regions of memory used for dynamic memory allocation
in a time-bounded fashion.

1 RT HEAP heap ;
2 char * heap buffer ;
3 ...
4 r t h e a p c r e a t e (&heap , ” heap ” , 1 0 2 4 , H SHARED) ;
5 r t h e a p a l l o c (&heap , 0 , TM NONBLOCK, ( v o i d * * )&
heap buffer ) ;
6 ...
7 memcpy ( h e a p b u f f e r , b u f f e r , BUFF LEN ) ;
8 ...
9 r t h e a p d e l e t e (& heap ) ; rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Signals

Show and code :)

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Message Queues a.k.a. mailboxes

asynchronous,
buffered,
limitations.

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Message Queues

Show and code :)

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Serialization

process of turning an object and its state in memory into a stream


of bytes for storing or sending through the network.

Use cases
messaging,
data storage,
calling a remote procedures (SOAP),
objects distribution, CORBA, COM,
detecting changes in time0varying data.
rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization

Message Queues – Xenomai

Message queueing is a method by which real-time tasks can


exchange or pass data through a Xenomai-managed queue of
messages. rt queue create()

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Timers – POSIX
RTOS services Timers – Xenomai
Timers Alarms – Xenomai

Timers – POSIX

RTC concept – used as reference,


using internal timing source – timers,
external time source.

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Timers – POSIX
RTOS services Timers – Xenomai
Timers Alarms – Xenomai

Timers – POSIX

modes of operation in embedded (ISR)


PWM,
Output Compare,
Input Capture,
timing.
Figure

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Timers – POSIX
RTOS services Timers – Xenomai
Timers Alarms – Xenomai

Timers – POSIX
SIGALARM
POSIX provided real-time programmable timer for each process. It
is called an alarm, is programmed using seconds and when
triggering sends signal SIGALARM.

sleep
method for suspending the process for given number of seconds.
Process during this stage is in standby state; normally it is used for
waiting for resources, blocks, IO operation.
Sleep can end faster that the set number of seconds and it is
possible when process receives signal. In such case sleep returns
number of not used seconds. rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Timers – POSIX
RTOS services Timers – Xenomai
Timers Alarms – Xenomai

Timers – POSIX
Timers
POSIX provides at least 3 timers, which generate signals when
”fired”:
ITIMER REAL,
ITIMER VIRTUAL,
ITIMER PROF,
1 #i n c l u d e <s y s / t i m e . h>
2
3 i n t g e t t i m e r ( i n t which , struct itimerval * value ) ;
4 i n t s e t i t i m e r ( i n t which , c o n s t s t r u c t i t i m e r v a l *
r e s t r i c t value , s t r u c t i t i m e r v a l * r e s t r i c t ovalue ) ;
rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Timers – POSIX
RTOS services Timers – Xenomai
Timers Alarms – Xenomai

Timers – Xenomai
Timers
1 #i n c l u d e < n a t i v e / t a s k . h>
2 #i n c l u d e < n a t i v e / t i m e r . h>
3 #i n c l u d e <r t d k . h>
4
5 c o n s t l o n g l o n g SLEEP TIME = 1 0 0 0 0 0 0 0 0 0 ; / * 1 000 000
000 n s = 1 s * /
6
7 RT TASK t a s k 1 ;
8 RTIME t i m e 1 ;
9 r t t a s k s e t p e r i o d i c (NULL , TM NOW, SLEEP TIME ) ;
10 time1 = r t t i m e r r e a d () ;
11 r t t a s k w a i t p e r i o d (NULL) ;
12 rys/CyRobekow

It is a part of Alchemi API


dr inż. Mateusz module.Real-time Operating Systems
Cholewiński Lecture 6
Last week Timers – POSIX
RTOS services Timers – Xenomai
Timers Alarms – Xenomai

Alarms – Xenomai

Alarms are general-purpose watchdog timers. Alchemy tasks may


create any number of alarms and use them to run a user-defined
handler, after a specified initial delay has elapsed.
1 i n t r t a l a r m c r e a t e ( RT ALARM * alarm , c o n s t c h a r *
name , v o i d ( * ) ( v o i d * a r g ) h a n d l e r , v o i d * arg )

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6


Last week Timers – POSIX
RTOS services Timers – Xenomai
Timers Alarms – Xenomai

Bibliography

1 https://xenomai.org/documentation/xenomai-3/html/
xeno3prm/
2 http://sequoia.ict.pwr.wroc.pl/~witold/opsys

rys/CyRobekow

dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy