Skip to content

Commit e9a79f3

Browse files
committed
drivers: mbox: Use nordic_tasks from dts instead of VPR_TASK definitions
Uses nordic_tasks from dts file to create mbox rx callbacks. Signed-off-by: Erdem Simsek <[email protected]>
1 parent 13f0ae1 commit e9a79f3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

drivers/mbox/mbox_nrf_vevif_task_rx.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ BUILD_ASSERT(VEVIF_TASKS_NUM == DT_NUM_IRQS(DT_DRV_INST(0)), "# IRQs != # tasks"
2323

2424
/* callbacks */
2525
struct mbox_vevif_task_rx_cbs {
26-
mbox_callback_t cb[TASKS_IDX_MAX - TASKS_IDX_MIN + 1U];
27-
void *user_data[TASKS_IDX_MAX - TASKS_IDX_MIN + 1U];
26+
mbox_callback_t cb[VEVIF_TASKS_NUM + 1U];
27+
void *user_data[VEVIF_TASKS_NUM + 1U];
2828
uint32_t enabled_mask;
2929
};
3030

@@ -37,10 +37,17 @@ static const uint8_t vevif_irqs[VEVIF_TASKS_NUM] = {
3737
LISTIFY(DT_NUM_IRQS(DT_DRV_INST(0)), VEVIF_IRQN, (,))
3838
};
3939

40+
static inline uint8_t vevif_task_to_idx(uint32_t id)
41+
{
42+
uint32_t mask_below = VEVIF_TASKS_MASK & ((1UL << id) - 1);
43+
44+
return __builtin_popcount(mask_below);
45+
}
46+
4047
static void vevif_task_rx_isr(const void *parameter)
4148
{
4249
uint8_t channel = *(uint8_t *)parameter;
43-
uint8_t idx = channel - TASKS_IDX_MIN;
50+
uint8_t idx = vevif_task_to_idx(channel);
4451

4552
nrf_vpr_csr_vevif_tasks_clear(BIT(channel));
4653

@@ -65,12 +72,13 @@ static int vevif_task_rx_register_callback(const struct device *dev, uint32_t id
6572
mbox_callback_t cb, void *user_data)
6673
{
6774
ARG_UNUSED(dev);
68-
uint8_t idx = id - TASKS_IDX_MIN;
6975

7076
if (!vevif_task_rx_is_task_valid(id)) {
7177
return -EINVAL;
7278
}
7379

80+
uint8_t idx = vevif_task_to_idx(id);
81+
7482
cbs.cb[idx] = cb;
7583
cbs.user_data[idx] = user_data;
7684

@@ -80,12 +88,13 @@ static int vevif_task_rx_register_callback(const struct device *dev, uint32_t id
8088
static int vevif_task_rx_set_enabled(const struct device *dev, uint32_t id, bool enable)
8189
{
8290
ARG_UNUSED(dev);
83-
uint8_t idx = id - TASKS_IDX_MIN;
8491

8592
if (!vevif_task_rx_is_task_valid(id)) {
8693
return -EINVAL;
8794
}
8895

96+
uint8_t idx = vevif_task_to_idx(id);
97+
8998
if (enable) {
9099
if ((cbs.enabled_mask & BIT(id)) != 0U) {
91100
return -EALREADY;

0 commit comments

Comments
 (0)