realtime process control with RTOS
Fork of mbed-os-example-mbed5-blinky by
main.cpp@16:c5c5f3964864, 2016-11-25 (annotated)
- Committer:
- ykuroda
- Date:
- Fri Nov 25 17:29:55 2016 +0000
- Revision:
- 16:c5c5f3964864
- Parent:
- 8:bb09890333fe
add comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ykuroda | 16:c5c5f3964864 | 1 | // |
ykuroda | 16:c5c5f3964864 | 2 | // mbed-os-control-ex1 |
ykuroda | 16:c5c5f3964864 | 3 | // 正確な時間管理をするプログラムの例 |
ykuroda | 16:c5c5f3964864 | 4 | // |
ykuroda | 16:c5c5f3964864 | 5 | // 20161027 ... v1.0 ... written by Y.Kuroda |
ykuroda | 16:c5c5f3964864 | 6 | // |
ykuroda | 16:c5c5f3964864 | 7 | // |
Jonathan Austin |
0:2757d7abb7d9 | 8 | #include "mbed.h" |
ykuroda | 16:c5c5f3964864 | 9 | #include "rtos.h" |
Jonathan Austin |
0:2757d7abb7d9 | 10 | |
ykuroda | 16:c5c5f3964864 | 11 | const int DELTA_T = 100; // mainスレッドの時間間隔の設定 [ms] |
ykuroda | 16:c5c5f3964864 | 12 | const int SIG_MYT = 0x1; // signal番号 |
Jonathan Austin |
0:2757d7abb7d9 | 13 | DigitalOut led1(LED1); |
Jonathan Austin |
0:2757d7abb7d9 | 14 | |
ykuroda | 16:c5c5f3964864 | 15 | void robot_control(void const* arg) { // ロボットの制御をするスレッド |
ykuroda | 16:c5c5f3964864 | 16 | while(true){ |
ykuroda | 16:c5c5f3964864 | 17 | Thread::signal_wait(SIG_MYT); // シグナルを待つ |
ykuroda | 16:c5c5f3964864 | 18 | |
ykuroda | 16:c5c5f3964864 | 19 | // ここに自分のプログラムを書きます. |
ykuroda | 16:c5c5f3964864 | 20 | // |
ykuroda | 16:c5c5f3964864 | 21 | // |
ykuroda | 16:c5c5f3964864 | 22 | // |
ykuroda | 16:c5c5f3964864 | 23 | Thread::wait(10); //これは時間稼ぎのダミー.消して良い. |
ykuroda | 16:c5c5f3964864 | 24 | // |
ykuroda | 16:c5c5f3964864 | 25 | // |
ykuroda | 16:c5c5f3964864 | 26 | // |
ykuroda | 16:c5c5f3964864 | 27 | |
ykuroda | 16:c5c5f3964864 | 28 | led1 = 0; // ループの最後でLEDを消す.処理が重くなると明るくなる |
Jonathan Austin |
0:2757d7abb7d9 | 29 | } |
Jonathan Austin |
0:2757d7abb7d9 | 30 | } |
Jonathan Austin |
1:846c97078558 | 31 | |
ykuroda | 16:c5c5f3964864 | 32 | |
ykuroda | 16:c5c5f3964864 | 33 | int main() { |
ykuroda | 16:c5c5f3964864 | 34 | Thread mythread(robot_control, (void*)0); // ロボ制御スレッドを起動 |
ykuroda | 16:c5c5f3964864 | 35 | |
ykuroda | 16:c5c5f3964864 | 36 | while(true){ |
ykuroda | 16:c5c5f3964864 | 37 | Thread::wait(DELTA_T); // mainスレッドの時間間隔の設定 [ms] |
ykuroda | 16:c5c5f3964864 | 38 | led1 = 1; // 処理の先頭でLEDをを点灯 |
ykuroda | 16:c5c5f3964864 | 39 | mythread.signal_set(SIG_MYT); // スレッドへ再開シグナルを送る |
ykuroda | 16:c5c5f3964864 | 40 | } |
ykuroda | 16:c5c5f3964864 | 41 | } |
ykuroda | 16:c5c5f3964864 | 42 |