📄 os_mbox.lst
字号:
322 * POST MESSAGE TO A MAILBOX
323 *
324 * Description: This function sends a message to a mailbox
325 *
326 * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
327 *
328 * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
329 *
330 * Returns : OS_NO_ERR The call was successful and the message was sent
331 * OS_MBOX_FULL If the mailbox already contains a message. You can can only send one
332 * message at a time and thus, the message MUST be consumed before you
333 * are allowed to send another one.
334 * OS_ERR_EVENT_TYPE If you are attempting to post to a non mailbox.
335 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
336 * OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
337 *
338 * Note(s) : 1) HPT means Highest Priority Task
339 *********************************************************************************************************
340 */
341
342 #if OS_MBOX_POST_EN > 0
343 INT8U OSMboxPost (OS_EVENT *pevent, void *msg)
344 {
345 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
348
349
350
351 #if OS_ARG_CHK_EN > 0
352 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
353 return (OS_ERR_PEVENT_NULL);
354 }
355 if (msg == (void *)0) { /* Make sure we are not posting a NULL pointer */
356 return (OS_ERR_POST_NULL_PTR);
357 }
358 #endif
359 if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
360 return (OS_ERR_EVENT_TYPE);
361 }
362 OS_ENTER_CRITICAL();
363 if (pevent->OSEventGrp != 0) { /* See if any task pending on mailbox */
364 (void)OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX); /* Ready HPT waiting on event */
365 OS_EXIT_CRITICAL();
366 OS_Sched(); /* Find highest priority task ready to run */
367 return (OS_NO_ERR);
368 }
369 if (pevent->OSEventPtr != (void *)0) { /* Make sure mailbox doesn't already have a msg */
C51 COMPILER V8.08 OS_MBOX 08/04/2008 21:49:52 PAGE 8
370 OS_EXIT_CRITICAL();
371 return (OS_MBOX_FULL);
372 }
373 pevent->OSEventPtr = msg; /* Place message in mailbox */
374 OS_EXIT_CRITICAL();
375 return (OS_NO_ERR);
376 }
377 #endif
378
379 /*$PAGE*/
380 /*
381 *********************************************************************************************************
382 * POST MESSAGE TO A MAILBOX
383 *
384 * Description: This function sends a message to a mailbox
385 *
386 * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
387 *
388 * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
389 *
390 * opt determines the type of POST performed:
391 * OS_POST_OPT_NONE POST to a single waiting task
392 * (Identical to OSMboxPost())
393 * OS_POST_OPT_BROADCAST POST to ALL tasks that are waiting on the mailbox
394 *
395 * Returns : OS_NO_ERR The call was successful and the message was sent
396 * OS_MBOX_FULL If the mailbox already contains a message. You can can only send one
397 * message at a time and thus, the message MUST be consumed before you
398 * are allowed to send another one.
399 * OS_ERR_EVENT_TYPE If you are attempting to post to a non mailbox.
400 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
401 * OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
402 *
403 * Note(s) : 1) HPT means Highest Priority Task
404 *
405 * Warning : Interrupts can be disabled for a long time if you do a 'broadcast'. In fact, the
406 * interrupt disable time is proportional to the number of tasks waiting on the mailbox.
407 *********************************************************************************************************
408 */
409
410 #if OS_MBOX_POST_OPT_EN > 0
411 INT8U OSMboxPostOpt (OS_EVENT *pevent, void *msg, INT8U opt)
412 {
413 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
416
417
418
419 #if OS_ARG_CHK_EN > 0
420 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
421 return (OS_ERR_PEVENT_NULL);
422 }
423 if (msg == (void *)0) { /* Make sure we are not posting a NULL pointer */
424 return (OS_ERR_POST_NULL_PTR);
425 }
426 #endif
427 if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
428 return (OS_ERR_EVENT_TYPE);
429 }
430 OS_ENTER_CRITICAL();
431 if (pevent->OSEventGrp != 0) { /* See if any task pending on mailbox */
C51 COMPILER V8.08 OS_MBOX 08/04/2008 21:49:52 PAGE 9
432 if ((opt & OS_POST_OPT_BROADCAST) != 0x00) { /* Do we need to post msg to ALL waiting tasks ? */
433 while (pevent->OSEventGrp != 0) { /* Yes, Post to ALL tasks waiting on mailbox */
434 (void)OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX);
435 }
436 } else {
437 (void)OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX); /* No, Post to HPT waiting on mbox */
438 }
439 OS_EXIT_CRITICAL();
440 OS_Sched(); /* Find HPT ready to run */
441 return (OS_NO_ERR);
442 }
443 if (pevent->OSEventPtr != (void *)0) { /* Make sure mailbox doesn't already have a msg */
444 OS_EXIT_CRITICAL();
445 return (OS_MBOX_FULL);
446 }
447 pevent->OSEventPtr = msg; /* Place message in mailbox */
448 OS_EXIT_CRITICAL();
449 return (OS_NO_ERR);
450 }
451 #endif
452
453 /*$PAGE*/
454 /*
455 *********************************************************************************************************
456 * QUERY A MESSAGE MAILBOX
457 *
458 * Description: This function obtains information about a message mailbox.
459 *
460 * Arguments : pevent is a pointer to the event control block associated with the desired mailbox
461 *
462 * p_mbox_data is a pointer to a structure that will contain information about the message
463 * mailbox.
464 *
465 * Returns : OS_NO_ERR The call was successful and the message was sent
466 * OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non mailbox.
467 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
468 * OS_ERR_PDATA_NULL If 'p_mbox_data' is a NULL pointer
469 *********************************************************************************************************
470 */
471
472 #if OS_MBOX_QUERY_EN > 0
473 INT8U OSMboxQuery (OS_EVENT *pevent, OS_MBOX_DATA *p_mbox_data)
474 {
475 INT8U i;
476 #if OS_LOWEST_PRIO <= 63
477 INT8U *psrc;
478 INT8U *pdest;
479 #else
INT16U *psrc;
INT16U *pdest;
#endif
483 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
486
487
488
489 #if OS_ARG_CHK_EN > 0
490 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
491 return (OS_ERR_PEVENT_NULL);
492 }
493 if (p_mbox_data == (OS_MBOX_DATA *)0) { /* Validate 'p_mbox_data' */
C51 COMPILER V8.08 OS_MBOX 08/04/2008 21:49:52 PAGE 10
494 return (OS_ERR_PDATA_NULL);
495 }
496 #endif
497 if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) { /* Validate event block type */
498 return (OS_ERR_EVENT_TYPE);
499 }
500 OS_ENTER_CRITICAL();
501 p_mbox_data->OSEventGrp = pevent->OSEventGrp; /* Copy message mailbox wait list */
502 psrc = &pevent->OSEventTbl[0];
503 pdest = &p_mbox_data->OSEventTbl[0];
504 for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
505 *pdest++ = *psrc++;
506 }
507 p_mbox_data->OSMsg = pevent->OSEventPtr; /* Get message from mailbox */
508 OS_EXIT_CRITICAL();
509 return (OS_NO_ERR);
510 }
511 #endif /* OS_MBOX_QUERY_EN */
512 #endif /* OS_MBOX_EN */
C51 COMPILATION COMPLETE. 0 WARNING(S), 57 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -