Skip to content

Commit 88d36cf

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 3cf6227 commit 88d36cf

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
@@ -435,12 +435,14 @@ static void counter_ambiq_isr(void *arg)
435435
#endif
436436

437437
#define AMBIQ_COUNTER_INIT(idx) \
438+
BUILD_ASSERT(DT_CHILD_NUM_STATUS_OKAY(DT_INST_PARENT(idx)) == 1, \
439+
"Too many children for Timer!"); \
438440
static void counter_irq_config_func_##idx(void); \
439441
static struct counter_ambiq_data counter_data_##idx; \
440442
static const struct counter_ambiq_config counter_config_##idx = { \
441443
.instance = (DT_REG_ADDR(DT_INST_PARENT(idx)) - SOC_TIMER_BASE) / \
442444
DT_REG_SIZE(DT_INST_PARENT(idx)), \
443-
.clk_src = DT_ENUM_IDX(DT_INST_PARENT(idx), clk_source), \
445+
.clk_src = DT_ENUM_IDX(DT_INST_PARENT(idx), clk_source), \
444446
.counter_info = {.max_top_value = UINT32_MAX, \
445447
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
446448
.channels = 1}, \

drivers/pwm/pwm_ambiq_ctimer.c

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

126126
static int ambiq_ctimer_pwm_set_cycles(const struct device *dev, uint32_t channel,
127-
uint32_t period_cycles, uint32_t pulse_cycles,
128-
pwm_flags_t flags)
127+
uint32_t period_cycles, uint32_t pulse_cycles,
128+
pwm_flags_t flags)
129129
{
130130
const struct pwm_ambiq_ctimer_config *config = dev->config;
131131

@@ -169,7 +169,7 @@ static int ambiq_ctimer_pwm_set_cycles(const struct device *dev, uint32_t channe
169169
}
170170

171171
static int ambiq_ctimer_pwm_get_cycles_per_sec(const struct device *dev, uint32_t channel,
172-
uint64_t *cycles)
172+
uint64_t *cycles)
173173
{
174174
struct pwm_ambiq_ctimer_data *data = dev->data;
175175
int err = 0;
@@ -227,21 +227,23 @@ static const struct pwm_driver_api pwm_ambiq_ctimer_driver_api = {
227227

228228
#define TEST_CHILDREN DT_PATH(test, test_children)
229229

230-
#define PWM_AMBIQ_CTIMER_DEVICE_INIT(n) \
230+
#define PWM_AMBIQ_CTIMER_DEVICE_INIT(n) \
231+
BUILD_ASSERT(DT_CHILD_NUM_STATUS_OKAY(DT_INST_PARENT(n)) == 1, \
232+
"Too many children for Timer!"); \
231233
PINCTRL_DT_INST_DEFINE(n); \
232-
static struct pwm_ambiq_ctimer_data pwm_ambiq_ctimer_data_##n = { \
234+
static struct pwm_ambiq_ctimer_data pwm_ambiq_ctimer_data_##n = { \
233235
.cycles = 0, \
234236
}; \
235-
static const struct pwm_ambiq_ctimer_config pwm_ambiq_ctimer_config_##n = { \
237+
static const struct pwm_ambiq_ctimer_config pwm_ambiq_ctimer_config_##n = { \
236238
.timer_num = (DT_REG_ADDR(DT_INST_PARENT(n)) - CTIMER_BASE) / \
237239
DT_REG_SIZE(DT_INST_PARENT(n)), \
238240
.timer_seg = DT_INST_ENUM_IDX(n, timer_segment), \
239-
.clock_sel = DT_ENUM_IDX(DT_INST_PARENT(n), clk_source), \
241+
.clock_sel = DT_ENUM_IDX(DT_INST_PARENT(n), clk_source), \
240242
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
241243
.pwm_type = DT_INST_ENUM_IDX(n, pwm_type)}; \
242244
\
243-
DEVICE_DT_INST_DEFINE(n, ambiq_ctimer_pwm_init, NULL, &pwm_ambiq_ctimer_data_##n, \
244-
&pwm_ambiq_ctimer_config_##n, POST_KERNEL, CONFIG_PWM_INIT_PRIORITY, \
245+
DEVICE_DT_INST_DEFINE(n, ambiq_ctimer_pwm_init, NULL, &pwm_ambiq_ctimer_data_##n, \
246+
&pwm_ambiq_ctimer_config_##n, POST_KERNEL, CONFIG_PWM_INIT_PRIORITY, \
245247
&pwm_ambiq_ctimer_driver_api);
246248

247249
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
@@ -179,14 +179,16 @@ static const struct pwm_driver_api pwm_ambiq_timer_driver_api = {
179179
};
180180

181181
#define PWM_AMBIQ_TIMER_DEVICE_INIT(n) \
182+
BUILD_ASSERT(DT_CHILD_NUM_STATUS_OKAY(DT_INST_PARENT(n)) == 1, \
183+
"Too many children for Timer!"); \
182184
PINCTRL_DT_INST_DEFINE(n); \
183185
static struct pwm_ambiq_timer_data pwm_ambiq_timer_data_##n = { \
184186
.cycles = 0, \
185187
}; \
186188
static const struct pwm_ambiq_timer_config pwm_ambiq_timer_config_##n = { \
187189
.timer_num = (DT_REG_ADDR(DT_INST_PARENT(n)) - TIMER_BASE) / \
188190
DT_REG_SIZE(DT_INST_PARENT(n)), \
189-
.clock_sel = DT_ENUM_IDX(DT_INST_PARENT(n), clk_source), \
191+
.clock_sel = DT_ENUM_IDX(DT_INST_PARENT(n), clk_source), \
190192
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n)}; \
191193
\
192194
DEVICE_DT_INST_DEFINE(n, ambiq_timer_pwm_init, NULL, &pwm_ambiq_timer_data_##n, \

0 commit comments

Comments
 (0)