Skip to content

Commit 90eb1b8

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 f6b8731 commit 90eb1b8

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ static DEVICE_API(pwm, pwm_ambiq_timer_driver_api) = {
225225
};
226226

227227
#define PWM_AMBIQ_TIMER_DEVICE_INIT(n) \
228+
BUILD_ASSERT(DT_CHILD_NUM_STATUS_OKAY(DT_INST_PARENT(n)) == 1, \
229+
"Too many children for Timer!"); \
228230
PINCTRL_DT_INST_DEFINE(n); \
229231
static struct pwm_ambiq_timer_data pwm_ambiq_timer_data_##n = { \
230232
.cycles = 0, \
@@ -233,7 +235,7 @@ static DEVICE_API(pwm, pwm_ambiq_timer_driver_api) = {
233235
.timer_num = (DT_REG_ADDR(DT_INST_PARENT(n)) - CTIMER_BASE) / \
234236
DT_REG_SIZE(DT_INST_PARENT(n)), \
235237
.timer_seg = DT_INST_ENUM_IDX(n, timer_segment), \
236-
.clock_sel = DT_ENUM_IDX(DT_INST_PARENT(n), clk_source), \
238+
.clock_sel = DT_ENUM_IDX(DT_INST_PARENT(n), clk_source), \
237239
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
238240
.pwm_type = DT_INST_ENUM_IDX(n, pwm_type)}; \
239241
\

drivers/pwm/pwm_ambiq_timer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,16 @@ static DEVICE_API(pwm, pwm_ambiq_timer_driver_api) = {
178178
};
179179

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

0 commit comments

Comments
 (0)