Demonstration of signal-wait on the F429ZI

Committer:
noutram
Date:
Thu Apr 26 07:57:38 2018 +0000
Revision:
0:0d639007cb27
Demonstration of signal-wait

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:0d639007cb27 1 #include "mbed.h"
noutram 0:0d639007cb27 2 #define WAIT_FOR_ISR 1
noutram 0:0d639007cb27 3 //Function declarations
noutram 0:0d639007cb27 4 void Function1();
noutram 0:0d639007cb27 5 void ISR();
noutram 0:0d639007cb27 6
noutram 0:0d639007cb27 7 //Thread
noutram 0:0d639007cb27 8 Thread t1;
noutram 0:0d639007cb27 9
noutram 0:0d639007cb27 10 //I/O
noutram 0:0d639007cb27 11 DigitalOut led1(LED1);
noutram 0:0d639007cb27 12 DigitalOut led2(LED2);
noutram 0:0d639007cb27 13 InterruptIn onBoardSwitch(USER_BUTTON);
noutram 0:0d639007cb27 14
noutram 0:0d639007cb27 15 //Switch ISR
noutram 0:0d639007cb27 16 void ISR() {
noutram 0:0d639007cb27 17 t1.signal_set(WAIT_FOR_ISR);
noutram 0:0d639007cb27 18 }
noutram 0:0d639007cb27 19
noutram 0:0d639007cb27 20 //Thread
noutram 0:0d639007cb27 21 void Function1() {
noutram 0:0d639007cb27 22 while (true) {
noutram 0:0d639007cb27 23 Thread::signal_wait(WAIT_FOR_ISR);
noutram 0:0d639007cb27 24 wait(0.2); //Debounce
noutram 0:0d639007cb27 25 Thread::signal_clr(WAIT_FOR_ISR);
noutram 0:0d639007cb27 26 led1 = !led1;
noutram 0:0d639007cb27 27 }
noutram 0:0d639007cb27 28 }
noutram 0:0d639007cb27 29
noutram 0:0d639007cb27 30 //Main thread
noutram 0:0d639007cb27 31 int main() {
noutram 0:0d639007cb27 32 //Initial state
noutram 0:0d639007cb27 33 led1 = 1;
noutram 0:0d639007cb27 34 led2 = 1;
noutram 0:0d639007cb27 35 onBoardSwitch.rise(ISR);
noutram 0:0d639007cb27 36
noutram 0:0d639007cb27 37 //Create and run threads (C function pointers)
noutram 0:0d639007cb27 38 t1.start(Function1);
noutram 0:0d639007cb27 39
noutram 0:0d639007cb27 40 //Main thread loop
noutram 0:0d639007cb27 41 while(1) {
noutram 0:0d639007cb27 42 led2 = !led2;
noutram 0:0d639007cb27 43 Thread::wait(100);
noutram 0:0d639007cb27 44 }
noutram 0:0d639007cb27 45 }