realtime process control with RTOS
Fork of mbed-os-example-mbed5-blinky by
main.cpp
- Committer:
- ykuroda
- Date:
- 2016-11-25
- Revision:
- 19:9381d775bfc5
- Parent:
- 8:bb09890333fe
- Child:
- 20:13fcc82f4cab
File content as of revision 19:9381d775bfc5:
//
// mbed-os-control-ex1
// 正確な時間管理をするプログラムの例
//
// 20161027 ... v1.0 ... written by Y.Kuroda
//
//
#include "mbed.h"
#include "rtos.h"
const int DELTA_T = 100; // mainスレッドの時間間隔の設定 [ms]
const int SIG_MYT = 0x1; // signal番号
DigitalOut led1(LED1);
void robot_control(void const* arg) { // ロボットの制御をするスレッド
while(true){
Thread::signal_wait(SIG_MYT); // シグナルを待つ
// ここに自分のプログラムを書きます.
//
//
//
Thread::wait(10); //これは時間稼ぎのダミー.消して良い.
//
//
//
led1 = 0; // ループの最後でLEDを消す.処理が重くなると明るくなる
}
}
int main() {
Thread mythread(robot_control, (void*)0); // ロボット制御スレッドを起動
while(true){
Thread::wait(DELTA_T); // mainスレッドの時間間隔の設定 [ms]
led1 = 1; // 処理の先頭でLEDをを点灯
mythread.signal_set(SIG_MYT); // スレッドへ再開シグナルを送る
}
}
Yoji KURODA
