Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:35

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  Message_queue_task
0004  *
0005  *  This task continuously sends messages to and receives messages from
0006  *  a global message queue.    The message buffer is viewed as an array
0007  *  of two sixty-four bit counts which are incremented when a message is
0008  *  received.
0009  *
0010  *  Input parameters:
0011  *    argument - task argument
0012  *
0013  *  Output parameters:  NONE
0014  *
0015  *  COPYRIGHT (c) 1989-1999.
0016  *  On-Line Applications Research Corporation (OAR).
0017  *
0018  * Redistribution and use in source and binary forms, with or without
0019  * modification, are permitted provided that the following conditions
0020  * are met:
0021  * 1. Redistributions of source code must retain the above copyright
0022  *    notice, this list of conditions and the following disclaimer.
0023  * 2. Redistributions in binary form must reproduce the above copyright
0024  *    notice, this list of conditions and the following disclaimer in the
0025  *    documentation and/or other materials provided with the distribution.
0026  *
0027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0037  * POSSIBILITY OF SUCH DAMAGE.
0038  */
0039 
0040 #ifdef HAVE_CONFIG_H
0041 #include "config.h"
0042 #endif
0043 
0044 #include "system.h"
0045 
0046 rtems_task Message_queue_task(
0047   rtems_task_argument index
0048 )
0049 {
0050   rtems_status_code  status;
0051   uint32_t     count;
0052   uint32_t     yield_count;
0053   uint32_t    *buffer_count;
0054   uint32_t    *overflow_count;
0055   size_t       size;
0056 
0057   Msg_buffer[ index ][0] = 0;
0058   Msg_buffer[ index ][1] = 0;
0059   Msg_buffer[ index ][2] = 0;
0060   Msg_buffer[ index ][3] = 0;
0061 
0062   puts( "Getting ID of msg queue" );
0063   while ( FOREVER ) {
0064     status = rtems_message_queue_ident(
0065       Queue_name[ 1 ],
0066       RTEMS_SEARCH_ALL_NODES,
0067       &Queue_id[ 1 ]
0068     );
0069     if ( status == RTEMS_SUCCESSFUL )
0070       break;
0071     puts( "rtems_message_queue_ident FAILED!!" );
0072     rtems_task_wake_after(2);
0073   }
0074 
0075   if ( rtems_object_get_local_node() == 1 ) {
0076       status = rtems_message_queue_send(
0077         Queue_id[ 1 ],
0078         (long (*)[4])Msg_buffer[ index ],
0079         16
0080       );
0081       directive_failed( status, "rtems_message_queue_send" );
0082       overflow_count = &Msg_buffer[ index ][0];
0083       buffer_count   = &Msg_buffer[ index ][1];
0084   } else {
0085       overflow_count = &Msg_buffer[ index ][2];
0086       buffer_count   = &Msg_buffer[ index ][3];
0087   }
0088 
0089   while ( Stop_Test == false ) {
0090     yield_count = 100;
0091 
0092     for ( count=MESSAGE_DOT_COUNT ; Stop_Test == false && count ; count-- ) {
0093       status = rtems_message_queue_receive(
0094         Queue_id[ 1 ],
0095         Msg_buffer[ index ],
0096         &size,
0097         RTEMS_DEFAULT_OPTIONS,
0098         RTEMS_NO_TIMEOUT
0099       );
0100       directive_failed( status, "rtems_message_queue_receive" );
0101 
0102       if ( *buffer_count == (uint32_t)0xffffffff ) {
0103         *buffer_count    = 0;
0104         *overflow_count += 1;
0105       } else
0106         *buffer_count += 1;
0107 
0108       status = rtems_message_queue_send(
0109         Queue_id[ 1 ],
0110         Msg_buffer[ index ],
0111         16
0112       );
0113       directive_failed( status, "rtems_message_queue_send" );
0114 
0115       if (Stop_Test == false)
0116         if ( rtems_object_get_local_node() == 1 && --yield_count == 0 ) {
0117           status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0118           directive_failed( status, "rtems_task_wake_after" );
0119 
0120           yield_count = 100;
0121         }
0122     }
0123     put_dot( 'm' );
0124   }
0125 
0126   Exit_test();
0127 }