[ab29fef] | 1 | /* |
---|
[b84f1fdc] | 2 | * COPYRIGHT (c) 1989-2009. |
---|
[ab29fef] | 3 | * On-Line Applications Research Corporation (OAR). |
---|
| 4 | * |
---|
| 5 | * The license and distribution terms for this file may be |
---|
| 6 | * found in the file LICENSE in this distribution or at |
---|
| 7 | * http://www.rtems.com/license/LICENSE. |
---|
| 8 | * |
---|
| 9 | * $Id$ |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | #include <tmacros.h> |
---|
| 13 | |
---|
[b84f1fdc] | 14 | rtems_task Init( |
---|
| 15 | rtems_task_argument argument |
---|
| 16 | ); |
---|
| 17 | rtems_timer_service_routine Malloc_From_TSR( |
---|
| 18 | rtems_id ignored_id, |
---|
| 19 | void *ignored_address |
---|
| 20 | ); |
---|
| 21 | |
---|
[ab29fef] | 22 | rtems_id Timer_id[ 3 ]; /* array of timer ids */ |
---|
| 23 | rtems_name Timer_name[ 3 ]; /* array of timer names */ |
---|
| 24 | |
---|
| 25 | volatile int TSR_fired; |
---|
| 26 | volatile void *TSR_malloc_ptr; |
---|
| 27 | |
---|
| 28 | rtems_timer_service_routine Malloc_From_TSR( |
---|
| 29 | rtems_id ignored_id, |
---|
| 30 | void *ignored_address |
---|
| 31 | ) |
---|
| 32 | { |
---|
| 33 | rtems_status_code status; |
---|
| 34 | |
---|
| 35 | TSR_fired = 2; |
---|
| 36 | puts( "TSR: calling malloc" ); |
---|
| 37 | TSR_malloc_ptr = malloc( 64 ); |
---|
| 38 | |
---|
| 39 | puts( "TSR: calling free" ); |
---|
| 40 | free( (void *) TSR_malloc_ptr ); |
---|
| 41 | |
---|
| 42 | puts( "TSR: delaying with rtems_task_wake_after" ); |
---|
| 43 | status = rtems_task_wake_after( TICKS_PER_SECOND / 2 ); |
---|
| 44 | directive_failed( status, "rtems_task_wake_after" ); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | rtems_task Init( |
---|
| 48 | rtems_task_argument argument |
---|
| 49 | ) |
---|
| 50 | { |
---|
| 51 | rtems_status_code status; |
---|
| 52 | |
---|
| 53 | puts( "\n\n*** TEST 45 ***" ); |
---|
| 54 | |
---|
| 55 | status = rtems_timer_initiate_server( |
---|
| 56 | RTEMS_TIMER_SERVER_DEFAULT_PRIORITY, |
---|
| 57 | RTEMS_MINIMUM_STACK_SIZE, |
---|
| 58 | RTEMS_DEFAULT_ATTRIBUTES |
---|
| 59 | ); |
---|
| 60 | directive_failed( status, "rtems_timer_initiate_server" ); |
---|
| 61 | |
---|
| 62 | /* |
---|
| 63 | * Initialize Timers |
---|
| 64 | */ |
---|
| 65 | |
---|
| 66 | Timer_name[ 1 ] = rtems_build_name( 'T', 'M', '1', ' ' ); |
---|
| 67 | Timer_name[ 2 ] = rtems_build_name( 'T', 'M', '2', ' ' ); |
---|
| 68 | |
---|
| 69 | puts( "INIT - rtems_timer_create - creating timer 1" ); |
---|
| 70 | status = rtems_timer_create( Timer_name[ 1 ], &Timer_id[ 1 ] ); |
---|
| 71 | directive_failed( status, "rtems_timer_create" ); |
---|
| 72 | printf( "INIT - timer 1 has id (0x%x)\n", Timer_id[ 1 ] ); |
---|
| 73 | |
---|
| 74 | puts( "INIT - rtems_timer_create - creating timer 2" ); |
---|
| 75 | status = rtems_timer_create( Timer_name[ 2 ], &Timer_id[ 2 ] ); |
---|
| 76 | directive_failed( status, "rtems_timer_create" ); |
---|
| 77 | printf( "INIT - timer 2 has id (0x%x)\n", Timer_id[ 2 ] ); |
---|
| 78 | |
---|
| 79 | /* |
---|
| 80 | * Schedule malloc TSR for 1 second from now |
---|
| 81 | */ |
---|
| 82 | |
---|
| 83 | TSR_fired = 0; |
---|
| 84 | TSR_malloc_ptr = (void *) 0xa5a5a5; |
---|
| 85 | puts( "TA1 - rtems_timer_server_fire_after - timer 1 in 1 seconds" ); |
---|
| 86 | status = rtems_timer_server_fire_after( |
---|
| 87 | Timer_id[ 1 ], |
---|
| 88 | 1 * TICKS_PER_SECOND, |
---|
| 89 | Malloc_From_TSR, |
---|
| 90 | NULL |
---|
| 91 | ); |
---|
| 92 | directive_failed( status, "rtems_timer_server_fire_after" ); |
---|
| 93 | |
---|
| 94 | puts( "TA1 - rtems_task_wake_after - 2 second" ); |
---|
| 95 | status = rtems_task_wake_after( 2 * TICKS_PER_SECOND ); |
---|
| 96 | directive_failed( status, "rtems_task_wake_after" ); |
---|
| 97 | |
---|
| 98 | if ( TSR_fired == 2 && |
---|
| 99 | (TSR_malloc_ptr && TSR_malloc_ptr != (void *)0xa5a5a5) ) |
---|
| 100 | puts( "TSR appears to have executed OK" ); |
---|
| 101 | else { |
---|
| 102 | printf( "FAILURE ptr=%p TSR_fired=%d\n", TSR_malloc_ptr, TSR_fired ); |
---|
| 103 | rtems_test_exit( 0 ); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /* |
---|
| 107 | * Delete timer and exit test |
---|
| 108 | */ |
---|
| 109 | puts( "TA1 - timer_deleting - timer 1" ); |
---|
| 110 | status = rtems_timer_delete( Timer_id[ 1 ] ); |
---|
| 111 | directive_failed( status, "rtems_timer_delete" ); |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | puts( "*** END OF TEST 45 *** " ); |
---|
| 115 | rtems_test_exit( 0 ); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | #define CONFIGURE_INIT |
---|
| 119 | /* configuration information */ |
---|
| 120 | |
---|
| 121 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 122 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 123 | |
---|
| 124 | /* Two Tasks: Init and Timer Server */ |
---|
| 125 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
| 126 | #define CONFIGURE_MAXIMUM_TIMERS 2 |
---|
| 127 | #define CONFIGURE_INIT_TASK_STACK_SIZE (RTEMS_MINIMUM_STACK_SIZE * 2) |
---|
| 128 | |
---|
| 129 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 130 | |
---|
| 131 | #define CONFIGURE_EXTRA_TASK_STACKS (1 * RTEMS_MINIMUM_STACK_SIZE) |
---|
| 132 | |
---|
| 133 | #include <rtems/confdefs.h> |
---|
| 134 | |
---|