📄 os_mbox.ls1
字号:
193 ; OS_EVENT *OSMboxCreate (void *msg)LG_REENTRANT
194 ; {
195 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status regis
ter */
196 ; OS_CPU_SR cpu_sr;
197 ; #endif
198 ; OS_EVENT *pevent;
199 ;
200 ;
201 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
202 ; return ((OS_EVENT *)0); /* ... can't CREATE from an ISR
*/
203 ; }
204 ; OS_ENTER_CRITICAL();
205 ; pevent = OSEventFreeList; /* Get next free event control block
*/
206 ; if (OSEventFreeList != (OS_EVENT *)0) { /* See if pool of free ECB pool was empt
y */
207 ; OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
208 ; }
209 ; OS_EXIT_CRITICAL();
210 ; if (pevent != (OS_EVENT *)0) {
211 ; pevent->OSEventType = OS_EVENT_TYPE_MBOX;
212 ; pevent->OSEventCnt = 0;
213 ; pevent->OSEventPtr = msg; /* Deposit message in event control bloc
k */
214 ; OS_EventWaitListInit(pevent);
215 ; }
216 ; return (pevent); /* Return pointer to event control block
*/
217 ; }
218 ; /*$PAGE*/
219 ; /*
220 ; *****************************************************************************************
****************
221 ; * DELETE A MAIBOX
222 ; *
223 ; * Description: This function deletes a mailbox and readies all tasks pending on the mailb
ox.
224 ; *
225 ; * Arguments : pevent is a pointer to the event control block associated with the
desired
A51 MACRO ASSEMBLER OS_MBOX 05/17/2005 11:19:54 PAGE 5
226 ; * mailbox.
227 ; *
228 ; * opt determines delete options as follows:
229 ; * opt == OS_DEL_NO_PEND Delete the mailbox ONLY if no task p
ending
230 ; * opt == OS_DEL_ALWAYS Deletes the mailbox even if tasks ar
e waiting.
231 ; * In this case, all the tasks pending
will be readied.
232 ; *
233 ; * err is a pointer to an error code that can contain one of the fo
llowing values:
234 ; * OS_NO_ERR The call was successful and the mail
box was deleted
235 ; * OS_ERR_DEL_ISR If you attempted to delete the mailb
ox from an ISR
236 ; * OS_ERR_INVALID_OPT An invalid option was specified
237 ; * OS_ERR_TASK_WAITING One or more tasks were waiting on th
e mailbox
238 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a ma
ilbox
239 ; * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
240 ; *
241 ; * Returns : pevent upon error
242 ; * (OS_EVENT *)0 if the mailbox was successfully deleted.
243 ; *
244 ; * Note(s) : 1) This function must be used with care. Tasks that would normally expect
the presence of
245 ; * the mailbox MUST check the return code of OSMboxPend().
246 ; * 2) OSMboxAccept() callers will not know that the intended mailbox has been
deleted!
247 ; * 3) This call can potentially disable interrupts for a long time. The inte
rrupt disable
248 ; * time is directly proportional to the number of tasks waiting on the mai
lbox.
249 ; * 4) Because ALL tasks pending on the mailbox will be readied, you MUST be c
areful in
250 ; * applications where the mailbox is used for mutual exclusion because the
resource(s)
251 ; * will no longer be guarded by the mailbox.
252 ; *****************************************************************************************
****************
253 ; */
254 ;
255 ; #if OS_MBOX_DEL_EN > 0
256 ; OS_EVENT *OSMboxDel (OS_EVENT *pevent, INT8U opt, INT8U *err)LG_REENTRANT
257 ; {
258 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU st
atus register */
259 ; OS_CPU_SR cpu_sr;
260 ; #endif
261 ; BOOLEAN tasks_waiting;
262 ;
263 ;
264 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
265 ; *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an IS
R */
266 ; return (pevent);
267 ; }
268 ; #if OS_ARG_CHK_EN > 0
269 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent'
*/
270 ; *err = OS_ERR_PEVENT_NULL;
271 ; return (pevent);
272 ; }
A51 MACRO ASSEMBLER OS_MBOX 05/17/2005 11:19:54 PAGE 6
273 ; if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type
*/
274 ; *err = OS_ERR_EVENT_TYPE;
275 ; return (pevent);
276 ; }
277 ; #endif
278 ; OS_ENTER_CRITICAL();
279 ; if (pevent->OSEventGrp != 0x00) { /* See if any tasks waiting on
mailbox */
280 ; tasks_waiting = TRUE; /* Yes
*/
281 ; } else {
282 ; tasks_waiting = FALSE; /* No
*/
283 ; }
284 ; switch (opt) {
285 ; case OS_DEL_NO_PEND: /* Delete mailbox only if no t
ask waiting */
286 ; if (tasks_waiting == FALSE) {
287 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
288 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block
to free list */
289 ; OSEventFreeList = pevent; /* Get next free event control
block */
290 ; OS_EXIT_CRITICAL();
291 ; *err = OS_NO_ERR;
292 ; return ((OS_EVENT *)0); /* Mailbox has been deleted
*/
293 ; } else {
294 ; OS_EXIT_CRITICAL();
295 ; *err = OS_ERR_TASK_WAITING;
296 ; return (pevent);
297 ; }
298 ;
299 ; case OS_DEL_ALWAYS: /* Always delete the mailbox
*/
300 ; while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for
mailbox */
301 ; OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX);
302 ; }
303 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
304 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block
to free list */
305 ; OSEventFreeList = pevent; /* Get next free event control
block */
306 ; OS_EXIT_CRITICAL();
307 ; if (tasks_waiting == TRUE) { /* Reschedule only if task(s)
were waiting */
308 ; OS_Sched(); /* Find highest priority task
ready to run */
309 ; }
310 ; *err = OS_NO_ERR;
311 ; return ((OS_EVENT *)0); /* Mailbox has been deleted
*/
312 ;
313 ; default:
314 ; OS_EXIT_CRITICAL();
315 ; *err = OS_ERR_INVALID_OPT;
316 ; return (pevent);
317 ; }
318 ; }
319 ; #endif
320 ;
321 ; /*$PAGE*/
322 ; /*
323 ; *****************************************************************************************
A51 MACRO ASSEMBLER OS_MBOX 05/17/2005 11:19:54 PAGE 7
****************
324 ; * PEND ON MAILBOX FOR A MESSAGE
325 ; *
326 ; * Description: This function waits for a message to be sent to a mailbox
327 ; *
328 ; * Arguments : pevent is a pointer to the event control block associated with the
desired mailbox
329 ; *
330 ; * timeout is an optional timeout period (in clock ticks). If non-zero
, your task will
331 ; * wait for a message to arrive at the mailbox up to the amount
of time
332 ; * specified by this argument. If you specify 0, however, your
task will wait
333 ; * forever at the specified mailbox or, until a message arrives
.
334 ; *
335 ; * err is a pointer to where an error message will be deposited. P
ossible error
336 ; * messages are:
337 ; *
338 ; * OS_NO_ERR The call was successful and your task re
ceived a
339 ; * message.
340 ; * OS_TIMEOUT A message was not received within the sp
ecified timeout
341 ; * OS_ERR_EVENT_TYPE Invalid event type
342 ; * OS_ERR_PEND_ISR If you called this function from an ISR
and the result
343 ; * would lead to a suspension.
344 ; * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
345 ; *
346 ; * Returns : != (void *)0 is a pointer to the message received
347 ; * == (void *)0 if no message was received or,
348 ; * if 'pevent' is a NULL pointer or,
349 ; * if you didn't pass the proper pointer to the event control b
lock.
350 ; *****************************************************************************************
****************
351 ; */
352 ;
353 ; void *OSMboxPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)LG_REENTRANT
354 ; {
355 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status regis
ter */
356 ; OS_CPU_SR cpu_sr;
357 ; #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -