feat: add lab-rv32i-freertos-semaphore-notify card

This commit is contained in:
user
2026-07-21 19:14:20 +02:00
commit 3ae96a0d06
67 changed files with 37159 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
# K12 — Semaphores and task notifications
## Position
- Series: FreeRTOS C++
- Lesson: L11, card K12
- Duration: 30 minutes
- Waiter priority 3, signaler priority 2
- Static semaphore controls; notification state in waiter TCB
## Outcome
The student selects a binary semaphore, counting semaphore or direct task
notification from the communication cardinality and state semantics, then
proves blocked/wake transitions and clear/value policy.
## Lesson plan
| Time | Mode | Evidence |
| --- | --- | --- |
| 05 | binary | empty 0, give 1, second give false, take 0 |
| 510 | counting | max/initial 2, take to 1 then 0 |
| 1015 | blocked waiter | third take blocks; signaler observes eBlocked |
| 1520 | release | one give wakes exactly one waiter; token consumed |
| 2025 | notification count | give/take returns 1, state lives in TCB |
| 2530 | notification value | explicit overwrite/wait yields 0xA5A55A5A |
## Acceptance
- binary and counting bounds are enforced;
- both handles equal caller static controls and heap delta is zero;
- waiter is blocked at all three intended waits;
- counting release is consumed immediately, leaving count 0;
- notification give/take returns exactly 1;
- explicit `overwrite` action transfers 0xA5A55A5A;
- event order connects counting block/release and both notification phases;
- target exits with PASS.
## Main traps
1. A semaphore signals availability; it does not carry a data record.
2. Notification targets one specific task/slot, not arbitrary consumers.
3. Clear-on-exit versus decrement changes binary/counting notification meaning.
4. Wrong action or clear mask can silently lose bits/value.
5. Identical wake behavior does not imply identical storage/cardinality.
+344
View File
@@ -0,0 +1,344 @@
% Generated from json/card_source.json by tools/render_card.py.
% Do not edit manually; update the JSON and regenerate.
\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[polish]{babel}
\usepackage{csquotes}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xcolor}
\usepackage[a4paper,left=2.15cm,right=2.15cm,top=0.5cm,bottom=0.5cm,headheight=24mm,headsep=3mm,includehead]{geometry}
\usepackage{eso-pic}
\usepackage{marginnote}
\usepackage{array}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{pdflscape}
\usepackage{float}
\usepackage{silence}
\WarningFilter{soulutf8}{This package is obsolete}
\usepackage{pdfcomment}
\usepackage{enumitem}
\usepackage{needspace}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{microtype}
\usepackage[most]{tcolorbox}
\usepackage{qrcode}
\IfFileExists{references.bib}{%
\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}%
\addbibresource{references.bib}%
}{}
\hypersetup{hidelinks}
\IfFileExists{build-meta.tex}{%
\input{build-meta.tex}%
}{%
\newcommand{\BuildCommit}{lokalna}%
}
\newcommand{\DocumentAuthor}{M. Pabiszczak}
\newcommand{\DocumentYear}{2026}
\newcommand{\CardSeries}{freertos-cpp}
\newcommand{\CardNumber}{12}
\newcommand{\CardCount}{16}
\newcommand{\CardSlug}{semaphore-notify}
\newcommand{\CardVersion}{v00.01}
\newcommand{\DocumentUUID}{fcb6107c-268f-4e86-a8cc-092e5875f6f0}
\newcommand{\EmptyCheck}{\(\square\)}
\newcommand{\EscAnswerLines}[1][3]{\par\noindent\dotfill\par\noindent\dotfill\par\noindent\dotfill}
\newcommand{\EscWriteRow}[1][2.8em]{\rule{0pt}{#1}}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0.45em}
\setlength{\headheight}{24mm}
\setlength{\headsep}{3mm}
\setlength{\footskip}{8mm}
\setlength{\marginparwidth}{1.5cm}
\setlength{\marginparsep}{0.25cm}
\renewcommand{\arraystretch}{1.22}
% Margin separator lines disabled for layout trial.
\newcommand{\ESCPageResourceHeader}{%
\begingroup%
\setlength{\parskip}{0pt}%
\setlength{\fboxsep}{0pt}%
\setlength{\fboxrule}{0.35pt}%
\setlength{\arrayrulewidth}{0.35pt}%
\noindent\fbox{%
\begin{minipage}[c][23.5mm][c]{\dimexpr\textwidth-2\fboxrule\relax}%
\begin{minipage}[c][23mm][c]{\dimexpr\linewidth-24mm-0.35pt\relax}%
\setlength{\tabcolsep}{0pt}%
\renewcommand{\arraystretch}{0}%
\begin{tabularx}{\linewidth}{@{}p{\dimexpr0.50000000\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.15126050\linewidth-\arrayrulewidth\relax}|X@{}}%
\parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries TITLE}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{7.7}{7.9}\selectfont\ttfamily\bfseries Semaphores and Task Notifications}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries VER.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.6}{6.8}\selectfont\ttfamily\bfseries v00.01}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries DATETIME}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries 2026-07-19T00:00:00+02:00}\hspace{0.45mm}}\par} \\%
\end{tabularx}%
\par\nointerlineskip%
\hrule height0.35pt%
\nointerlineskip%
\begin{tabularx}{\linewidth}{@{}p{\dimexpr0.50000000\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.25210084\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.14285714\linewidth-\arrayrulewidth\relax}|X@{}}%
\parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries PROJECT}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{7.7}{7.9}\selectfont\ttfamily\bfseries Freestanding C++ nad FreeRTOS}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries SERIES}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries FreeRTOS C++}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries CARD}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries 12/16}\hspace{0.45mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{3.2}{3.4}\selectfont\ttfamily\bfseries SHEET}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{6.4}{6.6}\selectfont\ttfamily\bfseries \thepage/\pageref{LastPage}}\hspace{0.45mm}}\par} \\%
\end{tabularx}%
\par\nointerlineskip%
\hrule height0.35pt%
\nointerlineskip%
\begin{tabularx}{\linewidth}{@{}p{\dimexpr0.05882353\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.05042017\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.14705882\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.09243697\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.07563025\linewidth-\arrayrulewidth\relax}|p{\dimexpr0.07563025\linewidth-\arrayrulewidth\relax}|X@{}}%
\parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries SUBJ.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries Inf.}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries PROG.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries CORE}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries SCOPE}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries LEVEL}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hspace{0.15mm}{\fontsize{2.85}{3}\selectfont\ttfamily\bfseries POS.}\par\nointerlineskip\vspace{0.12mm}\noindent\makebox[\linewidth][r]{{\fontsize{4.45}{4.65}\selectfont\ttfamily\bfseries}\hspace{0.15mm}}\par} & \parbox[c][5.19414mm][c]{\linewidth}{\hbox to\linewidth{\hspace{0.35mm}{\fontsize{3.4}{3.75}\selectfont\ttfamily\bfseries GITEA UUID}\hfill{\fontsize{3.4}{3.75}\selectfont\ttfamily fcb6107c-268f-4e86-a8cc-092e5875f6f0}\hspace{0.35mm}}\par\nointerlineskip\hbox to\linewidth{\hspace{0.35mm}{\fontsize{3.4}{3.75}\selectfont\ttfamily\bfseries CARD UUID} {\fontsize{3.4}{3.75}\selectfont\ttfamily fcb6107c-268f-4e86-a8cc-092e5875f6f0}\hfill{\fontsize{3.4}{3.75}\selectfont\ttfamily\bfseries AUTHOR M. Pabiszczak}\hspace{0.35mm}}} \\%
\end{tabularx}%
\par\nointerlineskip%
\hrule height0.35pt%
\nointerlineskip%
\begin{tabularx}{\linewidth}{@{}X@{}}%
\parbox[c][3.46276mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{4.5}{4.85}\selectfont\ttfamily\bfseries GITEA} {\fontsize{4.5}{4.85}\selectfont\ttfamily\href{https://zsl-gitea.mpabi.pl/edu-freertos-cpp/lab-rv32i-freertos-semaphore-notify}{\nolinkurl{https://zsl-gitea.mpabi.pl/edu-freertos-cpp/lab-rv32i-freertos-semaphore-notify}}}} \\%
\end{tabularx}%
\par\nointerlineskip%
\hrule height0.35pt%
\nointerlineskip%
\begin{tabularx}{\linewidth}{@{}X@{}}%
\parbox[c][3.46276mm][c]{\linewidth}{\hspace{0.45mm}{\fontsize{4.5}{4.85}\selectfont\ttfamily\bfseries HTML} {\fontsize{4.5}{4.85}\selectfont\ttfamily\href{}{\nolinkurl{}}}} \\%
\end{tabularx}%
\end{minipage}%
\vrule width0.35pt%
\begin{minipage}[c][23mm][c]{24mm}\centering%
{\tiny QR wyłączony}%
\end{minipage}%
\end{minipage}%
}%
\endgroup%
}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{\ESCPageResourceHeader}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\newcommand{\ESCMarginTag}[4]{%
\hspace*{#1}\textcolor{#2}{#3~#4}%
}
\newcommand{\ESCSectionBlockStart}{%
\Needspace{8\baselineskip}%
\par\vspace{0.35em}%
\noindent\textcolor{black!28}{\rule{\textwidth}{0.35pt}}%
\par\vspace{0.15em}%
}
\newcommand{\ESCSectionBlockEnd}{%
\par\vspace{0.25em}%
\noindent\textcolor{black!18}{\rule{\textwidth}{0.25pt}}%
\par\vspace{0.45em}%
}
\newcommand{\ESCTinyStepSeparator}{%
\par\vspace{0.10em}%
\noindent{\color{black!18}\leaders\hbox{\rule{0.60em}{0.22pt}\hspace{0.38em}}\hfill\kern0pt}%
\par\vspace{0.10em}%
}
\newtcolorbox{ESCTaskFrame}[1]{enhanced,breakable,arc=0pt,boxrule=0.35pt,colback=white,colframe=black,boxsep=0pt,left=1.4mm,right=1.4mm,top=0.8mm,bottom=0.8mm,colbacktitle=black!7,coltitle=black,title={\ttfamily\bfseries TASK\quad #1}}
\newtcolorbox{ESCBlockFrame}[1]{enhanced,breakable,arc=0pt,boxrule=0.35pt,colback=white,colframe=black!55,boxsep=0pt,left=1.0mm,right=1.0mm,top=0.6mm,bottom=0.6mm,colbacktitle=black!4,coltitle=black,title={\ttfamily\bfseries BLOCK\quad #1}}
\newtcolorbox{ESCStepFrame}[1]{enhanced,breakable,arc=0pt,boxrule=0.35pt,colback=white,colframe=black!28,boxsep=0pt,left=0.8mm,right=0.8mm,top=0.45mm,bottom=0.45mm,colbacktitle=black!2,coltitle=black,title={\ttfamily STEP\quad #1}}
\newtcolorbox{ESCConclusionFrame}{enhanced,breakable,arc=0pt,boxrule=0.45pt,colback=blue!2,colframe=blue!45!black,boxsep=0pt,left=1.2mm,right=1.2mm,top=0.7mm,bottom=0.7mm,colbacktitle=blue!7,coltitle=black,title={\ttfamily\bfseries WNIOSEK}}
\newcommand{\ESCLearningTreeWidget}{%
\reversemarginpar
\marginnote[%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\begin{minipage}[t]{\marginparwidth}%
\raggedright
{\bfseries\textcolor{black!65}{TECH}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\hspace*{0.28em}\textcolor{orange!85!black}{EK~LOCAL~DBG.SYNC}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.01}{Mierzy count, blocked state, wake sequence i TCB notification value.}}\par%
\hspace*{0.54em}\textcolor{blue!70!black}{KW~LOCAL~DBG.SYNC}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.01}{Pokazuje 0/1, 2/1/0, take=1, overwrite value i PASS.}}\par%
\end{minipage}%
}%
\end{minipage}%
]{}
\normalmarginpar
\marginnote{%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\hspace*{0.06cm}%
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
\raggedright
{\bfseries\textcolor{black!65}{OG}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\hspace*{0.28em}\textcolor{green!50!black}{EN~LOCAL~EN~RTOS.SYNC}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.01}{Analizuje cardinality i semantykę signal/count/value.}}\par%
\hspace*{0.54em}\textcolor{blue!70!black}{KW~LOCAL~KW~RTOS.SYNC}\textcolor{black!48}{\pdftooltip[width=\textwidth]{.01}{Dobiera mechanizm bez przypisywania semaphore payloadu ani notification wielu konsumentów.}}\par%
\end{minipage}%
}%
\end{minipage}%
}
}
\begin{document}
\sloppy
\vspace{1.0em}
\noindent{\Large\bfseries Cel karty}\par
\vspace{0.35em}
Uczeń wybiera binary/counting semaphore lub task notification na podstawie cardinality i stanu, a następnie dowodzi block/wake, bounds oraz action i clear policy.
\vspace{0.8em}
\noindent\textcolor{black!25}{\rule{\textwidth}{0.35pt}}
\vspace{0.7em}
\noindent{\Large\bfseries Zakres karty}\par
\vspace{0.35em}
Semaphore nie przechowuje payloadu. Notification jest kanałem jednego taska/TCB slotu; nie zastępuje kolejki wielu odbiorców.
\vspace{0.8em}
\noindent\textcolor{black!25}{\rule{\textwidth}{0.35pt}}
\clearpage
\ESCSectionBlockStart
\section{Binary i counting bounds}
\reversemarginpar
\marginnote[%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\begin{minipage}[t]{\marginparwidth}%
\raggedright
{\bfseries\textcolor{black!65}{TECH}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
]{}[-3.1em]
\normalmarginpar
\marginnote{%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\hspace*{0.06cm}%
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
\raggedright
{\bfseries\textcolor{black!65}{OG}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
}[-3.1em]
\begingroup
\scriptsize\ttfamily\color{black!60}\sloppy
\noindent drzewka: \pdftooltip[width=\textwidth]{D1}{K12.WE01.TECH.LOCAL.DBG.SYNC.01 | WE 01: Semaphores i notifications. Dobór i implementacja\textCR synchronizacji według cardinality, count/value i storage. | EK LOCAL DBG.SYNC.01: Mierzy\textCR count, blocked state, wake sequence i TCB notification value. | KW LOCAL DBG.SYNC.01:\textCR Pokazuje 0/1, 2/1/0, take=1, overwrite value i PASS.}\par
\vspace{0.10em}%
\noindent K1: Potwierdź bounds obu semaphore.\quad D1\par
\ESCTinyStepSeparator
\noindent K2: Pokaż eBlocked i natychmiastowy handoff count 0.\quad D1\par
\par\vspace{0.18em}%
\endgroup
Zmierz binary 0-1-0 i counting 2-1-0, odrzuć give przy maximum oraz zablokuj trzeci take.
\ESCSectionBlockEnd
\ESCSectionBlockStart
\section{Notification count i value}
\reversemarginpar
\marginnote[%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\begin{minipage}[t]{\marginparwidth}%
\raggedright
{\bfseries\textcolor{black!65}{TECH}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
]{}[-3.1em]
\normalmarginpar
\marginnote{%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\hspace*{0.06cm}%
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
\raggedright
{\bfseries\textcolor{black!65}{OG}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
}[-3.1em]
\begingroup
\scriptsize\ttfamily\color{black!60}\sloppy
\noindent drzewka: \pdftooltip[width=\textwidth]{D1}{K12.WE01.TECH.LOCAL.DBG.SYNC.01 | WE 01: Semaphores i notifications. Dobór i implementacja\textCR synchronizacji według cardinality, count/value i storage. | EK LOCAL DBG.SYNC.01: Mierzy\textCR count, blocked state, wake sequence i TCB notification value. | KW LOCAL DBG.SYNC.01:\textCR Pokazuje 0/1, 2/1/0, take=1, overwrite value i PASS.}\par
\vspace{0.10em}%
\noindent K1: Zapisz pending checkpoint i take result 1.\quad D1\par
\ESCTinyStepSeparator
\noindent K2: Odbierz overwrite 0xA5A55A5A.\quad D1\par
\par\vspace{0.18em}%
\endgroup
Zastąp jednoodbiorczy wake przez TCB give/take, a potem prześlij jawną wartość przez overwrite/wait.
\ESCSectionBlockEnd
\ESCSectionBlockStart
\section{Cardinality, storage i clear policy}
\reversemarginpar
\marginnote[%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\begin{minipage}[t]{\marginparwidth}%
\raggedright
{\bfseries\textcolor{black!65}{TECH}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
]{}[-3.1em]
\normalmarginpar
\marginnote{%
\begin{minipage}{\marginparwidth}%
\raggedright
{\fontsize{3.55}{3.95}\selectfont\ttfamily
\hspace*{0.06cm}%
\begin{minipage}[t]{\dimexpr\marginparwidth-0.06cm\relax}%
\raggedright
{\bfseries\textcolor{black!65}{OG}\par}%
\vspace{0.08em}%
\hspace*{0.00em}\textcolor{red}{WE~01}\textcolor{black!48}{}\par%
\end{minipage}%
}%
\end{minipage}%
}[-3.1em]
\begingroup
\scriptsize\ttfamily\color{black!60}\sloppy
\noindent drzewka: \pdftooltip[width=\textwidth]{D1}{K12.WE01.OG.LOCAL.RTOS.SYNC.01 | WE 01: Semaphores i notifications. Dobór i implementacja\textCR synchronizacji według cardinality, count/value i storage. | EN LOCAL RTOS.SYNC.01: Analizuje\textCR cardinality i semantykę signal/count/value. | KW LOCAL RTOS.SYNC.01: Dobiera mechanizm bez\textCR przypisywania semaphore payloadu ani notification wielu konsumentów.}\par
\vspace{0.10em}%
\noindent K1: Dobierz mechanizm do trzech scenariuszy.\quad D1\par
\ESCTinyStepSeparator
\noindent K2: Uzasadnij one receiver i brak payloadu semaphore.\quad D1\par
\par\vspace{0.18em}%
\endgroup
Porównaj caller semaphore control z notification state w TCB i dobierz clear-on-exit lub decrement do binary/counting znaczenia.
\ESCSectionBlockEnd
\end{document}
+196
View File
@@ -0,0 +1,196 @@
\documentclass[10pt]{article}
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage[polish]{babel}
\usepackage[a4paper,margin=1.55cm]{geometry}
\usepackage{array,tabularx,booktabs,amsmath,amssymb,xcolor,listings,hyperref,fancyhdr,lastpage,enumitem}
\definecolor{accent}{HTML}{16324A}\definecolor{accentlight}{HTML}{EEF3F7}\definecolor{rulegray}{HTML}{D7DEE5}
\hypersetup{colorlinks=true,linkcolor=accent,urlcolor=blue}
\IfFileExists{build-meta.tex}{\input{build-meta.tex}}{\newcommand{\BuildCommit}{local}}
\newcommand{\PublisherDomain}{mpabi}
\newcommand{\CardArea}{inf}
\newcommand{\CardSeries}{freertos-cpp}
\newcommand{\CardNumber}{12}
\newcommand{\CardCount}{16}
\newcommand{\CardSlug}{semaphore-notify}
\newcommand{\CardVersion}{v00.01}
\newcommand{\DocumentUUID}{fcb6107c-268f-4e86-a8cc-092e5875f6f0}
\newcommand{\blank}[1]{\rule{#1}{.2pt}}
\lstset{language=C++,basicstyle=\ttfamily\scriptsize,columns=fullflexible,keepspaces=true,frame=single,breaklines=true,showstringspaces=false,numbers=none,backgroundcolor=\color{accentlight},rulecolor=\color{rulegray}}
\pagestyle{fancy}\fancyhf{}
\lhead{\textbf{K12 · FreeRTOS C++ · sync}}\rhead{\small L11 · semaphore vs TCB notify}
\lfoot{\scriptsize commit \BuildCommit}\cfoot{\scriptsize \thepage/\pageref{LastPage}}\rfoot{\scriptsize V11.3.0 / \CardVersion}
\setlength{\headheight}{14pt}\setlength{\footskip}{19pt}
\setlist[itemize]{nosep,leftmargin=1.45em}\setlist[enumerate]{nosep,leftmargin=1.65em}
\begin{document}\sloppy
\begin{center}
{\LARGE\bfseries Semafory i task notifications}\par
\vspace{.25em}{\large sygnał 0/1, licznik slotów i kanał jednego TCB}\par
\end{center}
\noindent\begin{tabularx}{\textwidth}{@{}p{1.65cm}Xp{1.75cm}X@{}}
\toprule
Karta & K12 / \CardCount & Czas & 30 minut \\
Platforma & Hazard3 / RV32I & Taski & waiter 3 / signaler 2 \\
Storage & static controls + TCB & Heap delta & 0 B \\
Wersja & \CardVersion & UUID karty & \texttt{fcb6107c-...} \\
\bottomrule
\end{tabularx}
\section*{Trzy podobne wakeupy, trzy różne kontrakty}
\noindent\begin{tabularx}{\textwidth}{@{}p{3.6cm}p{3.2cm}p{3.6cm}X@{}}
\toprule Typ & Stan & Odbiorcy & Payload \\
\midrule
Binary semaphore & 0 lub 1 & waiter obiektu & brak \\
Counting semaphore & 0..Max & waiterzy obiektu & count zasobu \\
Task notification & value/state w TCB & jeden task/slot & value lub bits \\
\bottomrule
\end{tabularx}
\noindent\fcolorbox{accent}{accentlight}{\begin{minipage}{.94\textwidth}
\textbf{Kontrakt K12.} Semaphore nie jest magazynem danych. Notification jest
adresowana do konkretnego taska, a action oraz clear/decrement policy są częścią
typu operacji, nie szczegółem do domyślenia.
\end{minipage}}
\section*{Plan 30 minut}
\noindent\begin{tabularx}{\textwidth}{@{}p{1.35cm}p{3.1cm}X@{}}
\toprule Czas & Tryb & Dowód \\
\midrule
0--5 & binary & 0--1--0; drugi give przy full=false \\
5--10 & counting & initial/max 2; take 2--1--0 \\
10--15 & block & trzeci take: waiter eBlocked \\
15--20 & release & jeden give budzi; token od razu zużyty \\
20--25 & notify count & TCB give/take zwraca 1 \\
25--30 & notify value & overwrite/wait daje 0xA5A55A5A \\
\bottomrule
\end{tabularx}
\section*{Wybór}
Jeden producent budzi jeden znany task bez payloadu: \blank{4cm}. Trzech
workerów konkuruje o dwa sloty: \blank{4cm}.
\newpage
\section{Binary i counting: granice count}
\noindent\begin{tabularx}{\textwidth}{@{}p{4.6cm}p{3.4cm}X@{}}
\toprule Binary krok & Predykcja & Odczyt \\
\midrule
po create & 0 & \blank{2.5cm} \\
po pierwszym give & 1 & \blank{2.5cm} \\
drugi give przy full & false / nadal 1 & \blank{2.5cm} \\
po take(0) & 0 & \blank{2.5cm} \\
\bottomrule
\end{tabularx}
\vspace{1em}
\noindent\begin{tabularx}{\textwidth}{@{}p{4.6cm}p{3.4cm}X@{}}
\toprule Counting krok & Predykcja & Odczyt \\
\midrule
max / initial & 2 / 2 & \blank{2.5cm} \\
give przy max & false / 2 & \blank{2.5cm} \\
po take 1 & 1 & \blank{2.5cm} \\
po take 2 & 0 & \blank{2.5cm} \\
take 3, portMAX delay & waiter Blocked & \blank{2.5cm} \\
signaler give / handoff & waiter wakes, count 0 & \blank{2.5cm} \\
\bottomrule
\end{tabularx}
\section{Dlaczego count po handoff nadal wynosi zero?}
Give przekazuje dostępność oczekującemu waiterowi. Ponieważ waiter ma wyższy
priorytet, natychmiast kończy zablokowany take i konsumuje token, zanim signaler
ponownie odczyta count.
Narysuj kolejność: waiter block, signaler give, waiter ready/run/take, signaler
resume.\\[.5em]\blank{16cm}\\[1em]\blank{16cm}
\section*{Storage}
Oba uchwyty muszą równać się caller \texttt{StaticSemaphore\_t} w .bss. Create
i destroy nie zmieniają heapu. Notification nie ma trzeciego control block:
value/state istnieją już w TCB waitera.
\newpage
\section{Notification jako count 1}
\begin{lstlisting}
freertos::TaskNotification target{waiter_handle};
target.give();
// in waiter:
uint32_t n = freertos::TaskNotification::take(true, timeout);
\end{lstlisting}
\noindent\begin{tabularx}{\textwidth}{@{}p{5cm}p{3.2cm}X@{}}
\toprule Pomiar & Predykcja & Odczyt \\
\midrule
waiter przed give & Blocked & \blank{2.5cm} \\
notification value po give & 1 pending & checkpoint / GDB \\
take clear-on-exit result & 1 & \blank{2.5cm} \\
value po take & 0 & \blank{2.5cm} \\
\bottomrule
\end{tabularx}
\section{Notification jako jawna wartość}
\begin{lstlisting}
target.notify(0xA5A55A5A,
freertos::NotificationAction::overwrite);
uint32_t value;
TaskNotification::wait_value(value, timeout);
\end{lstlisting}
\noindent\begin{tabularx}{\textwidth}{@{}p{5cm}p{3.2cm}X@{}}
\toprule Pomiar & Predykcja & Odczyt \\
\midrule
waiter przed notify & Blocked & \blank{2.5cm} \\
action & overwrite & \blank{2.5cm} \\
received value & \texttt{0xA5A55A5A} & \blank{2.5cm} \\
clear on exit & wszystkie bits & \blank{2.5cm} \\
\bottomrule
\end{tabularx}
\section*{Clear kontra decrement}
\texttt{take(true)} zeruje cały count i zachowuje się jak binary. Z
\texttt{take(false)} odejmuje jeden i zachowuje się jak counting. Co zwrócą dwa
kolejne take(false), gdy przed nimi wykonano trzy give?\\[.5em]\blank{16cm}
\section*{Ćwiczenie wyboru}
Dobierz mechanizm: (a) dwa wolne bufory DMA, (b) UART budzi konkretny parser,
(c) przycisk publikuje strukturę z timestampem.\\[.5em]\blank{16cm}\\[1em]
\blank{16cm}
\newpage
\section{Hazard3/GDB i zaliczenie}
\begin{lstlisting}[language=bash]
make check
riscv64-unknown-elf-gdb build/task01_semaphore_notify/prog.elf
b synchronization_debug_checkpoint
\end{lstlisting}
\begin{lstlisting}
p g_binary_initial_count
p g_binary_after_give
p g_binary_second_give
p g_counting_initial_count
p g_count_after_take1
p g_count_after_take2
p g_waiter_state_for_counting
p g_waiter_state_for_notification
p g_notification_pending_checkpoint
p g_notification_take_value
p/x g_notification_message_value
p g_sync_pass
\end{lstlisting}
\section*{Zaliczenie}
\begin{itemize}
\item $\square$ rozróżniam binary signal, counting slots i TCB notification;
\item $\square$ pokazuję binary 0--1--0 i odrzucony drugi give;
\item $\square$ pokazuję counting 2--1--0, Blocked i handoff;
\item $\square$ notification give/take zwraca dokładnie 1;
\item $\square$ overwrite/wait przenosi 0xA5A55A5A;
\item $\square$ wyjaśniam storage, cardinality i clear policy.
\end{itemize}
\section*{Wyjście}
Dlaczego notification nie zastąpi kolejki wielu konsumentów?\\[.5em]
\blank{16cm}\\[1em]
Dlaczego semaphore count nie jest payloadem aplikacji?\\[.5em]\blank{16cm}
\vfill
\noindent\textbf{Następna karta K13:} typed \texttt{EventBits}, wait any/all,
clear-on-exit oraz koordynacja stanu wielu tasków.
\end{document}