[42d4ebe] | 1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
| 2 | |
---|
[ac7d5ef0] | 3 | /* Sm_test_task |
---|
| 4 | * |
---|
| 5 | * This task continuously obtains and releases a global semaphore. |
---|
| 6 | * |
---|
| 7 | * Input parameters: |
---|
| 8 | * argument - task argument |
---|
| 9 | * |
---|
| 10 | * Output parameters: NONE |
---|
| 11 | * |
---|
[08311cc3] | 12 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 13 | * On-Line Applications Research Corporation (OAR). |
---|
| 14 | * |
---|
[42d4ebe] | 15 | * Redistribution and use in source and binary forms, with or without |
---|
| 16 | * modification, are permitted provided that the following conditions |
---|
| 17 | * are met: |
---|
| 18 | * 1. Redistributions of source code must retain the above copyright |
---|
| 19 | * notice, this list of conditions and the following disclaimer. |
---|
| 20 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 21 | * notice, this list of conditions and the following disclaimer in the |
---|
| 22 | * documentation and/or other materials provided with the distribution. |
---|
| 23 | * |
---|
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
| 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 34 | * POSSIBILITY OF SUCH DAMAGE. |
---|
[ac7d5ef0] | 35 | */ |
---|
| 36 | |
---|
[a4bc4d6e] | 37 | #ifdef HAVE_CONFIG_H |
---|
| 38 | #include "config.h" |
---|
| 39 | #endif |
---|
| 40 | |
---|
[ac7d5ef0] | 41 | #include "system.h" |
---|
| 42 | |
---|
| 43 | rtems_task Semaphore_task( |
---|
| 44 | rtems_task_argument argument |
---|
| 45 | ) |
---|
| 46 | { |
---|
[d8e681e] | 47 | uint32_t count; |
---|
[ac7d5ef0] | 48 | rtems_status_code status; |
---|
[d8e681e] | 49 | uint32_t yield_count; |
---|
[ac7d5ef0] | 50 | |
---|
| 51 | puts( "Getting SMID of semaphore" ); |
---|
| 52 | while ( FOREVER ) { |
---|
| 53 | status = rtems_semaphore_ident( |
---|
| 54 | Semaphore_name[ 1 ], |
---|
| 55 | RTEMS_SEARCH_ALL_NODES, |
---|
| 56 | &Semaphore_id[ 1 ] |
---|
| 57 | ); |
---|
| 58 | if ( status == RTEMS_SUCCESSFUL ) |
---|
| 59 | break; |
---|
| 60 | puts( "rtems_semaphore_ident FAILED!!" ); |
---|
[2122a0b] | 61 | rtems_task_wake_after(2); |
---|
[ac7d5ef0] | 62 | } |
---|
| 63 | |
---|
[2122a0b] | 64 | yield_count = 100; |
---|
| 65 | |
---|
[f2ad3d1] | 66 | while ( Stop_Test == false ) { |
---|
[ac7d5ef0] | 67 | |
---|
[f2ad3d1] | 68 | for ( count=SEMAPHORE_DOT_COUNT ; Stop_Test == false && count ; count-- ) { |
---|
[ac7d5ef0] | 69 | status = rtems_semaphore_obtain( |
---|
| 70 | Semaphore_id[ 1 ], |
---|
| 71 | RTEMS_DEFAULT_OPTIONS, |
---|
| 72 | RTEMS_NO_TIMEOUT |
---|
| 73 | ); |
---|
| 74 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
| 75 | |
---|
| 76 | status = rtems_semaphore_release( Semaphore_id[ 1 ] ); |
---|
| 77 | directive_failed( status, "rtems_semaphore_release" ); |
---|
| 78 | |
---|
[f2ad3d1] | 79 | if ( Stop_Test == false ) |
---|
[a00dff42] | 80 | if ( rtems_object_get_local_node() == 1 && --yield_count == 0 ) { |
---|
[2122a0b] | 81 | status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
| 82 | directive_failed( status, "rtems_task_wake_after" ); |
---|
[ac7d5ef0] | 83 | |
---|
[2122a0b] | 84 | yield_count = 100; |
---|
| 85 | } |
---|
[ac7d5ef0] | 86 | } |
---|
| 87 | put_dot( 's' ); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | Exit_test(); |
---|
| 91 | } |
---|