Manuel Campos
/
Watchdog_sample_nocoverage_cvmanuel
initial version
Fork of Watchdog_sample_nocoverage by
Diff: main.cpp
- Revision:
- 6:57328a0cc08e
- Parent:
- 3:32a940251192
--- a/main.cpp Tue Feb 27 10:29:30 2018 +0000 +++ b/main.cpp Fri Mar 09 21:31:16 2018 +0000 @@ -15,20 +15,26 @@ DigitalOut led1(PTC12, OFF); DigitalOut led2(PTC13, OFF); +AnalogIn ain(A0); +AnalogIn ain1(A1); + + +Serial pc(USBTX, USBRX); // tx, rx, for debugging + // This ticker is used to feed the watch dog Ticker tick; // Threads -Thread threadT ; // timer thread -Thread threadLED1 ; // thread LED1 -Thread threadLED2 ; // thread LED2 +Thread threadT(osPriorityNormal, 1000); // timer thread +Thread threadLED1(osPriorityNormal, 1000); // thread LED1 +Thread threadLED2(osPriorityNormal, 1000); // thread LED2 // ------------Fault Injection Button------------- // Wait while the button is down // Use this to simulate a STUCK fault // ----------------------------------------------- void waitButton() { - while (!button) ; + while (!button) ; } // ---Thread for controlling LED 1---------------- @@ -41,8 +47,11 @@ if (evt.status == osEventSignal) { if (evt.value.signals & 0x01) led1 = ON ; if (evt.value.signals & 0x02) led1 = OFF ; + wdt_kickA(); } - waitButton() ; // POSSIBLE FAULT HERE + + + //waitButton() ; // POSSIBLE FAULT HERE } } @@ -56,8 +65,10 @@ if (evt.status == osEventSignal) { if (evt.value.signals & 0x01) led2 = ON ; if (evt.value.signals & 0x02) led2 = OFF ; + wdt_kickB(); } - // waitButton() ; // POSSIBLE FAULT HERE + + //waitButton() ; // POSSIBLE FAULT HERE } } @@ -72,10 +83,15 @@ Thread::wait(250) ; threadLED1.signal_set(0x2) ; threadLED2.signal_set(0x2) ; - // waitButton() ; // POSSIBLE FAULT HERE + + + waitButton() ; // POSSIBLE FAULT HERE } } + + + // -----------MAIN------------------------------- // Configure watchdog. Start threads. // Show start up with RED for 1sec @@ -85,16 +101,20 @@ // ---------------------------------------------- int main(void) { - wdt_32ms() ; // initialise watchdog - 32ms timeout - tick.attach_us(callback(&wdt_kick_all), 20000); // ticks every 20ms + wdt_1sec() ; // initialise watchdog - 32ms timeout + //tick.attach_us(callback(&wdt_kick_all), 20000); // ticks every 20ms + // start threads threadT.start(&timer_thread) ; // start the timer thread threadLED1.start(&led1_thread) ; // start the LED1 control thread threadLED2.start(&led2_thread) ; // start the LED2 control thread + + // show start-up led_red = OFF; Thread::wait(1000) ; led_red = ON; + } \ No newline at end of file