📄 os_sem.lst
字号:
C51 COMPILER V7.10 OS_SEM 08/23/2004 01:45:17 PAGE 1
C51 COMPILER V7.10, COMPILATION OF MODULE OS_SEM
OBJECT MODULE PLACED IN OS_SEM.OBJ
COMPILER INVOKED BY: D:\keil51\C51\BIN\C51.EXE OS_SEM.C BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 *********************************************************************************************************
3 * uC/OS-II
4 * The Real-Time Kernel
5 * SEMAPHORE MANAGEMENT
6 *
7 * (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
8 * All Rights Reserved
9 *
10 * V2.00
11 *
12 * File : OS_SEM.C
13 * By : Jean J. Labrosse
14 *********************************************************************************************************
15 */
16
17 #ifndef OS_MASTER_FILE
18 #include "includes.h"
19 #endif
20
21 #if OS_Sem_EN
22 /*
23 *********************************************************************************************************
24 * ACCEPT SEMAPHORE
25 *
26 * Description: This function checks the semaphore to see if a resource is available or, if an event
27 * occurred. Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the
28 * resource is not available or the event did not occur.
29 *
30 * Arguments : pevent is a pointer to the event control block
31 *
32 * Returns : > 0 if the resource is available or the event did not occur the semaphore is
33 * decremented to obtain the resource.
34 * == 0 if the resource is not available or the event did not occur or,
35 * you didn't pass a pointer to a semaphore
36 *********************************************************************************************************
37 */
38 #if OS_Sem_Accept_EN
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 */
}
C51 COMPILER V7.10 OS_SEM 08/23/2004 01:45:17 PAGE 2
#endif
57
58 /*$PAGE*/
59 /*
60 *********************************************************************************************************
61 * CREATE A SEMAPHORE
62 *
63 * Description: This function creates a semaphore.
64 *
65 * Arguments : cnt is the initial value for the semaphore. If the value is 0, no resource is
66 * available (or no event has occurred). You initialize the semaphore to a
67 * non-zero value to specify how many resources are available (e.g. if you have
68 * 10 resources, you would initialize the semaphore to 10).
69 *
70 * Returns : != (void *)0 is a pointer to the event control clock (OS_EVENT) associated with the
71 * created semaphore
72 * == (void *)0 if no event control blocks were available
73 *********************************************************************************************************
74 */
75 #if OS_Sem_Create_EN
76 OS_EVENT *OSSemCreate (INT16U cnt)reentrant
77 {
78 1 OS_EVENT *pevent;
79 1
80 1
81 1 OS_ENTER_CRITICAL();
82 1 pevent = OSEventFreeList; /* Get next free event control block */
83 1 if (OSEventFreeList != (OS_EVENT *)0)
84 1 { /* See if pool of free ECB pool was empty */
85 2 OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
86 2 }
87 1 OS_EXIT_CRITICAL();
88 1 if (pevent != (OS_EVENT *)0)
89 1 { /* Get an event control block */
90 2 pevent->OSEventType = OS_EVENT_TYPE_SEM;
91 2 pevent->OSEventCnt = cnt; /* Set semaphore value */
92 2 OSEventWaitListInit(pevent);
93 2 }
94 1 return (pevent);
95 1 }
96 #endif
97
98 /*$PAGE*/
99 /*
100 *********************************************************************************************************
101 * PEND ON SEMAPHORE
102 *
103 * Description: This function waits for a semaphore.
104 *
105 * Arguments : pevent is a pointer to the event control block associated with the desired
106 * semaphore.
107 *
108 * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
109 * wait for the resource up to the amount of time specified by this argument.
110 * If you specify 0, however, your task will wait forever at the specified
111 * semaphore or, until the resource becomes available (or the event occurs).
112 *
113 * err is a pointer to where an error message will be deposited. Possible error
114 * messages are:
115 *
116 * OS_NO_ERR The call was successful and your task owns the resource
117 * or, the event you are waiting for occurred.
C51 COMPILER V7.10 OS_SEM 08/23/2004 01:45:17 PAGE 3
118 * OS_TIMEOUT The semaphore was not received within the specified
119 * timeout.
120 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore.
121 * OS_ERR_PEND_ISR If you called this function from an ISR and the result
122 * would lead to a suspension.
123 *
124 * Returns : none
125 *********************************************************************************************************
126 */
127 #if OS_Sem_Pend_EN
128 void OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)reentrant
129 {
130 1 OS_ENTER_CRITICAL();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -