Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2009.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include "system.h"
0034 
0035 static void Test_Task_Support(
0036   uint32_t    node
0037 )
0038 {
0039   rtems_event_set   events;
0040   rtems_status_code status;
0041 
0042   if ( rtems_object_get_local_node() == node ) {
0043 
0044     for ( ; ; ) {
0045 
0046       status = rtems_event_receive(
0047         RTEMS_EVENT_16,
0048         RTEMS_NO_WAIT,
0049         RTEMS_NO_TIMEOUT,
0050         &events
0051       );
0052 
0053       if ( status == RTEMS_SUCCESSFUL )
0054         break;
0055 
0056       fatal_directive_status(status, RTEMS_UNSATISFIED, "rtems_event_receive");
0057 
0058       status = rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() );
0059       directive_failed( status, "rtems_task_wake_after" );
0060 
0061       put_name( Task_name[ node ], FALSE );
0062       puts( " - Suspending remote task" );
0063 
0064       status = rtems_task_suspend( remote_tid );
0065       directive_failed( status, "rtems_task_suspend" );
0066 
0067       status = rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() );
0068       directive_failed( status, "rtems_task_wake_after" );
0069 
0070       put_name( Task_name[ node ], FALSE );
0071       puts( " - Resuming remote task" );
0072 
0073       status = rtems_task_resume( remote_tid ) ;
0074       directive_failed( status, "rtems_task_resume" );
0075 
0076     }
0077 
0078   }  else {
0079 
0080     for ( ; ; ) {
0081       status = rtems_event_receive(
0082         RTEMS_EVENT_16,
0083         RTEMS_NO_WAIT,
0084         RTEMS_NO_TIMEOUT,
0085         &events
0086       );
0087 
0088       if ( status == RTEMS_SUCCESSFUL )
0089         break;
0090 
0091       fatal_directive_status(status, RTEMS_UNSATISFIED, "rtems_event_receive");
0092 
0093       put_name( Task_name[ remote_node ], FALSE );
0094       puts( " - have I been suspended???" );
0095 
0096       status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() / 2 );
0097       directive_failed( status, "rtems_task_wake_after" );
0098     }
0099 
0100   }
0101 
0102 }
0103 
0104 /*PAGE
0105  *
0106  *  Test_task
0107  */
0108 
0109 rtems_task Test_task(
0110   rtems_task_argument argument
0111 )
0112 {
0113   rtems_id          tid;
0114   rtems_status_code status;
0115 
0116   status = rtems_task_ident( RTEMS_WHO_AM_I, RTEMS_SEARCH_ALL_NODES, &tid );
0117   directive_failed( status, "rtems_task_ident" );
0118 
0119   puts( "Getting TID of remote task" );
0120   remote_node = (rtems_object_get_local_node() == 1) ? 2 : 1;
0121   printf( "Remote task's name is : " );
0122   put_name( Task_name[ remote_node ], TRUE );
0123 
0124   do {
0125       status = rtems_task_ident(
0126           Task_name[ remote_node ],
0127           RTEMS_SEARCH_ALL_NODES,
0128           &remote_tid
0129           );
0130   } while ( status != RTEMS_SUCCESSFUL );
0131 
0132   directive_failed( status, "rtems_task_ident" );
0133 
0134   status = rtems_timer_fire_after(
0135     Timer_id[ 1 ],
0136     5 * rtems_clock_get_ticks_per_second(),
0137     Delayed_send_event,
0138     NULL
0139   );
0140   directive_failed( status, "rtems_timer_fire_after" );
0141 
0142   Test_Task_Support( 1 );
0143 
0144   status = rtems_timer_fire_after(
0145     Timer_id[ 1 ],
0146     5 * rtems_clock_get_ticks_per_second(),
0147     Delayed_send_event,
0148     NULL
0149   );
0150   directive_failed( status, "rtems_timer_fire_after" );
0151 
0152   if ( rtems_object_get_local_node() == 1 ) {
0153     status = rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() );
0154     directive_failed( status, "rtems_task_wake_after" );
0155   }
0156 
0157   Test_Task_Support( 2 );
0158 
0159   puts( "*** END OF TEST 3 ***" );
0160   rtems_test_exit( 0 );
0161 }