Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2011.
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 void Priority_test_driver(
0036   rtems_task_priority priority_base
0037 )
0038 {
0039   rtems_task_priority previous_priority;
0040   uint32_t            index;
0041   rtems_status_code   status;
0042 
0043   for ( index = 1 ; index <= 5 ; index++ ) {
0044     switch ( index ) {
0045        case 1:
0046        case 2:
0047        case 3:
0048          Task_priority[ index ] = priority_base + index;
0049          break;
0050        default:
0051          Task_priority[ index ] = priority_base + 3;
0052          break;
0053     }
0054 
0055     status = rtems_task_create(
0056       Priority_task_name[ index ],
0057       Task_priority[ index ],
0058       RTEMS_MINIMUM_STACK_SIZE * 2,
0059       RTEMS_DEFAULT_MODES,
0060       RTEMS_DEFAULT_ATTRIBUTES,
0061       &Priority_task_id[ index ]
0062     );
0063     directive_failed( status, "rtems_task_create loop" );
0064 
0065   }
0066 
0067   if ( priority_base == 0 ) {
0068     for ( index = 1 ; index <= 5 ; index++ ) {
0069       status = rtems_task_start(
0070         Priority_task_id[ index ],
0071         Priority_task,
0072         index
0073       );
0074       directive_failed( status, "rtems_task_start loop" );
0075     }
0076   } else {
0077     for ( index = 5 ; index >= 1 ; index-- ) {
0078       status = rtems_task_start(
0079         Priority_task_id[ index ],
0080         Priority_task,
0081         index
0082       );
0083       directive_failed( status, "rtems_task_start loop" );
0084 
0085       status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
0086       directive_failed( status, "rtems_task_wake_after loop" );
0087 
0088       if ( priority_base == PRIORITY_INHERIT_BASE_PRIORITY ) {
0089         if ( index == 4 ) {
0090           status = rtems_task_set_priority(
0091             Priority_task_id[ 5 ],
0092             priority_base + 4,
0093             &previous_priority
0094           );
0095           printf(
0096         "PDRV - change priority of PRI5 from %" PRIdrtems_task_priority
0097               " to %" PRIdrtems_task_priority "\n",
0098              previous_priority,
0099              priority_base + 4
0100           );
0101           directive_failed( status, "PDRV rtems_task_set_priority" );
0102         }
0103         status = rtems_task_set_priority(
0104           Priority_task_id[ 5 ],
0105           RTEMS_CURRENT_PRIORITY,
0106           &previous_priority
0107         );
0108         directive_failed( status, "PDRV rtems_task_set_priority CURRENT" );
0109         printf(
0110           "PDRV - priority of PRI5 is %" PRIdrtems_task_priority "\n",
0111            previous_priority
0112         );
0113       }
0114     }
0115   }
0116 
0117   status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
0118   directive_failed( status, "rtems_task_wake_after after loop" );
0119 
0120   if ( priority_base == 0 ) {
0121     for ( index = 1 ; index <= 5 ; index++ ) {
0122       status = rtems_semaphore_release( Semaphore_id[ 2 ] );
0123       directive_failed( status, "rtems_semaphore_release loop" );
0124     }
0125   }
0126 
0127   if ( priority_base == PRIORITY_INHERIT_BASE_PRIORITY ) {
0128     puts( "PDRV - rtems_task_resume - PRI5" );
0129     status = rtems_task_resume( Priority_task_id[ 5 ] );
0130     directive_failed( status, "rtems_task_resume" );
0131 
0132     status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
0133     directive_failed( status, "rtems_task_wake_after so PRI5 can run" );
0134 
0135     status = rtems_task_delete( Priority_task_id[ 5 ] );
0136     directive_failed( status, "rtems_task_delete of PRI5" );
0137   } else {
0138     for ( index = 1 ; index <= 5 ; index++ ) {
0139       status = rtems_task_delete( Priority_task_id[ index ] );
0140       directive_failed( status, "rtems_task_delete loop" );
0141     }
0142   }
0143 }