#ifndef __WATCHDOG_H_INCLUDED__
#define __WATCHDOG_H_INCLUDED__

#include<stdint.h>



//some helper definition
enum {
    IGNORE = -1,

    //for action
    REBOOT   = 0,
    SHUTDOWN = -1,
    SUSPEND  = -2,
    NOOP     = -3,
    //> 0 means reboot_delay
};
    

#define WD_POLICY_NUMBER       (6)
#define NAME(_name) #_name


typedef struct{
    int64_t   start_ms;     //must be int, monitor start time, IGNORE means IGNORE this item, OK means already OK. other >= 0 value means the start time
    uint32_t  timeout_ms;             //if not OK after timeout_ms seconds, do the recovery produce.
    uint32_t  action[WD_POLICY_NUMBER];           //if not IGNORE, ask mcu do action. support retry up to 4 times. support REBOOT/SHUTDOWN/NOOP/reboot_delay
}wd_item_s;

typedef void ( *soft_watchdog_item_fail)(uint32_t fail_idx);

/* 初始化后，需要 soft_watchdog_start 来开启对应的wtd */
void soft_watchdog_init(wd_item_s *items, uint32_t item_cnt, soft_watchdog_item_fail fail_cb);


/* 关闭对应item的看门狗 */
void soft_watchdog_stop(uint32_t item);

/* 打开对应item的看门狗  */
void soft_watchdog_start(uint32_t item);

/* 打开对应item的看门狗     , timeout_ms后将超时 */
void soft_watchdog_timeout(uint32_t item, uint32_t timeout_ms);

/* 比如播放提示音：那么所有已经开始的wtd都要+timeout_ms后超时 */
void soft_watchdog_timeout_all(uint32_t timeout_ms);


void soft_watchdog_test();


#endif /* __WATCHDOG_H_INCLUDED__ */
