MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_mbox_controller_register

Function rt_mbox_controller_register

components/drivers/mailbox/mailbox.c:28–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26static void mbox_chan_timeout(void *param);
27
28rt_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
75rt_err_t rt_mbox_controller_unregister(struct rt_mbox_controller *ctrl)
76{

Callers 1

pic_mbox_probeFunction · 0.85

Calls 10

rt_callocFunction · 0.85
rt_snprintfFunction · 0.85
rt_dm_dev_get_nameFunction · 0.85
rt_timer_initFunction · 0.85
rt_list_initFunction · 0.85
rt_dm_dev_bind_fwdataFunction · 0.85
rt_list_insert_afterFunction · 0.85
rt_spin_lock_initFunction · 0.50
rt_spin_lockFunction · 0.50
rt_spin_unlockFunction · 0.50

Tested by

no test coverage detected