Just to try whether is it posible to call rtostimer::start()/stop() from an ISR. The answer seems to be NO.

Dependencies:   mbed-rtos mbed

Fork of boton_ISR by Carlos López Molina

main.cpp

Committer:
CarlosKitu
Date:
2017-01-03
Revision:
0:005ae170e5f9
Child:
1:fc92ede355c4

File content as of revision 0:005ae170e5f9:

#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;
  }
}