Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  Task_1
0004  *
0005  *  This test serves as a test task.  It verifies timeslicing activities
0006  *  and tswitch extension processing.
0007  *
0008  *  Input parameters:
0009  *    argument - task argument
0010  *
0011  *  Output parameters:  NONE
0012  *
0013  *  COPYRIGHT (c) 1989-1999.
0014  *  On-Line Applications Research Corporation (OAR).
0015  *
0016  * Redistribution and use in source and binary forms, with or without
0017  * modification, are permitted provided that the following conditions
0018  * are met:
0019  * 1. Redistributions of source code must retain the above copyright
0020  *    notice, this list of conditions and the following disclaimer.
0021  * 2. Redistributions in binary form must reproduce the above copyright
0022  *    notice, this list of conditions and the following disclaimer in the
0023  *    documentation and/or other materials provided with the distribution.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #ifdef HAVE_CONFIG_H
0039 #include "config.h"
0040 #endif
0041 
0042 #include "system.h"
0043 
0044 rtems_task Task_1(
0045   rtems_task_argument argument
0046 )
0047 {
0048   uint32_t    seconds;
0049   uint32_t    old_seconds;
0050   rtems_mode        previous_mode;
0051   rtems_time_of_day time;
0052   rtems_status_code status;
0053   uint32_t    start_time;
0054   uint32_t    end_time;
0055 
0056   puts( "TA1 - rtems_task_suspend - on Task 2" );
0057   status = rtems_task_suspend( Task_id[ 2 ] );
0058   directive_failed( status, "rtems_task_suspend of TA2" );
0059 
0060   puts( "TA1 - rtems_task_suspend - on Task 3" );
0061   status = rtems_task_suspend( Task_id[ 3 ] );
0062   directive_failed( status, "rtems_task_suspend of TA3" );
0063 
0064   status = rtems_clock_get_seconds_since_epoch( &start_time );
0065   directive_failed( status, "rtems_clock_get_seconds_since_epoch" );
0066 
0067   puts( "TA1 - killing time" );
0068 
0069   for ( ; ; ) {
0070     status = rtems_clock_get_seconds_since_epoch( &end_time );
0071     directive_failed( status, "rtems_clock_get_seconds_since_epoch" );
0072 
0073     if ( end_time > (start_time + 2) )
0074       break;
0075   }
0076 
0077   puts( "TA1 - rtems_task_resume - on Task 2" );
0078   status = rtems_task_resume( Task_id[ 2 ] );
0079   directive_failed( status, "rtems_task_resume of TA2" );
0080 
0081   puts( "TA1 - rtems_task_resume - on Task 3" );
0082   status = rtems_task_resume( Task_id[ 3 ] );
0083   directive_failed( status, "rtems_task_resume of TA3" );
0084 
0085   while ( FOREVER ) {
0086     if ( Run_count[ 1 ] == 3 ) {
0087       puts( "TA1 - rtems_task_mode - change mode to NO RTEMS_PREEMPT" );
0088 
0089       status = rtems_task_mode(
0090         RTEMS_NO_PREEMPT,
0091         RTEMS_PREEMPT_MASK,
0092         &previous_mode
0093       );
0094       directive_failed( status, "rtems_task_mode" );
0095 
0096       status = rtems_clock_get_tod( &time );
0097       directive_failed( status, "rtems_clock_get_tod" );
0098 
0099       old_seconds = time.second;
0100 
0101       for ( seconds = 0 ; seconds < 6 ; ) {
0102         status = rtems_clock_get_tod( &time );
0103         directive_failed( status, "rtems_clock_get_tod" );
0104 
0105         if ( time.second != old_seconds ) {
0106           old_seconds = time.second;
0107           seconds++;
0108           print_time( "TA1 - ", &time, "\n" );
0109         }
0110       }
0111 
0112       puts( "TA1 - rtems_task_mode - change mode to RTEMS_PREEMPT" );
0113       status = rtems_task_mode(
0114         RTEMS_PREEMPT,
0115         RTEMS_PREEMPT_MASK,
0116         &previous_mode
0117       );
0118       directive_failed( status, "rtems_task_mode" );
0119 
0120       while ( FOREVER );
0121     }
0122   }
0123 }