-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10c78f4
Add support for nRF52 Watchdog
manchoz 92a3167
Fix timeout limits
manchoz c79f54c
Remove default conf macro because typo in nRF SDK
manchoz f9674ad
Fix overflow calculation for reload_value.
manchoz c30ca66
Add SPDX identifier
manchoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/watchdog_api.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
* | ||
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.