Skip to content

Commit 10c78f4

Browse files
committed
Add support for nRF52 Watchdog
1 parent fe12608 commit 10c78f4

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/config/sdk_config.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4451,6 +4451,18 @@
44514451
#define NRFX_WDT_CONFIG_LOG_LEVEL 3
44524452
#endif
44534453

4454+
4455+
// <e> NRFX_WDT_CONFIG_NO_IRQ - Remove WDT IRQ handling from WDT driver.
4456+
//==========================================================
4457+
4458+
// <0=> Include WDT IRQ handling
4459+
// <1=> Remove WDT IRQ handling
4460+
4461+
#ifndef NRFX_WDT_CONFIG_NO_IRQ
4462+
#define NRFX_WDT_CONFIG_NO_IRQ 1
4463+
#endif
4464+
4465+
44544466
// <o> NRFX_WDT_CONFIG_INFO_COLOR - ANSI escape code prefix.
44554467

44564468
// <0=> Default
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2019 Trampoline SRL
3+
* Copyright (c) 2019 Giampaolo Mancini <[email protected]>
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "watchdog_api.h"
19+
#include "nrfx_wdt.h"
20+
21+
#if DEVICE_WATCHDOG
22+
23+
static void dummy(void) {
24+
}
25+
26+
watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
27+
{
28+
nrfx_err_t err_code;
29+
30+
// nRF would allow a 4294967295 ms refresh value but
31+
// Mbed OS allows max UINT32_MAX ms rehfreses.
32+
if ( config->timeout_ms < 15U && config->timeout_ms > 65535U ) {
33+
return WATCHDOG_STATUS_INVALID_ARGUMENT;
34+
}
35+
36+
nrfx_wdt_config_t nrf_cfg = NRFX_WDT_DEAFULT_CONFIG;
37+
38+
nrf_cfg.reload_value = config->timeout_ms;
39+
nrf_cfg.behaviour = NRF_WDT_BEHAVIOUR_RUN_SLEEP_HALT;
40+
41+
err_code = nrfx_wdt_init(&nrf_cfg, dummy);
42+
if (err_code != NRFX_SUCCESS) {
43+
return WATCHDOG_STATUS_INVALID_ARGUMENT;
44+
}
45+
46+
nrfx_wdt_channel_id channel;
47+
if (nrfx_wdt_channel_alloc(&channel) != NRF_SUCCESS) {
48+
return WATCHDOG_STATUS_INVALID_ARGUMENT;
49+
}
50+
nrfx_wdt_enable();
51+
nrfx_wdt_feed();
52+
53+
return WATCHDOG_STATUS_OK;
54+
}
55+
56+
void hal_watchdog_kick(void)
57+
{
58+
nrfx_wdt_feed();
59+
}
60+
61+
watchdog_status_t hal_watchdog_stop(void)
62+
{
63+
return WATCHDOG_STATUS_NOT_SUPPORTED;
64+
}
65+
66+
uint32_t hal_watchdog_get_reload_value(void)
67+
{
68+
// Convert to milliseconds from 32768 Hz clock ticks.
69+
return nrf_wdt_reload_value_get() / 32768U * 1000;
70+
}
71+
72+
watchdog_features_t hal_watchdog_get_platform_features(void)
73+
{
74+
watchdog_features_t features;
75+
features.max_timeout = 0xFFFF;
76+
features.update_config = false;
77+
features.disable_watchdog = false;
78+
return features;
79+
}
80+
81+
#endif // DEVICE_WATCHDOG

0 commit comments

Comments
 (0)