Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  Task_1
0004  *
0005  *  This routine serves as a test task.  It verifies the semaphore manager.
0006  *
0007  *  Input parameters:
0008  *    argument - task argument
0009  *
0010  *  Output parameters:  NONE
0011  *
0012  *  COPYRIGHT (c) 1989-2009.
0013  *  On-Line Applications Research Corporation (OAR).
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #ifdef HAVE_CONFIG_H
0038 #include "config.h"
0039 #endif
0040 
0041 #include "system.h"
0042 
0043 rtems_task Task_1(
0044   rtems_task_argument argument
0045 )
0046 {
0047   rtems_id          smid;
0048   rtems_status_code status;
0049 
0050   status = rtems_semaphore_ident(
0051     Semaphore_name[ 1 ],
0052     RTEMS_SEARCH_ALL_NODES,
0053     &smid
0054   );
0055   printf( "TA1 - rtems_semaphore_ident - smid => %08" PRIxrtems_id "\n", smid );
0056   directive_failed( status, "rtems_semaphore_ident of SM1" );
0057 
0058   puts( "TA1 - rtems_semaphore_obtain - wait forever on SM2" );
0059   status = rtems_semaphore_obtain(
0060     Semaphore_id[ 2 ],
0061     RTEMS_DEFAULT_OPTIONS,
0062     RTEMS_NO_TIMEOUT
0063   );
0064   directive_failed( status, "rtems_semaphore_obtain of SM2" );
0065   puts( "TA1 - got SM2" );
0066 
0067   puts( "TA1 - rtems_semaphore_obtain - wait forever on SM3" );
0068   status = rtems_semaphore_obtain(
0069     Semaphore_id[ 3 ],
0070     RTEMS_DEFAULT_OPTIONS,
0071     RTEMS_NO_TIMEOUT
0072   );
0073   directive_failed( status, "rtems_semaphore_obtain of SM3" );
0074   puts( "TA1 - got SM3" );
0075 
0076   puts( "TA1 - rtems_semaphore_obtain - get SM1 - RTEMS_NO_WAIT" );
0077   status = rtems_semaphore_obtain(
0078     Semaphore_id[ 1 ],
0079     RTEMS_NO_WAIT,
0080     RTEMS_NO_TIMEOUT
0081   );
0082   directive_failed( status, "rtems_semaphore_obtain of SM1" );
0083   puts( "TA1 - got SM1" );
0084 
0085   puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
0086   status = rtems_task_wake_after( 5 * rtems_clock_get_ticks_per_second() );
0087   directive_failed( status, "rtems_task_wake_after" );
0088 
0089   puts( "TA1 - rtems_semaphore_release - release SM1" );
0090   status = rtems_semaphore_release( Semaphore_id[ 1 ] );
0091   directive_failed( status, "rtems_semaphore_release of SM1" );
0092 
0093   puts(
0094     "TA1 - rtems_semaphore_obtain - waiting for SM1 with 10 second timeout"
0095   );
0096   status = rtems_semaphore_obtain(
0097     Semaphore_id[ 1 ],
0098     RTEMS_DEFAULT_OPTIONS,
0099     10 * rtems_clock_get_ticks_per_second()
0100   );
0101   directive_failed( status, "rtems_semaphore_obtain of SM1" );
0102   puts( "TA1 - got SM1" );
0103 
0104   puts( "TA1 - rtems_semaphore_release - release SM2" );
0105   status = rtems_semaphore_release( Semaphore_id[ 2 ] );
0106   directive_failed( status, "rtems_semaphore_release of SM2" );
0107 
0108   puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
0109   status = rtems_task_wake_after( 5 * rtems_clock_get_ticks_per_second() );
0110   directive_failed( status, "rtems_task_wake_after" );
0111 
0112   puts( "TA1 - rtems_task_delete - delete TA3" );
0113   status = rtems_task_delete( Task_id[ 3 ] );
0114   directive_failed( status, "rtems_task_delete of TA3" );
0115 
0116   status = rtems_task_create(
0117     Task_name[ 4 ],
0118     4,
0119     RTEMS_MINIMUM_STACK_SIZE,
0120     RTEMS_DEFAULT_MODES,
0121     RTEMS_DEFAULT_ATTRIBUTES,
0122     &Task_id[ 4 ]
0123   );
0124   directive_failed( status, "rtems_task_create of TA4" );
0125 
0126   status = rtems_task_create(
0127     Task_name[ 5 ],
0128     4,
0129     RTEMS_MINIMUM_STACK_SIZE,
0130     RTEMS_DEFAULT_MODES,
0131     RTEMS_DEFAULT_ATTRIBUTES,
0132     &Task_id[ 5 ]
0133    );
0134   directive_failed( status, "rtems_task_create of TA5" );
0135 
0136   status = rtems_task_start( Task_id[ 4 ], Task_4, 0 );
0137   directive_failed( status, "rtems_task_start of TA4" );
0138 
0139   status = rtems_task_start( Task_id[ 5 ], Task5, 0 );
0140   directive_failed( status, "rtems_task_start of TA5" );
0141 
0142   puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
0143   status = rtems_task_wake_after( 5 * rtems_clock_get_ticks_per_second() );
0144   directive_failed( status, "rtems_task_wake_after" );
0145 
0146   puts( "TA1 - rtems_task_delete - delete TA4" );
0147   status = rtems_task_delete( Task_id[ 4 ] );
0148   directive_failed( status, "rtems_task_delete of TA4" );
0149 
0150   puts( "TA1 - rtems_semaphore_release - release SM1" );
0151   status = rtems_semaphore_release( Semaphore_id[ 1 ] );
0152   directive_failed( status, "rtems_semaphore_release on SM1" );
0153 
0154   puts( "TA1 - rtems_task_wake_after - sleep 5 seconds" );
0155   status = rtems_task_wake_after( 5 * rtems_clock_get_ticks_per_second() );
0156   directive_failed( status, "rtems_task_wake_after" );
0157 
0158   puts( "TA1 - rtems_semaphore_delete - delete SM1" );
0159   status = rtems_semaphore_delete( Semaphore_id[ 1 ] );
0160   directive_failed( status, "rtems_semaphore_delete of SM1" );
0161 
0162   puts( "TA1 - rtems_semaphore_delete - delete SM3" );
0163   status = rtems_semaphore_delete( Semaphore_id[ 3 ] );
0164   directive_failed( status, "rtems_semaphore_delete of SM3" );
0165 
0166   puts( "TA1 - rtems_task_exit" );
0167   rtems_task_exit();
0168 }