I can not resume thread with rtos. I write the program as follows, but when I execute the second callback, the start method returns osErrorParameter with osStatus.
Please tell me how to fix it.
#include "mbed.h"
Thread thread;
DigitalOut led1(LED1);
volatile bool running = true;
void printOSStatus(osStatus status)
{
if (status == osOK)
{
printf("osOK\n");
}
else if (status == osErrorValue)
{
printf("osErrorValue\n");
}
else if (status == osErrorResource)
{
printf("osErrorResource\n");
}
else if (status == osErrorTimeoutResource)
{
printf("osErrorTimeoutResource\n");
}
else if (status == osErrorNoMemory)
{
printf("osErrorNoMemory\n");
}
else if (status == osErrorISR)
{
printf("osErrorISR\n");
}
else if (status == osErrorISRRecursive)
{
printf("osErrorISRRecrusive\n");
}
else if (status == osErrorPriority)
{
printf("osErrorPriority\n");
}
else if (status == osErrorParameter)
{
printf("osErrorParameter\n");
}
else if (status == osErrorOS)
{
printf("osErrorOS\n");
}
else if (status == osEventSignal)
{
printf("osEventSignal\n");
}
else if (status == osEventMessage)
{
printf("osEventMessage\n");
}
else if (status == osEventMail)
{
printf("osEventMail\n");
}
else if (status == osEventTimeout)
{
printf("osEventTimeout\n");
}
else
{
printf("else\n");
}
}
void blink(DigitalOut *led) {
printf("blink start\n");
while (running) {
*led = !*led;
printf("blink while\n");
wait(1);
}
}
int main() {
printf("main\n");
osStatus status = thread.start(callback(blink, &led1));
printOSStatus(status);
wait(3);
running = false;
thread.join();
printf("running = false\n");
wait(3);
status = thread.start(callback(blink, &led1));
printOSStatus(status);
printf("running = start\n");
wait(1);
running = false;
thread.join();
printf("running = false\n");
}