8 years, 10 months ago.

RTOS basic question (RTOS基礎的な質問)

I was interested in os recently. I was going to move it, but it does not work as expected.
(最近リアルタイムOSという物を知り、遊んでみようと思い、 動かそうとしたのですが、思ったように動かないので教えてください。)

Sample code is no problem.
(サンプルコードは問題なく動きました。)

sample code

#include "mbed.h"
#include "rtos.h"
 
DigitalOut led1(LED1);
DigitalOut led2(LED2);

void led2_thread(void const *args) {
    while (true) {
        led2 = !led2;
        Thread::wait(1000);
    }
}
 
int main() {
    Thread thread(led2_thread);
    
    while (true) {
        led1 = !led1;
        Thread::wait(500);
    }
}


Code is remodeled,Because it was different from my image of RTOS.
(コードが私のRTOSに抱いているのイメージとは違ったので、 イメージに合うように改造してみました。)

Remodeled code

#include "mbed.h"
#include "rtos.h"
 
DigitalOut led1(LED1);
DigitalOut led2(LED2);

void led1_thread(void const *argument) {
    while (true) {
        led1 = !led1;
        Thread::wait(500);
    }
}

void led2_thread(void const *argument) {
    while (true) {
        led2 = !led2;
        Thread::wait(1000);
    }
}
 
int main() {
    Thread thread1(led1_thread);
    Thread thread2(led2_thread);
    while (true){;}
}


In the case of remodeled code, Flashing timing of LED is off. please tell me why it seems to be.
(改造したコードだと、LEDの点滅がだんだんズレていきます。 どうしてでしょうか?)

1 Answer

8 years, 10 months ago.

Pass the proc. to OS in main using Thread::wait(osWaitForever) I think the reason is a interrupt lost occures with jump instruction to itself.

Accepted Answer

thank you ! Once I have chenged code from "while (true){:}" to "Thread::wait(osWaitForever)" ,I have solved the problem. I do not know well why interrupt lost happens, but the OS will be such a thing...?

(ありがとうございます。 言われた通り、Thread::wait(osWaitForever)にしたら、ちゃんと動く様になりました。 interrupt lost がなぜ起こっているのかよくわかりませんが、OSってそういう物なんでしょうね。)

posted by Morimoto Nozomi 02 Jul 2015