Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 3 months ago.
how to set priority
could anyone give a simple example how to set the priority of a threat?
thanks in advance
Question relating to:
1 Answer
11 years, 3 months ago.
Within a test project like rtos_basic, look at:
-the class Thread :you find the function set_priority
-in rtx/cmsi_os.h you find the definition of  priority (line 154)
I hope this can help you
Robert
thank you for the fast respons, I will look into it.
update: I got it working using the rtos_basic program with some code from this program: https://mbed.org/users/JimCarver/code/KL46_eCompass/file/ba1dbfb683fb/main.cpp
setting and printing priority in RTOS
#include "mbed.h"
#include "rtos.h"
 
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Serial pc(USBTX, USBRX); // tx, rx
Thread *(test);
 
void led2_thread(void const *args) {
    while (true) {
        led2 = !led2;        
        Thread::wait(1000);       
    }
}
int main() {
    Thread thread(led2_thread);
    test = &thread;
    test->set_priority(osPriorityHigh);
    pc.printf("%i\n\r",test->get_priority());
        
    while (true) {
        led1 = !led1;
        Thread::wait(500);        
    }
}
The program sends a 2 to the serial program on my computer confirming that the priority is set high.
posted by 07 Aug 2014