This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Taking action following system reset due to watchdog timer violation

Other Parts Discussed in Thread: LAUNCHXL2-RM46, HALCOGEN

Hi,

I've set up a watchdog timer on my LAUNCHXL2-RM46 that initiates a system restart when it expires. I'm having trouble making the system behave differently when it encounters a restart initiated by the watchdog timer. 

I've tried reading systemREG1->SYSESR. This looks like it is assigned a value to indicate the reason for restart was due to watchdog timer, but the value is cleared by SYS_EXCEPTION = WATCHDOG_RESET in sys_startup.c. By the time my main code runs, the evidence of the reason for restart is gone.

I'm also finding that if I call a function I define elsewhere in my code from sys_startup.c, the program hangs once it reaches that function. For instance, trying to blink an LED from this function doesn't work.

What is intended best practice for dealing with a system restart due to watchdog expiry?

Is the intention for me to modify the sys_startup.c file such that it doesn't clear the exception status register so I can read and clear it from my main? Would I be introducing problems into the rest of the startup sequence if I modify this file?

Am I encountering failure when trying to blink the LED from a function called from sys_startup.c because the proper initialization on the board hasn't occurred following the restart?

Thanks,

Paul

 

  • It might be better to only modify sys_startup.c within the /* USER CODE BEGIN (n) */ and /* USER CODE END */ statements. That way if you need to modify your HALCoGen, it will not undo your modifications. You could define an external static variable in the /* USER CODE BEGIN (4) */ section. Then in the /* USER CODE BEGIN (11) */ section do my_ext_reset_status = SYS_EXCEPTION; In main you can now check "my_ext_reset_status " to see the reset source.
  • Hi Bob,

    Thanks for your reply. You've hit on one of my primary concerns with editing sys_startup.c - I don't want to have to redo code if re-generating in HALCoGen, and so am sticking to modifications between the USER CODE BEGIN/END statements as you've suggested.

    Can you elaborate on the definition and placement of the external static variable? I'm experiencing trouble having the variable retain its value once the system restarts. This is what I'm trying now: Suppose I use the following three files 

    sys_startup.c

    Here I am assigning a value to my_ext_reset_status

    If the reason for reset was the watchdog timer, then I assign a value of 1 here

    sys_main.c

    Here I am checking the value of my_ext_reset_status

    If I've just assigned a value of 1 in sys_startup.c, I now see the value here as 0

    common_header.h

    Here I am declaring a static variable so it is known to both .c files

    static int my_ext_reset_status;

    How or where should the variable be defined such that it keeps its value? 

    Thanks,

    Paul

  • Paul,

    I overlooked the problem that the RAM is probably getting cleared during PBIST. Let me think about this.
  • Paul,

    If you just need to identify the Watchdog reset, disable the clearing of the exception status register for the watchdog in sys_startup.c something like this:

    /* USER CODE BEGIN (17) */
    #if 0
    /* USER CODE END */
    
                /* Clear the Watchdog reset flag in Exception Status register */ 
                SYS_EXCEPTION = WATCHDOG_RESET;
            
    /* USER CODE BEGIN (18) */
    #endif
    /* USER CODE END */
    

    Now you can read the system exception status register in main. Be sure to clear the watchdog flag after you read it, or it will still be set on other resets (except power-on).

  • Sneaky.

    Thanks for the suggestion Bob. This implementation worked for me and should save from having to recode following HALCoGen regeneration.

    For completeness, I've implemented this change, and am checking the register from my sys_main.c file:

    from within the main function:
    //Check reason for system restart
    uint32 checkSYSESR = systemREG1->SYSESR;
    if (checkSYSESR == 0x2008)
    {
    ResetByWatchdog();
    }



    void ResetByWatchdog(void)
    {
    //Reset the watchdog register here, because prevented this in sys_startup.c
    SYS_EXCEPTION = WATCHDOG_RESET;
    //Perform any other necessary actions

    }