| 26 | static void mbox_chan_timeout(void *param); |
| 27 | |
| 28 | rt_err_t rt_mbox_controller_register(struct rt_mbox_controller *ctrl) |
| 29 | { |
| 30 | int len; |
| 31 | struct rt_mbox_chan *chan; |
| 32 | char timer_name[RT_NAME_MAX]; |
| 33 | |
| 34 | if (!ctrl || !ctrl->dev || !ctrl->ops || !ctrl->num_chans) |
| 35 | { |
| 36 | return -RT_EINVAL; |
| 37 | } |
| 38 | |
| 39 | ctrl->chans = rt_calloc(ctrl->num_chans, sizeof(struct rt_mbox_chan)); |
| 40 | |
| 41 | if (!ctrl->chans) |
| 42 | { |
| 43 | return -RT_ENOMEM; |
| 44 | } |
| 45 | |
| 46 | len = rt_snprintf(timer_name, sizeof(timer_name), "%s-", |
| 47 | rt_dm_dev_get_name(ctrl->dev)); |
| 48 | |
| 49 | RT_ASSERT(len < sizeof(timer_name)); |
| 50 | |
| 51 | chan = &ctrl->chans[0]; |
| 52 | |
| 53 | for (int i = 0; i < ctrl->num_chans; ++i, ++chan) |
| 54 | { |
| 55 | chan->ctrl = ctrl; |
| 56 | rt_spin_lock_init(&chan->lock); |
| 57 | |
| 58 | rt_snprintf(&timer_name[len], sizeof(timer_name) - len, "%d", i); |
| 59 | rt_timer_init(&chan->timer, timer_name, mbox_chan_timeout, chan, |
| 60 | 0, RT_TIMER_FLAG_ONE_SHOT); |
| 61 | } |
| 62 | |
| 63 | rt_list_init(&ctrl->list); |
| 64 | rt_dm_dev_bind_fwdata(ctrl->dev, RT_NULL, ctrl); |
| 65 | |
| 66 | rt_spin_lock(&mbox_ops_lock); |
| 67 | |
| 68 | rt_list_insert_after(&mbox_nodes, &ctrl->list); |
| 69 | |
| 70 | rt_spin_unlock(&mbox_ops_lock); |
| 71 | |
| 72 | return RT_EOK; |
| 73 | } |
| 74 | |
| 75 | rt_err_t rt_mbox_controller_unregister(struct rt_mbox_controller *ctrl) |
| 76 | { |
no test coverage detected