📄 os_sem.src
字号:
; .\OS_SEM.SRC generated from: OS_SEM.C
; COMPILER INVOKED BY:
; D:\Keil\C51\BIN\C51.EXE OS_SEM.C LARGE BROWSE DEBUG OBJECTEXTEND SRC(.\OS_SEM.SRC)
$NOMOD51
NAME OS_SEM
P0 DATA 080H
P1 DATA 090H
P2 DATA 0A0H
P3 DATA 0B0H
T0 BIT 0B0H.4
AC BIT 0D0H.6
T1 BIT 0B0H.5
EA BIT 0A8H.7
IE DATA 0A8H
RD BIT 0B0H.7
ES BIT 0A8H.4
IP DATA 0B8H
RI BIT 098H.0
INT0 BIT 0B0H.2
CY BIT 0D0H.7
TI BIT 098H.1
INT1 BIT 0B0H.3
PS BIT 0B8H.4
SP DATA 081H
OV BIT 0D0H.2
WR BIT 0B0H.6
SBUF DATA 099H
PCON DATA 087H
SCON DATA 098H
TMOD DATA 089H
TCON DATA 088H
IE0 BIT 088H.1
IE1 BIT 088H.3
B DATA 0F0H
ACC DATA 0E0H
ET0 BIT 0A8H.1
ET1 BIT 0A8H.3
TF0 BIT 088H.5
TF1 BIT 088H.7
RB8 BIT 098H.2
TH0 DATA 08CH
EX0 BIT 0A8H.0
IT0 BIT 088H.0
TH1 DATA 08DH
TB8 BIT 098H.3
EX1 BIT 0A8H.2
IT1 BIT 088H.2
P BIT 0D0H.0
SM0 BIT 098H.7
TL0 DATA 08AH
SM1 BIT 098H.6
TL1 DATA 08BH
SM2 BIT 098H.5
PT0 BIT 0B8H.1
PT1 BIT 0B8H.3
RS0 BIT 0D0H.3
TR0 BIT 088H.4
RS1 BIT 0D0H.4
TR1 BIT 088H.6
PX0 BIT 0B8H.0
PX1 BIT 0B8H.2
DPH DATA 083H
DPL DATA 082H
REN BIT 098H.4
RXD BIT 0B0H.0
TXD BIT 0B0H.1
F0 BIT 0D0H.5
PSW DATA 0D0H
; /*
; *********************************************************************************************************
; * uC/OS-II
; * The Real-Time Kernel
; * SEMAPHORE MANAGEMENT
; *
; * (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
; * All Rights Reserved
; *
; * V2.00
; *
; * File : OS_SEM.C
; * By : Jean J. Labrosse
; *********************************************************************************************************
; */
;
; #ifndef OS_MASTER_FILE
; #include "includes.h"
; #endif
;
; #if OS_SEM_EN
; /*
; *********************************************************************************************************
; * ACCEPT SEMAPHORE
; *
; * Description: This function checks the semaphore to see if a resource is available or, if an event
; * occurred. Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the
; * resource is not available or the event did not occur.
; *
; * Arguments : pevent is a pointer to the event control block
; *
; * Returns : > 0 if the resource is available or the event did not occur the semaphore is
; * decremented to obtain the resource.
; * == 0 if the resource is not available or the event did not occur or,
; * you didn't pass a pointer to a semaphore
; *********************************************************************************************************
; */
;
; INT16U OSSemAccept (OS_EVENT *pevent) reentrant
; {
; INT16U cnt;
;
;
; OS_ENTER_CRITICAL();
; if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
; OS_EXIT_CRITICAL();
; return (0);
; }
; cnt = pevent->OSEventCnt;
; if (cnt > 0) { /* See if resource is available */
; pevent->OSEventCnt--; /* Yes, decrement semaphore and notify caller */
; }
; OS_EXIT_CRITICAL();
; return (cnt); /* Return semaphore count */
; }
;
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * CREATE A SEMAPHORE
; *
; * Description: This function creates a semaphore.
; *
; * Arguments : cnt is the initial value for the semaphore. If the value is 0, no resource is
; * available (or no event has occurred). You initialize the semaphore to a
; * non-zero value to specify how many resources are available (e.g. if you have
; * 10 resources, you would initialize the semaphore to 10).
; *
; * Returns : != (void *)0 is a pointer to the event control clock (OS_EVENT) associated with the
; * created semaphore
; * == (void *)0 if no event control blocks were available
; *********************************************************************************************************
; */
;
; OS_EVENT *OSSemCreate (INT16U cnt) reentrant
; {
; OS_EVENT *pevent;
;
;
; OS_ENTER_CRITICAL();
; pevent = OSEventFreeList; /* Get next free event control block */
; if (OSEventFreeList != (OS_EVENT *)0) { /* See if pool of free ECB pool was empty */
; OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
; }
; OS_EXIT_CRITICAL();
; if (pevent != (OS_EVENT *)0) { /* Get an event control block */
; pevent->OSEventType = OS_EVENT_TYPE_SEM;
; pevent->OSEventCnt = cnt; /* Set semaphore value */
; OSEventWaitListInit(pevent);
; }
; return (pevent);
; }
;
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * PEND ON SEMAPHORE
; *
; * Description: This function waits for a semaphore.
; *
; * Arguments : pevent is a pointer to the event control block associated with the desired
; * semaphore.
; *
; * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
; * wait for the resource up to the amount of time specified by this argument.
; * If you specify 0, however, your task will wait forever at the specified
; * semaphore or, until the resource becomes available (or the event occurs).
; *
; * err is a pointer to where an error message will be deposited. Possible error
; * messages are:
; *
; * OS_NO_ERR The call was successful and your task owns the resource
; * or, the event you are waiting for occurred.
; * OS_TIMEOUT The semaphore was not received within the specified
; * timeout.
; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore.
; * OS_ERR_PEND_ISR If you called this function from an ISR and the result
; * would lead to a suspension.
; *
; * Returns : none
; *********************************************************************************************************
; */
;
; void OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) reentrant
; {
; OS_ENTER_CRITICAL();
; if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
; OS_EXIT_CRITICAL();
; *err = OS_ERR_EVENT_TYPE;
; }
; if (pevent->OSEventCnt > 0) { /* If sem. is positive, resource available ... */
; pevent->OSEventCnt--; /* ... decrement semaphore only if positive. */
; OS_EXIT_CRITICAL();
; *err = OS_NO_ERR;
; } else if (OSIntNesting > 0) { /* See if called from ISR ... */
; OS_EXIT_CRITICAL(); /* ... can't PEND from an ISR */
; *err = OS_ERR_PEND_ISR;
; } else { /* Otherwise, must wait until event occurs */
; OSTCBCur->OSTCBStat |= OS_STAT_SEM; /* Resource not available, pend on semaphore */
; OSTCBCur->OSTCBDly = timeout; /* Store pend timeout in TCB */
; OSEventTaskWait(pevent); /* Suspend task until event or timeout occurs */
; OS_EXIT_CRITICAL();
; OSSched(); /* Find next highest priority task ready */
; OS_ENTER_CRITICAL();
; if (OSTCBCur->OSTCBStat & OS_STAT_SEM) { /* Must have timed out if still waiting for event*/
; OSEventTO(pevent);
; OS_EXIT_CRITICAL();
; *err = OS_TIMEOUT; /* Indicate that didn't get event within TO */
; } else {
; OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
; OS_EXIT_CRITICAL();
; *err = OS_NO_ERR;
; }
; }
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * POST TO A SEMAPHORE
; *
; * Description: This function signals a semaphore
; *
; * Arguments : pevent is a pointer to the event control block associated with the desired
; * semaphore.
; *
; * Returns : OS_NO_ERR The call was successful and the semaphore was signaled.
; * OS_SEM_OVF If the semaphore count exceeded its limit. In other words, you have
; * signalled the semaphore more often than you waited on it with either
; * OSSemAccept() or OSSemPend().
; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore
; *********************************************************************************************************
; */
;
; INT8U OSSemPost (OS_EVENT *pevent) reentrant
; {
; OS_ENTER_CRITICAL();
; if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
; OS_EXIT_CRITICAL();
; return (OS_ERR_EVENT_TYPE);
; }
; if (pevent->OSEventGrp) { /* See if any task waiting for semaphore */
; OSEventTaskRdy(pevent, (void *)0, OS_STAT_SEM); /* Ready highest prio task waiting on event */
; OS_EXIT_CRITICAL();
; OSSched(); /* Find highest priority task ready to run */
; return (OS_NO_ERR);
; } else {
; if (pevent->OSEventCnt < 65535) { /* Make sure semaphore will not overflow */
; pevent->OSEventCnt++; /* Increment semaphore count to register event */
; OS_EXIT_CRITICAL();
; return (OS_NO_ERR);
; } else { /* Semaphore value has reached its maximum */
; OS_EXIT_CRITICAL();
; return (OS_SEM_OVF);
; }
; }
; }
; /*
; *********************************************************************************************************
; * QUERY A SEMAPHORE
; *
; * Description: This function obtains information about a semaphore
; *
; * Arguments : pevent is a pointer to the event control block associated with the desired
; * semaphore
; *
; * pdata is a pointer to a structure that will contain information about the
; * semaphore.
; *
; * Returns : OS_NO_ERR The call was successful and the message was sent
; * OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non semaphore.
; *********************************************************************************************************
; */
;
; INT8U OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *ppdata) reentrant
; {
; INT8U i;
; INT8U *psrc;
; INT8U *pdest;
;
;
; OS_ENTER_CRITICAL();
; if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
; OS_EXIT_CRITICAL();
; return (OS_ERR_EVENT_TYPE);
; }
; ppdata->OSEventGrp = pevent->OSEventGrp; /* Copy message mailbox wait list */
; psrc = &pevent->OSEventTbl[0];
; pdest = &ppdata->OSEventTbl[0];
; for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
; *pdest++ = *psrc++;
; }
; ppdata->OSCnt = pevent->OSEventCnt; /* Get semaphore count */
; OS_EXIT_CRITICAL();
; return (OS_NO_ERR);
; }
; #endif
; *** sync lost ***
; *** sync lost ***
; *** sync lost ***
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -