/ src / platform / platform_watchdog_nrf52.c
platform_watchdog_nrf52.c
 1  #include "platform_watchdog.h"
 2  
 3  #include "sdk_common.h"
 4  #include "app_error.h"
 5  #include "nrfx_wdt.h"
 6  
 7  static void wdt_event_handler(void)
 8  {
 9  	// from example:
10  	//NOTE: The max amount of time we can spend in WDT
11  	// interrupt is two cycles of 32768[Hz] clock
12  	// - after that, reset occurs
13  }
14  
15  static ret_code_t platform_watchdog_nrf52_initialize(platform_watchdog_driver_config_t* config)
16  {
17      nrfx_wdt_config_t driver_config = NRFX_WDT_DEAFULT_CONFIG;
18  
19  	nrfx_err_t err_code = nrfx_wdt_init(&driver_config, wdt_event_handler);
20  	APP_ERROR_CHECK(err_code);
21  
22  	nrfx_wdt_channel_id channel;
23  	err_code = nrfx_wdt_channel_alloc(&channel);
24  	APP_ERROR_CHECK(err_code);
25  
26  	return NRFX_SUCCESS;
27  }
28  
29  static void platform_watchdog_nrf52_enable(void)
30  {
31  	nrfx_wdt_enable();
32  }
33  
34  static void platform_watchdog_nrf52_disable(void)
35  {
36  	// not supported on this platform.
37  }
38  
39  static void platform_watchdog_nrf52_feed()
40  {
41  	nrfx_wdt_feed();
42  }
43  
44  platform_watchdog_driver_t platform_watchdog_nrf52 = {
45  	.initialize = platform_watchdog_nrf52_initialize,
46  	.enable = platform_watchdog_nrf52_enable,
47  	.disable = platform_watchdog_nrf52_disable,
48  	.feed = platform_watchdog_nrf52_feed,
49  };