📄 os_sem.lst
字号:
C51 COMPILER V7.02a OS_SEM 10/16/2006 15:27:51 PAGE 1
C51 COMPILER V7.02a, COMPILATION OF MODULE OS_SEM
OBJECT MODULE PLACED IN .\OS_SEM.obj
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE ..\uc_os_II\OS_SEM.C BROWSE DEBUG OBJECTEXTEND PRINT(.\OS_SEM.lst) OBJECT(.
-\OS_SEM.obj)
stmt 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
39 INT16U OSSemAccept (OS_EVENT DT_XDATA *pevent) REENTRANT
40 {
41 1 INT16U cnt;
42 1
43 1
44 1 OS_ENTER_CRITICAL();
45 1 if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
46 2 OS_EXIT_CRITICAL();
47 2 return (0);
48 2 }
49 1 cnt = pevent->OSEventCnt;
50 1 if (cnt > 0) { /* See if resource is available */
51 2 pevent->OSEventCnt--; /* Yes, decrement semaphore and notify caller */
52 2 }
53 1 OS_EXIT_CRITICAL();
54 1 return (cnt); /* Return semaphore count */
C51 COMPILER V7.02a OS_SEM 10/16/2006 15:27:51 PAGE 2
55 1 }
56
57 /*$PAGE*/
58 /*
59 *********************************************************************************************************
60 * CREATE A SEMAPHORE
61 *
62 * Description: This function creates a semaphore.
63 *
64 * Arguments : cnt is the initial value for the semaphore. If the value is 0, no resource is
65 * available (or no event has occurred). You initialize the semaphore to a
66 * non-zero value to specify how many resources are available (e.g. if you have
67 * 10 resources, you would initialize the semaphore to 10).
68 *
69 * Returns : != (void *)0 is a pointer to the event control clock (OS_EVENT) associated with the
70 * created semaphore
71 * == (void *)0 if no event control blocks were available
72 *********************************************************************************************************
73 */
74
75 OS_EVENT DT_XDATA *OSSemCreate (INT16U cnt) REENTRANT
76 {
77 1 OS_EVENT DT_XDATA *pevent;
78 1
79 1
80 1 OS_ENTER_CRITICAL();
81 1 pevent = OSEventFreeList; /* Get next free event control block */
82 1 if (OSEventFreeList != (OS_EVENT DT_XDATA *)0) { /* See if pool of free ECB pool was em
-pty */
83 2 OSEventFreeList = (OS_EVENT DT_XDATA *)OSEventFreeList->OSEventPtr;
84 2 }
85 1 OS_EXIT_CRITICAL();
86 1 if (pevent != (OS_EVENT DT_XDATA *)0) { /* Get an event control block
- */
87 2 pevent->OSEventType = OS_EVENT_TYPE_SEM;
88 2 pevent->OSEventCnt = cnt; /* Set semaphore value */
89 2 OSEventWaitListInit(pevent);
90 2 }
91 1 return (pevent);
92 1 }
93
94 /*$PAGE*/
95 /*
96 *********************************************************************************************************
97 * PEND ON SEMAPHORE
98 *
99 * Description: This function waits for a semaphore.
100 *
101 * Arguments : pevent is a pointer to the event control block associated with the desired
102 * semaphore.
103 *
104 * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
105 * wait for the resource up to the amount of time specified by this argument.
106 * If you specify 0, however, your task will wait forever at the specified
107 * semaphore or, until the resource becomes available (or the event occurs).
108 *
109 * err is a pointer to where an error message will be deposited. Possible error
110 * messages are:
111 *
112 * OS_NO_ERR The call was successful and your task owns the resource
113 * or, the event you are waiting for occurred.
114 * OS_TIMEOUT The semaphore was not received within the specified
C51 COMPILER V7.02a OS_SEM 10/16/2006 15:27:51 PAGE 3
115 * timeout.
116 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore.
117 * OS_ERR_PEND_ISR If you called this function from an ISR and the result
118 * would lead to a suspension.
119 *
120 * Returns : none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -