os_sem.lst
来自「在51上运行的小的OS系统」· LST 代码 · 共 578 行 · 第 1/3 页
LST
578 行
309 OS_ENTER_CRITICAL();
310 if (OSTCBCur->OSTCBPendTO == TRUE) { /* See if we timedout */
311 OS_EventTO(pevent);
312 OS_EXIT_CRITICAL();
313 *err = OS_TIMEOUT; /* Indicate that didn't get event within TO */
314 return;
315 }
316 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
317 OS_EXIT_CRITICAL();
318 *err = OS_NO_ERR;
319 }
320 /*$PAGE*/
321 /*
322 *********************************************************************************************************
323 * POST TO A SEMAPHORE
324 *
325 * Description: This function signals a semaphore
326 *
327 * Arguments : pevent is a pointer to the event control block associated with the desired
328 * semaphore.
329 *
330 * Returns : OS_NO_ERR The call was successful and the semaphore was signaled.
331 * OS_SEM_OVF If the semaphore count exceeded its limit. In other words, you have
332 * signalled the semaphore more often than you waited on it with either
333 * OSSemAccept() or OSSemPend().
334 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore
335 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
336 *********************************************************************************************************
337 */
338
339 INT8U OSSemPost (OS_EVENT *pevent)
340 {
341 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
344
345
346
347 #if OS_ARG_CHK_EN > 0
348 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
349 return (OS_ERR_PEVENT_NULL);
350 }
351 #endif
352 if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
353 return (OS_ERR_EVENT_TYPE);
354 }
355 OS_ENTER_CRITICAL();
356 if (pevent->OSEventGrp != 0) { /* See if any task waiting for semaphore*/
357 (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM); /* Ready HPT waiting on event */
358 OS_EXIT_CRITICAL();
359 OS_Sched(); /* Find HPT ready to run */
360 return (OS_NO_ERR);
361 }
362 if (pevent->OSEventCnt < 65535u) { /* Make sure semaphore will not overflow */
363 pevent->OSEventCnt++; /* Increment semaphore count to register event */
364 OS_EXIT_CRITICAL();
365 return (OS_NO_ERR);
366 }
367 OS_EXIT_CRITICAL(); /* Semaphore value has reached its maximum */
368 return (OS_SEM_OVF);
369 }
370 /*$PAGE*/
C51 COMPILER V8.08 OS_SEM 08/04/2008 21:49:52 PAGE 8
371 /*
372 *********************************************************************************************************
373 * QUERY A SEMAPHORE
374 *
375 * Description: This function obtains information about a semaphore
376 *
377 * Arguments : pevent is a pointer to the event control block associated with the desired
378 * semaphore
379 *
380 * p_sem_data is a pointer to a structure that will contain information about the
381 * semaphore.
382 *
383 * Returns : OS_NO_ERR The call was successful and the message was sent
384 * OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non semaphore.
385 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
386 * OS_ERR_PDATA_NULL If 'p_sem_data' is a NULL pointer
387 *********************************************************************************************************
388 */
389
390 #if OS_SEM_QUERY_EN > 0
391 INT8U OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *p_sem_data)
392 {
393 #if OS_LOWEST_PRIO <= 63
394 INT8U *psrc;
395 INT8U *pdest;
396 #else
INT16U *psrc;
INT16U *pdest;
#endif
400 INT8U i;
401 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
404
405
406
407 #if OS_ARG_CHK_EN > 0
408 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
409 return (OS_ERR_PEVENT_NULL);
410 }
411 if (p_sem_data == (OS_SEM_DATA *)0) { /* Validate 'p_sem_data' */
412 return (OS_ERR_PDATA_NULL);
413 }
414 #endif
415 if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
416 return (OS_ERR_EVENT_TYPE);
417 }
418 OS_ENTER_CRITICAL();
419 p_sem_data->OSEventGrp = pevent->OSEventGrp; /* Copy message mailbox wait list */
420 psrc = &pevent->OSEventTbl[0];
421 pdest = &p_sem_data->OSEventTbl[0];
422 for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
423 *pdest++ = *psrc++;
424 }
425 p_sem_data->OSCnt = pevent->OSEventCnt; /* Get semaphore count */
426 OS_EXIT_CRITICAL();
427 return (OS_NO_ERR);
428 }
429 #endif /* OS_SEM_QUERY_EN */
430
431 /*$PAGE*/
432 /*
C51 COMPILER V8.08 OS_SEM 08/04/2008 21:49:52 PAGE 9
433 *********************************************************************************************************
434 * SET SEMAPHORE
435 *
436 * Description: This function sets the semaphore count to the value specified as an argument. Typically,
437 * this value would be 0.
438 *
439 * You would typically use this function when a semaphore is used as a signaling mechanism
440 * and, you want to reset the count value.
441 *
442 * Arguments : pevent is a pointer to the event control block
443 *
444 * cnt is the new value for the semaphore count. You would pass 0 to reset the
445 * semaphore count.
446 *
447 * err is a pointer to an error code returned by the function as follows:
448 *
449 * OS_NO_ERR The call was successful and the semaphore value was set.
450 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore.
451 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
452 * OS_ERR_TASK_WAITING If tasks are waiting on the semaphore.
453 *********************************************************************************************************
454 */
455
456 #if OS_SEM_SET_EN > 0
457 void OSSemSet (OS_EVENT *pevent, INT16U cnt, INT8U *err)
458 {
459 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
462
463
464
465 #if OS_ARG_CHK_EN > 0
466 if (err == (INT8U *)0) { /* Validate 'err' */
467 return;
468 }
469 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
470 *err = OS_ERR_PEVENT_NULL;
471 return;
472 }
473 #endif
474 if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
475 *err = OS_ERR_EVENT_TYPE;
476 return;
477 }
478 OS_ENTER_CRITICAL();
479 *err = OS_NO_ERR;
480 if (pevent->OSEventCnt > 0) { /* See if semaphore already has a count */
481 pevent->OSEventCnt = cnt; /* Yes, set it to the new value specified. */
482 } else { /* No */
483 if (pevent->OSEventGrp == 0) { /* See if task(s) waiting? */
484 pevent->OSEventCnt = cnt; /* No, OK to set the value */
485 } else {
486 *err = OS_ERR_TASK_WAITING;
487 }
488 }
489 OS_EXIT_CRITICAL();
490 }
491 #endif
492
493 #endif /* OS_SEM_EN */
C51 COMPILATION COMPLETE. 0 WARNING(S), 57 ERROR(S)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?