![](/media/cache/profiles/e6e23936f2d0414c639133d8b9721135.jpg.50x50_q85.jpg)
Just to try whether is it posible to call rtostimer::start()/stop() from an ISR. The answer seems to be NO.
Fork of boton_ISR by
Diff: main.cpp
- Revision:
- 0:005ae170e5f9
- Child:
- 1:fc92ede355c4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jan 03 13:49:43 2017 +0000 @@ -0,0 +1,70 @@ +#include "mbed.h" +#include "rtos.h" + +DigitalOut myled(LED1); +Serial pc(SERIAL_TX, SERIAL_RX); + +volatile int contador_timer = 0; +volatile int estado_timer = 0; +RtosTimer * timer; + +class Counter { +public: + Counter(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to Counter + _interrupt.rise(this, &Counter::increment); // attach increment function of this counter instance + _interrupt.mode(PullUp); + } + + void increment() { + _count++; + + if(estado_timer==0) + { + myled = 1 - myled; + ; + timer->start(1000); + } + else{ + timer->stop(); + myled = 1 - myled; + } + estado_timer = 1 - estado_timer; + } + + int read() { + return _count; + } + +private: + InterruptIn _interrupt; + volatile int _count; +}; + +void tick(void const * arg){ + contador_timer += 1; + //myled = 1 - myled; + } + + +Counter counter(PC_9); // Boton azul + + +int main() { + + myled = 1; + timer = new RtosTimer(tick, osTimerPeriodic, (void *) 0); + //timer->start(1000); + + while(1){ + //wait(1); + Thread::wait(2100); + //if (counter.read()==2) timer->start(1000); + //if (counter.read()==10) timer->stop(); + //pc.printf("bucle princ %i\r\n", counter.read()); + pc.printf("bucle princ. contador_timer: %i contador_boton %i\r\n", contador_timer, counter.read()); + //myled = 1 - myled; + } +} + + +