os_q.lst
来自「该源码是本人经调试通过的UCOS2操作系统在51单片机上移植好的源代码」· LST 代码 · 共 776 行 · 第 1/4 页
LST
776 行
368 2 OSTCBCur->OSTCBMsg = (void *)0; /* Extract message from TCB (Put there by QPost) */
369 2 OSTCBCur->OSTCBStat = OS_STAT_RDY;
370 2 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event */
371 2 OS_EXIT_CRITICAL();
372 2 *err = OS_NO_ERR;
373 2 return (msg); /* Return message received */
374 2 }
375 1 OS_EventTO(pevent); /* Timed out */
376 1 OS_EXIT_CRITICAL();
377 1 *err = OS_TIMEOUT; /* Indicate a timeout occured */
378 1 return ((void *)0); /* No message received */
379 1 }
380 #endif
381 /*$PAGE*/
382 /*
383 *********************************************************************************************************
384 * POST MESSAGE TO A QUEUE
385 *
386 * Description: This function sends a message to a queue
387 *
388 * Arguments : pevent is a pointer to the event control block associated with the desired queue
389 *
390 * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
391 *
392 * Returns : OS_NO_ERR The call was successful and the message was sent
393 * OS_Q_FULL If the queue cannot accept any more messages because it is full.
394 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
395 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
396 * OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
397 *********************************************************************************************************
398 */
399
400 #if OS_Q_POST_EN > 0
401 INT8U OSQPost (OS_EVENT *pevent, void *msg) reentrant
402 {
403 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
406 1 OS_Q *pq;
407 1
408 1
409 1 #if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
return (OS_ERR_PEVENT_NULL);
}
if (msg == (void *)0) { /* Make sure we are not posting a NULL pointer */
return (OS_ERR_POST_NULL_PTR);
}
if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
return (OS_ERR_EVENT_TYPE);
}
#endif
420 1 OS_ENTER_CRITICAL();
421 1 if (pevent->OSEventGrp != 0x00) { /* See if any task pending on queue */
422 2 OS_EventTaskRdy(pevent, msg, OS_STAT_Q); /* Ready highest priority task waiting on event */
423 2 OS_EXIT_CRITICAL();
424 2 OS_Sched(); /* Find highest priority task ready to run */
425 2 return (OS_NO_ERR);
426 2 }
427 1 pq = (OS_Q *)pevent->OSEventPtr; /* Point to queue control block */
C51 COMPILER V7.20 OS_Q 09/25/2006 10:08:41 PAGE 8
428 1 if (pq->OSQEntries >= pq->OSQSize) { /* Make sure queue is not full */
429 2 OS_EXIT_CRITICAL();
430 2 return (OS_Q_FULL);
431 2 }
432 1 *pq->OSQIn++ = msg; /* Insert message into queue */
433 1 pq->OSQEntries++; /* Update the nbr of entries in the queue */
434 1 if (pq->OSQIn == pq->OSQEnd) { /* Wrap IN ptr if we are at end of queue */
435 2 pq->OSQIn = pq->OSQStart;
436 2 }
437 1 OS_EXIT_CRITICAL();
438 1 return (OS_NO_ERR);
439 1 }
440 #endif
441 /*$PAGE*/
442 /*
443 *********************************************************************************************************
444 * POST MESSAGE TO THE FRONT OF A QUEUE
445 *
446 * Description: This function sends a message to a queue but unlike OSQPost(), the message is posted at
447 * the front instead of the end of the queue. Using OSQPostFront() allows you to send
448 * 'priority' messages.
449 *
450 * Arguments : pevent is a pointer to the event control block associated with the desired queue
451 *
452 * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
453 *
454 * Returns : OS_NO_ERR The call was successful and the message was sent
455 * OS_Q_FULL If the queue cannot accept any more messages because it is full.
456 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
457 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
458 * OS_ERR_POST_NULL_PTR If you are attempting to post to a non queue.
459 *********************************************************************************************************
460 */
461
462 #if OS_Q_POST_FRONT_EN > 0
INT8U OSQPostFront (OS_EVENT *pevent, void *msg) reentrant
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OS_Q *pq;
#if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
return (OS_ERR_PEVENT_NULL);
}
if (msg == (void *)0) { /* Make sure we are not posting a NULL pointer */
return (OS_ERR_POST_NULL_PTR);
}
if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
return (OS_ERR_EVENT_TYPE);
}
#endif
OS_ENTER_CRITICAL();
if (pevent->OSEventGrp != 0x00) { /* See if any task pending on queue */
OS_EventTaskRdy(pevent, msg, OS_STAT_Q); /* Ready highest priority task waiting on event */
OS_EXIT_CRITICAL();
OS_Sched(); /* Find highest priority task ready to run */
return (OS_NO_ERR);
}
pq = (OS_Q *)pevent->OSEventPtr; /* Point to queue control block */
C51 COMPILER V7.20 OS_Q 09/25/2006 10:08:41 PAGE 9
if (pq->OSQEntries >= pq->OSQSize) { /* Make sure queue is not full */
OS_EXIT_CRITICAL();
return (OS_Q_FULL);
}
if (pq->OSQOut == pq->OSQStart) { /* Wrap OUT ptr if we are at the 1st queue entry */
pq->OSQOut = pq->OSQEnd;
}
pq->OSQOut--;
*pq->OSQOut = msg; /* Insert message into queue */
pq->OSQEntries++; /* Update the nbr of entries in the queue */
OS_EXIT_CRITICAL();
return (OS_NO_ERR);
}
#endif
504 /*$PAGE*/
505 /*
506 *********************************************************************************************************
507 * POST MESSAGE TO A QUEUE
508 *
509 * Description: This function sends a message to a queue. This call has been added to reduce code size
510 * since it can replace both OSQPost() and OSQPostFront(). Also, this function adds the
511 * capability to broadcast a message to ALL tasks waiting on the message queue.
512 *
513 * Arguments : pevent is a pointer to the event control block associated with the desired queue
514 *
515 * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
516 *
517 * opt determines the type of POST performed:
518 * OS_POST_OPT_NONE POST to a single waiting task
519 * (Identical to OSQPost())
520 * OS_POST_OPT_BROADCAST POST to ALL tasks that are waiting on the queue
521 * OS_POST_OPT_FRONT POST as LIFO (Simulates OSQPostFront())
522 *
523 * Below is a list of ALL the possible combination of these flags:
524 *
525 * 1) OS_POST_OPT_NONE
526 * identical to OSQPost()
527 *
528 * 2) OS_POST_OPT_FRONT
529 * identical to OSQPostFront()
530 *
531 * 3) OS_POST_OPT_BROADCAST
532 * identical to OSQPost() but will broadcast 'msg' to ALL waiting tasks
533 *
534 * 4) OS_POST_OPT_FRONT + OS_POST_OPT_BROADCAST is identical to
535 * OSQPostFront() except that will broadcast 'msg' to ALL waiting tasks
536 *
537 * Returns : OS_NO_ERR The call was successful and the message was sent
538 * OS_Q_FULL If the queue cannot accept any more messages because it is full.
539 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
540 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
541 * OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
542 *
543 * Warning : Interrupts can be disabled for a long time if you do a 'broadcast'. In fact, the
544 * interrupt disable time is proportional to the number of tasks waiting on the queue.
545 *********************************************************************************************************
546 */
547
548 #if OS_Q_POST_OPT_EN > 0
INT8U OSQPostOpt (OS_EVENT *pevent, void *msg, INT8U opt) reentrant
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
C51 COMPILER V7.20 OS_Q 09/25/2006 10:08:41 PAGE 10
OS_CPU_SR cpu_sr;
#endif
OS_Q *pq;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?