realtime process control with RTOS
Fork of mbed-os-example-mbed5-blinky by
Diff: main.cpp
- Revision:
- 16:c5c5f3964864
- Parent:
- 8:bb09890333fe
--- a/main.cpp Mon Oct 24 14:30:02 2016 +0100
+++ b/main.cpp Fri Nov 25 17:29:55 2016 +0000
@@ -1,13 +1,42 @@
+//
+// 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);
-// main() runs in its own thread in the OS
-// (note the calls to Thread::wait below for delays)
-int main() {
- while (true) {
- led1 = !led1;
- Thread::wait(500);
+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
