📄 os_sem.lst
字号:
131 1 if (pevent->OSEventType != OS_EVENT_TYPE_SEM) /* Validate event block type */
132 1 {
133 2 OS_EXIT_CRITICAL();
134 2 *err = OS_ERR_EVENT_TYPE;
135 2 }
136 1 if (pevent->OSEventCnt > 0) /* If sem. is positive, resource available ... */
137 1 {
138 2 pevent->OSEventCnt--; /* ... decrement semaphore only if positive. */
139 2 OS_EXIT_CRITICAL();
140 2 *err = OS_NO_ERR;
141 2 }
142 1 else if (OSIntNesting > 0) /* See if called from ISR ... */
143 1 {
144 2 OS_EXIT_CRITICAL(); /* ... can't PEND from an ISR */
145 2 *err = OS_ERR_PEND_ISR;
146 2 }
147 1 else
148 1 { /* Otherwise, must wait until event occurs */
149 2 OSTCBCur->OSTCBStat |= OS_STAT_SEM; /* Resource not available, pend on semaphore */
150 2 OSTCBCur->OSTCBDly = timeout; /* Store pend timeout in TCB */
151 2 OSEventTaskWait(pevent); /* Suspend task until event or timeout occurs */
152 2 OS_EXIT_CRITICAL();
153 2 OSSched(); /* Find next highest priority task ready */
154 2 OS_ENTER_CRITICAL();
155 2 if (OSTCBCur->OSTCBStat & OS_STAT_SEM)
156 2 { /* Must have timed out if still waiting for event*/
157 3 OSEventTO(pevent);
158 3 OS_EXIT_CRITICAL();
159 3 *err = OS_TIMEOUT; /* Indicate that didn't get event within TO */
160 3 }
161 2 else
162 2 {
163 3 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
164 3 OS_EXIT_CRITICAL();
165 3 *err = OS_NO_ERR;
166 3 }
167 2 }
168 1 }
169 #endif
170 /*$PAGE*/
171 /*
172 *********************************************************************************************************
173 * POST TO A SEMAPHORE
174 *
175 * Description: This function signals a semaphore
176 *
177 * Arguments : pevent is a pointer to the event control block associated with the desired
178 * semaphore.
179 *
C51 COMPILER V7.10 OS_SEM 08/23/2004 01:45:17 PAGE 4
180 * Returns : OS_NO_ERR The call was successful and the semaphore was signaled.
181 * OS_SEM_OVF If the semaphore count exceeded its limit. In other words, you have
182 * signalled the semaphore more often than you waited on it with either
183 * OSSemAccept() or OSSemPend().
184 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore
185 *********************************************************************************************************
186 */
187 #if OS_Sem_Post_EN
188 INT8U OSSemPost (OS_EVENT *pevent)reentrant
189 {
190 1 OS_ENTER_CRITICAL();
191 1 if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
192 2 OS_EXIT_CRITICAL();
193 2 return (OS_ERR_EVENT_TYPE);
194 2 }
195 1 if (pevent->OSEventGrp) { /* See if any task waiting for semaphore */
196 2 OSEventTaskRdy(pevent, (void *)0, OS_STAT_SEM); /* Ready highest prio task waiting on event */
197 2 OS_EXIT_CRITICAL();
198 2 OSSched(); /* Find highest priority task ready to run */
199 2 return (OS_NO_ERR);
200 2 } else {
201 2 if (pevent->OSEventCnt < 65535) { /* Make sure semaphore will not overflow */
202 3 pevent->OSEventCnt++; /* Increment semaphore count to register event */
203 3 OS_EXIT_CRITICAL();
204 3 return (OS_NO_ERR);
205 3 } else { /* Semaphore value has reached its maximum */
206 3 OS_EXIT_CRITICAL();
207 3 return (OS_SEM_OVF);
208 3 }
209 2 }
210 1 }
211 #endif
212 /*
213 *********************************************************************************************************
214 * QUERY A SEMAPHORE
215 *
216 * Description: This function obtains information about a semaphore
217 *
218 * Arguments : pevent is a pointer to the event control block associated with the desired
219 * semaphore
220 *
221 * dataptr is a pointer to a structure that will contain information about the
222 * semaphore.
223 *
224 * Returns : OS_NO_ERR The call was successful and the message was sent
225 * OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non semaphore.
226 *********************************************************************************************************
227 */
228 #if OS_Sem_Query_EN
INT8U OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *dataptr)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);
}
dataptr->OSEventGrp = pevent->OSEventGrp; /* Copy message mailbox wait list *
C51 COMPILER V7.10 OS_SEM 08/23/2004 01:45:17 PAGE 5
-/
psrc = &pevent->OSEventTbl[0];
pdest = &dataptr->OSEventTbl[0];
for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
*pdest++ = *psrc++;
}
dataptr->OSCnt = pevent->OSEventCnt; /* Get semaphore count *
-/
OS_EXIT_CRITICAL();
return (OS_NO_ERR);
}
#endif
252 #endif
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 608 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -