Lab6 - Step 2: Modify the Program to Increase the Watchdog Fault Coverage
Fork of Watchdog_sample_nocoverage by
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "wdt.h" 00004 00005 // Sample program using the Watchdog 00006 // --------------------------------- 00007 // * Three threads co-operate to flash two LEDs 00008 // * A simple way to inject a fault, by pressing a button 00009 // * The watchdog is configured with a 32ms timeout 00010 00011 #define ON 1 00012 #define OFF 0 00013 DigitalOut led_red(LED_RED, ON); 00014 DigitalIn button(PTD0, PullUp); 00015 DigitalOut led1(PTC12, OFF); 00016 DigitalOut led2(PTC13, OFF); 00017 00018 // This ticker is used to feed the watch dog 00019 Ticker tick; 00020 00021 // Threads 00022 Thread threadT(osPriorityNormal, 2000) ; // timer thread 00023 Thread threadLED1(osPriorityNormal, 2000) ; // thread LED1 00024 Thread threadLED2(osPriorityNormal, 2000) ; // thread LED2 00025 00026 // ------------Fault Injection Button------------- 00027 // Wait while the button is down 00028 // Use this to simulate a STUCK fault 00029 // ----------------------------------------------- 00030 void waitButton() { 00031 while (!button) ; 00032 } 00033 00034 // ---Thread for controlling LED 1---------------- 00035 // Turn LED1 on/off in response to signals 00036 // ----------------------------------------------- 00037 void led1_thread() { // method to run in thread 00038 osEvent evt ; 00039 while (true) { 00040 evt = Thread::signal_wait(0x0); // wait for any signal 00041 if (evt.status == osEventSignal) { 00042 if (evt.value.signals & 0x01) led1 = ON ; 00043 if (evt.value.signals & 0x02) led1 = OFF ; 00044 } 00045 waitButton() ; // POSSIBLE FAULT HERE 00046 wdt_kickA(); 00047 } 00048 } 00049 00050 // ---Thread for controlling LED 2---------------- 00051 // Turn LED2 on/off in response to signals 00052 // ----------------------------------------------- 00053 void led2_thread() { // method to run in thread 00054 osEvent evt ; 00055 while (true) { 00056 evt = Thread::signal_wait(0x0); // wait for any signal 00057 if (evt.status == osEventSignal) { 00058 if (evt.value.signals & 0x01) led2 = ON ; 00059 if (evt.value.signals & 0x02) led2 = OFF ; 00060 } 00061 //waitButton() ; // POSSIBLE FAULT HERE 00062 wdt_kickB(); 00063 } 00064 } 00065 00066 // ---Thread for timing -------------------------- 00067 // Send signals to the other threads 00068 // ----------------------------------------------- 00069 void timer_thread() { // method to run in thread 00070 while (true) { 00071 Thread::wait(250) ; 00072 threadLED1.signal_set(0x1) ; 00073 threadLED2.signal_set(0x1) ; 00074 Thread::wait(250) ; 00075 threadLED1.signal_set(0x2) ; 00076 threadLED2.signal_set(0x2) ; 00077 //waitButton() ; // POSSIBLE FAULT HERE 00078 } 00079 } 00080 00081 // -----------MAIN------------------------------- 00082 // Configure watchdog. Start threads. 00083 // Show start up with RED for 1sec 00084 // Remember the watchdog is running 00085 // - 1024ms to set it once 00086 // - then must feed it every 32ms 00087 // ---------------------------------------------- 00088 00089 int main(void) { 00090 wdt_1sec() ; // initialise watchdog - 32ms timeout 00091 //tick.attach_us(callback(&wdt_kick_all), 20000); // ticks every 20ms 00092 00093 // start threads 00094 threadT.start(&timer_thread) ; // start the timer thread 00095 threadLED1.start(&led1_thread) ; // start the LED1 control thread 00096 threadLED2.start(&led2_thread) ; // start the LED2 control thread 00097 00098 // show start-up 00099 led_red = OFF; 00100 Thread::wait(1000) ; 00101 led_red = ON; 00102 }
Generated on Wed Jul 13 2022 22:48:06 by
1.7.2
