Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
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 <tmacros.h>
0034 
0035 const char rtems_test_name[] = "SP 59";
0036 
0037 /* forward declarations to avoid warnings */
0038 rtems_task Init(rtems_task_argument argument);
0039 rtems_task Blocking_task(rtems_task_argument ignored);
0040 
0041 uint8_t Region_Memory[512] CPU_STRUCTURE_ALIGNMENT;
0042 #define ALLOC_SIZE ( sizeof( Region_Memory ) / 2 )
0043 rtems_id Region;
0044 
0045 rtems_task Blocking_task(
0046   rtems_task_argument ignored
0047 )
0048 {
0049   rtems_status_code    status;
0050   void                *address_1;
0051 
0052   puts( "Blocking_task - wait for memory" );
0053   status = rtems_region_get_segment(
0054     Region,
0055     ALLOC_SIZE,
0056     RTEMS_DEFAULT_OPTIONS,
0057     RTEMS_NO_TIMEOUT,
0058     &address_1
0059   );
0060   directive_failed( status, "rtems_region_get_segment" );
0061 
0062   puts( "Blocking_task - Got memory segment after freed" );
0063 
0064   puts( "Blocking_task - delete self" );
0065   rtems_task_exit();
0066 }
0067 
0068 rtems_task Init(
0069   rtems_task_argument ignored
0070 )
0071 {
0072   rtems_status_code     status;
0073   rtems_id              task_id;
0074   void                 *address_1;
0075   rtems_task_priority   priority;
0076 
0077   TEST_BEGIN();
0078 
0079   priority = RTEMS_MAXIMUM_PRIORITY / 4;
0080   priority = (priority * 3) + (priority / 2);
0081   printf(
0082     "Init - blocking task priority will be %" PRIdrtems_task_priority "\n",
0083      priority
0084   );
0085 
0086   puts( "Init - rtems_task_create - delay task - OK" );
0087   status = rtems_task_create(
0088      rtems_build_name( 'T', 'A', '1', ' ' ),
0089      priority,
0090      RTEMS_MINIMUM_STACK_SIZE,
0091      RTEMS_DEFAULT_OPTIONS,
0092      RTEMS_DEFAULT_ATTRIBUTES,
0093      &task_id
0094   );
0095   directive_failed( status, "rtems_task_create" );
0096 
0097   puts( "Init - rtems_task_start - delay task - OK" );
0098   status = rtems_task_start( task_id, Blocking_task, 0 );
0099   directive_failed( status, "rtems_task_start" );
0100 
0101   puts( "Init - rtems_region_create - OK" );
0102   status = rtems_region_create(
0103     rtems_build_name('R', 'N', '0', '1'),
0104     Region_Memory,
0105     sizeof( Region_Memory ),
0106     64,
0107     RTEMS_PRIORITY,
0108     &Region
0109   );
0110   directive_failed( status, "rtems_region_create of RN1" );
0111 
0112   puts( "Init - rtems_region_get_segment - get segment to consume memory" );
0113   rtems_region_get_segment(
0114     Region,
0115     ALLOC_SIZE,
0116     RTEMS_DEFAULT_OPTIONS,
0117     RTEMS_NO_TIMEOUT,
0118     &address_1
0119   );
0120   directive_failed( status, "rtems_region_get_segment" );
0121 
0122   puts( "Init - rtems_task_wake_after - let other task block - OK" );
0123   status = rtems_task_wake_after( RTEMS_MILLISECONDS_TO_TICKS(1000) );
0124   directive_failed( status, "rtems_task_wake_after" );
0125 
0126   puts( "Init - rtems_region_return_segment - return segment" );
0127   status = rtems_region_return_segment( Region, address_1 );
0128   directive_failed( status, "rtems_region_return_segment" );
0129 
0130   puts( "Init - rtems_task_wake_after - let other task run again - OK" );
0131   status = rtems_task_wake_after( RTEMS_MILLISECONDS_TO_TICKS(1000) );
0132   directive_failed( status, "rtems_task_wake_after" );
0133 
0134   TEST_END();
0135   rtems_test_exit(0);
0136 }
0137 
0138 /* configuration information */
0139 
0140 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0141 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0142 
0143 #define CONFIGURE_MAXIMUM_TASKS         2
0144 #define CONFIGURE_MAXIMUM_REGIONS       1
0145 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0146 
0147 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0148 
0149 #define CONFIGURE_INIT
0150 #include <rtems/confdefs.h>
0151 
0152 /* global variables */