1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 #include "2ndboot.h"
5 #include "sys.h"
6 #include "cmsis.h"
7 #include "hal_wdt.h"
8 #include "hal_bootmode.h"
9 
set_silent_reboot_flag(void)10 static int set_silent_reboot_flag(void)
11 {
12     hal_sw_bootmode_set(HAL_SW_BOOTMODE_RESERVED_BIT24);
13     return 0;
14 }
15 
app_wdt_irq_handle(enum HAL_WDT_ID_T id,uint32_t status)16 static void app_wdt_irq_handle(enum HAL_WDT_ID_T id, uint32_t status)
17 {
18     analog_aud_codec_mute();
19     set_silent_reboot_flag();
20 }
21 
wdg_init(unsigned int ms)22 void wdg_init(unsigned int ms)
23 {
24     uint32_t lock = int_lock();
25 
26     hal_wdt_set_irq_callback(HAL_WDT_ID_0, app_wdt_irq_handle);
27     hal_wdt_set_timeout(HAL_WDT_ID_0, ms /1000);
28     hal_wdt_start(HAL_WDT_ID_0);
29 
30 	int_unlock(lock);
31 }
32 
wdg_feed(void)33 void wdg_feed(void)
34 {
35     hal_wdt_ping(HAL_WDT_ID_0);
36 }
37 
wdg_finish()38 void wdg_finish()
39 {
40     uint32_t lock = 0;
41 
42     lock = int_lock();
43     hal_wdt_stop(HAL_WDT_ID_0);
44     int_unlock(lock);
45 }