📄 os_mbox.src
字号:
; .\OS_MBOX.SRC generated from: OS_MBOX.C
; COMPILER INVOKED BY:
; D:\Keil\C51\BIN\C51.EXE OS_MBOX.C LARGE BROWSE DEBUG OBJECTEXTEND SRC(.\OS_MBOX.SRC)
$NOMOD51
NAME OS_MBOX
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
; * MESSAGE MAILBOX MANAGEMENT
; *
; * (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
; * All Rights Reserved
; *
; * V2.00
; *
; * File : OS_MBOX.C
; * By : Jean J. Labrosse
; *********************************************************************************************************
; */
;
; #ifndef OS_MASTER_FILE
; #include "includes.h"
; #endif
;
; #if OS_MBOX_EN
; /*
; *********************************************************************************************************
; * ACCEPT MESSAGE FROM MAILBOX
; *
; * Description: This function checks the mailbox to see if a message is available. Unlike OSMboxPend(),
; * OSMboxAccept() does not suspend the calling task if a message is not available.
; *
; * Arguments : pevent is a pointer to the event control block
; *
; * Returns : != (void *)0 is the message in the mailbox if one is available. The mailbox is cleared
; * so the next time OSMboxAccept() is called, the mailbox will be empty.
; * == (void *)0 if the mailbox is empty or if you didn't pass the proper event pointer.
; *********************************************************************************************************
; */
;
; void *OSMboxAccept (OS_EVENT *pevent) reentrant
; {
; void *msg;
;
;
; OS_ENTER_CRITICAL();
; if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
; OS_EXIT_CRITICAL();
; return ((void *)0);
; }
; msg = pevent->OSEventPtr;
; if (msg != (void *)0) { /* See if there is already a message */
; pevent->OSEventPtr = (void *)0; /* Clear the mailbox */
; }
; OS_EXIT_CRITICAL();
; return (msg); /* Return the message received (or NULL) */
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * CREATE A MESSAGE MAILBOX
; *
; * Description: This function creates a message mailbox if free event control blocks are available.
; *
; * Arguments : msg is a pointer to a message that you wish to deposit in the mailbox. If
; * you set this value to the NULL pointer (i.e. (void *)0) then the mailbox
; * will be considered empty.
; *
; * Returns : != (void *)0 is a pointer to the event control clock (OS_EVENT) associated with the
; * created mailbox
; * == (void *)0 if no event control blocks were available
; *********************************************************************************************************
; */
;
; OS_EVENT *OSMboxCreate (void *msg) 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) {
; pevent->OSEventType = OS_EVENT_TYPE_MBOX;
; pevent->OSEventPtr = msg; /* Deposit message in event control block */
; OSEventWaitListInit(pevent);
; }
; return (pevent); /* Return pointer to event control block */
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * PEND ON MAILBOX FOR A MESSAGE
; *
; * Description: This function waits for a message to be sent to a mailbox
; *
; * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
; *
; * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
; * wait for a message to arrive at the mailbox up to the amount of time
; * specified by this argument. If you specify 0, however, your task will wait
; * forever at the specified mailbox or, until a message arrives.
; *
; * 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 received a message.
; * OS_TIMEOUT A message was not received within the specified timeout
; * OS_ERR_EVENT_TYPE Invalid event type
; * OS_ERR_PEND_ISR If you called this function from an ISR and the result
; * would lead to a suspension.
; *
; * Returns : != (void *)0 is a pointer to the message received
; * == (void *)0 if no message was received or you didn't pass the proper pointer to the
; * event control block.
; *********************************************************************************************************
; */
;
; void *OSMboxPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) reentrant
; {
; void *msg;
;
;
; OS_ENTER_CRITICAL();
; if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
; OS_EXIT_CRITICAL();
; *err = OS_ERR_EVENT_TYPE;
; return ((void *)0);
; }
; msg = pevent->OSEventPtr;
; if (msg != (void *)0) { /* See if there is already a message */
; pevent->OSEventPtr = (void *)0; /* Clear the mailbox */
; 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 {
; OSTCBCur->OSTCBStat |= OS_STAT_MBOX; /* Message not available, task will pend */
; OSTCBCur->OSTCBDly = timeout; /* Load timeout in TCB */
; OSEventTaskWait(pevent); /* Suspend task until event or timeout occurs */
; OS_EXIT_CRITICAL();
; OSSched(); /* Find next highest priority task ready to run */
; OS_ENTER_CRITICAL();
; if ((msg = OSTCBCur->OSTCBMsg) != (void *)0) { /* See if we were given the message */
; OSTCBCur->OSTCBMsg = (void *)0; /* Yes, clear message received */
; OSTCBCur->OSTCBStat = OS_STAT_RDY;
; OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event */
; OS_EXIT_CRITICAL();
; *err = OS_NO_ERR;
; } else if (OSTCBCur->OSTCBStat & OS_STAT_MBOX) { /* If status is not OS_STAT_RDY, timed out */
; OSEventTO(pevent); /* Make task ready */
; OS_EXIT_CRITICAL();
; msg = (void *)0; /* Set message contents to NULL */
; *err = OS_TIMEOUT; /* Indicate that a timeout occured */
; } else {
; msg = pevent->OSEventPtr; /* Message received */
; pevent->OSEventPtr = (void *)0; /* Clear the mailbox */
; OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
; OS_EXIT_CRITICAL();
; *err = OS_NO_ERR;
; }
; }
; return (msg); /* Return the message received (or NULL) */
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * POST MESSAGE TO A MAILBOX
; *
; * Description: This function sends a message to a mailbox
; *
; * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
; *
; * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
; *
; * Returns : OS_NO_ERR The call was successful and the message was sent
; * OS_MBOX_FULL If the mailbox already contains a message. You can can only send one
; * message at a time and thus, the message MUST be consumed before you are
; * allowed to send another one.
; * OS_ERR_EVENT_TYPE If you are attempting to post to a non mailbox.
; *********************************************************************************************************
; */
;
; INT8U OSMboxPost (OS_EVENT *pevent, void *msg) reentrant
; {
; OS_ENTER_CRITICAL();
; if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
; OS_EXIT_CRITICAL();
; return (OS_ERR_EVENT_TYPE);
; }
; if (pevent->OSEventGrp) { /* See if any task pending on mailbox */
; OSEventTaskRdy(pevent, msg, OS_STAT_MBOX); /* Ready highest priority task waiting on event */
; OS_EXIT_CRITICAL();
; OSSched(); /* Find highest priority task ready to run */
; return (OS_NO_ERR);
; } else {
; if (pevent->OSEventPtr != (void *)0) { /* Make sure mailbox doesn't already have a msg */
; OS_EXIT_CRITICAL();
; return (OS_MBOX_FULL);
; } else {
; pevent->OSEventPtr = msg; /* Place message in mailbox */
; OS_EXIT_CRITICAL();
; return (OS_NO_ERR);
; }
; }
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; * QUERY A MESSAGE MAILBOX
; *
; * Description: This function obtains information about a message mailbox.
; *
; * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
; *
; * pdata is a pointer to a structure that will contain information about the message
; * mailbox.
; *
; * 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 mailbox.
; *********************************************************************************************************
; */
;
; INT8U OSMboxQuery (OS_EVENT *pevent, OS_MBOX_DATA *ppdata) reentrant
; {
; INT8U i;
; INT8U *psrc;
; INT8U *pdest;
;
;
; OS_ENTER_CRITICAL();
; if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* 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->OSMsg = pevent->OSEventPtr; /* Get message from mailbox */
; 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 + -