1 #include "msgbox_sx.h"
2 #include "FreeRTOS.h"
3 #include "hal_msgbox.h"
4 #include "../platform-msgbox.h"
5 
6 struct msgbox_adapt {
7     struct messagebox *msgbox;
8     struct msg_channel *msg_ch_send;
9     struct msg_channel *msg_ch_rec;
10     struct msg_endpoint *edp;
11 };
12 
hal_msgbox_init(void)13 uint32_t hal_msgbox_init(void)
14 {
15     return messagebox_init_sx();
16 }
17 
func_cb_tx(unsigned long i,void * d)18 static int func_cb_tx(unsigned long i, void *d)
19 {
20     struct msgbox_adapt *adp = d;
21     struct msg_endpoint *edp = adp->edp;
22 
23     if (edp->tx_done)
24         edp->tx_done(edp->data);
25 
26     return 0;
27 }
28 
func_cb_rec(unsigned long i,void * d)29 static int func_cb_rec(unsigned long i, void *d)
30 {
31     struct msgbox_adapt *adp = d;
32     struct msg_endpoint *edp = adp->edp;
33 
34     if (edp->rec)
35         edp->rec(i, edp->data);
36 
37     return 0;
38 }
39 
hal_msgbox_alloc_channel(struct msg_endpoint * edp,uint32_t remote,uint32_t read,uint32_t write)40 uint32_t hal_msgbox_alloc_channel(struct msg_endpoint *edp, uint32_t remote,
41                   uint32_t read, uint32_t write)
42 {
43     struct msgbox_adapt *adp;
44     struct messagebox *msg;
45     struct msg_channel *chl;
46 
47     if (edp->remote_amp == ARM_MSG_CORE)
48         msg = msgbox_cpu;
49     else
50         msg = msgbox_dsp;
51 
52     adp = pvPortMalloc(sizeof(struct msgbox_adapt));
53 
54     adp->msgbox = msg;
55     adp->edp = edp;
56     edp->private = adp;
57 
58     chl = msgbox_alloc_channel_sx(msg, read, MSGBOX_CHANNEL_RECEIVE,
59                       func_cb_rec, adp);
60     adp->msg_ch_rec = chl;
61 
62     chl = msgbox_alloc_channel_sx(msg, write, MSGBOX_CHANNEL_SEND,
63                       func_cb_tx, adp);
64     adp->msg_ch_send = chl;
65 
66     return 0;
67 }
68 
hal_msgbox_channel_send(struct msg_endpoint * edp,uint8_t * bf,uint32_t len)69 uint32_t hal_msgbox_channel_send(struct msg_endpoint *edp, uint8_t *bf,
70                  uint32_t len)
71 {
72     struct msgbox_adapt *adp = edp->private;
73 
74     return msgbox_channel_send_data_sx(adp->msg_ch_send, bf, len);
75 }
76 
hal_msgbox_free_channel(struct msg_endpoint * edp)77 void hal_msgbox_free_channel(struct msg_endpoint *edp)
78 {
79     struct msgbox_adapt *adp = edp->private;
80 
81     msgbox_free_channel_sx(adp->msgbox, adp->msg_ch_rec);
82     msgbox_free_channel_sx(adp->msgbox, adp->msg_ch_send);
83 
84     vPortFree(adp);
85 }
86 
87 
88