7 years, 5 months ago.

Any Simple Example Using mbed RTOS?

Hello,

I am trying to run a simple example using mbed RTOS. I imported RTOS_basic example but I've got a warning that the way the thread is created is deprecated: (Thread thread(led2_thread); Is there a simple but updated example? Something like creating 2 threads, starting them and making one thread waiting for a signal from the other thread.

thanks

1 Answer

7 years, 5 months ago.

From https://github.com/ARMmbed/mbed-os/blob/master/rtos/Thread.h

/** The Thread class allow defining, creating, and controlling thread functions in the system.
 *
 *  Example:
 *  @code
 *  #include "mbed.h"
 *  #include "rtos.h"
 *
 *  Thread thread;
 *  DigitalOut led1(LED1);
 *  volatile bool running = true;
 *
 *  // Blink function toggles the led in a long running loop
 *  void blink(DigitalOut *led) {
 *      while (running) {
 *          *led = !*led;
 *          Thread::wait(1000);
 *      }
 *  }
 *
 *  // Spawns a thread to run blink for 5 seconds
 *  int main() {
 *      thread.start(led1, blink);
 *      Thread::wait(5000);
 *      running = false;
 *      thread.join();
 *  }

When creating Thread thread you can add arguments for priority and other options as seen in the constructor :

Thread(osPriority priority=osPriorityNormal,
           uint32_t stack_size=DEFAULT_STACK_SIZE,
           unsigned char *stack_pointer=NULL) {
        constructor(priority, stack_size, stack_pointer);
}

Accepted Answer