Skip to content

Commit 5d330bf

Browse files
authored
Merge pull request #11684 from manchoz/nrf52_watchdog_api
Add support for nRF52 Watchdog
2 parents 9db54bc + c30ca66 commit 5d330bf

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2019 Trampoline SRL
3+
* Copyright (c) 2019 Giampaolo Mancini <[email protected]>
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "watchdog_api.h"
20+
#include "nrfx_wdt.h"
21+
22+
#if DEVICE_WATCHDOG
23+
24+
static void dummy(void) {
25+
}
26+
27+
watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
28+
{
29+
nrfx_err_t err_code;
30+
31+
// The nRF watchdogs accept a range from 0xF to maximum 0xFFFF_FFFF
32+
// 32768 Hz ticks. (Plase, see
33+
// https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.3.0%2Fstructnrfx__wdt__config__t.html)
34+
// Min timeout values in ms range from 0x1 to (0xFFFFFFFF / 0x8000) * 1000
35+
if ( config->timeout_ms < 0x1 && config->timeout_ms > 0x07CFFFFF ) {
36+
return WATCHDOG_STATUS_INVALID_ARGUMENT;
37+
}
38+
39+
nrfx_wdt_config_t nrf_cfg;
40+
41+
nrf_cfg.reload_value = config->timeout_ms;
42+
nrf_cfg.behaviour = NRF_WDT_BEHAVIOUR_RUN_SLEEP_HALT;
43+
nrf_cfg.interrupt_priority = NRFX_WDT_CONFIG_NO_IRQ;
44+
45+
err_code = nrfx_wdt_init(&nrf_cfg, dummy);
46+
if (err_code != NRFX_SUCCESS) {
47+
return WATCHDOG_STATUS_INVALID_ARGUMENT;
48+
}
49+
50+
nrfx_wdt_channel_id channel;
51+
if (nrfx_wdt_channel_alloc(&channel) != NRF_SUCCESS) {
52+
return WATCHDOG_STATUS_INVALID_ARGUMENT;
53+
}
54+
nrfx_wdt_enable();
55+
nrfx_wdt_feed();
56+
57+
return WATCHDOG_STATUS_OK;
58+
}
59+
60+
void hal_watchdog_kick(void)
61+
{
62+
nrfx_wdt_feed();
63+
}
64+
65+
watchdog_status_t hal_watchdog_stop(void)
66+
{
67+
return WATCHDOG_STATUS_NOT_SUPPORTED;
68+
}
69+
70+
uint32_t hal_watchdog_get_reload_value(void)
71+
{
72+
// Convert to milliseconds from 32768 Hz clock ticks.
73+
return (uint64_t)nrf_wdt_reload_value_get() / 32768U * 1000;
74+
}
75+
76+
watchdog_features_t hal_watchdog_get_platform_features(void)
77+
{
78+
watchdog_features_t features;
79+
80+
features.max_timeout = 0x07CFFFFF;
81+
features.update_config = false;
82+
features.disable_watchdog = false;
83+
return features;
84+
}
85+
86+
#endif // DEVICE_WATCHDOG

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/drivers/src/nrfx_wdt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ nrfx_err_t nrfx_wdt_init(nrfx_wdt_config_t const * p_config,
9090

9191
nrf_wdt_behaviour_set(p_config->behaviour);
9292

93-
nrf_wdt_reload_value_set((p_config->reload_value * 32768) / 1000);
93+
nrf_wdt_reload_value_set(((uint64_t)p_config->reload_value * 32768) / 1000);
9494

9595
NRFX_IRQ_PRIORITY_SET(WDT_IRQn, p_config->interrupt_priority);
9696
NRFX_IRQ_ENABLE(WDT_IRQn);

0 commit comments

Comments
 (0)