Skip to content

Commit 94a7c85

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 94a7c85

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
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: 2 additions & 0 deletions
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, \

drivers/pwm/pwm_ambiq_timer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ 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, \

0 commit comments

Comments
 (0)