Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  Test_task
0004  *
0005  *  This task is used for three test tasks.  It obtains its task id and
0006  *  based upon that id, performs certain actions.
0007  *
0008  *       Task_1 delays 5 seconds and deletes itself.
0009  *       Task_2 delays 10 seconds and then loops until
0010  *             deleted by the third task.
0011  *       Task 3 delays 15 seconds, then deletes task 2 and itself.
0012  *
0013  *  Input parameters:
0014  *    argument - task argument
0015  *
0016  *  Output parameters:  NONE
0017  *
0018  *  COPYRIGHT (c) 1989-2009.
0019  *  On-Line Applications Research Corporation (OAR).
0020  *
0021  * Redistribution and use in source and binary forms, with or without
0022  * modification, are permitted provided that the following conditions
0023  * are met:
0024  * 1. Redistributions of source code must retain the above copyright
0025  *    notice, this list of conditions and the following disclaimer.
0026  * 2. Redistributions in binary form must reproduce the above copyright
0027  *    notice, this list of conditions and the following disclaimer in the
0028  *    documentation and/or other materials provided with the distribution.
0029  *
0030  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0031  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0032  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0033  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0034  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0035  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0036  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0037  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0038  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0039  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0040  * POSSIBILITY OF SUCH DAMAGE.
0041  */
0042 
0043 #ifdef HAVE_CONFIG_H
0044 #include "config.h"
0045 #endif
0046 
0047 #include "system.h"
0048 
0049 rtems_task Test_task(
0050   rtems_task_argument argument
0051 )
0052 {
0053   rtems_status_code status;
0054   rtems_id          tid;
0055   rtems_time_of_day time;
0056 
0057   status = rtems_task_ident( RTEMS_WHO_AM_I, RTEMS_SEARCH_ALL_NODES, &tid );
0058   directive_failed( status, "rtems_task_ident" );
0059 
0060   status = rtems_clock_get_tod( &time );
0061   directive_failed( status, "rtems_clock_get_tod" );
0062 
0063   put_name( Task_name[ task_number( tid ) ], FALSE );
0064   print_time( " - rtems_clock_get_tod - ", &time, "\n" );
0065 
0066   status = rtems_task_wake_after( task_number( tid ) * 1 * rtems_clock_get_ticks_per_second() );
0067   directive_failed( status, "rtems_task_wake_after" );
0068 
0069   status = rtems_clock_get_tod( &time );
0070   directive_failed( status, "rtems_clock_get_tod" );
0071   put_name( Task_name[ task_number( tid ) ], FALSE );
0072   print_time( " - rtems_clock_get_tod - ", &time, "\n" );
0073 
0074   if ( task_number(tid) == 1 ) {          /* TASK 1 */
0075     put_name( Task_name[ 1 ], FALSE );
0076     printf( " - deleting self\n" );
0077     rtems_task_exit();
0078   }
0079   else if ( task_number(tid) == 2 ) {     /* TASK 2 */
0080     put_name( Task_name[ 2 ], FALSE );
0081     printf( " - waiting to be deleted by " );
0082     put_name( Task_name[ 3 ], TRUE );
0083     while ( FOREVER );
0084   }
0085   else {                                  /* TASK 3 */
0086     put_name( Task_name[ 3 ], FALSE );
0087     printf( " - getting TID of " );
0088     put_name( Task_name[ 2 ], TRUE );
0089     do {
0090       status = rtems_task_ident( Task_name[ 2 ], RTEMS_SEARCH_ALL_NODES, &tid );
0091     } while ( status != RTEMS_SUCCESSFUL );
0092     directive_failed( status, "rtems_task_ident" );
0093 
0094     put_name( Task_name[ 3 ], FALSE );
0095     printf( " - deleting " );
0096     put_name( Task_name[ 2 ], TRUE );
0097     status = rtems_task_delete( tid );
0098     directive_failed( status, "rtems_task_delete of Task 2" );
0099 
0100     puts( "*** END OF TEST 1 ***" );
0101     rtems_test_exit(0);
0102   }
0103 }