Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 27 of 27

Thread: WDT_T4 - Watchdog Library for Teensy 4

  1. #26
    Member profor's Avatar
    Join Date
    Jun 2015
    Location
    Stupava, Slovakia
    Posts
    27

    callback not firing?

    Dear all,
    it seems the callback does not fire in my test sketch.
    The aim of the sketch is to be able to copy last function name into DMAMEM arrays to see in which function did the WDT fired.
    The code is self explanatory i hope and i am using the DMAMEM area as i read somewhere that that memory is kept during code upload (or during wdt reset) while the teensy is powered.

    Code:
    #include "Watchdog_t4.h"
    #include "elapsedMillis.h"
    #include <Bounce.h>
    WDT_T4<WDT3> wdt;
    
    DMAMEM  char  lastFunc[32];
    DMAMEM  char  lastLastFunc[32];
    DMAMEM  uint32_t  wdfired;
    uint32_t  bttn_1_pressed = 0;
    uint32_t  bttn_2_pressed = 0;
    
    #define debug_out1  3
    #define debug_out2  4
    
    
    void myCallback() {
      digitalWriteFast(LED_BUILTIN, HIGH);
      wdfired++;    //  indicate the fired wdt
    }
    
    elapsedMicros oneMillis;
    elapsedMillis wdtRefresh;
    
    #define millisecond         998
    #define wdtRefreshInterval  40
    
    const int button_clear = 2;
    const int button_1 = 0;
    const int button_2 = 1;
    Bounce bttn_clear = Bounce(button_clear,10); 
    Bounce bttn_1 = Bounce(button_1,10); 
    Bounce bttn_2 = Bounce(button_2,10); 
    
    
    void setup() {
      
      Serial.begin(1);
      pinMode(button_clear, INPUT_PULLUP);
      pinMode(button_1, INPUT_PULLUP);
      pinMode(button_2, INPUT_PULLUP);
      pinMode(debug_out1, OUTPUT);
      pinMode(debug_out2, OUTPUT);
      pinMode(LED_BUILTIN,  OUTPUT);
    
    
      while (!Serial);
      
      Serial.print("Begin wdt test / wdtfired: ");
      Serial.println(wdfired);  // at first run, display random data in DMAMEM array
      
      WDT_timings_t config;
      config.window = 30;
      config.timeout = 55;
      config.callback = myCallback;
      wdt.begin(config);
      wdtRefresh = 0;
    
    }
    
    void loop() {
    
      if (bttn_clear.update()) {
        if (bttn_clear.fallingEdge()) {
          Serial.print(F(" wdfired "));   // at first run, display random data in DMAMEM array
          Serial.print(wdfired);
          wdfired = 0;
          Serial.println(F(" cleared"));
          Serial.println(lastLastFunc);   //  print previous func array
          Serial.println(lastFunc);     //  print last func array
       
    /*      for (uint8_t  q = 0;  q < sizeof(lastFunc); q++)  {
            Serial.print(lastFunc[q]);
          } */
    
          memset(lastFunc,  '.',  sizeof(lastFunc));      //  preset them
          memset(lastLastFunc,  '.',  sizeof(lastLastFunc));   
          
        }
      }
    
      if (bttn_1.update()) {        //  button debounce
        if (bttn_1.fallingEdge()) {
          Serial.println(F("Button 1 pressed"));  
          bttn_1_pressed++;         //  just increase the variable
        }
      }
    
        if (bttn_2.update()) {
        if (bttn_2.fallingEdge()) {
          Serial.println(F("Button 2 pressed"));  
          bttn_2_pressed++;
        }
      }
      
      if  (oneMillis > millisecond) {   //  1 ms interval
        oneMillis = 0;
    //    digitalWriteFast(LED_BUILTIN, LOW);
        test1();
        test_kurna_snad_to_pojde();
        digitalWrite(debug_out2,  !digitalRead(debug_out2));
      }
    
    
      if  (wdtRefresh > wdtRefreshInterval) {   //  wdt feeder 41 ms
        wdtRefresh = 0;
        wdt.feed();
        digitalWrite(debug_out1,  !digitalRead(debug_out1));
      }
    
    }
    
    FASTRUN void  test1() {
      memcpy(lastLastFunc,  lastFunc, sizeof(lastFunc));    //  copy last to previous
      memcpy(lastFunc,  __func__, sizeof(__func__));      //  update last
      while (bttn_1_pressed)  {
        
      }
    }
    
    FASTRUN void  test_kurna_snad_to_pojde() {
      memcpy(lastLastFunc,  lastFunc, sizeof(lastFunc));
      memcpy(lastFunc,  __func__, sizeof(__func__));
      while (bttn_2_pressed)  {
        
      }  
    }
    I am running the code on Teensy 4.1.

    Thank You a lot

  2. #27
    Member profor's Avatar
    Join Date
    Jun 2015
    Location
    Stupava, Slovakia
    Posts
    27
    OK my fault, i did not follow the example code here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •