drivers: watchdog: drop get_dev_data/get_dev_config usage
Replace all get_dev_data()/get_dev_config() accessor utilities with dev->data and dev->config. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
468de7eb29
commit
ee434ebdee
|
@ -25,19 +25,10 @@ struct wdt_counter_config {
|
|||
const struct device *counter;
|
||||
};
|
||||
|
||||
static inline struct wdt_counter_data *get_dev_data(const struct device *dev)
|
||||
{
|
||||
return dev->data;
|
||||
}
|
||||
|
||||
static inline const struct wdt_counter_config *get_dev_config(const struct device *dev)
|
||||
{
|
||||
return dev->config;
|
||||
}
|
||||
|
||||
static int wdt_counter_setup(const struct device *dev, uint8_t options)
|
||||
{
|
||||
const struct device *counter = get_dev_config(dev)->counter;
|
||||
const struct wdt_counter_config *config = dev->config;
|
||||
const struct device *counter = config->counter;
|
||||
|
||||
if ((options & WDT_OPT_PAUSE_IN_SLEEP) || (options & WDT_OPT_PAUSE_IN_SLEEP)) {
|
||||
return -ENOTSUP;
|
||||
|
@ -48,7 +39,8 @@ static int wdt_counter_setup(const struct device *dev, uint8_t options)
|
|||
|
||||
static int wdt_counter_disable(const struct device *dev)
|
||||
{
|
||||
const struct device *counter = get_dev_config(dev)->counter;
|
||||
const struct wdt_counter_config *config = dev->config;
|
||||
const struct device *counter = config->counter;
|
||||
|
||||
return counter_stop(counter);
|
||||
}
|
||||
|
@ -58,7 +50,7 @@ static void counter_alarm_callback(const struct device *dev,
|
|||
void *user_data)
|
||||
{
|
||||
const struct device *wdt_dev = user_data;
|
||||
struct wdt_counter_data *data = get_dev_data(wdt_dev);
|
||||
struct wdt_counter_data *data = wdt_dev->data;
|
||||
|
||||
counter_stop(dev);
|
||||
if (data->callback[chan_id]) {
|
||||
|
@ -71,8 +63,9 @@ static void counter_alarm_callback(const struct device *dev,
|
|||
|
||||
static int timeout_set(const struct device *dev, int chan_id, bool cancel)
|
||||
{
|
||||
struct wdt_counter_data *data = get_dev_data(dev);
|
||||
const struct device *counter = get_dev_config(dev)->counter;
|
||||
const struct wdt_counter_config *config = dev->config;
|
||||
struct wdt_counter_data *data = dev->data;
|
||||
const struct device *counter = config->counter;
|
||||
struct counter_alarm_cfg alarm_cfg = {
|
||||
.callback = counter_alarm_callback,
|
||||
.ticks = data->timeout[chan_id],
|
||||
|
@ -94,8 +87,8 @@ static int timeout_set(const struct device *dev, int chan_id, bool cancel)
|
|||
static int wdt_counter_install_timeout(const struct device *dev,
|
||||
const struct wdt_timeout_cfg *cfg)
|
||||
{
|
||||
struct wdt_counter_data *data = get_dev_data(dev);
|
||||
const struct wdt_counter_config *config = get_dev_config(dev);
|
||||
struct wdt_counter_data *data = dev->data;
|
||||
const struct wdt_counter_config *config = dev->config;
|
||||
const struct device *counter = config->counter;
|
||||
int chan_id;
|
||||
|
||||
|
@ -140,7 +133,9 @@ static int wdt_counter_install_timeout(const struct device *dev,
|
|||
|
||||
static int wdt_counter_feed(const struct device *dev, int chan_id)
|
||||
{
|
||||
if (chan_id > counter_get_num_of_channels(get_dev_config(dev)->counter)) {
|
||||
const struct wdt_counter_config *config = dev->config;
|
||||
|
||||
if (chan_id > counter_get_num_of_channels(config->counter)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -162,8 +157,9 @@ static const struct wdt_counter_config wdt_counter_config = {
|
|||
|
||||
static int wdt_counter_init(const struct device *dev)
|
||||
{
|
||||
struct wdt_counter_data *data = get_dev_data(dev);
|
||||
uint8_t ch_cnt = counter_get_num_of_channels(get_dev_config(dev)->counter);
|
||||
const struct wdt_counter_config *config = dev->config;
|
||||
struct wdt_counter_data *data = dev->data;
|
||||
uint8_t ch_cnt = counter_get_num_of_channels(config->counter);
|
||||
|
||||
data->alloc_cnt = MIN(ch_cnt, CONFIG_WDT_COUNTER_CH_COUNT);
|
||||
|
||||
|
|
|
@ -22,19 +22,10 @@ struct wdt_nrfx_config {
|
|||
nrfx_wdt_config_t config;
|
||||
};
|
||||
|
||||
static inline struct wdt_nrfx_data *get_dev_data(const struct device *dev)
|
||||
{
|
||||
return dev->data;
|
||||
}
|
||||
|
||||
static inline const struct wdt_nrfx_config *get_dev_config(const struct device *dev)
|
||||
{
|
||||
return dev->config;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
nrf_wdt_behaviour_t behaviour;
|
||||
|
||||
/* Activate all available options. Run in all cases. */
|
||||
|
@ -50,16 +41,16 @@ static int wdt_nrf_setup(const struct device *dev, uint8_t options)
|
|||
behaviour &= ~NRF_WDT_BEHAVIOUR_RUN_HALT;
|
||||
}
|
||||
|
||||
nrf_wdt_behaviour_set(get_dev_config(dev)->wdt.p_reg, behaviour);
|
||||
nrf_wdt_behaviour_set(config->wdt.p_reg, behaviour);
|
||||
/* The watchdog timer is driven by the LFCLK clock running at 32768 Hz.
|
||||
* The timeout value given in milliseconds needs to be converted here
|
||||
* to watchdog ticks.*/
|
||||
nrf_wdt_reload_value_set(
|
||||
get_dev_config(dev)->wdt.p_reg,
|
||||
(uint32_t)(((uint64_t)get_dev_data(dev)->m_timeout * 32768U)
|
||||
config->wdt.p_reg,
|
||||
(uint32_t)(((uint64_t)data->m_timeout * 32768U)
|
||||
/ 1000));
|
||||
|
||||
nrfx_wdt_enable(&get_dev_config(dev)->wdt);
|
||||
nrfx_wdt_enable(&config->wdt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -74,6 +65,8 @@ static int wdt_nrf_disable(const struct device *dev)
|
|||
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;
|
||||
nrfx_wdt_channel_id channel_id;
|
||||
|
||||
|
@ -85,7 +78,7 @@ static int wdt_nrf_install_timeout(const struct device *dev,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (get_dev_data(dev)->m_allocated_channels == 0U) {
|
||||
if (data->m_allocated_channels == 0U) {
|
||||
/* According to relevant Product Specifications, watchdogs
|
||||
* in all nRF chips can use reload values (determining
|
||||
* the timeout) from range 0xF-0xFFFFFFFF given in 32768 Hz
|
||||
|
@ -97,12 +90,12 @@ static int wdt_nrf_install_timeout(const struct device *dev,
|
|||
}
|
||||
|
||||
/* Save timeout value from first registered watchdog channel. */
|
||||
get_dev_data(dev)->m_timeout = cfg->window.max;
|
||||
} else if (cfg->window.max != get_dev_data(dev)->m_timeout) {
|
||||
data->m_timeout = cfg->window.max;
|
||||
} else if (cfg->window.max != data->m_timeout) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err_code = nrfx_wdt_channel_alloc(&get_dev_config(dev)->wdt,
|
||||
err_code = nrfx_wdt_channel_alloc(&config->wdt,
|
||||
&channel_id);
|
||||
|
||||
if (err_code == NRFX_ERROR_NO_MEM) {
|
||||
|
@ -110,20 +103,23 @@ static int wdt_nrf_install_timeout(const struct device *dev,
|
|||
}
|
||||
|
||||
if (cfg->callback != NULL) {
|
||||
get_dev_data(dev)->m_callbacks[channel_id] = cfg->callback;
|
||||
data->m_callbacks[channel_id] = cfg->callback;
|
||||
}
|
||||
|
||||
get_dev_data(dev)->m_allocated_channels++;
|
||||
data->m_allocated_channels++;
|
||||
return channel_id;
|
||||
}
|
||||
|
||||
static int wdt_nrf_feed(const struct device *dev, int channel_id)
|
||||
{
|
||||
if (channel_id > get_dev_data(dev)->m_allocated_channels) {
|
||||
const struct wdt_nrfx_config *config = dev->config;
|
||||
struct wdt_nrfx_data *data = dev->data;
|
||||
|
||||
if (channel_id > data->m_allocated_channels) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
nrfx_wdt_channel_feed(&get_dev_config(dev)->wdt,
|
||||
nrfx_wdt_channel_feed(&config->wdt,
|
||||
(nrfx_wdt_channel_id)channel_id);
|
||||
|
||||
return 0;
|
||||
|
@ -138,13 +134,15 @@ static const struct wdt_driver_api wdt_nrfx_driver_api = {
|
|||
|
||||
static void wdt_event_handler(const struct device *dev)
|
||||
{
|
||||
const struct wdt_nrfx_config *config = dev->config;
|
||||
struct wdt_nrfx_data *data = dev->data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < get_dev_data(dev)->m_allocated_channels; ++i) {
|
||||
if (nrf_wdt_request_status(get_dev_config(dev)->wdt.p_reg,
|
||||
for (i = 0; i < data->m_allocated_channels; ++i) {
|
||||
if (nrf_wdt_request_status(config->wdt.p_reg,
|
||||
(nrf_wdt_rr_register_t)i)) {
|
||||
if (get_dev_data(dev)->m_callbacks[i]) {
|
||||
get_dev_data(dev)->m_callbacks[i](dev, i);
|
||||
if (data->m_callbacks[i]) {
|
||||
data->m_callbacks[i](dev, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,11 +157,12 @@ static void wdt_event_handler(const struct device *dev)
|
|||
} \
|
||||
static int wdt_##idx##_init(const struct device *dev) \
|
||||
{ \
|
||||
const struct wdt_nrfx_config *config = dev->config; \
|
||||
nrfx_err_t err_code; \
|
||||
IRQ_CONNECT(DT_IRQN(WDT(idx)), DT_IRQ(WDT(idx), priority), \
|
||||
nrfx_isr, nrfx_wdt_##idx##_irq_handler, 0); \
|
||||
err_code = nrfx_wdt_init(&get_dev_config(dev)->wdt, \
|
||||
&get_dev_config(dev)->config, \
|
||||
err_code = nrfx_wdt_init(&config->wdt, \
|
||||
&config->config, \
|
||||
wdt_##idx##_event_handler); \
|
||||
if (err_code != NRFX_SUCCESS) { \
|
||||
return -EBUSY; \
|
||||
|
|
Loading…
Reference in a new issue