📄 os_flag.ls1
字号:
297 ; * Arguments : pgrp is a pointer to the desired event flag group.
298 ; *
299 ; * opt determines delete options as follows:
300 ; * opt == OS_DEL_NO_PEND Deletes the event flag group ONLY if
no task pending
301 ; * opt == OS_DEL_ALWAYS Deletes the event flag group even if
tasks are
302 ; * waiting. In this case, all the task
s pending will be
303 ; * readied.
304 ; *
305 ; * err is a pointer to an error code that can contain one of the fo
llowing values:
306 ; * OS_NO_ERR The call was successful and the even
t flag group was
307 ; * deleted
308 ; * OS_ERR_DEL_ISR If you attempted to delete the event
flag group from
309 ; * an ISR
310 ; * OS_FLAG_INVALID_PGRP If 'pgrp' is a NULL pointer.
311 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to an e
vent flag group
312 ; * OS_ERR_INVALID_OPT An invalid option was specified
313 ; * OS_ERR_TASK_WAITING One or more tasks were waiting on th
e event flag
A51 MACRO ASSEMBLER OS_FLAG 08/08/2005 11:36:41 PAGE 7
314 ; * group.
315 ; *
316 ; * Returns : pevent upon error
317 ; * (OS_EVENT *)0 if the semaphore was successfully deleted.
318 ; *
319 ; * Note(s) : 1) This function must be used with care. Tasks that would normally expect
the presence of
320 ; * the event flag group MUST check the return code of OSFlagAccept() and O
SFlagPend().
321 ; * 2) This call can potentially disable interrupts for a long time. The inte
rrupt disable
322 ; * time is directly proportional to the number of tasks waiting on the eve
nt flag group.
323 ; *****************************************************************************************
****************
324 ; */
325 ;
326 ; #if OS_FLAG_DEL_EN > 0
327 ; OS_FLAG_GRP *OSFlagDel (OS_FLAG_GRP *pgrp, INT8U opt, INT8U *err)
328 ; {
329 ;
330 ; BOOLEAN tasks_waiting;
331 ; OS_FLAG_NODE *pnode;
332 ;
333 ;
334 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
335 ; *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an IS
R */
336 ; return (pgrp);
337 ; }
338 ; #if OS_ARG_CHK_EN > 0
339 ; if (pgrp == (OS_FLAG_GRP *)0) { /* Validate 'pgrp'
*/
340 ; *err = OS_FLAG_INVALID_PGRP;
341 ; return (pgrp);
342 ; }
343 ; if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Validate event group type
*/
344 ; *err = OS_ERR_EVENT_TYPE;
345 ; return (pgrp);
346 ; }
347 ; #endif
348 ; OS_ENTER_CRITICAL();
349 ; if (pgrp->OSFlagWaitList != (void *)0) { /* See if any tasks waiting on
event flags */
350 ; tasks_waiting = TRUE; /* Yes
*/
351 ; } else {
352 ; tasks_waiting = FALSE; /* No
*/
353 ; }
354 ; switch (opt) {
355 ; case OS_DEL_NO_PEND: /* Delete group if no task wai
ting */
356 ; if (tasks_waiting == FALSE) {
357 ; pgrp->OSFlagType = OS_EVENT_TYPE_UNUSED;
358 ; pgrp->OSFlagWaitList = (void *)OSFlagFreeList; /* Return group to free l
ist */
359 ; OSFlagFreeList = pgrp;
360 ; OS_EXIT_CRITICAL();
361 ; *err = OS_NO_ERR;
362 ; return ((OS_FLAG_GRP *)0); /* Event Flag Group has been d
eleted */
363 ; } else {
364 ; OS_EXIT_CRITICAL();
A51 MACRO ASSEMBLER OS_FLAG 08/08/2005 11:36:41 PAGE 8
365 ; *err = OS_ERR_TASK_WAITING;
366 ; return (pgrp);
367 ; }
368 ;
369 ; case OS_DEL_ALWAYS: /* Always delete the event fla
g group */
370 ; pnode = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;
371 ; while (pnode != (OS_FLAG_NODE *)0) { /* Ready ALL tasks waiting for
flags */
372 ; OS_FlagTaskRdy(pnode, (OS_FLAGS)0);
373 ; pnode = (OS_FLAG_NODE *)pnode->OSFlagNodeNext;
374 ; }
375 ; pgrp->OSFlagType = OS_EVENT_TYPE_UNUSED;
376 ; pgrp->OSFlagWaitList = (void *)OSFlagFreeList;/* Return group to free list
*/
377 ; OSFlagFreeList = pgrp;
378 ; OS_EXIT_CRITICAL();
379 ; if (tasks_waiting == TRUE) { /* Reschedule only if task(s)
were waiting */
380 ; OS_Sched(); /* Find highest priority task
ready to run */
381 ; }
382 ; *err = OS_NO_ERR;
383 ; return ((OS_FLAG_GRP *)0); /* Event Flag Group has been d
eleted */
384 ;
385 ; default:
386 ; OS_EXIT_CRITICAL();
387 ; *err = OS_ERR_INVALID_OPT;
388 ; return (pgrp);
389 ; }
390 ; }
391 ; #endif
392 ; /*$PAGE*/
393 ; /*
394 ; *****************************************************************************************
****************
395 ; * WAIT ON AN EVENT FLAG GROUP
396 ; *
397 ; * Description: This function is called to wait for a combination of bits to be set in an
event flag
398 ; * group. Your application can wait for ANY bit to be set or ALL bits to be
set.
399 ; *
400 ; * Arguments : pgrp is a pointer to the desired event flag group.
401 ; *
402 ; * flags Is a bit pattern indicating which bit(s) (i.e. flags) you wi
sh to wait for.
403 ; * The bits you want are specified by setting the corresponding
bits in
404 ; * 'flags'. e.g. if your application wants to wait for bits 0
and 1 then
405 ; * 'flags' would contain 0x03.
406 ; *
407 ; * wait_type specifies whether you want ALL bits to be set or ANY of the
bits to be set.
408 ; * You can specify the following argument:
409 ; *
410 ; * OS_FLAG_WAIT_CLR_ALL You will wait for ALL bits in 'mask'
to be clear (0)
411 ; * OS_FLAG_WAIT_SET_ALL You will wait for ALL bits in 'mask'
to be set (1)
412 ; * OS_FLAG_WAIT_CLR_ANY You will wait for ANY bit in 'mask'
to be clear (0)
413 ; * OS_FLAG_WAIT_SET_ANY You will wait for ANY bit in 'mask'
to be set (1)
A51 MACRO ASSEMBLER OS_FLAG 08/08/2005 11:36:41 PAGE 9
414 ; *
415 ; * NOTE: Add OS_FLAG_CONSUME if you want the event flag to be '
consumed' by
416 ; * the call. Example, to wait for any flag in a group AN
D then clear
417 ; * the flags that are present, set 'wait_type' to:
418 ; *
419 ; * OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME
420 ; *
421 ; * timeout is an optional timeout (in clock ticks) that your task will
wait for the
422 ; * desired bit combination. If you specify 0, however, your ta
sk will wait
423 ; * forever at the specified event flag group or, until a messag
e arrives.
424 ; *
425 ; * err is a pointer to an error code and can be:
426 ; * OS_NO_ERR The desired bits have been set within
the specified
427 ; * 'timeout'.
428 ; * OS_ERR_PEND_ISR If you tried to PEND from an ISR
429 ; * OS_FLAG_INVALID_PGRP If 'pgrp' is a NULL pointer.
430 ; * OS_ERR_EVENT_TYPE You are not pointing to an event flag
group
431 ; * OS_TIMEOUT The bit(s) have not been set in the s
pecified
432 ; * 'timeout'.
433 ; * OS_FLAG_ERR_WAIT_TYPE You didn't specify a proper 'wait_typ
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -