1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
/*
* ===========================================================================================
*
* Filename: hal_mailbox.c
*
* Description: mbox impl.for hal.
*
* Version: Melis3.0
* Create: 2019-11-27 17:32:09
* Revision: none
* Compiler: GCC:version 7.2.1 20170904 (release),ARM/embedded-7-branch revision 255204
*
* Author: [email protected]
* Organization: BU1-PSW
* Last Modified: 2019-11-27 18:02:12
*
* ===========================================================================================
*/
#include <hal_queue.h>
#include <rtdef.h>
#include <rtthread.h>
#include <log.h>
hal_mailbox_t hal_mailbox_create(const char *name, unsigned int size)
{
return rt_mb_create("hal_layer", size, RT_IPC_FLAG_FIFO);
}
int hal_mailbox_delete(hal_mailbox_t mailbox)
{
if (mailbox == NULL)
{
__err("fatal error, parameter is invalid.");
return -1;
}
rt_mb_delete(mailbox);
return 0;
}
int hal_mailbox_send(hal_mailbox_t mailbox, unsigned int value)
{
rt_err_t ret;
if (mailbox == NULL)
{
__err("fatal error, parameter is invalid.");
return -1;
}
ret = rt_mb_send(mailbox, value);
if (ret != RT_EOK)
{
// timeout.
return -2;
}
return 0;
}
int hal_mailbox_send_wait(hal_mailbox_t mailbox, unsigned int value, int timeout)
{
rt_err_t ret;
if (mailbox == NULL)
{
__err("fatal error, parameter is invalid.");
return -1;
}
ret = rt_mb_send_wait(mailbox, value, timeout);
if (ret != RT_EOK)
{
// timeout.
return -2;
}
return 0;
}
int hal_mailbox_recv(hal_mailbox_t mailbox, unsigned int *value, int timeout)
{
rt_err_t ret;
if (mailbox == NULL || value == NULL)
{
__err("fatal error, parameter is invalid.");
return -1;
}
ret = rt_mb_recv(mailbox, (rt_ubase_t *)value, timeout);
if (ret != RT_EOK)
{
// timeout.
return -2;
}
return 0;
}
int hal_is_mailbox_empty(hal_mailbox_t mailbox)
{
rt_err_t ret = -1;
int arg;
if (mailbox == NULL)
{
__err("fatal error, parameter is invalid.");
return -1;
}
ret = rt_mb_control(mailbox, RT_IPC_CMD_GET_STATE, &arg);
if (ret != RT_EOK)
return -2;
return (arg == 0)? 1: 0;
}
hal_workqueue *hal_workqueue_create(const char *name, unsigned short stack_size, unsigned char priority)
{
return rt_workqueue_create(name, stack_size, priority);
}
int hal_workqueue_dowork(hal_workqueue *queue, hal_work *work)
{
int ret = 0;
ret = rt_workqueue_dowork(queue, work);
return ret;
}
hal_queue_t hal_queue_create(const char *name, unsigned int item_size, unsigned int queue_size)
{
return rt_mq_create("hal_layer", item_size, queue_size, RT_IPC_FLAG_FIFO);
}
int hal_queue_delete(hal_queue_t queue)
{
if (queue == NULL)
{
__err("fatal error, parameter is invalid.");
return -1;
}
rt_mq_delete(queue);
return 0;
}
int hal_queue_send_wait(hal_queue_t queue, void *buffer, int timeout)
{
rt_err_t ret;
if (queue == NULL)
{
__err("fatal error, parameter is invalid.");
return -1;
}
ret = rt_mq_send_wait(queue, buffer, queue->msg_size, timeout);
if (ret != RT_EOK)
{
return -2;
}
return 0;
}
int hal_queue_send(hal_queue_t queue, void *buffer)
{
return hal_queue_send_wait(queue, buffer, 0);
}
int hal_queue_recv(hal_queue_t queue, void *buffer, int timeout)
{
rt_err_t ret;
if (queue == NULL)
{
__err("fatal error, parameter is invalid.");
return -1;
}
ret = rt_mq_recv(queue, buffer, queue->msg_size, timeout);
if (ret != RT_EOK)
{
return -2;
}
return 0;
}
int hal_is_queue_empty(hal_queue_t queue)
{
rt_err_t ret = -1;
int arg;
if (queue == NULL)
{
__err("fatal error, parameter is invalid.");
return -1;
}
ret = rt_mq_control(queue, RT_IPC_CMD_GET_STATE, &arg);
if (ret != RT_EOK)
return -2;
return (arg == 0)? 1: 0;
}
|