📄 os_sem.ls1
字号:
desired
370 ; * semaphore.
371 ; *
372 ; * opt determines delete options as follows:
373 ; * opt == OS_DEL_NO_PEND Delete semaphore ONLY if no task pen
ding
374 ; * opt == OS_DEL_ALWAYS Deletes the semaphore even if tasks
are waiting.
375 ; * In this case, all the tasks pending
will be readied.
376 ; *
377 ; * err is a pointer to an error code that can contain one of the fo
llowing values:
378 ; * OS_NO_ERR The call was successful and the sema
phore was deleted
379 ; * OS_ERR_DEL_ISR If you attempted to delete the semap
hore from an ISR
380 ; * OS_ERR_INVALID_OPT An invalid option was specified
381 ; * OS_ERR_TASK_WAITING One or more tasks were waiting on th
e semaphore
382 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a se
maphore
383 ; * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
384 ; *
385 ; * Returns : pevent upon error
386 ; * (OS_EVENT *)0 if the semaphore was successfully deleted.
387 ; *
388 ; * Note(s) : 1) This function must be used with care. Tasks that would normally expect
the presence of
389 ; * the semaphore MUST check the return code of OSSemPend().
390 ; * 2) OSSemAccept() callers will not know that the intended semaphore has bee
n deleted unless
391 ; * they check 'pevent' to see that it's a NULL pointer.
392 ; * 3) This call can potentially disable interrupts for a long time. The inte
rrupt disable
393 ; * time is directly proportional to the number of tasks waiting on the sem
aphore.
394 ; * 4) Because ALL tasks pending on the semaphore will be readied, you MUST be
careful in
395 ; * applications where the semaphore is used for mutual exclusion because t
he resource(s)
396 ; * will no longer be guarded by the semaphore.
397 ; *****************************************************************************************
****************
398 ; */
399 ;
400 ; #if OS_SEM_DEL_EN > 0
401 ; OS_EVENT *OSSemDel (OS_EVENT *pevent, INT8U opt, INT8U *err)LG_REENTRANT
402 ; {
403 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU st
atus register */
404 ; OS_CPU_SR cpu_sr;
405 ; #endif
A51 MACRO ASSEMBLER OS_SEM 05/17/2005 11:19:57 PAGE 8
406 ; BOOLEAN tasks_waiting;
407 ;
408 ;
409 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
410 ; *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an IS
R */
411 ; return (pevent);
412 ; }
413 ; #if OS_ARG_CHK_EN > 0
414 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent'
*/
415 ; *err = OS_ERR_PEVENT_NULL;
416 ; return (pevent);
417 ; }
418 ; if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type
*/
419 ; *err = OS_ERR_EVENT_TYPE;
420 ; return (pevent);
421 ; }
422 ; #endif
423 ; OS_ENTER_CRITICAL();
424 ; if (pevent->OSEventGrp != 0x00) { /* See if any tasks waiting on
semaphore */
425 ; tasks_waiting = TRUE; /* Yes
*/
426 ; } else {
427 ; tasks_waiting = FALSE; /* No
*/
428 ; }
429 ; switch (opt) {
430 ; case OS_DEL_NO_PEND: /* Delete semaphore only if no
task waiting */
431 ; if (tasks_waiting == FALSE) {
432 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
433 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block
to free list */
434 ; OSEventFreeList = pevent; /* Get next free event control
block */
435 ; OS_EXIT_CRITICAL();
436 ; *err = OS_NO_ERR;
437 ; return ((OS_EVENT *)0); /* Semaphore has been deleted
*/
438 ; } else {
439 ; OS_EXIT_CRITICAL();
440 ; *err = OS_ERR_TASK_WAITING;
441 ; return (pevent);
442 ; }
443 ;
444 ; case OS_DEL_ALWAYS: /* Always delete the semaphore
*/
445 ; while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for
semaphore */
446 ; OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);
447 ; }
448 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
449 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block
to free list */
450 ; OSEventFreeList = pevent; /* Get next free event control
block */
451 ; OS_EXIT_CRITICAL();
452 ; if (tasks_waiting == TRUE) { /* Reschedule only if task(s)
were waiting */
453 ; OS_Sched(); /* Find highest priority task
ready to run */
454 ; }
A51 MACRO ASSEMBLER OS_SEM 05/17/2005 11:19:57 PAGE 9
455 ; *err = OS_NO_ERR;
456 ; return ((OS_EVENT *)0); /* Semaphore has been deleted
*/
457 ;
458 ; default:
459 ; OS_EXIT_CRITICAL();
460 ; *err = OS_ERR_INVALID_OPT;
461 ; return (pevent);
462 ; }
463 ; }
464 ; #endif
465 ;
466 ; /*$PAGE*/
467 ; /*
468 ; *****************************************************************************************
****************
469 ; * PEND ON SEMAPHORE
470 ; *
471 ; * Description: This function waits for a semaphore.
472 ; *
473 ; * Arguments : pevent is a pointer to the event control block associated with the
desired
474 ; * semaphore.
475 ; *
476 ; * timeout is an optional timeout period (in clock ticks). If non-zero
, your task will
477 ; * wait for the resource up to the amount of time specified by
this argument.
478 ; * If you specify 0, however, your task will wait forever at th
e specified
479 ; * semaphore or, until the resource becomes available (or the e
vent occurs).
480 ; *
481 ; * err is a pointer to where an error message will be deposited. P
ossible error
482 ; * messages are:
483 ; *
484 ; * OS_NO_ERR The call was successful and your task ow
ns the resource
485 ; * or, the event you are waiting for occurr
ed.
486 ; * OS_TIMEOUT The semaphore was not received within th
e specified
487 ; * timeout.
488 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaph
ore.
489 ; * OS_ERR_PEND_ISR If you called this function from an ISR
and the result
490 ; * would lead to a suspension.
491 ; * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
492 ; *
493 ; * Returns : none
494 ; *****************************************************************************************
****************
495 ; */
496 ;
497 ; void OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)LG_REENTRANT
498
---- 499 RSEG ?PR?_?OSSemPend?OS_SEM
0000 500 _?OSSemPend:
501 USING 0
502 ; SOURCE LINE # 244
0000 90FFFE 503 MOV DPTR,#0FFFEH
0003 120000 F 504 LCALL ?C?ADDXBP
0006 EC 505 MOV A,R4
0007 F0 506 MOVX @DPTR,A
A51 MACRO ASSEMBLER OS_SEM 05/17/2005 11:19:57 PAGE 10
0008 A3 507 INC DPTR
0009 ED 508 MOV A,R5
000A F0 509 MOVX @DPTR,A
000B 90FFFD 510 MOV DPTR,#0FFFDH
000E 120000 F 511 LCALL ?C?ADDXBP
0011 120000 F 512 LCALL ?C?PSTXDATA
513 ; {
514 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status
register */
515 ; OS_CPU_SR cpu_sr;
516 ; #endif
517 ;
518 ;
519 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
520 ; SOURCE LINE # 251
0014 900000 F 521 MOV DPTR,#OSIntNesting
0017 E0 522 MOVX A,@DPTR
0018 D3 523 SETB C
0019 9400 524 SUBB A,#00H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -