10 years, 9 months ago.

How to reference the 'main' thread when using RTOS ?

I am using RTOS and I would like to set a signal for the 'main thread'. However, there is no function or object to refer to for the main thread which executes the main() function. Any ideas how I could set that signal (without having to create a new thread and put everything into the new thread) ?

3 Answers

10 years, 7 months ago.

Possibly this is what you are trying to achieve. I can't see how to do it with the signal_set and signal_wait methods. Incedently, does anyone know what the signal (0x1) is? Can other signal values be used and if so are they separate or can you use a mask to set, or more likely, wait on different signals simultaneously? I can't find any real documentation on how these should be used.

main.ccp

#include "mbed.h"
#include "rtos.h"

DigitalOut led(LED1);
osThreadId mainThreadID;

void signal_thread(void const *argument) {
    while (true) {
        Thread::wait(1000);
        osSignalSet(mainThreadID, 0x1);
    }
}

int main (void) {
    mainThreadID = osThreadGetId();
    Thread thread(signal_thread);
    
    while (true) {
        // Signal flags that are reported as event are automatically cleared.
        osSignalWait(0x1, osWaitForever);
        led = !led;
    }
}

Little documentation about it yeah, but if I remember correctly it is a bit mask. So if you wait on 0x3, it will start either when signal is set to 0x3, or when one is set to 0x1 and another one sets 0x2.

posted by Erik - 12 Sep 2013
10 years, 9 months ago.

Main is the main(principal) thread of the application. You can't refer the main thread. If you want you can reset the mbed and the aplication will start over. If you need data before reset save that data to memory and load-it when the application restart.

10 years, 9 months ago.

@Alexandru Pahomi can you explain specifically how to retrieve the data used before reset()? like give an example. let's say I have : int data = 5; then I do mbedreset(). What do I do next to retrieve data?