\doxysection{C:/\+\+Users/\+yoneda/\+\+Documents/\+\+Pico\+\_\+\+Projects/\+tinykernel/\+tinykernel/\+include/\+tinykernel/\+kernel.hpp ファイル} \label{kernel_8hpp}\index{C:/Users/yoneda/Documents/Pico\_Projects/tinykernel/tinykernel/include/tinykernel/kernel.hpp@{C:/Users/yoneda/Documents/Pico\_Projects/tinykernel/tinykernel/include/tinykernel/kernel.hpp}} {\ttfamily \+\#include $<$stdint.\+h$>$}\newline {\ttfamily \+\#include $<$stddef.\+h$>$}\newline {\ttfamily \+\#include "{}pico/\+runtime.\+h"{}}\newline \doxysubsubsection*{クラス} \begin{DoxyCompactItemize} \item struct \textbf{ tk::\+\+Task\+Handle} \begin{DoxyCompactList}\small\item\em タスクの識別ハンドル \end{DoxyCompactList}\item class \textbf{ tk::\+\+Preempt\+Guard} \begin{DoxyCompactList}\small\item\em プリエンプション禁止をスコープ単位で安全に管理する RAII クラス \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsubsection*{名前空間} \begin{DoxyCompactItemize} \item namespace \textbf{ tk} \item namespace \textbf{ tk::\+detail} \end{DoxyCompactItemize} \doxysubsubsection*{マクロ定義} \begin{DoxyCompactItemize} \item \+\#define \textbf{ TK\+\_\+\+TICKS\+\_\+\+PER\+\_\+\+SEC}~1000u \item \+\#define \textbf{ TK\+\_\+\+TIME\+\_\+\+SLICE\+\_\+\+MS}~10u \item \+\#define \textbf{ TK\+\_\+\+MAX\+\_\+\+TASKS}~32u \item \+\#define \textbf{ TK\+\_\+\+DEFAULT\+\_\+\+STACK\+\_\+\+SIZE}~(4 $\ast$ 1024) \item \+\#define \textbf{ TK\+\_\+\+TASK}(fn, prio) \begin{DoxyCompactList}\small\item\em リンク時にタスクを自動登録するマクロ (静的タスク登録) \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsubsection*{型定義} \begin{DoxyCompactItemize} \item using \textbf{ tk::\+\+Task\+Fn} = void ($\ast$)(void$\ast$ arg) \item using \textbf{ tk::\+task\+\_\+mask\+\_\+t} = uint32\+\_\+t \end{DoxyCompactItemize} \doxysubsubsection*{列挙型} \begin{DoxyCompactItemize} \item enum \textbf{ tk::\+\+Prio} : uint32\+\_\+t \{ \textbf{ tk::\+\+PRIO\+\_\+\+REALTIME} = 1 , \textbf{ tk::\+\+PRIO\+\_\+\+HIGH} = 5 , \textbf{ tk::\+\+PRIO\+\_\+\+NORMAL} = 9 , \textbf{ tk::\+\+PRIO\+\_\+\+LOW} = 13 \} \begin{DoxyCompactList}\small\item\em タスクの優先度レベル \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsubsection*{関数} \begin{DoxyCompactItemize} \item \textbf{ Task\+Handle} \textbf{ tk::\+create} (\textbf{ Task\+Fn} fn, void $\ast$arg=nullptr, uint32\+\_\+t prio=\textbf{ PRIO\+\_\+\+NORMAL}) \begin{DoxyCompactList}\small\item\em タスクを生成・登録します \end{DoxyCompactList}\item void \textbf{ tk::\+start} () \begin{DoxyCompactList}\small\item\em tinykernel スケジューラを起動します \end{DoxyCompactList}\item void \textbf{ tk::\+yield} () \begin{DoxyCompactList}\small\item\em 現在実行中のタスクを一時中断し、同優先度の他のタスクへ CPU を譲渡します \end{DoxyCompactList}\item void \textbf{ tk::\+sleep\+\_\+ms} (uint32\+\_\+t ms) \begin{DoxyCompactList}\small\item\em 現在のタスクを指定時間スリープさせます \end{DoxyCompactList}\item void \textbf{ tk::\+exit} (int code=0) \begin{DoxyCompactList}\small\item\em 現在のタスクを終了・破棄します \end{DoxyCompactList}\item uint64\+\_\+t \textbf{ tk::\+now\+\_\+ms} () \begin{DoxyCompactList}\small\item\em システム起動時からの経過時間をミリ秒単位で取得します \end{DoxyCompactList}\item bool \textbf{ tk::\+lock} () \begin{DoxyCompactList}\small\item\em ハードウェアスピンロックと全割り込み禁止によるクリティカルセクションに入ります \end{DoxyCompactList}\item void \textbf{ tk::\+unlock} (bool was\+\_\+enabled) \begin{DoxyCompactList}\small\item\em \doxyref{tk::\+lock()}{p.}{namespacetk_a6540aa25eb8562f6d6c8b37977d6cfe8} で入ったクリティカルセクションを抜けます \end{DoxyCompactList}\item void \textbf{ tk::\+preempt\+\_\+disable} () \begin{DoxyCompactList}\small\item\em 自コアのタスクスイッチ (プリエンプション) を一時的に禁止します \end{DoxyCompactList}\item void \textbf{ tk::\+preempt\+\_\+enable} () \begin{DoxyCompactList}\small\item\em 自コアのタスクスイッチ (プリエンプション) を再開します \end{DoxyCompactList}\item void \textbf{ tk::\+detail::\+static\+\_\+register} (const char $\ast$name, \textbf{ Task\+Fn} fn, uint32\+\_\+t prio) \item uint32\+\_\+t \textbf{ tk::\+detail::\+sched\+\_\+lock} () \item void \textbf{ tk::\+detail::\+sched\+\_\+unlock} (uint32\+\_\+t save) \item void \textbf{ tk::\+detail::\+block\+\_\+current\+\_\+task\+\_\+locked} () \item void \textbf{ tk::\+detail::\+wake\+\_\+task\+\_\+locked} (\textbf{ Task\+Handle} handle) \item uint8\+\_\+t \textbf{ tk::\+detail::\+current\+\_\+task\+\_\+slot} () \item uint8\+\_\+t \textbf{ tk::\+detail::\+find\+\_\+highest\+\_\+prio\+\_\+waiter} (\textbf{ task\+\_\+mask\+\_\+t} wait\+\_\+mask) \end{DoxyCompactItemize} \label{kernel_8hpp_doc-define-members} \doxysubsection{マクロ定義詳解} \index{kernel.hpp@{kernel.hpp}!TK\_DEFAULT\_STACK\_SIZE@{TK\_DEFAULT\_STACK\_SIZE}} \index{TK\_DEFAULT\_STACK\_SIZE@{TK\_DEFAULT\_STACK\_SIZE}!kernel.hpp@{kernel.hpp}} \doxysubsubsection{TK\_DEFAULT\_STACK\_SIZE} {\footnotesize\ttfamily \label{kernel_8hpp_afde197f9493ef5bdb5b715ce8b52148d} \+\#define TK\+\_\+\+DEFAULT\+\_\+\+STACK\+\_\+\+SIZE~(4 $\ast$ 1024)} 1タスクあたりのスタックサイズ (バイト) \index{kernel.hpp@{kernel.hpp}!TK\_MAX\_TASKS@{TK\_MAX\_TASKS}} \index{TK\_MAX\_TASKS@{TK\_MAX\_TASKS}!kernel.hpp@{kernel.hpp}} \doxysubsubsection{TK\_MAX\_TASKS} {\footnotesize\ttfamily \label{kernel_8hpp_a22e1d9f532aa297014c125110226443c} \+\#define TK\+\_\+\+MAX\+\_\+\+TASKS~32u} 最大タスク数 (スロット0は\+Core0アイドル、スロット1は\+Core1アイドル専用) \index{kernel.hpp@{kernel.hpp}!TK\_TASK@{TK\_TASK}} \index{TK\_TASK@{TK\_TASK}!kernel.hpp@{kernel.hpp}} \doxysubsubsection{TK\_TASK} {\footnotesize\ttfamily \label{kernel_8hpp_af57e92069cc01608150a45032c5ad473} \+\#define TK\+\_\+\+TASK(\begin{DoxyParamCaption}\item[{}]{fn}{, }\item[{}]{prio}{}\end{DoxyParamCaption})} {\bfseries 値:} \begin{DoxyCode}{0} \DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ tk\_register\_\#\#fn(\textcolor{keywordtype}{void})\ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)} \DoxyCodeLine{\ \ \ \ ::tk::detail::static\_register(\#fn,\ fn,\ (prio));\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)} \DoxyCodeLine{\}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)} \DoxyCodeLine{PICO\_RUNTIME\_INIT\_FUNC(tk\_register\_\#\#fn,\ \textcolor{stringliteral}{"{}ZZ900"{}});} \end{DoxyCode} リンク時にタスクを自動登録するマクロ (静的タスク登録) main() の開始前に Pico SDK のランタイムイニシャライザを利用してタスクを登録します。 \begin{DoxyParams}{引数} {\em fn} & タスク関数名 (void fn(void$\ast$ arg)) \\ \hline {\em prio} & タスク優先度 (例: \doxyref{tk::\+\+PRIO\+\_\+\+NORMAL}{p.}{namespacetk_a3d47fbd63b95ed3b46bed70c2fa1e50ea0e6779023b97999c2cef66ba1d4d1fca}) \\ \hline \end{DoxyParams} \index{kernel.hpp@{kernel.hpp}!TK\_TICKS\_PER\_SEC@{TK\_TICKS\_PER\_SEC}} \index{TK\_TICKS\_PER\_SEC@{TK\_TICKS\_PER\_SEC}!kernel.hpp@{kernel.hpp}} \doxysubsubsection{TK\_TICKS\_PER\_SEC} {\footnotesize\ttfamily \label{kernel_8hpp_a5c791131c5ad22ed87a8d3ca2cd57d33} \+\#define TK\+\_\+\+TICKS\+\_\+\+PER\+\_\+\+SEC~1000u} 1秒あたりのタイマースケジューラtick数 (Hz) \index{kernel.hpp@{kernel.hpp}!TK\_TIME\_SLICE\_MS@{TK\_TIME\_SLICE\_MS}} \index{TK\_TIME\_SLICE\_MS@{TK\_TIME\_SLICE\_MS}!kernel.hpp@{kernel.hpp}} \doxysubsubsection{TK\_TIME\_SLICE\_MS} {\footnotesize\ttfamily \label{kernel_8hpp_af32989639aecb5479b4239639fd133f7} \+\#define TK\+\_\+\+TIME\+\_\+\+SLICE\+\_\+\+MS~10u} 同一優先度タスク間のタイムスライス時間 (ミリ秒)