\doxysection{tk 名前空間} \label{namespacetk}\index{tk@{tk}} \doxysubsubsection*{名前空間} \begin{DoxyCompactItemize} \item namespace \textbf{ detail} \end{DoxyCompactItemize} \doxysubsubsection*{クラス} \begin{DoxyCompactItemize} \item class \textbf{ Actor} \begin{DoxyCompactList}\small\item\em メッセージ駆動型タスク (アクター) の基底クラス \end{DoxyCompactList}\item class \textbf{ Event\+Hub} \begin{DoxyCompactList}\small\item\em メッセージ型ごとの超軽量 Pub/\+\+Sub ディスパッチャ \end{DoxyCompactList}\item class \textbf{ Lock\+Guard} \begin{DoxyCompactList}\small\item\em ミューテックスのロックをスコープ単位で安全に管理する RAII クラス (std::\+lock\+\_\+guard 相当) \end{DoxyCompactList}\item struct \textbf{ Message} \begin{DoxyCompactList}\small\item\em デフォルトの軽量メッセージ構造体 \end{DoxyCompactList}\item class \textbf{ Mutex} \begin{DoxyCompactList}\small\item\em 所有権・優先度順ウェイクアップ・\+RAII 対応のミューテックス (排他ロック) \end{DoxyCompactList}\item class \textbf{ Preempt\+Guard} \begin{DoxyCompactList}\small\item\em プリエンプション禁止をスコープ単位で安全に管理する RAII クラス \end{DoxyCompactList}\item class \textbf{ Semaphore} \begin{DoxyCompactList}\small\item\em 計数セマフォ (Counting \doxyref{Semaphore}{p.}{classtk_1_1_semaphore}) / バイナリセマフォ \end{DoxyCompactList}\item struct \textbf{ Task\+Handle} \begin{DoxyCompactList}\small\item\em タスクの識別ハンドル \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsubsection*{型定義} \begin{DoxyCompactItemize} \item using \textbf{ Task\+Fn} = void ($\ast$)(void$\ast$ arg) \item using \textbf{ task\+\_\+mask\+\_\+t} = uint32\+\_\+t \item using \textbf{ Binary\+Semaphore} = \textbf{ Semaphore} \begin{DoxyCompactList}\small\item\em バイナリセマフォ (初期値1, 最大1) の型エイリアス \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsubsection*{列挙型} \begin{DoxyCompactItemize} \item enum \textbf{ Prio} : uint32\+\_\+t \{ \textbf{ PRIO\+\_\+\+REALTIME} = 1 , \textbf{ PRIO\+\_\+\+HIGH} = 5 , \textbf{ PRIO\+\_\+\+NORMAL} = 9 , \textbf{ PRIO\+\_\+\+LOW} = 13 \} \begin{DoxyCompactList}\small\item\em タスクの優先度レベル \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsubsection*{関数} \begin{DoxyCompactItemize} \item {\footnotesize template$<$typename Msg\+Type$>$ }\\size\+\_\+t \textbf{ publish} (const Msg\+Type \&msg) \begin{DoxyCompactList}\small\item\em メッセージの型を指定して、購読しているすべての \doxyref{Actor}{p.}{classtk_1_1_actor} へ同報配信します \end{DoxyCompactList}\item size\+\_\+t \textbf{ publish} (uint32\+\_\+t id, uintptr\+\_\+t arg=0) \begin{DoxyCompactList}\small\item\em \doxyref{tk::\+\+Message}{p.}{structtk_1_1_message} 型の同報配信ショートカット \end{DoxyCompactList}\item \textbf{ Task\+Handle} \textbf{ 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{ start} () \begin{DoxyCompactList}\small\item\em tinykernel スケジューラを起動します \end{DoxyCompactList}\item void \textbf{ yield} () \begin{DoxyCompactList}\small\item\em 現在実行中のタスクを一時中断し、同優先度の他のタスクへ CPU を譲渡します \end{DoxyCompactList}\item void \textbf{ sleep\+\_\+ms} (uint32\+\_\+t ms) \begin{DoxyCompactList}\small\item\em 現在のタスクを指定時間スリープさせます \end{DoxyCompactList}\item void \textbf{ exit} (int code=0) \begin{DoxyCompactList}\small\item\em 現在のタスクを終了・破棄します \end{DoxyCompactList}\item uint64\+\_\+t \textbf{ now\+\_\+ms} () \begin{DoxyCompactList}\small\item\em システム起動時からの経過時間をミリ秒単位で取得します \end{DoxyCompactList}\item bool \textbf{ lock} () \begin{DoxyCompactList}\small\item\em ハードウェアスピンロックと全割り込み禁止によるクリティカルセクションに入ります \end{DoxyCompactList}\item void \textbf{ unlock} (bool was\+\_\+enabled) \begin{DoxyCompactList}\small\item\em \doxyref{tk::\+lock()}{p.}{namespacetk_a6540aa25eb8562f6d6c8b37977d6cfe8} で入ったクリティカルセクションを抜けます \end{DoxyCompactList}\item void \textbf{ preempt\+\_\+disable} () \begin{DoxyCompactList}\small\item\em 自コアのタスクスイッチ (プリエンプション) を一時的に禁止します \end{DoxyCompactList}\item void \textbf{ preempt\+\_\+enable} () \begin{DoxyCompactList}\small\item\em 自コアのタスクスイッチ (プリエンプション) を再開します \end{DoxyCompactList}\end{DoxyCompactItemize} \label{namespacetk_doc-typedef-members} \doxysubsection{型定義詳解} \index{tk@{tk}!BinarySemaphore@{BinarySemaphore}} \index{BinarySemaphore@{BinarySemaphore}!tk@{tk}} \doxysubsubsection{BinarySemaphore} {\footnotesize\ttfamily \label{namespacetk_ab1f2fa3d79e99f13610bd330a0df928b} using \textbf{ tk::\+\+Binary\+Semaphore} = \textbf{ Semaphore}} バイナリセマフォ (初期値1, 最大1) の型エイリアス \index{tk@{tk}!task\_mask\_t@{task\_mask\_t}} \index{task\_mask\_t@{task\_mask\_t}!tk@{tk}} \doxysubsubsection{task\_mask\_t} {\footnotesize\ttfamily \label{namespacetk_add371a241ec6c1695ef4e67935317edd} using \textbf{ tk::\+task\+\_\+mask\+\_\+t} = uint32\+\_\+t} \index{tk@{tk}!TaskFn@{TaskFn}} \index{TaskFn@{TaskFn}!tk@{tk}} \doxysubsubsection{TaskFn} {\footnotesize\ttfamily \label{namespacetk_a8908cf1e54cdc4e14ac3003126722cfc} using \textbf{ tk::\+\+Task\+Fn} = void ($\ast$)(void$\ast$ arg)} タスク関数のシグネチャ (void func(void$\ast$ arg)) \label{namespacetk_doc-enum-members} \doxysubsection{列挙型詳解} \index{tk@{tk}!Prio@{Prio}} \index{Prio@{Prio}!tk@{tk}} \doxysubsubsection{Prio} {\footnotesize\ttfamily \label{namespacetk_a3d47fbd63b95ed3b46bed70c2fa1e50e} enum \textbf{ tk::\+\+Prio} :\+ uint32\+\_\+t} タスクの優先度レベル 数値が小さいほど高優先度です。0..15 の範囲で指定します (15 はアイドルタスク専用)。 \begin{DoxyEnumFields}[2]{列挙値} \raisebox{\heightof{T}}[0pt][0pt]{\index{PRIO\_REALTIME@{PRIO\_REALTIME}!tk@{tk}} \index{tk@{tk}!PRIO\_REALTIME@{PRIO\_REALTIME}} }\label{namespacetk_a3d47fbd63b95ed3b46bed70c2fa1e50eabbefd771d1fb2ac0708c1bd5371e5a75} PRIO\+\_\+\+REALTIME&リアルタイム最優先 \\ \hline \raisebox{\heightof{T}}[0pt][0pt]{\index{PRIO\_HIGH@{PRIO\_HIGH}!tk@{tk}} \index{tk@{tk}!PRIO\_HIGH@{PRIO\_HIGH}} }\label{namespacetk_a3d47fbd63b95ed3b46bed70c2fa1e50ea614240a3a3fc1094c6daa0fdca92ba37} PRIO\+\_\+\+HIGH&高優先度 \\ \hline \raisebox{\heightof{T}}[0pt][0pt]{\index{PRIO\_NORMAL@{PRIO\_NORMAL}!tk@{tk}} \index{tk@{tk}!PRIO\_NORMAL@{PRIO\_NORMAL}} }\label{namespacetk_a3d47fbd63b95ed3b46bed70c2fa1e50ea0e6779023b97999c2cef66ba1d4d1fca} PRIO\+\_\+\+NORMAL&通常優先度 (デフォルト) \\ \hline \raisebox{\heightof{T}}[0pt][0pt]{\index{PRIO\_LOW@{PRIO\_LOW}!tk@{tk}} \index{tk@{tk}!PRIO\_LOW@{PRIO\_LOW}} }\label{namespacetk_a3d47fbd63b95ed3b46bed70c2fa1e50eacf084edcfe985b77c205a37c3bd60519} PRIO\+\_\+\+LOW&低優先度 \\ \hline \end{DoxyEnumFields} \label{namespacetk_doc-func-members} \doxysubsection{関数詳解} \index{tk@{tk}!create@{create}} \index{create@{create}!tk@{tk}} \doxysubsubsection{create()} {\footnotesize\ttfamily \label{namespacetk_a6e721332f5a7d85998345ed218de7394} \textbf{ tk::\+\+Task\+Handle} tk::\+create (\begin{DoxyParamCaption}\item[{\textbf{ Task\+Fn}}]{fn}{, }\item[{void $\ast$}]{arg}{ = {\ttfamily nullptr}, }\item[{uint32\+\_\+t}]{prio}{ = {\ttfamily \textbf{ PRIO\+\_\+\+NORMAL}}}\end{DoxyParamCaption})} タスクを生成・登録します \doxyref{tk::\+start()}{p.}{namespacetk_a675f1829b87e2a43239b6f80a526d0ed} を呼び出す前に登録する必要があります。 \begin{DoxyParams}{引数} {\em fn} & タスク関数ポインタ (void ($\ast$)(void$\ast$ arg)) \\ \hline {\em arg} & タスク関数に渡すユーザー引数ポインタ (省略時: nullptr) \\ \hline {\em prio} & タスクの優先度 (省略時: \doxyref{tk::\+\+PRIO\+\_\+\+NORMAL}{p.}{namespacetk_a3d47fbd63b95ed3b46bed70c2fa1e50ea0e6779023b97999c2cef66ba1d4d1fca}) \\ \hline \end{DoxyParams} \begin{DoxyReturn}{戻り値} \doxyref{Task\+Handle}{p.}{structtk_1_1_task_handle} 生成されたタスクのハンドル。登録失敗時は is\+\_\+valid() が false \end{DoxyReturn} \index{tk@{tk}!exit@{exit}} \index{exit@{exit}!tk@{tk}} \doxysubsubsection{exit()} {\footnotesize\ttfamily \label{namespacetk_aba50cfc62cb8be71cf96df7f495a7a3d} void tk::\+exit (\begin{DoxyParamCaption}\item[{int}]{code}{ = {\ttfamily 0}}\end{DoxyParamCaption})} 現在のタスクを終了・破棄します \begin{DoxyParams}{引数} {\em code} & 終了コード (予約用、省略時: 0) \\ \hline \end{DoxyParams} \begin{DoxyNote}{覚え書き} タスク関数の末尾に到達した場合は自動的に呼ばれます。 \end{DoxyNote} \index{tk@{tk}!lock@{lock}} \index{lock@{lock}!tk@{tk}} \doxysubsubsection{lock()} {\footnotesize\ttfamily \label{namespacetk_a6540aa25eb8562f6d6c8b37977d6cfe8} bool tk::\+lock (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})} ハードウェアスピンロックと全割り込み禁止によるクリティカルセクションに入ります \begin{DoxyReturn}{戻り値} true 呼び出し前の割り込みが有効だった場合 false 呼び出し前の割り込みが無効だった場合 \end{DoxyReturn} \begin{DoxyWarning}{警告} 長時間のロックは避けてください。数マイクロ秒以内のレジスタ操作等に使用します。 \end{DoxyWarning} \index{tk@{tk}!now\_ms@{now\_ms}} \index{now\_ms@{now\_ms}!tk@{tk}} \doxysubsubsection{now\_ms()} {\footnotesize\ttfamily \label{namespacetk_a46e15375fba47cbd1a93278f17e77848} uint64\+\_\+t tk::\+now\+\_\+ms (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})} システム起動時からの経過時間をミリ秒単位で取得します \begin{DoxyReturn}{戻り値} uint64\+\_\+t 経過ミリ秒数 (分解能: 1 / TK\+\_\+\+TICKS\+\_\+\+PER\+\_\+\+SEC 秒) \end{DoxyReturn} \index{tk@{tk}!preempt\_disable@{preempt\_disable}} \index{preempt\_disable@{preempt\_disable}!tk@{tk}} \doxysubsubsection{preempt\_disable()} {\footnotesize\ttfamily \label{namespacetk_a3254a7e2a9f5ed3abe44e8cf62a8dcfe} void tk::\+preempt\+\_\+disable (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})} 自コアのタスクスイッチ (プリエンプション) を一時的に禁止します 割り込み (Sys\+Tick やタイマー、\+NVIC) は停止しないため、通信クロックや時刻更新を 阻害することなく、自タスクの処理をアトミックに実行できます。ネスト (入れ子) 呼び出しに対応しています。 \begin{DoxySeeAlso}{参照} \doxyref{tk::\+\+Preempt\+Guard}{p.}{classtk_1_1_preempt_guard}, \doxyref{tk::\+preempt\+\_\+enable()}{p.}{namespacetk_a70e6ee5f456e67a24ce13ff0fd04e4d9} \end{DoxySeeAlso} \index{tk@{tk}!preempt\_enable@{preempt\_enable}} \index{preempt\_enable@{preempt\_enable}!tk@{tk}} \doxysubsubsection{preempt\_enable()} {\footnotesize\ttfamily \label{namespacetk_a70e6ee5f456e67a24ce13ff0fd04e4d9} void tk::\+preempt\+\_\+enable (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})} 自コアのタスクスイッチ (プリエンプション) を再開します ネストカウンタが 0 に戻った時点で、保留されていたタスクスイッチが即座に実行されます。 \begin{DoxySeeAlso}{参照} \doxyref{tk::\+\+Preempt\+Guard}{p.}{classtk_1_1_preempt_guard}, \doxyref{tk::\+preempt\+\_\+disable()}{p.}{namespacetk_a3254a7e2a9f5ed3abe44e8cf62a8dcfe} \end{DoxySeeAlso} \index{tk@{tk}!publish@{publish}} \index{publish@{publish}!tk@{tk}} \doxysubsubsection{publish()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}} {\footnotesize\ttfamily \label{namespacetk_a083495c9bf857a63f6c20a20aac0ca52} template$<$typename Msg\+Type$>$ \\ size\+\_\+t tk::\+publish (\begin{DoxyParamCaption}\item[{const Msg\+Type \&}]{msg}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}} メッセージの型を指定して、購読しているすべての \doxyref{Actor}{p.}{classtk_1_1_actor} へ同報配信します 送信側は \doxyref{Actor}{p.}{classtk_1_1_actor} のインスタンスや名前を知る必要がありません (完全疎結合)。 メッセージの実体は各 \doxyref{Actor}{p.}{classtk_1_1_actor} のキューへ値コピーされるため、スタック上のローカル変数でも安全に渡せます。 \begin{DoxyTemplParams}{テンプレート引数} {\em Msg\+Type} & 配信するメッセージ型 \\ \hline \end{DoxyTemplParams} \begin{DoxyParams}{引数} {\em msg} & 送信するメッセージ \\ \hline \end{DoxyParams} \begin{DoxyReturn}{戻り値} size\+\_\+t 配信に成功した \doxyref{Actor}{p.}{classtk_1_1_actor} の数 \end{DoxyReturn} \begin{DoxyCode}{0} \DoxyCodeLine{MyEvent\ ev\{1,\ \textcolor{stringliteral}{"{}Button\ Pressed"{}}\};} \DoxyCodeLine{tk::publish(ev);\ \textcolor{comment}{//\ MyEvent\ を受け付けるすべての\ Actor\ に届く}} \end{DoxyCode} \index{tk@{tk}!publish@{publish}} \index{publish@{publish}!tk@{tk}} \doxysubsubsection{publish()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}} {\footnotesize\ttfamily \label{namespacetk_a5549bec310750722a1964de1145b9fed} size\+\_\+t tk::\+publish (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{id}{, }\item[{uintptr\+\_\+t}]{arg}{ = {\ttfamily 0}}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}} \doxyref{tk::\+\+Message}{p.}{structtk_1_1_message} 型の同報配信ショートカット \begin{DoxyParams}{引数} {\em id} & メッセージ\+ID \\ \hline {\em arg} & 引数 (省略時: 0) \\ \hline \end{DoxyParams} \begin{DoxyReturn}{戻り値} size\+\_\+t 配信に成功した \doxyref{Actor}{p.}{classtk_1_1_actor} の数 \end{DoxyReturn} \index{tk@{tk}!sleep\_ms@{sleep\_ms}} \index{sleep\_ms@{sleep\_ms}!tk@{tk}} \doxysubsubsection{sleep\_ms()} {\footnotesize\ttfamily \label{namespacetk_aae83f84121085578a7568437a8dc2447} void tk::\+sleep\+\_\+ms (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{ms}{}\end{DoxyParamCaption})} 現在のタスクを指定時間スリープさせます スリープ中はタスクが休止状態になり、\+CPU は他のタスクへ自動的に割り当てられます (CPU消費ゼロ)。 \begin{DoxyParams}{引数} {\em ms} & スリープする時間 (ミリ秒) \\ \hline \end{DoxyParams} \begin{DoxyNote}{覚え書き} タスクコンテキスト内から呼び出す必要があります。 \end{DoxyNote} \index{tk@{tk}!start@{start}} \index{start@{start}!tk@{tk}} \doxysubsubsection{start()} {\footnotesize\ttfamily \label{namespacetk_a675f1829b87e2a43239b6f80a526d0ed} void tk::\+start (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})} tinykernel スケジューラを起動します Core 0 のスケジューラを開始し、\+Core 1 を自動ブートしてデュアルコア並行実行を開始します。 この関数から制御が戻ることはありません (Never returns)。 \index{tk@{tk}!unlock@{unlock}} \index{unlock@{unlock}!tk@{tk}} \doxysubsubsection{unlock()} {\footnotesize\ttfamily \label{namespacetk_a752b12f6862815c94a52347af52578b7} void tk::\+unlock (\begin{DoxyParamCaption}\item[{bool}]{was\+\_\+enabled}{}\end{DoxyParamCaption})} \doxyref{tk::\+lock()}{p.}{namespacetk_a6540aa25eb8562f6d6c8b37977d6cfe8} で入ったクリティカルセクションを抜けます \begin{DoxyParams}{引数} {\em was\+\_\+enabled} & \doxyref{tk::\+lock()}{p.}{namespacetk_a6540aa25eb8562f6d6c8b37977d6cfe8} の戻り値 \\ \hline \end{DoxyParams} \index{tk@{tk}!yield@{yield}} \index{yield@{yield}!tk@{tk}} \doxysubsubsection{yield()} {\footnotesize\ttfamily \label{namespacetk_a8081956b0a19b87d5b7c81b772373397} void tk::\+yield (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})} 現在実行中のタスクを一時中断し、同優先度の他のタスクへ CPU を譲渡します \begin{DoxyNote}{覚え書き} タスクコンテキスト内から呼び出す必要があります。 \end{DoxyNote}