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
Revision 1:fc92ede355c4, committed 2017-01-03
- Comitter:
- CarlosKitu
- Date:
- Tue Jan 03 14:14:51 2017 +0000
- Parent:
- 0:005ae170e5f9
- Commit message:
- Just to try whether is it posible to call rtostimer::start()/stop() from an ISR. The answer seems to be NO.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 005ae170e5f9 -r fc92ede355c4 main.cpp --- a/main.cpp Tue Jan 03 13:49:43 2017 +0000 +++ b/main.cpp Tue Jan 03 14:14:51 2017 +0000 @@ -4,67 +4,93 @@ DigitalOut myled(LED1); Serial pc(SERIAL_TX, SERIAL_RX); -volatile int contador_timer = 0; -volatile int estado_timer = 0; +volatile int count_timer = 0; +volatile int state_timer = 0; +volatile int count_button = 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++; +void increment() { + count_button ++; - if(estado_timer==0) - { - myled = 1 - myled; - ; - timer->start(1000); - } - else{ - timer->stop(); - myled = 1 - myled; - } - estado_timer = 1 - estado_timer; + if(state_timer==0) + { + myled = 1 - myled; + timer->start(1000); + } + else{ + timer->stop(); + myled = 1 - myled; } + state_timer = 1 - state_timer; +} - int read() { - return _count; - } + -private: - InterruptIn _interrupt; - volatile int _count; -}; +InterruptIn interrupt(PC_9); + -void tick(void const * arg){ - contador_timer += 1; + +void timeout(void const * arg){ + count_timer += 1; //myled = 1 - myled; } -Counter counter(PC_9); // Boton azul - int main() { myled = 1; - timer = new RtosTimer(tick, osTimerPeriodic, (void *) 0); + timer = new RtosTimer(timeout, osTimerPeriodic, (void *) 0); + interrupt.rise(&increment); + interrupt.mode(PullUp); //timer->start(1000); while(1){ - //wait(1); Thread::wait(2100); - //if (counter.read()==2) timer->start(1000); - //if (counter.read()==10) timer->stop(); + if (count_button==10) timer->start(1000); + if (count_button==20) 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()); + pc.printf("count_timer: %i count_button %i\r\n", count_timer, count_button); //myled = 1 - myled; } } - +/* CONSOLE +count_timer: 0 count_button 0 +count_timer: 0 count_button 0 +count_timer: 0 count_button 0 +count_timer: 0 count_button 0 +count_timer: 0 count_button 1 +count_timer: 0 count_button 1 +count_timer: 0 count_button 2 +count_timer: 0 count_button 4 +count_timer: 0 count_button 5 +count_timer: 0 count_button 6 +count_timer: 0 count_button 7 +count_timer: 0 count_button 8 +count_timer: 0 count_button 9 +count_timer: 0 count_button 10 +count_timer: 2 count_button 10 +count_timer: 4 count_button 10 +count_timer: 6 count_button 11 +count_timer: 8 count_button 12 +count_timer: 10 count_button 12 +count_timer: 12 count_button 12 +count_timer: 14 count_button 14 +count_timer: 16 count_button 14 +count_timer: 18 count_button 14 +count_timer: 21 count_button 15 +count_timer: 23 count_button 15 +count_timer: 25 count_button 17 +count_timer: 27 count_button 18 +count_timer: 29 count_button 20 +count_timer: 29 count_button 20 +count_timer: 29 count_button 20 +count_timer: 29 count_button 21 +count_timer: 29 count_button 21 +count_timer: 29 count_button 22 +count_timer: 29 count_button 23 +count_timer: 29 count_button 24 +*/