Skip to content

watchdog Instructions for using watchdog*

1. watchdog overview*

  • watchdog timer, also known as watchdog timer, is a very simple and effective detection tool in the field of computer dependability.

  • The basic idea of the Watchdog is to set a counter and a threshold for the monitored target. The watchdog itself increments the count and waits for the monitored target to periodically reset the count. If an error occurs on the target and the count is not reset, the watchdog detects the overflow and takes recovery action (usually restart).

2. watchdog function features*

  • Support automatic dog feeding
  • Manual feeding of dogs is supported
  • You can manually restart the system
/*******************************************
* Watchdog initialization
*
* Parameters:
* reset_timeout_ms: Watchdog reset chip timeout
* level_timeout_ms: The watchdog generates a timeout
* irq_handler: Interrupt the service callback function
* pdata: Interrupt service callback function private parameter
*******************************************/
void gx_watchdog_init(
     uint16_t reset_timeout_ms,
     uint16_t level_timeout_ms,
     irq_handler_t irq_handler,
     void *pdata
)


/*******************************************
* The watchdog feeds the dog
*******************************************/
void gx_watchdog_ping(void)


/******************************************
* restart
*
* Returns:
* int Reset function, will not return
******************************************/
int gx_reboot(void)


/*****************************************
* Guard dog off
******************************************/
void gx_watchdog_stop(void)

4. watchdog code example*

  • Use a watchdog in your App
    lvp_tws/app/sample/lvp_app_sample.c
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    int watchdog_callback(int irq, void *pdata)     // The watchdog interrupts the service function
    {
        gx_reboot();        // restart
        return 0;
    }
    
    static int SampleAppSuspend(void *priv)
    {
        // Turn off the watchdog. If there is sleep, turning off the watchdog before sleep will reduce some power consumption
        gx_watchdog_stop();
        return 0;
    }
    
    static int SampleAppResume(void *priv)
    {
        return 0;
    }
    
    static int SampleAppInit(void)
    {
        printf(LOG_TAG" ---- %s ----\n", __func__);
        // The timeout period is set to 3s
        gx_watchdog_init(3000, 3000, watchdog_callback, NULL);
        return 0;
    }
    
    // App Event Process
    static int SampleAppEventResponse(APP_EVENT *app_event)
    {
        // To feed the dog, this interface is called every time audio in interrupts, usually at 60ms
        // You can also feed your dog on a timer, and you can feed your dog during a timeout
        gx_watchdog_ping();
    
        return 0;
    }
    
    // APP Main Loop
    static int SampleAppTaskLoop(void)
    {
        return 0;
    }
    
    
    LVP_APP sample_app = {
        .app_name = "sample app",
        .AppInit = SampleAppInit,
        .AppEventResponse = SampleAppEventResponse,
        .AppTaskLoop = SampleAppTaskLoop,
        .AppSuspend = SampleAppSuspend,
        .suspend_priv = "SampleAppSuspend",
        .AppResume = SampleAppResume,
        .resume_priv = "SampleAppResume",
    };
    
    LVP_REGISTER_APP(sample_app);