os_q.ls1
来自「在51单片机上移植成功的UCOS-II操作系统源代码,包括源代码及相关注释」· LS1 代码 · 共 740 行 · 第 1/4 页
LS1
740 行
294 ; * OS_NO_ERR The call was successful and your task rece
ived a message.
295 ; * OS_TIMEOUT A message was not received within the spec
ified timeout
296 ; * OS_ERR_EVENT_TYPE You didn't pass a pointer to a queue
297 ; * OS_ERR_PEND_ISR If you called this function from an ISR a
nd the result
298 ; * would lead to a suspension.
299 ; *
300 ; * Returns : != (void *)0 is a pointer to the message received
301 ; * == (void *)0 if no message was received or you didn't pass a pointer to a
queue.
302 ; *****************************************************************************************
****************
303 ; */
304 ;
305 ; void *OSQPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) reentrant
306 ; {
307 ; void *msg;
308 ; OS_Q *pq;
309 ;
310 ;
311 ; OS_ENTER_CRITICAL();
312 ; if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type
*/
313 ; OS_EXIT_CRITICAL();
314 ; *err = OS_ERR_EVENT_TYPE;
315 ; return ((void *)0);
316 ; }
317 ; pq = pevent->OSEventPtr; /* Point at queue control block
*/
318 ; if (pq->OSQEntries != 0) { /* See if any messages in the queue
*/
319 ; msg = *pq->OSQOut++; /* Yes, extract oldest message from the
queue */
320 ; pq->OSQEntries--; /* Update the number of entries in the q
ueue */
A51 MACRO ASSEMBLER OS_Q 09/09/2007 21:12:59 PAGE 7
321 ; if (pq->OSQOut == pq->OSQEnd) { /* Wrap OUT pointer if we are at the end
of the queue */
322 ; pq->OSQOut = pq->OSQStart;
323 ; }
324 ; OS_EXIT_CRITICAL();
325 ; *err = OS_NO_ERR;
326 ; } else if (OSIntNesting > 0) { /* See if called from ISR ...
*/
327 ; OS_EXIT_CRITICAL(); /* ... can't PEND from an ISR
*/
328 ; *err = OS_ERR_PEND_ISR;
329 ; } else {
330 ; OSTCBCur->OSTCBStat |= OS_STAT_Q; /* Task will have to pend for a message
to be posted */
331 ; OSTCBCur->OSTCBDly = timeout; /* Load timeout into TCB
*/
332 ; OSEventTaskWait(pevent); /* Suspend task until event or timeout o
ccurs */
333 ; OS_EXIT_CRITICAL();
334 ; OSSched(); /* Find next highest priority task ready
to run */
335 ; OS_ENTER_CRITICAL();
336 ; if ((msg = OSTCBCur->OSTCBMsg) != (void *)0) {/* Did we get a message?
*/
337 ; OSTCBCur->OSTCBMsg = (void *)0; /* Extract message from TCB (Put th
ere by QPost) */
338 ; OSTCBCur->OSTCBStat = OS_STAT_RDY;
339 ; OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event
*/
340 ; OS_EXIT_CRITICAL();
341 ; *err = OS_NO_ERR;
342 ; } else if (OSTCBCur->OSTCBStat & OS_STAT_Q) { /* Timed out if status indicates pe
nding on Q */
343 ; OSEventTO(pevent);
344 ; OS_EXIT_CRITICAL();
345 ; msg = (void *)0; /* No message received
*/
346 ; *err = OS_TIMEOUT; /* Indicate a timeout occured
*/
347 ; } else {
348 ; msg = *pq->OSQOut++; /* Extract message from queue
*/
349 ; pq->OSQEntries--; /* Update the number of entries in
the queue */
350 ; if (pq->OSQOut == pq->OSQEnd) { /* Wrap OUT pointer if we are at th
e end of Q */
351 ; pq->OSQOut = pq->OSQStart;
352 ; }
353 ; OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
354 ; OS_EXIT_CRITICAL();
355 ; *err = OS_NO_ERR;
356 ; }
357 ; }
358 ; return (msg); /* Return message received (or NULL
) */
359 ; }
360 ; /*$PAGE*/
361 ; /*
362 ; *****************************************************************************************
****************
363 ; * POST MESSAGE TO A QUEUE
364 ; *
365 ; * Description: This function sends a message to a queue
366 ; *
367 ; * Arguments : pevent is a pointer to the event control block associated with the
desired queue
A51 MACRO ASSEMBLER OS_Q 09/09/2007 21:12:59 PAGE 8
368 ; *
369 ; * msg is a pointer to the message to send. You MUST NOT send a NU
LL pointer.
370 ; *
371 ; * Returns : OS_NO_ERR The call was successful and the message was sent
372 ; * OS_Q_FULL If the queue cannot accept any more messages because it
is full.
373 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
374 ; *****************************************************************************************
****************
375 ; */
376 ;
377 ; INT8U OSQPost (OS_EVENT *pevent, void *msg) reentrant
378 ; {
379 ; OS_Q *pq;
380 ;
381 ;
382 ; OS_ENTER_CRITICAL();
383 ; if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type
*/
384 ; OS_EXIT_CRITICAL();
385 ; return (OS_ERR_EVENT_TYPE);
386 ; }
387 ; if (pevent->OSEventGrp) { /* See if any task pending on queue
*/
388 ; OSEventTaskRdy(pevent, msg, OS_STAT_Q); /* Ready highest priority task wait
ing on event */
389 ; OS_EXIT_CRITICAL();
390 ; OSSched(); /* Find highest priority task ready
to run */
391 ; return (OS_NO_ERR);
392 ; } else {
393 ; pq = pevent->OSEventPtr; /* Point to queue control block
*/
394 ; if (pq->OSQEntries >= pq->OSQSize) { /* Make sure queue is not full
*/
395 ; OS_EXIT_CRITICAL();
396 ; return (OS_Q_FULL);
397 ; } else {
398 ; *pq->OSQIn++ = msg; /* Insert message into queue
*/
399 ; pq->OSQEntries++; /* Update the nbr of entries in the
queue */
400 ; if (pq->OSQIn == pq->OSQEnd) { /* Wrap IN ptr if we are at end of
queue */
401 ; pq->OSQIn = pq->OSQStart;
402 ; }
403 ; OS_EXIT_CRITICAL();
404 ; }
405 ; return (OS_NO_ERR);
406 ; }
407 ; }
408 ; /*$PAGE*/
409 ; /*
410 ; *****************************************************************************************
****************
411 ; * POST MESSAGE TO THE FRONT OF A QUEUE
412 ; *
413 ; * Description: This function sends a message to a queue but unlike OSQPost(), the message
is posted at
414 ; * the front instead of the end of the queue. Using OSQPostFront() allows yo
u to send
415 ; * 'priority' messages.
416 ; *
417 ; * Arguments : pevent is a pointer to the event control block associated with the
desired queue
A51 MACRO ASSEMBLER OS_Q 09/09/2007 21:12:59 PAGE 9
418 ; *
419 ; * msg is a pointer to the message to send. You MUST NOT send a NU
LL pointer.
420 ; *
421 ; * Returns : OS_NO_ERR The call was successful and the message was sent
422 ; * OS_Q_FULL If the queue cannot accept any more messages because it
is full.
423 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
424 ; *****************************************************************************************
****************
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?