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