ok

Dependencies:   mbed-rtos mbed

Fork of rtos_basic by mbed official

Committer:
avnisha
Date:
Fri Feb 14 20:01:37 2014 +0000
Revision:
8:a76c9654e215
Parent:
3:c92e21f305d8
add features

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:491820ee784d 1 #include "mbed.h"
avnisha 8:a76c9654e215 2 #include "cmsis_os.h"
emilmont 1:491820ee784d 3 #include "rtos.h"
emilmont 1:491820ee784d 4
avnisha 8:a76c9654e215 5 Serial pc(USBTX, USBRX);
avnisha 8:a76c9654e215 6
avnisha 8:a76c9654e215 7
avnisha 8:a76c9654e215 8 /*
avnisha 8:a76c9654e215 9 typedef enum {
avnisha 8:a76c9654e215 10 osPriorityIdle = -3, ///< priority: idle (lowest)
avnisha 8:a76c9654e215 11 osPriorityLow = -2, ///< priority: low
avnisha 8:a76c9654e215 12 osPriorityBelowNormal = -1, ///< priority: below normal
avnisha 8:a76c9654e215 13 osPriorityNormal = 0, ///< priority: normal (default)
avnisha 8:a76c9654e215 14 osPriorityAboveNormal = +1, ///< priority: above normal
avnisha 8:a76c9654e215 15 osPriorityHigh = +2, ///< priority: high
avnisha 8:a76c9654e215 16 osPriorityRealtime = +3, ///< priority: realtime (highest)
avnisha 8:a76c9654e215 17 osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
avnisha 8:a76c9654e215 18 } osPriority;
avnisha 8:a76c9654e215 19 */
avnisha 8:a76c9654e215 20
avnisha 8:a76c9654e215 21
emilmont 1:491820ee784d 22 DigitalOut led1(LED1);
emilmont 1:491820ee784d 23 DigitalOut led2(LED2);
avnisha 8:a76c9654e215 24
avnisha 8:a76c9654e215 25 /*
avnisha 8:a76c9654e215 26 * This thread just flips the led2
avnisha 8:a76c9654e215 27 */
avnisha 8:a76c9654e215 28
emilmont 1:491820ee784d 29
emilmont 3:c92e21f305d8 30 void led2_thread(void const *args) {
emilmont 1:491820ee784d 31 while (true) {
emilmont 1:491820ee784d 32 led2 = !led2;
emilmont 1:491820ee784d 33 Thread::wait(1000);
emilmont 1:491820ee784d 34 }
emilmont 1:491820ee784d 35 }
avnisha 8:a76c9654e215 36
avnisha 8:a76c9654e215 37
avnisha 8:a76c9654e215 38 /*
avnisha 8:a76c9654e215 39 * This thread does non blocking read
avnisha 8:a76c9654e215 40 */
avnisha 8:a76c9654e215 41
avnisha 8:a76c9654e215 42 void nbread_thread(void const *args) {
avnisha 8:a76c9654e215 43 while(1) {
avnisha 8:a76c9654e215 44 if(pc.readable()) {
avnisha 8:a76c9654e215 45 pc.printf("got a character: %c\r\n", pc.getc());
avnisha 8:a76c9654e215 46 }
avnisha 8:a76c9654e215 47
avnisha 8:a76c9654e215 48 Thread::wait(10);
avnisha 8:a76c9654e215 49 }
avnisha 8:a76c9654e215 50 }
avnisha 8:a76c9654e215 51
avnisha 8:a76c9654e215 52 /*
avnisha 8:a76c9654e215 53 * the main thread sets upthread priorities and flips led's
avnisha 8:a76c9654e215 54 */
emilmont 1:491820ee784d 55
emilmont 1:491820ee784d 56 int main() {
avnisha 8:a76c9654e215 57
avnisha 8:a76c9654e215 58 osPriority pri;
emilmont 1:491820ee784d 59 Thread thread(led2_thread);
avnisha 8:a76c9654e215 60 Thread thread1(nbread_thread);
emilmont 1:491820ee784d 61
avnisha 8:a76c9654e215 62 pc.printf("testing thread features \r\n");
avnisha 8:a76c9654e215 63 printf("led2_thread priority: %d\r\n", thread.get_priority());
avnisha 8:a76c9654e215 64 pri = osPriorityHigh;
avnisha 8:a76c9654e215 65 thread.set_priority(pri);
avnisha 8:a76c9654e215 66 printf("led2_thread priority: %d\r\n", thread.get_priority());
emilmont 1:491820ee784d 67 while (true) {
emilmont 1:491820ee784d 68 led1 = !led1;
emilmont 1:491820ee784d 69 Thread::wait(500);
emilmont 1:491820ee784d 70 }
emilmont 1:491820ee784d 71 }