part 2

Fork of Watchdog_sample_nocoverage by William Marsh

Files at this revision

API Documentation at this revision

Comitter:
dhenis
Date:
Fri Mar 09 23:06:31 2018 +0000
Parent:
5:9817756efc34
Commit message:
1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9817756efc34 -r 658d42dab71d main.cpp
--- a/main.cpp	Tue Feb 27 10:29:30 2018 +0000
+++ b/main.cpp	Fri Mar 09 23:06:31 2018 +0000
@@ -1,36 +1,44 @@
 #include "mbed.h"
 #include "rtos.h"
 #include "wdt.h"
-
+ 
 // Sample program using the Watchdog
 // ---------------------------------
 //    * Three threads co-operate to flash two LEDs
 //    * A simple way to inject a fault, by pressing a button 
 //    * The watchdog is configured with a 32ms timeout
-
+ 
 #define ON 1
 #define OFF 0
 DigitalOut led_red(LED_RED, ON);
 DigitalIn button(PTD0, PullUp);
 DigitalOut led1(PTC12, OFF);
 DigitalOut led2(PTC13, OFF);
-
+          // Ticker for reading analog
+AnalogIn ain(A0) ; 
+ 
+    char vstring[] = "X.XX\r\n" ;
+ 
+Serial pc(USBTX, USBRX); // tx, rx, for debugging
 // This ticker is used to feed the watch dog
 Ticker tick;
-
+ int oke = 0;
 // 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) ;  
+    oke =1;
+    while (!button) {
+    };  
 }
 
+
 // ---Thread for controlling LED 1----------------
 //   Turn LED1 on/off in response to signals 
 // -----------------------------------------------
@@ -38,14 +46,21 @@
     osEvent evt ;
     while (true) {
         evt = Thread::signal_wait(0x0); // wait for any signal
+               
+        wdt_kickA();
+
         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
+            
+   
     }
 }
-
+ 
 // ---Thread for controlling LED 2----------------
 //   Turn LED2 on/off in response to signals 
 // -----------------------------------------------
@@ -53,29 +68,42 @@
     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
+        //wdt_kickA();
+        
+        }
+        
+        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) ;
+         
         Thread::wait(250) ;
         threadLED1.signal_set(0x2) ;
         threadLED2.signal_set(0x2) ;
-        // waitButton() ; // POSSIBLE FAULT HERE
+       
+        //tick.attach_us(callback(&wdt_kick_all), 20000); // ticks every 20ms    
+        
+        
+       // waitButton() ; // POSSIBLE FAULT HERE
     }
 }
-
+ 
 // -----------MAIN-------------------------------
 //    Configure watchdog. Start threads. 
 //    Show start up with RED for 1sec
@@ -83,10 +111,14 @@
 //       - 1024ms to set it once
 //       - 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
+    //wdt_32ms();
+ 
+    
+    //tick.attach_us(callback(&wdt_kick_all), 20000); // ticks every 20ms    
     
     // start threads
     threadT.start(&timer_thread) ; // start the timer thread