Skip to content

Commit 5faf471

Browse files
JordanYateskartben
authored andcommitted
drivers: watchdog: stm32 iwdg: constant to config
Move the instance pointer, which is a constant value, into a dedicated config structure. At the same time, remove the type casting macros as this pattern has been removed from the tree for some years now. Signed-off-by: Jordan Yates <[email protected]>
1 parent 2509de7 commit 5faf471

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

drivers/watchdog/wdt_iwdg_stm32.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ static void iwdg_stm32_convert_timeout(uint32_t timeout,
8484

8585
static int iwdg_stm32_setup(const struct device *dev, uint8_t options)
8686
{
87-
struct iwdg_stm32_data *data = IWDG_STM32_DATA(dev);
88-
IWDG_TypeDef *iwdg = IWDG_STM32_STRUCT(dev);
87+
const struct iwdg_stm32_config *cfg = dev->config;
88+
struct iwdg_stm32_data *data = dev->data;
8989
uint32_t tickstart;
9090

9191
/* Deactivate running when debugger is attached. */
@@ -111,23 +111,23 @@ static int iwdg_stm32_setup(const struct device *dev, uint8_t options)
111111
}
112112

113113
/* Enable the IWDG now and write IWDG registers at the same time */
114-
LL_IWDG_Enable(iwdg);
115-
LL_IWDG_EnableWriteAccess(iwdg);
114+
LL_IWDG_Enable(cfg->instance);
115+
LL_IWDG_EnableWriteAccess(cfg->instance);
116116
/* Write the prescaler and reload counter to the IWDG registers*/
117-
LL_IWDG_SetPrescaler(iwdg, data->prescaler);
118-
LL_IWDG_SetReloadCounter(iwdg, data->reload);
117+
LL_IWDG_SetPrescaler(cfg->instance, data->prescaler);
118+
LL_IWDG_SetReloadCounter(cfg->instance, data->reload);
119119

120120
tickstart = k_uptime_get_32();
121121

122122
/* Wait for the update operation completed */
123-
while (LL_IWDG_IsReady(iwdg) == 0) {
123+
while (LL_IWDG_IsReady(cfg->instance) == 0) {
124124
if ((k_uptime_get_32() - tickstart) > IWDG_SR_UPDATE_TIMEOUT) {
125125
return -ENODEV;
126126
}
127127
}
128128

129129
/* Reload counter just before leaving */
130-
LL_IWDG_ReloadCounter(iwdg);
130+
LL_IWDG_ReloadCounter(cfg->instance);
131131

132132
return 0;
133133
}
@@ -143,7 +143,7 @@ static int iwdg_stm32_disable(const struct device *dev)
143143
static int iwdg_stm32_install_timeout(const struct device *dev,
144144
const struct wdt_timeout_cfg *config)
145145
{
146-
struct iwdg_stm32_data *data = IWDG_STM32_DATA(dev);
146+
struct iwdg_stm32_data *data = dev->data;
147147
uint32_t timeout = config->window.max * USEC_PER_MSEC;
148148
uint32_t prescaler = 0U;
149149
uint32_t reload = 0U;
@@ -175,10 +175,10 @@ static int iwdg_stm32_install_timeout(const struct device *dev,
175175

176176
static int iwdg_stm32_feed(const struct device *dev, int channel_id)
177177
{
178-
IWDG_TypeDef *iwdg = IWDG_STM32_STRUCT(dev);
178+
const struct iwdg_stm32_config *cfg = dev->config;
179179

180180
ARG_UNUSED(channel_id);
181-
LL_IWDG_ReloadCounter(iwdg);
181+
LL_IWDG_ReloadCounter(cfg->instance);
182182

183183
return 0;
184184
}
@@ -214,11 +214,12 @@ static int iwdg_stm32_init(const struct device *dev)
214214
return 0;
215215
}
216216

217-
static struct iwdg_stm32_data iwdg_stm32_dev_data = {
218-
.Instance = (IWDG_TypeDef *)DT_INST_REG_ADDR(0)
217+
static const struct iwdg_stm32_config iwdg_stm32_dev_cfg = {
218+
.instance = (IWDG_TypeDef *)DT_INST_REG_ADDR(0),
219219
};
220+
static struct iwdg_stm32_data iwdg_stm32_dev_data;
220221

221222
DEVICE_DT_INST_DEFINE(0, iwdg_stm32_init, NULL,
222-
&iwdg_stm32_dev_data, NULL,
223+
&iwdg_stm32_dev_data, &iwdg_stm32_dev_cfg,
223224
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
224225
&iwdg_stm32_api);

drivers/watchdog/wdt_iwdg_stm32.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@
2020
*
2121
*/
2222

23-
/* driver data */
24-
struct iwdg_stm32_data {
23+
struct iwdg_stm32_config {
2524
/* IWDG peripheral instance. */
26-
IWDG_TypeDef *Instance;
25+
IWDG_TypeDef *instance;
26+
};
27+
28+
struct iwdg_stm32_data {
2729
uint32_t prescaler;
2830
uint32_t reload;
2931
};
3032

31-
#define IWDG_STM32_DATA(dev) \
32-
((struct iwdg_stm32_data * const)(dev)->data)
33-
34-
#define IWDG_STM32_STRUCT(dev) \
35-
((IWDG_TypeDef *)(IWDG_STM32_DATA(dev))->Instance)
36-
3733
#endif /* ZEPHYR_DRIVERS_WATCHDOG_IWDG_STM32_H_ */

0 commit comments

Comments
 (0)