リアルタイムふうOS データ構造

Data structure

Task Control Block: TCB

struct st_tcb {
    struct st_tcb *link;
    struct st_tcb *back_link;
    void       (*entry)( byte state );
    uint16     time;
    uint8      state;
    uint8      next_state;
    uint8      trg;
};

typedef struct st_tcb tcb_type;

Que of waiting for run: ReadyQ

起床されたタスクの実行待ちリスト。繋がれたTCBを順に実行する。
ReadyQ

struct st_que {
    struct st_tcb  *link;
    struct st_tcb  *back_link;
};

typedef struct st_que  que_type;

que_type  ReadyQ;

Que of waiting for timeout:TimerQ

タイムアウト待ちタスクのリスト。基準タイマ割込みで繋がれた最初のTCBのtimeを減算する。time=0ならばタイムアウト待ちキューからTCBを削除し、実行待ちキューにTCBを追加する。

TimerQ

struct st_que {
    struct st_tcb  *link;
    struct st_tcb  *back_link;
};

typedef struct st_que  que_type;

que_type  TimerQ;

Event flag: FLAG

FLAG

Semaphore: SEM

セマフォsignal動作待ちタスクのリスト。セマフォにより排他制御を行う。size=1とすればバイナリセマフォとなる。

SEM

struct st_sem {
    struct st_tcb  *link;
    struct st_tcb  *back_link;
    uint8          count;
    uint8          size;
};

typedef struct st_sem  sem_type;

Mail box: MBX

メッセージ単位でタスク間の同期をとる。バッファはユーザ側で用意する。

MBX

struct st_mbx {
    tcb_type  *tcb;
    uint8     *msg;
    uint8     n;
    uint8     n_max;
};

typedef struct st_mbx  mbx_type;

OS work area

OSのワークエリアはアプリケーションで使用するタスク数、メールボックス数、イベントフラグ数、セマフォ数を定義して予め領域を確保する。

OS work

/* ユーザー定義 ここから */
#define N_TCB       10  /* TCBの最大同時定義数 [12byte/tcb] */
#define N_MBX       10  /* メールボックスの定義数 [6byte/mbx] */
#define N_FLAG      10  /* イベントフラグの定義数 [6byte/flag] */
#define N_SEM       10  /* セマフォの定義数 [6byte/sem] */
/* ユーザー定義 ここまで */

/* 実行制御用Queue */
static volatile que_type    TimerQ;     /* タイムアウト待ちQueue */
static volatile que_type    ReadyQ;     /* 実行待ちQueue */

/* TCB */
static volatile tcb_type    Tcb[ N_TCB ];   /* TaskControlBlock */

/* メールボックス */
static volatile mbx_type    Mbx[ N_MBX ];

/* イベントフラグ */
static volatile flag_type   Flag[ N_FLAG ];

/* セマフォ */
static volatile sem_type    Sem[ N_SEM ];

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です