メインページ | モジュール | 名前空間一覧 | クラス階層 | 構成 | ファイル一覧 | 名前空間メンバ | 構成メンバ | ファイルメンバ | 関連ページ

クラス テンプレートtoppers::task_body< Diagnostics, Stub > の解説
[カーネルオブジェクト管理]

タスク本体のデータおよび動作を定義する基底クラス [詳細]

#include <toppers/task.hpp>

toppers::task_body< Diagnostics, Stub >に対する継承グラフ

toppers::task_context_body< Diagnostics, Stub > すべてのメンバ一覧

Public メンバ関数

 task_body (VP_INT exinf)
 拡張情報を受取るコンストラクタ

const task< 0, Diagnostics,
Stub > & 
get_task () const
 自タスク管理オブジェクトの参照

void run ()
 タスク本体動作の実行

VP_INT get_extended_info () const
 タスクの拡張情報の参照


Static Public メンバ関数

void exit ()
 タスクの終了

void exit_and_destroy ()
 タスクの終了と削除

ER sleep (forever_tag=forever)
 タスクの起床待ち

ER sleep (TMO tmout)
 タスクの起床待ち(タイムアウト指定)

ER delay (RELTIM dlytim)
 タスクの遅延

ER yield ()
 タスクの切り替え


Static Public 変数

const task_context_tag task_context = toppers::task_context
 タスクコンテキストを指定する定数

const non_task_context_tag non_task_context = toppers::non_task_context
 非タスクコンテキストを指定する定数

const task_context_tag context_independent = toppers::task_context
 現在のコンテキスト(すなわちタスクコンテキスト)を指定する定数


Protected 型

typedef Stub stub
 サービスコールスタブ


Protected メンバ関数

 ~task_body ()
 デストラクタ


Static Protected メンバ関数

ID get_task_id ()
 実行中のタスクID番号を参照する


解説

template<class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS, class Stub = TOPPERS_DEFAULT_STUB>
class toppers::task_body< Diagnostics, Stub >

  タスクを作成する場合、task_body テンプレートクラスから public 継承した クラスを定義し、その型をtask_entry テンプレート関数のテンプレート引数 に渡す。

/*  task_body.h */
#ifndef TASK_BODY_H
#define TASK_BODY_H

#define MAIN_PRIORITY   5       /* メインタスクの優先度 */
#define STACKSIZE       0x2000

typedef struct
{
    int counter;
} MY_TASK_DATA;

#ifdef  __cplusplus
extern "C" {
#endif

extern MY_TASK_DATA my_task_data;

void my_task(VP_INT);

#ifdef  __cplusplus
}
#endif

#endif
//  task_body.cpp
#include <toppers/task.hpp>
#include "task_body.h"

MY_TASK_DATA my_task_data = { 0 };

class my_task_body : public toppers::task_body<>
{
public:
    explicit my_task_body(VP_INT exinf)
        : toppers::task_body<>(exinf)
    {
    }

    MY_TASK_DATA& get_data()
    {
        return *(MY_TASK_DATA*)get_extended_info();
    }

    void run()
    {
        for (;;)
        {
            delay(10);
            ++get_data().counter;
        }
    }
};

void my_task(VP_INT exinf)
{
    toppers::task_entry<my_task_body>(exinf);
}

/*  task_body.cfg   */
INCLUDE("\"task_body.h\"");

CRE_TSK(MY_TASK, { TA_HLNG | TA_ACT, (VP_INT)&my_task_data, my_task, MID_PRIORITY, STACK_SIZE, NULL });

#include "./systask/cxxrt.cfg"
#include "./systask/timer.cfg"
#include "./systask/serial.cfg"
#include "./systask/logtask.cfg"
参照:
task task_entry task_body::terminator


メンバ関数の解説

template<class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS, class Stub = TOPPERS_DEFAULT_STUB>
void toppers::task_body< Diagnostics, Stub >::exit  )  [inline, static]
 

  自タスクを終了させる。 自動記憶域に生成されたインスタンスのデストラクタを確実に呼出すため、 直接ext_tsk を呼出すのではなく、例外をスローしている。
  task_entry を使用する場合は内部で例外がキャッチされるが、タスクの エントリ関数を自作する場合は関数のトップレベルで例外をキャッチする 必要がある。

例外:
task_body::terminator 
参照:
task_entry

template<class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS, class Stub = TOPPERS_DEFAULT_STUB>
void toppers::task_body< Diagnostics, Stub >::exit_and_destroy  )  [inline, static]
 

  自タスクを終了させた後、削除する。 自動記憶域に生成されたインスタンスのデストラクタを確実に呼出すため、 直接exd_tsk を呼出すのではなく、例外をスローしている。
  task_entry を使用する場合は内部で例外がキャッチされるが、タスクの エントリ関数を自作する場合は関数のトップレベルで例外をキャッチする 必要がある。

例外:
task_body::terminator 
参照:
task_entry