ENSMM / Mbed 2 deprecated Timeout

Dependencies:   mbed

Fork of Timeout by Joël Imbaud

Committer:
jimbaud
Date:
Tue Jan 08 10:23:12 2019 +0000
Revision:
0:7a0f7fbc736b
Child:
1:50617d33bd51
se the Timeout interface to set up an interrupt to call a function after a specified delay.; You can create any number of Timeout objects, allowing multiple outstanding interrupts at the same time.; ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jimbaud 0:7a0f7fbc736b 1 /* https://os.mbed.com/docs/v5.7/reference/timer.html
jimbaud 0:7a0f7fbc736b 2
jimbaud 0:7a0f7fbc736b 3 Use the Timeout interface to set up an interrupt to call a function after a specified delay.
jimbaud 0:7a0f7fbc736b 4 You can create any number of Timeout objects, allowing multiple outstanding interrupts at the same time.
jimbaud 0:7a0f7fbc736b 5 Warnings and notes
jimbaud 0:7a0f7fbc736b 6 Timers are based on 32-bit int microsecond counters, so they can only time up to a maximum of 2^31-1 microseconds (30 minutes). They are designed for times between microseconds and seconds. For longer times, you should consider the time() real time clock.
jimbaud 0:7a0f7fbc736b 7 No blocking code in ISR: avoid any call to wait, infinite while loop or blocking calls in general.
jimbaud 0:7a0f7fbc736b 8 No printf, malloc or new in ISR: Avoid any call to bulky library functions. In particular, certain library functions (such as printf, malloc and new) are not re-entrant, and their behavior could be corrupted when called from an ISR.
jimbaud 0:7a0f7fbc736b 9 */
jimbaud 0:7a0f7fbc736b 10
jimbaud 0:7a0f7fbc736b 11 #include "mbed.h"
jimbaud 0:7a0f7fbc736b 12
jimbaud 0:7a0f7fbc736b 13 Timeout flipper;
jimbaud 0:7a0f7fbc736b 14 DigitalOut led1(LED1);
jimbaud 0:7a0f7fbc736b 15
jimbaud 0:7a0f7fbc736b 16 void flip() {
jimbaud 0:7a0f7fbc736b 17 led1 = !led1;
jimbaud 0:7a0f7fbc736b 18 }
jimbaud 0:7a0f7fbc736b 19
jimbaud 0:7a0f7fbc736b 20 int main() {
jimbaud 0:7a0f7fbc736b 21 led2 = 1;
jimbaud 0:7a0f7fbc736b 22 flipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds
jimbaud 0:7a0f7fbc736b 23 // spin in a main loop. flipper will interrupt it to call flip
jimbaud 0:7a0f7fbc736b 24
jimbaud 0:7a0f7fbc736b 25 while(1) {
jimbaud 0:7a0f7fbc736b 26 }
jimbaud 0:7a0f7fbc736b 27 }