Torsten Wylegala
/
rtos-example
rtos example
Fork of mbed_blinky by
Revision 8:ec1a44f8e456, committed 2016-02-04
- Comitter:
- torstenwylegala
- Date:
- Thu Feb 04 10:43:16 2016 +0000
- Parent:
- 7:aecc1c3ea8db
- Commit message:
- init
Changed in this revision
diff -r aecc1c3ea8db -r ec1a44f8e456 Runnable.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Runnable.cpp Thu Feb 04 10:43:16 2016 +0000 @@ -0,0 +1,10 @@ +#include "Runnable.h" + + +void Runnable::callback(void const *argument){ + + Runnable *runnable = (Runnable*)argument; + + runnable->run(); + +} \ No newline at end of file
diff -r aecc1c3ea8db -r ec1a44f8e456 Runnable.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Runnable.h Thu Feb 04 10:43:16 2016 +0000 @@ -0,0 +1,20 @@ +#ifndef RUNNABLE_H_ +#define RUNNABLE_H_ + +#include "mbed.h" + +class Runnable { + +private: + +public: + + virtual void run() = 0; + + static void callback(void const *argument); + +}; + + + +#endif \ No newline at end of file
diff -r aecc1c3ea8db -r ec1a44f8e456 ThreadTestClass.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ThreadTestClass.cpp Thu Feb 04 10:43:16 2016 +0000 @@ -0,0 +1,18 @@ +#include "ThreadTestClass.h" + +ThreadTestClass::ThreadTestClass(): led2(LED2){ + + led2 = true; + +} + +void ThreadTestClass::run(){ + + while(true){ + + led2 = !led2; + + Thread::wait(2000); + } + +} \ No newline at end of file
diff -r aecc1c3ea8db -r ec1a44f8e456 ThreadTestClass.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ThreadTestClass.h Thu Feb 04 10:43:16 2016 +0000 @@ -0,0 +1,26 @@ +#ifndef THREADTESTCLASS_H_ +#define THREADTESTCLASS_H_ + +#include "mbed.h" +#include "rtos.h" + +#include "Runnable.h" + +class ThreadTestClass : public Runnable { + +private: + + DigitalOut led2; + + +public: + + ThreadTestClass(); + + void run(); + +}; + + + +#endif \ No newline at end of file
diff -r aecc1c3ea8db -r ec1a44f8e456 TimerTestClass.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TimerTestClass.cpp Thu Feb 04 10:43:16 2016 +0000 @@ -0,0 +1,13 @@ +#include "TimerTestClass.h" + +TimerTestClass::TimerTestClass(): led1(LED1){ + + led1 = true; + +} + +void TimerTestClass::run(){ + + led1 = !led1; + +} \ No newline at end of file
diff -r aecc1c3ea8db -r ec1a44f8e456 TimerTestClass.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TimerTestClass.h Thu Feb 04 10:43:16 2016 +0000 @@ -0,0 +1,26 @@ +#ifndef TIMERTESTCLASS_H_ +#define TIMERTESTCLASS_H_ + +#include "mbed.h" +#include "rtos.h" + +#include "Runnable.h" + +class TimerTestClass : public Runnable { + +private: + + DigitalOut led1; + + +public: + + TimerTestClass(); + + void run(); + +}; + + + +#endif \ No newline at end of file
diff -r aecc1c3ea8db -r ec1a44f8e456 main.cpp --- a/main.cpp Thu Mar 26 22:33:50 2015 +0000 +++ b/main.cpp Thu Feb 04 10:43:16 2016 +0000 @@ -1,12 +1,40 @@ #include "mbed.h" - -DigitalOut myled(LED1); +#include "rtos.h" -int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); - } -} +#include "TimerTestClass.h" +#include "ThreadTestClass.h" + +/*DigitalOut LEDs[4] = { + DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4) +}; + +void blink(void const *n) { + LEDs[(int)n] = !LEDs[(int)n]; +}*/ + +int main(void) { + + TimerTestClass timerTestClass; + + RtosTimer testTimer(&Runnable::callback,osTimerPeriodic,(void*)&timerTestClass); + testTimer.start(1000); + + ThreadTestClass threadTestClass; + + Thread thread(&Runnable::callback,(void*)&threadTestClass); + + + //led_1_timer.start(2000); + + /*RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0); + RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1); + RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2); + RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3); + + led_1_timer.start(2000); + led_2_timer.start(1000); + led_3_timer.start(500); + led_4_timer.start(250);*/ + + Thread::wait(osWaitForever); +} \ No newline at end of file
diff -r aecc1c3ea8db -r ec1a44f8e456 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Feb 04 10:43:16 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#85a52b7ef44b