📄 os_sem.lst
字号:
#endif
206
207 /*$PAGE*/
208 /*
209 *********************************************************************************************************
210 * PEND ON SEMAPHORE
211 *
212 * Description: This function waits for a semaphore.
213 *
214 * Arguments : pevent is a pointer to the event control block associated with the desired
215 * semaphore.
216 *
217 * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
218 * wait for the resource up to the amount of time specified by this argument.
219 * If you specify 0, however, your task will wait forever at the specified
220 * semaphore or, until the resource becomes available (or the event occurs).
221 *
222 * err is a pointer to where an error message will be deposited. Possible error
223 * messages are:
224 *
225 * OS_NO_ERR The call was successful and your task owns the resource
226 * or, the event you are waiting for occurred.
227 * OS_TIMEOUT The semaphore was not received within the specified
228 * timeout.
229 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore.
230 * OS_ERR_PEND_ISR If you called this function from an ISR and the result
231 * would lead to a suspension.
232 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
233 *
234 * Returns : none
235 *********************************************************************************************************
236 */
237
238 void OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)reentrant
239 {
240 1
C51 COMPILER V8.08 OS_SEM 02/25/2009 12:35:33 PAGE 5
241 1
242 1
243 1 if (OSIntNesting > 0) { /* See if called from ISR ... */
244 2 *err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR */
245 2 return;
246 2 }
247 1 #if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
*err = OS_ERR_PEVENT_NULL;
return;
}
if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
*err = OS_ERR_EVENT_TYPE;
return;
}
#endif
257 1 OS_ENTER_CRITICAL();
258 1 if (pevent->OSEventCnt > 0) { /* If sem. is positive, resource available ... */
259 2 pevent->OSEventCnt--; /* ... decrement semaphore only if positive. */
260 2 OS_EXIT_CRITICAL();
261 2 *err = OS_NO_ERR;
262 2 return;
263 2 }
264 1 /* Otherwise, must wait until event occurs */
265 1 OSTCBCur->OSTCBStat |= OS_STAT_SEM; /* Resource not available, pend on semaphore */
266 1 OSTCBCur->OSTCBDly = timeout; /* Store pend timeout in TCB */
267 1 OS_EventTaskWait(pevent); /* Suspend task until event or timeout occurs */
268 1 OS_EXIT_CRITICAL();
269 1 OS_Sched(); /* Find next highest priority task ready */
270 1 OS_ENTER_CRITICAL();
271 1 if (OSTCBCur->OSTCBStat & OS_STAT_SEM) { /* Must have timed out if still waiting for event*/
272 2 OS_EventTO(pevent);
273 2 OS_EXIT_CRITICAL();
274 2 *err = OS_TIMEOUT; /* Indicate that didn't get event within TO */
275 2 return;
276 2 }
277 1 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
278 1 OS_EXIT_CRITICAL();
279 1 *err = OS_NO_ERR;
280 1 }
281 /*$PAGE*/
282 /*
283 *********************************************************************************************************
284 * POST TO A SEMAPHORE
285 *
286 * Description: This function signals a semaphore
287 *
288 * Arguments : pevent is a pointer to the event control block associated with the desired
289 * semaphore.
290 *
291 * Returns : OS_NO_ERR The call was successful and the semaphore was signaled.
292 * OS_SEM_OVF If the semaphore count exceeded its limit. In other words, you have
293 * signalled the semaphore more often than you waited on it with either
294 * OSSemAccept() or OSSemPend().
295 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore
296 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
297 *********************************************************************************************************
298 */
299
300 INT8U OSSemPost (OS_EVENT *pevent) reentrant
301 {
302 1
C51 COMPILER V8.08 OS_SEM 02/25/2009 12:35:33 PAGE 6
303 1
304 1
305 1 #if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
return (OS_ERR_PEVENT_NULL);
}
if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
return (OS_ERR_EVENT_TYPE);
}
#endif
313 1 OS_ENTER_CRITICAL();
314 1 if (pevent->OSEventGrp != 0x00) { /* See if any task waiting for semaphore */
315 2 OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM); /* Ready highest prio task waiting on event */
316 2 OS_EXIT_CRITICAL();
317 2 OS_Sched(); /* Find highest priority task ready to run */
318 2 return (OS_NO_ERR);
319 2 }
320 1 if (pevent->OSEventCnt < 65535) { /* Make sure semaphore will not overflow */
321 2 pevent->OSEventCnt++; /* Increment semaphore count to register event */
322 2 OS_EXIT_CRITICAL();
323 2 return (OS_NO_ERR);
324 2 }
325 1 OS_EXIT_CRITICAL(); /* Semaphore value has reached its maximum */
326 1 return (OS_SEM_OVF);
327 1 }
328 /*$PAGE*/
329 /*
330 *********************************************************************************************************
331 * QUERY A SEMAPHORE
332 *
333 * Description: This function obtains information about a semaphore
334 *
335 * Arguments : pevent is a pointer to the event control block associated with the desired
336 * semaphore
337 *
338 * pdata is a pointer to a structure that will contain information about the
339 * semaphore.
340 *
341 * Returns : OS_NO_ERR The call was successful and the message was sent
342 * OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non semaphore.
343 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
344 *********************************************************************************************************
345 */
346
347 #if OS_SEM_QUERY_EN > 0
INT8U OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *ppdata)reentrant
{
INT8U *psrc;
INT8U *pdest;
#if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
return (OS_ERR_PEVENT_NULL);
}
if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
return (OS_ERR_EVENT_TYPE);
}
#endif
OS_ENTER_CRITICAL();
ppdata->OSEventGrp = pevent->OSEventGrp; /* Copy message mailbox wait list */
C51 COMPILER V8.08 OS_SEM 02/25/2009 12:35:33 PAGE 7
psrc = &pevent->OSEventTbl[0];
pdest = &ppdata->OSEventTbl[0];
#if OS_EVENT_TBL_SIZE > 0
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 1
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 2
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 3
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 4
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 5
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 6
*pdest++ = *psrc++;
#endif
#if OS_EVENT_TBL_SIZE > 7
*pdest = *psrc;
#endif
ppdata->OSCnt = pevent->OSEventCnt; /* Get semaphore count */
OS_EXIT_CRITICAL();
return (OS_NO_ERR);
}
#endif /* OS_SEM_QUERY_EN */
403 #endif /* OS_SEM_EN */
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 712 ----
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 + -