Skip to content
Draft
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
10 changes: 1 addition & 9 deletions drivers/watchdog/Kconfig.nrfx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ config WDT_NRFX
bool "nRF WDT nrfx driver"
default y
depends on DT_HAS_NORDIC_NRF_WDT_ENABLED
select NRFX_WDT0 if HAS_HW_NRF_WDT0
select NRFX_WDT1 if HAS_HW_NRF_WDT1
select NRFX_WDT30 if HAS_HW_NRF_WDT30
select NRFX_WDT31 if HAS_HW_NRF_WDT31
select NRFX_WDT010 if HAS_HW_NRF_WDT010
select NRFX_WDT011 if HAS_HW_NRF_WDT011
select NRFX_WDT130 if HAS_HW_NRF_WDT130
select NRFX_WDT131 if HAS_HW_NRF_WDT131
select NRFX_WDT132 if HAS_HW_NRF_WDT132
select NRFX_WDT
help
Enable support for nrfx WDT driver for nRF MCU series.

Expand Down
147 changes: 52 additions & 95 deletions drivers/watchdog/wdt_nrfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT nordic_nrf_wdt

#include <zephyr/kernel.h>
#include <zephyr/sys/math_extras.h>
#include <nrfx_wdt.h>
Expand All @@ -19,6 +21,7 @@
#endif

struct wdt_nrfx_data {
nrfx_wdt_t wdt;
wdt_callback_t m_callbacks[NRF_WDT_CHANNEL_NUMBER];
uint32_t m_timeout;
uint8_t m_allocated_channels;
Expand All @@ -28,15 +31,10 @@
#endif
};

struct wdt_nrfx_config {
nrfx_wdt_t wdt;
};

static int wdt_nrf_setup(const struct device *dev, uint8_t options)
{
const struct wdt_nrfx_config *config = dev->config;
struct wdt_nrfx_data *data = dev->data;
nrfx_err_t err_code;
int err_code;

nrfx_wdt_config_t wdt_config = {
.reload_value = data->m_timeout
Expand All @@ -54,13 +52,13 @@
wdt_config.behaviour |= NRF_WDT_BEHAVIOUR_RUN_HALT_MASK;
}

err_code = nrfx_wdt_reconfigure(&config->wdt, &wdt_config);
err_code = nrfx_wdt_reconfigure(&data->wdt, &wdt_config);

if (err_code != NRFX_SUCCESS) {
return -EBUSY;
if (err_code < 0) {
return err_code;
}

nrfx_wdt_enable(&config->wdt);
nrfx_wdt_enable(&data->wdt);

data->enabled = true;
return 0;
Expand All @@ -69,23 +67,22 @@
static int wdt_nrf_disable(const struct device *dev)
{
#if NRFX_WDT_HAS_STOP
const struct wdt_nrfx_config *config = dev->config;
struct wdt_nrfx_data *data = dev->data;
nrfx_err_t err_code;
int err_code;
int channel_id;

err_code = nrfx_wdt_stop(&config->wdt);
err_code = nrfx_wdt_stop(&data->wdt);

if (err_code != NRFX_SUCCESS) {
if (err_code < 0) {
/* This can only happen if wdt_nrf_setup() is not called first. */
return -EFAULT;
return err_code;
}

#if defined(WDT_NRFX_SYNC_STOP)
k_sem_take(&data->sync_stop, K_FOREVER);
#endif

nrfx_wdt_channels_free(&config->wdt);
nrfx_wdt_channels_free(&data->wdt);

for (channel_id = 0; channel_id < data->m_allocated_channels; channel_id++) {
data->m_callbacks[channel_id] = NULL;
Expand All @@ -103,9 +100,8 @@
static int wdt_nrf_install_timeout(const struct device *dev,
const struct wdt_timeout_cfg *cfg)
{
const struct wdt_nrfx_config *config = dev->config;
struct wdt_nrfx_data *data = dev->data;
nrfx_err_t err_code;
int err_code;
nrfx_wdt_channel_id channel_id;

if (data->enabled) {
Expand All @@ -125,10 +121,10 @@
* in all nRF chips can use reload values (determining
* the timeout) from range 0xF-0xFFFFFFFF given in 32768 Hz
* clock ticks. This makes the allowed range of 0x1-0x07CFFFFF
* in milliseconds. Check if the provided value is within
* this range.
* in milliseconds, defined using NRF_WDT_RR_VALUE_MS symbol.
* Check if the provided value is within this range.
*/
if ((cfg->window.max == 0U) || (cfg->window.max > 0x07CFFFFF)) {
if ((cfg->window.max == 0U) || (cfg->window.max > NRF_WDT_RR_VALUE_MS)) {
return -EINVAL;
}

Expand All @@ -138,11 +134,11 @@
return -EINVAL;
}

err_code = nrfx_wdt_channel_alloc(&config->wdt,
err_code = nrfx_wdt_channel_alloc(&data->wdt,
&channel_id);

Check notice on line 139 in drivers/watchdog/wdt_nrfx.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/watchdog/wdt_nrfx.c:139 - err_code = nrfx_wdt_channel_alloc(&data->wdt, - &channel_id); + err_code = nrfx_wdt_channel_alloc(&data->wdt, &channel_id);
if (err_code == NRFX_ERROR_NO_MEM) {
return -ENOMEM;
if (err_code == -ENOMEM) {
return err_code;
}

if (cfg->callback != NULL) {
Expand All @@ -155,7 +151,6 @@

static int wdt_nrf_feed(const struct device *dev, int channel_id)
{
const struct wdt_nrfx_config *config = dev->config;
struct wdt_nrfx_data *data = dev->data;

if ((channel_id >= data->m_allocated_channels) || (channel_id < 0)) {
Expand All @@ -166,9 +161,9 @@
return -EAGAIN;
}

nrfx_wdt_channel_feed(&config->wdt,
nrfx_wdt_channel_feed(&data->wdt,
(nrfx_wdt_channel_id)channel_id);

Check notice on line 166 in drivers/watchdog/wdt_nrfx.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/watchdog/wdt_nrfx.c:166 - nrfx_wdt_channel_feed(&data->wdt, - (nrfx_wdt_channel_id)channel_id); + nrfx_wdt_channel_feed(&data->wdt, (nrfx_wdt_channel_id)channel_id);
return 0;
}

Expand Down Expand Up @@ -205,84 +200,46 @@

#define WDT(idx) DT_NODELABEL(wdt##idx)

#define WDT_NRFX_WDT_IRQ(idx) \
#define WDT_NRFX_WDT_IRQ(inst) \
COND_CODE_1(CONFIG_WDT_NRFX_NO_IRQ, \
(), \
(IRQ_CONNECT(DT_IRQN(WDT(idx)), DT_IRQ(WDT(idx), priority), \
nrfx_isr, nrfx_wdt_##idx##_irq_handler, 0)))
(IRQ_CONNECT(DT_INST_IRQN(inst), DT_INST_IRQ(inst, priority), \
nrfx_wdt_irq_handler, &wdt_##inst##_data.wdt, 0)))

#define WDT_NRFX_WDT_DEVICE(idx) \
static void wdt_##idx##_event_handler(nrf_wdt_event_t event_type, \
uint32_t requests, \
void *p_context) \
#define WDT_NRFX_WDT_DEVICE(inst) \
static void wdt_##inst##_event_handler(nrf_wdt_event_t event_type, \
uint32_t requests, \
void *p_context) \
{ \
wdt_event_handler(DEVICE_DT_GET(WDT(idx)), event_type, \
wdt_event_handler(DEVICE_DT_INST_GET(inst), event_type, \
requests, p_context); \
} \
static int wdt_##idx##_init(const struct device *dev) \
static struct wdt_nrfx_data wdt_##inst##_data = { \
.wdt = NRFX_WDT_INSTANCE(DT_INST_REG_ADDR(inst)), \
IF_ENABLED(WDT_NRFX_SYNC_STOP, \
(.sync_stop = Z_SEM_INITIALIZER( \
wdt_##inst##_data.sync_stop, 0, 1),)) \
}; \
static int wdt_##inst##_init(const struct device *dev) \
{ \
const struct wdt_nrfx_config *config = dev->config; \
nrfx_err_t err_code; \
WDT_NRFX_WDT_IRQ(idx); \
err_code = nrfx_wdt_init(&config->wdt, \
int err_code; \
struct wdt_nrfx_data *data = dev->data; \
WDT_NRFX_WDT_IRQ(inst); \
err_code = nrfx_wdt_init(&data->wdt, \
NULL, \
IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ) \
? NULL \
: wdt_##idx##_event_handler, \
: wdt_##inst##_event_handler, \
NULL); \
if (err_code != NRFX_SUCCESS) { \
return -EBUSY; \
} \
return 0; \
return err_code; \
} \
static struct wdt_nrfx_data wdt_##idx##_data = { \
IF_ENABLED(WDT_NRFX_SYNC_STOP, \
(.sync_stop = Z_SEM_INITIALIZER( \
wdt_##idx##_data.sync_stop, 0, 1),)) \
}; \
static const struct wdt_nrfx_config wdt_##idx##z_config = { \
.wdt = NRFX_WDT_INSTANCE(idx), \
}; \
DEVICE_DT_DEFINE(WDT(idx), \
wdt_##idx##_init, \
NULL, \
&wdt_##idx##_data, \
&wdt_##idx##z_config, \
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&wdt_nrfx_driver_api)

#ifdef CONFIG_HAS_HW_NRF_WDT0
WDT_NRFX_WDT_DEVICE(0);
#endif

#ifdef CONFIG_HAS_HW_NRF_WDT1
WDT_NRFX_WDT_DEVICE(1);
#endif

#ifdef CONFIG_HAS_HW_NRF_WDT30
WDT_NRFX_WDT_DEVICE(30);
#endif

#ifdef CONFIG_HAS_HW_NRF_WDT31
WDT_NRFX_WDT_DEVICE(31);
#endif

#ifdef CONFIG_HAS_HW_NRF_WDT010
WDT_NRFX_WDT_DEVICE(010);
#endif

#ifdef CONFIG_HAS_HW_NRF_WDT011
WDT_NRFX_WDT_DEVICE(011);
#endif

#ifdef CONFIG_HAS_HW_NRF_WDT130
WDT_NRFX_WDT_DEVICE(130);
#endif

#ifdef CONFIG_HAS_HW_NRF_WDT131
WDT_NRFX_WDT_DEVICE(131);
#endif

#ifdef CONFIG_HAS_HW_NRF_WDT132
WDT_NRFX_WDT_DEVICE(132);
#endif
DEVICE_DT_INST_DEFINE(inst, \
wdt_##inst##_init, \
NULL, \
&wdt_##inst##_data, \
NULL, \
PRE_KERNEL_1, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&wdt_nrfx_driver_api)

Check notice on line 243 in drivers/watchdog/wdt_nrfx.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/watchdog/wdt_nrfx.c:243 -#define WDT_NRFX_WDT_IRQ(inst) \ +#define WDT_NRFX_WDT_IRQ(inst) \ COND_CODE_1(CONFIG_WDT_NRFX_NO_IRQ, \ (), \ (IRQ_CONNECT(DT_INST_IRQN(inst), DT_INST_IRQ(inst, priority), \ nrfx_wdt_irq_handler, &wdt_##inst##_data.wdt, 0))) -#define WDT_NRFX_WDT_DEVICE(inst) \ - static void wdt_##inst##_event_handler(nrf_wdt_event_t event_type, \ - uint32_t requests, \ - void *p_context) \ - { \ - wdt_event_handler(DEVICE_DT_INST_GET(inst), event_type, \ - requests, p_context); \ - } \ - static struct wdt_nrfx_data wdt_##inst##_data = { \ - .wdt = NRFX_WDT_INSTANCE(DT_INST_REG_ADDR(inst)), \ +#define WDT_NRFX_WDT_DEVICE(inst) \ + static void wdt_##inst##_event_handler(nrf_wdt_event_t event_type, uint32_t requests, \ + void *p_context) \ + { \ + wdt_event_handler(DEVICE_DT_INST_GET(inst), event_type, requests, p_context); \ + } \ + static struct wdt_nrfx_data wdt_##inst##_data = { \ + .wdt = NRFX_WDT_INSTANCE(DT_INST_REG_ADDR(inst)), \ IF_ENABLED(WDT_NRFX_SYNC_STOP, \ (.sync_stop = Z_SEM_INITIALIZER( \ - wdt_##inst##_data.sync_stop, 0, 1),)) \ - }; \ - static int wdt_##inst##_init(const struct device *dev) \ - { \ - int err_code; \ - struct wdt_nrfx_data *data = dev->data; \ - WDT_NRFX_WDT_IRQ(inst); \ - err_code = nrfx_wdt_init(&data->wdt, \ - NULL, \ - IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ) \ - ? NULL \ - : wdt_##inst##_event_handler, \ - NULL); \ - return err_code; \ - } \ - DEVICE_DT_INST_DEFINE(inst, \ - wdt_##inst##_init, \ - NULL, \ - &wdt_##inst##_data, \ - NULL, \ - PRE_KERNEL_1, \ - CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + wdt_##inst##_data.sync_stop, 0, 1),)) }; \ + static int wdt_##inst##_init(const struct device *dev) \ + { \ + int err_code; \ + struct wdt_nrfx_data *data = dev->data; \ + WDT_NRFX_WDT_IRQ(inst); \ + err_code = nrfx_wdt_init( \ + &data->wdt, NULL, \ + IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ) ? NULL : wdt_##inst##_event_handler, \ + NULL); \ + return err_code; \ + } \ + DEVICE_DT_INST_DEFINE(inst, wdt_##inst##_init, NULL, &wdt_##inst##_data, NULL, \ + PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \

DT_INST_FOREACH_STATUS_OKAY(WDT_NRFX_WDT_DEVICE)
45 changes: 0 additions & 45 deletions modules/hal_nordic/nrfx/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1233,51 +1233,6 @@ config NRFX_USBREG
config NRFX_WDT
bool

config NRFX_WDT0
bool "WDT0 driver instance"
depends on $(dt_nodelabel_exists,wdt0)
select NRFX_WDT

config NRFX_WDT1
bool "WDT1 driver instance"
depends on $(dt_nodelabel_exists,wdt1)
select NRFX_WDT

config NRFX_WDT30
bool "WDT30 driver instance"
depends on $(dt_nodelabel_exists,wdt30)
select NRFX_WDT

config NRFX_WDT31
bool "WDT31 driver instance"
depends on $(dt_nodelabel_exists,wdt31)
select NRFX_WDT

config NRFX_WDT010
bool "WDT010 driver instance"
depends on $(dt_nodelabel_exists,wdt010)
select NRFX_WDT

config NRFX_WDT011
bool "WDT011 driver instance"
depends on $(dt_nodelabel_exists,wdt011)
select NRFX_WDT

config NRFX_WDT130
bool "WDT130 driver instance"
depends on $(dt_nodelabel_exists,wdt130)
select NRFX_WDT

config NRFX_WDT131
bool "WDT131 driver instance"
depends on $(dt_nodelabel_exists,wdt131)
select NRFX_WDT

config NRFX_WDT132
bool "WDT132 driver instance"
depends on $(dt_nodelabel_exists,wdt132)
select NRFX_WDT

menu "Peripheral Resource Sharing module"

config NRFX_PRS
Expand Down
22 changes: 22 additions & 0 deletions modules/hal_nordic/nrfx/nrfx_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,25 @@
default: return "unknown";
}
}

char const *nrfx_new_error_string_get(int code)
{
#define NRFX_NEW_ERROR_STRING_CASE(code) case code: return #code

Check warning on line 51 in modules/hal_nordic/nrfx/nrfx_glue.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

MACRO_WITH_FLOW_CONTROL

modules/hal_nordic/nrfx/nrfx_glue.c:51 Macros with flow control statements should be avoided
switch (-code)

Check failure on line 52 in modules/hal_nordic/nrfx/nrfx_glue.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

OPEN_BRACE

modules/hal_nordic/nrfx/nrfx_glue.c:52 that open brace { should be on the previous line
{
NRFX_NEW_ERROR_STRING_CASE(0);

Check notice on line 54 in modules/hal_nordic/nrfx/nrfx_glue.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrfx/nrfx_glue.c:54 - #define NRFX_NEW_ERROR_STRING_CASE(code) case code: return #code - switch (-code) - { +#define NRFX_NEW_ERROR_STRING_CASE(code) \ + case code: \ + return #code + switch (-code) {
NRFX_NEW_ERROR_STRING_CASE(ECANCELED);
NRFX_NEW_ERROR_STRING_CASE(ENOMEM);
NRFX_NEW_ERROR_STRING_CASE(ENOTSUP);
NRFX_NEW_ERROR_STRING_CASE(EINVAL);
NRFX_NEW_ERROR_STRING_CASE(EINPROGRESS);
NRFX_NEW_ERROR_STRING_CASE(E2BIG);
NRFX_NEW_ERROR_STRING_CASE(ETIMEDOUT);
NRFX_NEW_ERROR_STRING_CASE(EPERM);
NRFX_NEW_ERROR_STRING_CASE(EFAULT);
NRFX_NEW_ERROR_STRING_CASE(EACCES);
NRFX_NEW_ERROR_STRING_CASE(EBUSY);
NRFX_NEW_ERROR_STRING_CASE(EALREADY);
default: return "unknown";
}

Check notice on line 68 in modules/hal_nordic/nrfx/nrfx_glue.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrfx/nrfx_glue.c:68 - default: return "unknown"; + default: + return "unknown";
}
27 changes: 0 additions & 27 deletions modules/hal_nordic/nrfx/nrfx_kconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,33 +987,6 @@
#ifdef CONFIG_NRFX_WDT_LOG
#define NRFX_WDT_CONFIG_LOG_ENABLED 1
#endif
#ifdef CONFIG_NRFX_WDT0
#define NRFX_WDT0_ENABLED 1
#endif
#ifdef CONFIG_NRFX_WDT1
#define NRFX_WDT1_ENABLED 1
#endif
#ifdef CONFIG_NRFX_WDT30
#define NRFX_WDT30_ENABLED 1
#endif
#ifdef CONFIG_NRFX_WDT31
#define NRFX_WDT31_ENABLED 1
#endif
#ifdef CONFIG_NRFX_WDT010
#define NRFX_WDT010_ENABLED 1
#endif
#ifdef CONFIG_NRFX_WDT011
#define NRFX_WDT011_ENABLED 1
#endif
#ifdef CONFIG_NRFX_WDT130
#define NRFX_WDT130_ENABLED 1
#endif
#ifdef CONFIG_NRFX_WDT131
#define NRFX_WDT131_ENABLED 1
#endif
#ifdef CONFIG_NRFX_WDT132
#define NRFX_WDT132_ENABLED 1
#endif

#ifdef CONFIG_NRF52_ANOMALY_109_WORKAROUND
#define NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 1
Expand Down
10 changes: 10 additions & 0 deletions modules/hal_nordic/nrfx/nrfx_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@
#define NRFX_LOG_ERROR_STRING_GET(error_code) nrfx_error_string_get(error_code)
extern char const *nrfx_error_string_get(nrfx_err_t code);

/**
* @brief Macro for getting the textual representation of a given errno error code.
*
* @param[in] error_code Errno error code.
*
* @return String containing the textual representation of the errno error code.
*/
#define NRFX_NEW_LOG_ERROR_STRING_GET(error_code) nrfx_new_error_string_get(error_code)
extern char const *nrfx_new_error_string_get(int code);

Check notice on line 139 in modules/hal_nordic/nrfx/nrfx_log.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrfx/nrfx_log.h:139 -#define NRFX_NEW_LOG_ERROR_STRING_GET(error_code) nrfx_new_error_string_get(error_code) +#define NRFX_NEW_LOG_ERROR_STRING_GET(error_code) nrfx_new_error_string_get(error_code)

/** @} */

#ifdef __cplusplus
Expand Down
Loading
Loading