rtos2

Dependencies:   mbed-rtos mbed

Fork of rtos_2 by Xisco Sastre Cabot

Committer:
xiscosc
Date:
Fri Nov 13 14:41:24 2015 +0000
Revision:
7:14841d8f93e4
Parent:
3:c92e21f305d8
rtos2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:491820ee784d 1 #include "mbed.h"
emilmont 1:491820ee784d 2 #include "rtos.h"
emilmont 1:491820ee784d 3 DigitalOut led1(LED1);
emilmont 1:491820ee784d 4 DigitalOut led2(LED2);
xiscosc 7:14841d8f93e4 5 double status;
xiscosc 7:14841d8f93e4 6 Timer t;
xiscosc 7:14841d8f93e4 7 bool b;
xiscosc 7:14841d8f93e4 8
xiscosc 7:14841d8f93e4 9 void thread1(void const *args) {
emilmont 1:491820ee784d 10 while (true) {
xiscosc 7:14841d8f93e4 11 t.stop();
xiscosc 7:14841d8f93e4 12 if (b) {
xiscosc 7:14841d8f93e4 13 printf("The time taken was %f seconds \r\n", t.read());
xiscosc 7:14841d8f93e4 14 b = false;
xiscosc 7:14841d8f93e4 15 }
xiscosc 7:14841d8f93e4 16 t.reset();
xiscosc 7:14841d8f93e4 17 led1 = !led1;
xiscosc 7:14841d8f93e4 18 for(double i=0; i<100000; i++) {
xiscosc 7:14841d8f93e4 19 status = i;
xiscosc 7:14841d8f93e4 20 }
xiscosc 7:14841d8f93e4 21 led1 = !led1;
xiscosc 7:14841d8f93e4 22 Thread::wait(300);
xiscosc 7:14841d8f93e4 23 }
emilmont 1:491820ee784d 24 }
xiscosc 7:14841d8f93e4 25
xiscosc 7:14841d8f93e4 26
xiscosc 7:14841d8f93e4 27 int main() {
xiscosc 7:14841d8f93e4 28 led1 = false;
xiscosc 7:14841d8f93e4 29 led2 = false;
xiscosc 7:14841d8f93e4 30 b = true;
xiscosc 7:14841d8f93e4 31 osThreadSetPriority(osThreadGetId(),osPriorityHigh);
xiscosc 7:14841d8f93e4 32 Thread my_thread1(thread1, NULL, osPriorityHigh);
xiscosc 7:14841d8f93e4 33 while (true) {
xiscosc 7:14841d8f93e4 34 t.reset();
xiscosc 7:14841d8f93e4 35 t.start();
xiscosc 7:14841d8f93e4 36 led2 = !led2;
xiscosc 7:14841d8f93e4 37 for(double i=0; i<100000; i++) {
xiscosc 7:14841d8f93e4 38 status = i;
xiscosc 7:14841d8f93e4 39 }
xiscosc 7:14841d8f93e4 40 led2 = !led2;
xiscosc 7:14841d8f93e4 41 Thread::wait(300);
xiscosc 7:14841d8f93e4 42 }
emilmont 1:491820ee784d 43 }