Skip to content
Snippets Groups Projects
Commit 5691809b authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Vorbereitung 22.4.2024

parent 1deab766
No related branches found
No related tags found
No related merge requests found
obj-m += hellomod-1.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
obj-m += hellomod-2.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
File added
% bs-20240415.pdf - Lecture Slides on Operating Systems
% Copyright (C) 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
\documentclass[10pt,t]{beamer}
\usepackage{pgslides}
\usepackage{tikz}
\title{Treiberentwicklung,\\[\medskipamount]Echtzeit- und Betriebssysteme}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{22.\ April 2024}
\begin{document}
\maketitleframe
%\nosectionnonumber{\inserttitle}
\nosectionnonumber{Treiberentwicklung, Echtzeit- und Betriebssysteme}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\begin{itemize}
\color{medgreen}
\item[1.1] Was ist ein Betriebssystem?
\item[1.2] Zu dieser Lehrveranstaltung
\end{itemize}
\item[\textbf{2}] \textbf{Unix}
\begin{itemize}
\color{medgreen}
\item[2.1] Grundkonzepte
\item[2.2] Die Kommmandozeile: Grundlagen
\item[2.3] Dateisysteme
\item[2.4] Ein- und Ausgabeströme
\item[2.5] Pipes
\item[2.6] Verzweigungen und Schleifen
\end{itemize}
\item[\textbf{3}] \textbf{Treiberentwicklung}
\begin{itemize}
\color{red}
\item[3.1] Mikrocontroller
\item[3.2] Betriebssysteme ohne Speicherschutz
\item[3.3] Linux-Kernel-Module
\end{itemize}
\vspace{-\smallskipamount}
\item[\textbf{\dots}]
\end{itemize}
\end{frame}
\setcounter{section}{2}
\section{Treiberentwicklung}
\subsection{Mikrocontroller}
\subsubsection{I/O-Ports}
\begin{frame}[fragile]
\showsection
\showsubsection
% \showsubsubsection
% \vspace*{-1.5\medskipamount}
% {\normalsize\textbf{\color{structure}3.1.2\quad Interrupts}}
\medskip
Kommunikation mit externen Geräten
\bigskip
\begin{center}
\includegraphics{io-ports-and-interrupts.pdf}
\end{center}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\showsubsubsection
In Output-Port schreiben = Aktoren ansteuern
Beispiel: LED
\medskip
\begin{lstlisting}
#include <avr/io.h>
...
DDRC = 0x70;
PORTC = 0x40;
\end{lstlisting}
\begin{picture}(0,0)
\put(3,0.67){\begin{minipage}{3cm}
\color{red}%
binär: 0111\,0000\\
binär: 0100\,0000
\end{minipage}}
\put(10,0.67){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}}
\end{picture}
\bigskip
\lstinline{DDR} = Data Direction Register\\
Bit = 1 für Output-Port\\
Bit = 0 für Input-Port
\bigskip
\emph{Details: siehe Datenblatt und Schaltplan}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\showsubsubsection
Aus Input-Port lesen = Sensoren abfragen
Beispiel: Taster
\medskip
\begin{lstlisting}
#include <avr/io.h>
...
DDRC = 0xfd;
while ((PINC & 0x02) == 0)
; /* just wait */
\end{lstlisting}
\begin{picture}(0,0)(-1.5,-0.42)
\put(3,0.67){\begin{minipage}{3cm}
\color{red}%
binär: 1111\,1101\\
binär: 0000\,0010
\end{minipage}}
\put(10,0.67){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}}
\end{picture}
\bigskip
\lstinline{DDR} = Data Direction Register\\
Bit = 1 für Output-Port\\
Bit = 0 für Input-Port
\bigskip
\emph{Details: siehe Datenblatt und Schaltplan}
\bigskip
Praktikumsaufgabe in \emph{Hardwarenahe Programmierung\/}: Druckknopfampel
\end{frame}
\subsubsection{Interrupts}
\begin{frame}[fragile]
\showsubsection
\showsubsubsection
Externes Gerät ruft (per Stromsignal) Unterprogramm auf
Zeiger hinterlegen: "`Interrupt-Vektor"'
Beispiel: eingebaute Uhr\hfill
\makebox(0,0)[tr]{%
\only<1->{\begin{minipage}[t]{4.7cm}
\vspace*{-0.3cm}%
statt Zählschleife (\lstinline{_delay_ms}):\\
Hauptprogramm kann\\
andere Dinge tun
\end{minipage}}%
}
\medskip
\begin{lstlisting}
#include <avr/interrupt.h>
...
ISR (TIMER0B_COMP_vect)
{
PORTD ^= 0x40;
}
\end{lstlisting}
\begin{picture}(0,0)
\color{red}
\put(1.9,3.1){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-1.4,-1.0);}}}
\put(2.0,3.2){\makebox(0,0)[l]{"`Dies ist ein Interrupt-Handler."'}}
\put(2.3,2.6){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-0.6,-0.55);}}}
\put(2.4,2.6){\makebox(0,0)[l]{Interrupt-Vektor darauf zeigen lassen}}
\end{picture}
Initialisierung über spezielle Ports:
\lstinline{TCCR0B}, \lstinline{TIMSK0}
\bigskip
\emph{Details: siehe Datenblatt und Schaltplan}
\vspace*{-2.5cm}\hfill
{\color{red}Herstellerspezifisch!}%
\hspace*{1cm}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\showsubsubsection
Externes Gerät ruft (per Stromsignal) Unterprogramm auf
Zeiger hinterlegen: "`Interrupt-Vektor"'
Beispiel: Taster\hfill
\makebox(0,0)[tr]{%
\begin{minipage}[t]{4.7cm}
\vspace*{-0.3cm}%
statt \newterm{Busy Waiting\/}:\\
Hauptprogramm kann\\
andere Dinge tun
\end{minipage}}
\medskip
\begin{lstlisting}
#include <avr/interrupt.h>
...
ISR (INT0_vect)
{
PORTD ^= 0x40;
}
\end{lstlisting}
\medskip
Initialisierung über spezielle Ports:
\lstinline{EICRA}, \lstinline{EIMSK}
\bigskip
\emph{Details: siehe Datenblatt und Schaltplan}
\vspace*{-2.5cm}\hfill
{\color{red}Herstellerspezifisch!}%
\hspace*{1cm}
\end{frame}
\subsubsection{volatile-Variable}
\begin{frame}[fragile]
\showsubsection
\showsubsubsection
Externes Gerät ruft (per Stromsignal) Unterprogramm auf
Zeiger hinterlegen: "`Interrupt-Vektor"'
Beispiel: Taster
\vspace*{-2.5pt}
\begin{minipage}[t]{5cm}
\begin{onlyenv}<1>
\begin{lstlisting}[gobble=8]
¡#include <avr/interrupt.h>
...
uint8_t key_pressed = 0;
ISR (INT0_vect)
{
key_pressed = 1;
}¿
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<2>
\begin{lstlisting}[gobble=8]
¡#include <avr/interrupt.h>
...
volatile uint8_t key_pressed = 0;
ISR (INT0_vect)
{
key_pressed = 1;
}¿
\end{lstlisting}
\end{onlyenv}
\end{minipage}\hfill
\begin{minipage}[t]{6cm}
\begin{lstlisting}[gobble=6]
¡int main (void)
{
...
while (1)
{
while (!key_pressed)
; /* just wait */
PORTD ^= 0x40;
key_pressed = 0;
}
return 0;
}¿
\end{lstlisting}
\end{minipage}
\pause
\begin{picture}(0,0)
\color{red}
\put(10.3,4.0){\makebox(0,0)[b]{\begin{minipage}{6cm}
\begin{center}
\textbf{volatile}:\\
Speicherzugriff\\
nicht wegoptimieren
\end{center}
\end{minipage}}}
\put(10.3,3.95){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-0.5,-0.9);}}}
\end{picture}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\showsubsubsection
Was ist eigentlich \lstinline{PORTD}?
\bigskip
\pause
\lstinline[style=cmd]{avr-gcc -Wall -Os -mmcu=atmega328p blink-3.c -E}
\bigskip
\pause
\lstinline{PORTD = 0x01;}\\
\textarrow\quad
\lstinline[style=terminal]{(*(volatile uint8_t *)((0x0B) + 0x20)) = 0x01;}\\
\pause
\begin{picture}(0,2)(0,-1.7)
\color{red}
\put(5.75,0.3){$\underbrace{\rule{2.95cm}{0pt}}_{\mbox{Zahl: \lstinline|0x2B|}}$}
\pause
\put(1.55,0.3){$\underbrace{\rule{4.0cm}{0pt}}_{\mbox{\shortstack[t]{Umwandlung in Zeiger\\
auf \lstinline|volatile uint8_t|}}}$}
\pause
\put(1.32,-1){\makebox(0,0)[b]{\tikz{\draw[-latex](0,0)--(0,1.3)}}}
\put(1.12,-1.1){\makebox(0,0)[tl]{Dereferenzierung des Zeigers}}
\end{picture}
\pause
\textarrow\quad
\lstinline|volatile uint8_t|-Variable an Speicheradresse \lstinline|0x2B|
\pause
\bigskip
\bigskip
\textarrow\quad
\lstinline|PORTA = PORTB = PORTC = PORTD = 0| ist eine schlechte Idee.
\end{frame}
\subsection{Betriebssysteme ohne Speicherschutz}
\begin{frame}[fragile]
% \showsection
\showsubsection
\begin{itemize}
\item
FreeDOS (früher: PC-DOS, MS-DOS, DR-DOS, Novell-DOS,\\
aber auch Apple-DOS, Commodore-DOS, \dots):\\[\smallskipamount]
Direkter Zugriff auf Speicher, I/O-Ports und Interrupts
\pause
\medskip
\item
Bildschirm (Textmodus): ab Speicherzelle \lstinline{B800:0000}\\
abwechselnd Zeichen (CP\,437) und Attribut (Farbe, Hintergrund)
\pause
\medskip
\item
Bildschirm (Grafikmodus): später
\end{itemize}
\end{frame}
\subsection{Linux-Kernel-Module}
\begin{frame}[fragile]
% \showsection
\showsubsection
\begin{itemize}
\item
\lstinline{#include <linux/module.h>}\\
\lstinline{#include <linux/kernel.h>}
\item
Zwei "`Hauptprogramme"': \lstinline{init_module()}, \lstinline{cleanup_module()}
\item
\lstinline{printk()} statt \lstinline{printf()}
\item
Compilieren mit speziellem \file{Makefile}
\pause
\item
Angabe der Lizenz ist wichtig: \lstinline{MODULE_LICENSE()}
\end{itemize}
\end{frame}
\end{document}
/*
* hello-1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
/*
* hello-2.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
MODULE_LICENSE("GPL");
int init_module(void)
{
printk(KERN_INFO "Hello world 2.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 2.\n");
}
../common/io-ports-and-interrupts.pdf
\ No newline at end of file
../common/logo-hochschule-bochum-cvh-text.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
../common/pgslides.sty
\ No newline at end of file
This diff is collapsed.
File added
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage{pstricks,pst-node}
\pagestyle{empty}
\begin{document}
\psset{unit=1cm}%
\begin{pspicture}(0,0)(10,6)
\rput(0,0){\psframe[framearc=0.25](2,5)}
\rput(1,4.5){\makebox(0,0)[t]{Prozessor}}
\rput(2.0,3.7){\pnode{p0}}
\rput(2.0,3.3){\pnode{q0}}
\rput(2.0,1.0){\pnode{i0}}
\rput(2.12,1.2){\pnode{j0}}
\rput(2.02,1.3){\pnode{k0}}
\rput(2.12,1.4){\pnode{l0}}
\rput(3.5,1.4){\pnode{m0}}
\rput(8,0){\psframe[framearc=0.25](2,5)}
\rput(9,4.5){\makebox(0,0)[t]{\shortstack{externes\\Gerät}}}
\rput(8.0,3.7){\pnode{p1}}
\rput(7.88,3.3){\pnode{q1}}
\rput(7.98,3.2){\pnode{r1}}
\rput(7.88,3.1){\pnode{s1}}
\rput(6.5,3.1){\pnode{t1}}
\rput(8.0,1.0){\pnode{i1}}
\rput(8.0,1.2){\pnode{j1}}
\ncline{->}{p0}{p1}
\ncline{q0}{q1}
\nccurve[angleB=90]{q1}{r1}
\nccurve[angleA=-90]{r1}{s1}
\ncline{->}{s1}{t1}
\rput(2.2,3.8){\makebox(0,0)[lb]{Prozessor schreibt in Output-Port}}
\rput(2.2,3.1){\makebox(0,0)[lt]{Prozessor liest Input-Port}}
\ncline{->}{i1}{i0}
\rput(7.8,1.1){\makebox(0,0)[rb]{externes Gerät ruft Interrupt auf}}
\end{pspicture}
\end{document}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment