📄 os_sem.lst
字号:
212
213 /*$PAGE*/
214 /*
215 *********************************************************************************************************
216 * PEND ON SEMAPHORE
217 *
218 * Description: This function waits for a semaphore.
219 *
220 * Arguments : pevent is a pointer to the event control block associated with the desired
221 * semaphore.
222 *
223 * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
224 * wait for the resource up to the amount of time specified by this argument.
225 * If you specify 0, however, your task will wait forever at the specified
226 * semaphore or, until the resource becomes available (or the event occurs).
227 *
228 * err is a pointer to where an error message will be deposited. Possible error
229 * messages are:
230 *
231 * OS_NO_ERR The call was successful and your task owns the resource
232 * or, the event you are waiting for occurred.
233 * OS_TIMEOUT The semaphore was not received within the specified
234 * timeout.
235 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore.
236 * OS_ERR_PEND_ISR If you called this function from an ISR and the result
237 * would lead to a suspension.
238 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
239 *
240 * Returns : none
C51 COMPILER V7.20 OS_SEM 04/25/2005 23:03:48 PAGE 5
241 *********************************************************************************************************
242 */
243
244 void OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)LG_REENTRANT
245 {
246 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
247 1 OS_CPU_SR cpu_sr;
248 1 #endif
249 1
250 1
251 1 if (OSIntNesting > 0) { /* See if called from ISR ... */
252 2 *err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR */
253 2 return;
254 2 }
255 1 #if OS_ARG_CHK_EN > 0
256 1 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
257 2 *err = OS_ERR_PEVENT_NULL;
258 2 return;
259 2 }
260 1 if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
261 2 *err = OS_ERR_EVENT_TYPE;
262 2 return;
263 2 }
264 1 #endif
265 1 OS_ENTER_CRITICAL();
266 1 if (pevent->OSEventCnt > 0) { /* If sem. is positive, resource available ... */
267 2 pevent->OSEventCnt--; /* ... decrement semaphore only if positive. */
268 2 OS_EXIT_CRITICAL();
269 2 *err = OS_NO_ERR;
270 2 return;
271 2 }
272 1 /* Otherwise, must wait until event occurs */
273 1 OSTCBCur->OSTCBStat |= OS_STAT_SEM; /* Resource not available, pend on semaphore */
274 1 OSTCBCur->OSTCBDly = timeout; /* Store pend timeout in TCB */
275 1 OS_EventTaskWait(pevent); /* Suspend task until event or timeout occurs */
276 1 OS_EXIT_CRITICAL();
277 1 OS_Sched(); /* Find next highest priority task ready */
278 1 OS_ENTER_CRITICAL();
279 1 if (OSTCBCur->OSTCBStat & OS_STAT_SEM) { /* Must have timed out if still waiting for event*/
280 2 OS_EventTO(pevent);
281 2 OS_EXIT_CRITICAL();
282 2 *err = OS_TIMEOUT; /* Indicate that didn't get event within TO */
283 2 return;
284 2 }
285 1 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
286 1 OS_EXIT_CRITICAL();
287 1 *err = OS_NO_ERR;
288 1 }
289 /*$PAGE*/
290 /*
291 *********************************************************************************************************
292 * POST TO A SEMAPHORE
293 *
294 * Description: This function signals a semaphore
295 *
296 * Arguments : pevent is a pointer to the event control block associated with the desired
297 * semaphore.
298 *
299 * Returns : OS_NO_ERR The call was successful and the semaphore was signaled.
300 * OS_SEM_OVF If the semaphore count exceeded its limit. In other words, you have
301 * signalled the semaphore more often than you waited on it with either
302 * OSSemAccept() or OSSemPend().
C51 COMPILER V7.20 OS_SEM 04/25/2005 23:03:48 PAGE 6
303 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore
304 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
305 *********************************************************************************************************
306 */
307
308 INT8U OSSemPost (OS_EVENT *pevent)LG_REENTRANT
309 {
310 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
311 1 OS_CPU_SR cpu_sr;
312 1 #endif
313 1
314 1
315 1 #if OS_ARG_CHK_EN > 0
316 1 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
317 2 return (OS_ERR_PEVENT_NULL);
318 2 }
319 1 if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
320 2 return (OS_ERR_EVENT_TYPE);
321 2 }
322 1 #endif
323 1 OS_ENTER_CRITICAL();
324 1 if (pevent->OSEventGrp != 0x00) { /* See if any task waiting for semaphore */
325 2 OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM); /* Ready highest prio task waiting on event */
326 2 OS_EXIT_CRITICAL();
327 2 OS_Sched(); /* Find highest priority task ready to run */
328 2 return (OS_NO_ERR);
329 2 }
330 1 if (pevent->OSEventCnt < 65535) { /* Make sure semaphore will not overflow */
331 2 pevent->OSEventCnt++; /* Increment semaphore count to register event */
332 2 OS_EXIT_CRITICAL();
333 2 return (OS_NO_ERR);
334 2 }
335 1 OS_EXIT_CRITICAL(); /* Semaphore value has reached its maximum */
336 1 return (OS_SEM_OVF);
337 1 }
338 /*$PAGE*/
339 /*
340 *********************************************************************************************************
341 * QUERY A SEMAPHORE
342 *
343 * Description: This function obtains information about a semaphore
344 *
345 * Arguments : pevent is a pointer to the event control block associated with the desired
346 * semaphore
347 *
348 * pdata is a pointer to a structure that will contain information about the
349 * semaphore.
350 *
351 * Returns : OS_NO_ERR The call was successful and the message was sent
352 * OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non semaphore.
353 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
354 *********************************************************************************************************
355 */
356
357 #if OS_SEM_QUERY_EN > 0
INT8U OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *pdata)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT8U *psrc;
INT8U *pdest;
C51 COMPILER V7.20 OS_SEM 04/25/2005 23:03:48 PAGE 7
#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();
pdata->OSEventGrp = pevent->OSEventGrp; /* Copy message mailbox wait list */
psrc = &pevent->OSEventTbl[0];
pdest = &pdata->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
pdata->OSCnt = pevent->OSEventCnt; /* Get semaphore count */
OS_EXIT_CRITICAL();
return (OS_NO_ERR);
}
#endif /* OS_SEM_QUERY_EN */
415 #endif /* OS_SEM_EN */
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 958 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILER V7.20 OS_SEM 04/25/2005 23:03:48 PAGE 8
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -