Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Watchdog_sample_nocoverage by
Revision 6:ddffcc0aeba1, committed 2018-03-09
- Comitter:
- Peilingyi
- Date:
- Fri Mar 09 23:31:49 2018 +0000
- Parent:
- 5:9817756efc34
- Commit message:
- Lab6-1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Feb 27 10:29:30 2018 +0000 +++ b/main.cpp Fri Mar 09 23:31:49 2018 +0000 @@ -14,35 +14,51 @@ DigitalIn button(PTD0, PullUp); DigitalOut led1(PTC12, OFF); DigitalOut led2(PTC13, OFF); +Serial pc(USBTX, USBRX); // 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 + +//define the state of watch dog +enum wState {Working, Stopped} ; +wState watchdogflag; +int led1counter1=0; +int led1counter2=0; +int led2counter1=0; +int led2counter2=0; // ------------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---------------- // Turn LED1 on/off in response to signals // ----------------------------------------------- void led1_thread() { // method to run in thread osEvent evt ; + while (true) { + wdt_kickA(); evt = Thread::signal_wait(0x0); // wait for any signal if (evt.status == osEventSignal) { if (evt.value.signals & 0x01) led1 = ON ; if (evt.value.signals & 0x02) led1 = OFF ; + } - waitButton() ; // POSSIBLE FAULT HERE + + + // waitButton() ; // POSSIBLE FAULT HERE } } @@ -51,28 +67,38 @@ // ----------------------------------------------- void led2_thread() { // method to run in thread osEvent evt ; + + while (true) { + evt = Thread::signal_wait(0x0); // wait for any signal + wdt_kickB(); if (evt.status == osEventSignal) { if (evt.value.signals & 0x01) led2 = ON ; if (evt.value.signals & 0x02) led2 = OFF ; + } - // waitButton() ; // POSSIBLE FAULT HERE + + // waitButton() ; // POSSIBLE FAULT HERE + } } + // ---Thread for timing -------------------------- // Send signals to the other threads // ----------------------------------------------- void timer_thread() { // method to run in thread while (true) { Thread::wait(250) ; - threadLED1.signal_set(0x1) ; - threadLED2.signal_set(0x1) ; + threadLED1.signal_set(0x1) ;//on + threadLED2.signal_set(0x1) ;//on + Thread::wait(250) ; - threadLED1.signal_set(0x2) ; - threadLED2.signal_set(0x2) ; - // waitButton() ; // POSSIBLE FAULT HERE + threadLED1.signal_set(0x2) ;//off + threadLED2.signal_set(0x2) ;//off + + waitButton() ; // POSSIBLE FAULT HERE } } @@ -84,17 +110,24 @@ // - then must feed it every 32ms // ---------------------------------------------- + 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); + + // 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