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

Committer:
CarlosKitu
Date:
Tue Jan 03 14:14:51 2017 +0000
Revision:
1:fc92ede355c4
Parent:
0:005ae170e5f9
Just to try whether is it posible to call rtostimer::start()/stop() from an ISR. The answer seems to be NO.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CarlosKitu 0:005ae170e5f9 1 #include "mbed.h"
CarlosKitu 0:005ae170e5f9 2 #include "rtos.h"
CarlosKitu 0:005ae170e5f9 3
CarlosKitu 0:005ae170e5f9 4 DigitalOut myled(LED1);
CarlosKitu 0:005ae170e5f9 5 Serial pc(SERIAL_TX, SERIAL_RX);
CarlosKitu 0:005ae170e5f9 6
CarlosKitu 1:fc92ede355c4 7 volatile int count_timer = 0;
CarlosKitu 1:fc92ede355c4 8 volatile int state_timer = 0;
CarlosKitu 1:fc92ede355c4 9 volatile int count_button = 0;
CarlosKitu 1:fc92ede355c4 10
CarlosKitu 0:005ae170e5f9 11 RtosTimer * timer;
CarlosKitu 0:005ae170e5f9 12
CarlosKitu 1:fc92ede355c4 13 void increment() {
CarlosKitu 1:fc92ede355c4 14 count_button ++;
CarlosKitu 0:005ae170e5f9 15
CarlosKitu 1:fc92ede355c4 16 if(state_timer==0)
CarlosKitu 1:fc92ede355c4 17 {
CarlosKitu 1:fc92ede355c4 18 myled = 1 - myled;
CarlosKitu 1:fc92ede355c4 19 timer->start(1000);
CarlosKitu 1:fc92ede355c4 20 }
CarlosKitu 1:fc92ede355c4 21 else{
CarlosKitu 1:fc92ede355c4 22 timer->stop();
CarlosKitu 1:fc92ede355c4 23 myled = 1 - myled;
CarlosKitu 0:005ae170e5f9 24 }
CarlosKitu 1:fc92ede355c4 25 state_timer = 1 - state_timer;
CarlosKitu 1:fc92ede355c4 26 }
CarlosKitu 0:005ae170e5f9 27
CarlosKitu 1:fc92ede355c4 28
CarlosKitu 0:005ae170e5f9 29
CarlosKitu 1:fc92ede355c4 30 InterruptIn interrupt(PC_9);
CarlosKitu 1:fc92ede355c4 31
CarlosKitu 0:005ae170e5f9 32
CarlosKitu 1:fc92ede355c4 33
CarlosKitu 1:fc92ede355c4 34 void timeout(void const * arg){
CarlosKitu 1:fc92ede355c4 35 count_timer += 1;
CarlosKitu 0:005ae170e5f9 36 //myled = 1 - myled;
CarlosKitu 0:005ae170e5f9 37 }
CarlosKitu 0:005ae170e5f9 38
CarlosKitu 0:005ae170e5f9 39
CarlosKitu 0:005ae170e5f9 40
CarlosKitu 0:005ae170e5f9 41 int main() {
CarlosKitu 0:005ae170e5f9 42
CarlosKitu 0:005ae170e5f9 43 myled = 1;
CarlosKitu 1:fc92ede355c4 44 timer = new RtosTimer(timeout, osTimerPeriodic, (void *) 0);
CarlosKitu 1:fc92ede355c4 45 interrupt.rise(&increment);
CarlosKitu 1:fc92ede355c4 46 interrupt.mode(PullUp);
CarlosKitu 0:005ae170e5f9 47 //timer->start(1000);
CarlosKitu 0:005ae170e5f9 48
CarlosKitu 0:005ae170e5f9 49 while(1){
CarlosKitu 0:005ae170e5f9 50 Thread::wait(2100);
CarlosKitu 1:fc92ede355c4 51 if (count_button==10) timer->start(1000);
CarlosKitu 1:fc92ede355c4 52 if (count_button==20) timer->stop();
CarlosKitu 0:005ae170e5f9 53 //pc.printf("bucle princ %i\r\n", counter.read());
CarlosKitu 1:fc92ede355c4 54 pc.printf("count_timer: %i count_button %i\r\n", count_timer, count_button);
CarlosKitu 0:005ae170e5f9 55 //myled = 1 - myled;
CarlosKitu 0:005ae170e5f9 56 }
CarlosKitu 0:005ae170e5f9 57 }
CarlosKitu 0:005ae170e5f9 58
CarlosKitu 0:005ae170e5f9 59
CarlosKitu 1:fc92ede355c4 60 /* CONSOLE
CarlosKitu 1:fc92ede355c4 61 count_timer: 0 count_button 0
CarlosKitu 1:fc92ede355c4 62 count_timer: 0 count_button 0
CarlosKitu 1:fc92ede355c4 63 count_timer: 0 count_button 0
CarlosKitu 1:fc92ede355c4 64 count_timer: 0 count_button 0
CarlosKitu 1:fc92ede355c4 65 count_timer: 0 count_button 1
CarlosKitu 1:fc92ede355c4 66 count_timer: 0 count_button 1
CarlosKitu 1:fc92ede355c4 67 count_timer: 0 count_button 2
CarlosKitu 1:fc92ede355c4 68 count_timer: 0 count_button 4
CarlosKitu 1:fc92ede355c4 69 count_timer: 0 count_button 5
CarlosKitu 1:fc92ede355c4 70 count_timer: 0 count_button 6
CarlosKitu 1:fc92ede355c4 71 count_timer: 0 count_button 7
CarlosKitu 1:fc92ede355c4 72 count_timer: 0 count_button 8
CarlosKitu 1:fc92ede355c4 73 count_timer: 0 count_button 9
CarlosKitu 1:fc92ede355c4 74 count_timer: 0 count_button 10
CarlosKitu 1:fc92ede355c4 75 count_timer: 2 count_button 10
CarlosKitu 1:fc92ede355c4 76 count_timer: 4 count_button 10
CarlosKitu 1:fc92ede355c4 77 count_timer: 6 count_button 11
CarlosKitu 1:fc92ede355c4 78 count_timer: 8 count_button 12
CarlosKitu 1:fc92ede355c4 79 count_timer: 10 count_button 12
CarlosKitu 1:fc92ede355c4 80 count_timer: 12 count_button 12
CarlosKitu 1:fc92ede355c4 81 count_timer: 14 count_button 14
CarlosKitu 1:fc92ede355c4 82 count_timer: 16 count_button 14
CarlosKitu 1:fc92ede355c4 83 count_timer: 18 count_button 14
CarlosKitu 1:fc92ede355c4 84 count_timer: 21 count_button 15
CarlosKitu 1:fc92ede355c4 85 count_timer: 23 count_button 15
CarlosKitu 1:fc92ede355c4 86 count_timer: 25 count_button 17
CarlosKitu 1:fc92ede355c4 87 count_timer: 27 count_button 18
CarlosKitu 1:fc92ede355c4 88 count_timer: 29 count_button 20
CarlosKitu 1:fc92ede355c4 89 count_timer: 29 count_button 20
CarlosKitu 1:fc92ede355c4 90 count_timer: 29 count_button 20
CarlosKitu 1:fc92ede355c4 91 count_timer: 29 count_button 21
CarlosKitu 1:fc92ede355c4 92 count_timer: 29 count_button 21
CarlosKitu 1:fc92ede355c4 93 count_timer: 29 count_button 22
CarlosKitu 1:fc92ede355c4 94 count_timer: 29 count_button 23
CarlosKitu 1:fc92ede355c4 95 count_timer: 29 count_button 24
CarlosKitu 1:fc92ede355c4 96 */