📄 os_q.lst
字号:
367 2 OSTCBCur->OSTCBStat = OS_STAT_RDY;
368 2 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event */
369 2 OS_EXIT_CRITICAL();
370 2 *err = OS_NO_ERR;
371 2 return (msg); /* Return message received */
372 2 }
373 1 OS_EventTO(pevent); /* Timed out */
374 1 OS_EXIT_CRITICAL();
375 1 *err = OS_TIMEOUT; /* Indicate a timeout occured */
376 1 return ((void *)0); /* No message received */
377 1 }
378 /*$PAGE*/
379 /*
380 *********************************************************************************************************
381 * POST MESSAGE TO A QUEUE
382 *
383 * Description: This function sends a message to a queue
384 *
385 * Arguments : pevent is a pointer to the event control block associated with the desired queue
386 *
387 * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
388 *
389 * Returns : OS_NO_ERR The call was successful and the message was sent
390 * OS_Q_FULL If the queue cannot accept any more messages because it is full.
391 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
392 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
393 * OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
394 *********************************************************************************************************
395 */
396
397 #if OS_Q_POST_EN > 0
398 INT8U OSQPost (OS_EVENT *pevent, void *msg) KCREENTRANT
399 {
400 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
401 1 OS_CPU_SR cpu_sr;
402 1 #endif
403 1 OS_Q *pq;
404 1
405 1
406 1 #if OS_ARG_CHK_EN > 0
407 1 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
408 2 return (OS_ERR_PEVENT_NULL);
409 2 }
410 1 if (msg == (void *)0) { /* Make sure we are not posting a NULL pointer */
411 2 return (OS_ERR_POST_NULL_PTR);
412 2 }
413 1 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
414 2 return (OS_ERR_EVENT_TYPE);
415 2 }
416 1 #endif
417 1 OS_ENTER_CRITICAL();
418 1 if (pevent->OSEventGrp != 0x00) { /* See if any task pending on queue */
419 2 OS_EventTaskRdy(pevent, msg, OS_STAT_Q); /* Ready highest priority task waiting on event */
420 2 OS_EXIT_CRITICAL();
421 2 OS_Sched(); /* Find highest priority task ready to run */
422 2 return (OS_NO_ERR);
423 2 }
424 1 pq = (OS_Q *)pevent->OSEventPtr; /* Point to queue control block */
425 1 if (pq->OSQEntries >= pq->OSQSize) { /* Make sure queue is not full */
426 2 OS_EXIT_CRITICAL();
C51 COMPILER V8.02 OS_Q 05/22/2008 18:01:52 PAGE 8
427 2 return (OS_Q_FULL);
428 2 }
429 1 *pq->OSQIn++ = msg; /* Insert message into queue */
430 1 pq->OSQEntries++; /* Update the nbr of entries in the queue */
431 1 if (pq->OSQIn == pq->OSQEnd) { /* Wrap IN ptr if we are at end of queue */
432 2 pq->OSQIn = pq->OSQStart;
433 2 }
434 1 OS_EXIT_CRITICAL();
435 1 return (OS_NO_ERR);
436 1 }
437 #endif
438 /*$PAGE*/
439 /*
440 *********************************************************************************************************
441 * POST MESSAGE TO THE FRONT OF A QUEUE
442 *
443 * Description: This function sends a message to a queue but unlike OSQPost(), the message is posted at
444 * the front instead of the end of the queue. Using OSQPostFront() allows you to send
445 * 'priority' messages.
446 *
447 * Arguments : pevent is a pointer to the event control block associated with the desired queue
448 *
449 * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
450 *
451 * Returns : OS_NO_ERR The call was successful and the message was sent
452 * OS_Q_FULL If the queue cannot accept any more messages because it is full.
453 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
454 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
455 * OS_ERR_POST_NULL_PTR If you are attempting to post to a non queue.
456 *********************************************************************************************************
457 */
458
459 #if OS_Q_POST_FRONT_EN > 0
INT8U OSQPostFront (OS_EVENT *pevent, void *msg) KCREENTRANT
{
#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 */
if (pq->OSQEntries >= pq->OSQSize) { /* Make sure queue is not full */
OS_EXIT_CRITICAL();
C51 COMPILER V8.02 OS_Q 05/22/2008 18:01:52 PAGE 9
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
501 /*$PAGE*/
502 /*
503 *********************************************************************************************************
504 * POST MESSAGE TO A QUEUE
505 *
506 * Description: This function sends a message to a queue. This call has been added to reduce code size
507 * since it can replace both OSQPost() and OSQPostFront(). Also, this function adds the
508 * capability to broadcast a message to ALL tasks waiting on the message queue.
509 *
510 * Arguments : pevent is a pointer to the event control block associated with the desired queue
511 *
512 * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
513 *
514 * opt determines the type of POST performed:
515 * OS_POST_OPT_NONE POST to a single waiting task
516 * (Identical to OSQPost())
517 * OS_POST_OPT_BROADCAST POST to ALL tasks that are waiting on the queue
518 * OS_POST_OPT_FRONT POST as LIFO (Simulates OSQPostFront())
519 *
520 * Below is a list of ALL the possible combination of these flags:
521 *
522 * 1) OS_POST_OPT_NONE
523 * identical to OSQPost()
524 *
525 * 2) OS_POST_OPT_FRONT
526 * identical to OSQPostFront()
527 *
528 * 3) OS_POST_OPT_BROADCAST
529 * identical to OSQPost() but will broadcast 'msg' to ALL waiting tasks
530 *
531 * 4) OS_POST_OPT_FRONT + OS_POST_OPT_BROADCAST is identical to
532 * OSQPostFront() except that will broadcast 'msg' to ALL waiting tasks
533 *
534 * Returns : OS_NO_ERR The call was successful and the message was sent
535 * OS_Q_FULL If the queue cannot accept any more messages because it is full.
536 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
537 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
538 * OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
539 *
540 * Warning : Interrupts can be disabled for a long time if you do a 'broadcast'. In fact, the
541 * interrupt disable time is proportional to the number of tasks waiting on the queue.
542 *********************************************************************************************************
543 */
544
545 #if OS_Q_POST_OPT_EN > 0
INT8U OSQPostOpt (OS_EVENT *pevent, void *msg, INT8U opt) KCREENTRANT
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
C51 COMPILER V8.02 OS_Q 05/22/2008 18:01:52 PAGE 10
OS_Q *pq;
#if OS_ARG_CHK_EN > 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -