Skip to content

Add support for nRF52 Watchdog #11684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4451,6 +4451,18 @@
#define NRFX_WDT_CONFIG_LOG_LEVEL 3
#endif


// <e> NRFX_WDT_CONFIG_NO_IRQ - Remove WDT IRQ handling from WDT driver.
//==========================================================

// <0=> Include WDT IRQ handling
// <1=> Remove WDT IRQ handling

#ifndef NRFX_WDT_CONFIG_NO_IRQ
#define NRFX_WDT_CONFIG_NO_IRQ 1
#endif


// <o> NRFX_WDT_CONFIG_INFO_COLOR - ANSI escape code prefix.

// <0=> Default
Expand Down
86 changes: 86 additions & 0 deletions targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/watchdog_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2019 Trampoline SRL
* Copyright (c) 2019 Giampaolo Mancini <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPDX identifiers please to new files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added SPDX for Apache-2.0.

* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "watchdog_api.h"
#include "nrfx_wdt.h"

#if DEVICE_WATCHDOG

static void dummy(void) {
}

watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
{
nrfx_err_t err_code;

// The nRF watchdogs accept a range from 0xF to maximum 0xFFFF_FFFF
// 32768 Hz ticks. (Plase, see
// https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.3.0%2Fstructnrfx__wdt__config__t.html)
// Min timeout values in ms range from 0x1 to (0xFFFFFFFF / 0x8000) * 1000
if ( config->timeout_ms < 0x1 && config->timeout_ms > 0x07CFFFFF ) {
return WATCHDOG_STATUS_INVALID_ARGUMENT;
}

nrfx_wdt_config_t nrf_cfg;

nrf_cfg.reload_value = config->timeout_ms;
nrf_cfg.behaviour = NRF_WDT_BEHAVIOUR_RUN_SLEEP_HALT;
nrf_cfg.interrupt_priority = NRFX_WDT_CONFIG_NO_IRQ;

err_code = nrfx_wdt_init(&nrf_cfg, dummy);
if (err_code != NRFX_SUCCESS) {
return WATCHDOG_STATUS_INVALID_ARGUMENT;
}

nrfx_wdt_channel_id channel;
if (nrfx_wdt_channel_alloc(&channel) != NRF_SUCCESS) {
return WATCHDOG_STATUS_INVALID_ARGUMENT;
}
nrfx_wdt_enable();
nrfx_wdt_feed();

return WATCHDOG_STATUS_OK;
}

void hal_watchdog_kick(void)
{
nrfx_wdt_feed();
}

watchdog_status_t hal_watchdog_stop(void)
{
return WATCHDOG_STATUS_NOT_SUPPORTED;
}

uint32_t hal_watchdog_get_reload_value(void)
{
// Convert to milliseconds from 32768 Hz clock ticks.
return (uint64_t)nrf_wdt_reload_value_get() / 32768U * 1000;
}

watchdog_features_t hal_watchdog_get_platform_features(void)
{
watchdog_features_t features;

features.max_timeout = 0x07CFFFFF;
features.update_config = false;
features.disable_watchdog = false;
return features;
}

#endif // DEVICE_WATCHDOG
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ nrfx_err_t nrfx_wdt_init(nrfx_wdt_config_t const * p_config,

nrf_wdt_behaviour_set(p_config->behaviour);

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

NRFX_IRQ_PRIORITY_SET(WDT_IRQn, p_config->interrupt_priority);
NRFX_IRQ_ENABLE(WDT_IRQn);
Expand Down