Skip to content

Commit 2117dbe

Browse files
RichardSWheatleyAlessandroLuo
authored andcommitted
drivers: add assert to check for max children in timer
check for max number of children in timer. Signed-off-by: Richard Wheatley <richard.wheatley@ambiq.com>
1 parent 986c0b9 commit 2117dbe

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

drivers/counter/counter_ambiq_timer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,14 @@ static void counter_ambiq_isr(void *arg)
438438
#endif
439439

440440
#define AMBIQ_COUNTER_INIT(idx) \
441+
BUILD_ASSERT(DT_CHILD_NUM_STATUS_OKAY(DT_INST_PARENT(idx)) == 1, \
442+
"Too many children for Timer!"); \
441443
static void counter_irq_config_func_##idx(void); \
442444
static struct counter_ambiq_data counter_data_##idx; \
443445
static const struct counter_ambiq_config counter_config_##idx = { \
444446
.instance = (DT_REG_ADDR(DT_INST_PARENT(idx)) - SOC_TIMER_BASE) / \
445447
DT_REG_SIZE(DT_INST_PARENT(idx)), \
446-
.clk_src = DT_ENUM_IDX(DT_INST_PARENT(idx), clk_source), \
448+
.clk_src = DT_ENUM_IDX(DT_INST_PARENT(idx), clk_source), \
447449
.counter_info = {.max_top_value = UINT32_MAX, \
448450
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
449451
.channels = 1}, \

drivers/pwm/pwm_ambiq_ctimer.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ static void start_clock(uint32_t clock_sel)
127127
}
128128

129129
static int ambiq_ctimer_pwm_set_cycles(const struct device *dev, uint32_t channel,
130-
uint32_t period_cycles, uint32_t pulse_cycles,
131-
pwm_flags_t flags)
130+
uint32_t period_cycles, uint32_t pulse_cycles,
131+
pwm_flags_t flags)
132132
{
133133
const struct pwm_ambiq_ctimer_config *config = dev->config;
134134

@@ -172,7 +172,7 @@ static int ambiq_ctimer_pwm_set_cycles(const struct device *dev, uint32_t channe
172172
}
173173

174174
static int ambiq_ctimer_pwm_get_cycles_per_sec(const struct device *dev, uint32_t channel,
175-
uint64_t *cycles)
175+
uint64_t *cycles)
176176
{
177177
struct pwm_ambiq_ctimer_data *data = dev->data;
178178
int err = 0;
@@ -230,21 +230,23 @@ static const struct DEVICE_API(pwm, pwm_ambiq_ctimer_driver_api) = {
230230

231231
#define TEST_CHILDREN DT_PATH(test, test_children)
232232

233-
#define PWM_AMBIQ_CTIMER_DEVICE_INIT(n) \
233+
#define PWM_AMBIQ_CTIMER_DEVICE_INIT(n) \
234+
BUILD_ASSERT(DT_CHILD_NUM_STATUS_OKAY(DT_INST_PARENT(n)) == 1, \
235+
"Too many children for Timer!"); \
234236
PINCTRL_DT_INST_DEFINE(n); \
235-
static struct pwm_ambiq_ctimer_data pwm_ambiq_ctimer_data_##n = { \
237+
static struct pwm_ambiq_ctimer_data pwm_ambiq_ctimer_data_##n = { \
236238
.cycles = 0, \
237239
}; \
238-
static const struct pwm_ambiq_ctimer_config pwm_ambiq_ctimer_config_##n = { \
240+
static const struct pwm_ambiq_ctimer_config pwm_ambiq_ctimer_config_##n = { \
239241
.timer_num = (DT_REG_ADDR(DT_INST_PARENT(n)) - CTIMER_BASE) / \
240242
DT_REG_SIZE(DT_INST_PARENT(n)), \
241243
.timer_seg = DT_INST_ENUM_IDX(n, timer_segment), \
242-
.clock_sel = DT_ENUM_IDX(DT_INST_PARENT(n), clk_source), \
244+
.clock_sel = DT_ENUM_IDX(DT_INST_PARENT(n), clk_source), \
243245
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
244246
.pwm_type = DT_INST_ENUM_IDX(n, pwm_type)}; \
245247
\
246-
DEVICE_DT_INST_DEFINE(n, ambiq_ctimer_pwm_init, NULL, &pwm_ambiq_ctimer_data_##n, \
247-
&pwm_ambiq_ctimer_config_##n, POST_KERNEL, CONFIG_PWM_INIT_PRIORITY, \
248+
DEVICE_DT_INST_DEFINE(n, ambiq_ctimer_pwm_init, NULL, &pwm_ambiq_ctimer_data_##n, \
249+
&pwm_ambiq_ctimer_config_##n, POST_KERNEL, CONFIG_PWM_INIT_PRIORITY, \
248250
&pwm_ambiq_ctimer_driver_api);
249251

250252
DT_INST_FOREACH_STATUS_OKAY(PWM_AMBIQ_CTIMER_DEVICE_INIT)

drivers/pwm/pwm_ambiq_timer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,16 @@ static const struct DEVICE_API(pwm, pwm_ambiq_timer_driver_api) = {
182182
};
183183

184184
#define PWM_AMBIQ_TIMER_DEVICE_INIT(n) \
185+
BUILD_ASSERT(DT_CHILD_NUM_STATUS_OKAY(DT_INST_PARENT(n)) == 1, \
186+
"Too many children for Timer!"); \
185187
PINCTRL_DT_INST_DEFINE(n); \
186188
static struct pwm_ambiq_timer_data pwm_ambiq_timer_data_##n = { \
187189
.cycles = 0, \
188190
}; \
189191
static const struct pwm_ambiq_timer_config pwm_ambiq_timer_config_##n = { \
190192
.timer_num = (DT_REG_ADDR(DT_INST_PARENT(n)) - TIMER_BASE) / \
191193
DT_REG_SIZE(DT_INST_PARENT(n)), \
192-
.clock_sel = DT_ENUM_IDX(DT_INST_PARENT(n), clk_source), \
194+
.clock_sel = DT_ENUM_IDX(DT_INST_PARENT(n), clk_source), \
193195
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n)}; \
194196
\
195197
DEVICE_DT_INST_DEFINE(n, ambiq_timer_pwm_init, NULL, &pwm_ambiq_timer_data_##n, \

0 commit comments

Comments
 (0)