1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2009. |
---|
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 | |
---|
14 | #define MAXIMUM_STACKS 3 |
---|
15 | |
---|
16 | typedef struct { |
---|
17 | uint8_t Space[CPU_STACK_MINIMUM_SIZE]; |
---|
18 | } StackMemory_t; |
---|
19 | |
---|
20 | int stackToAlloc = 0; |
---|
21 | StackMemory_t Stacks[3]; |
---|
22 | void *StackDeallocated = NULL; |
---|
23 | |
---|
24 | void *StackAllocator(uint32_t size) |
---|
25 | { |
---|
26 | if (stackToAlloc < MAXIMUM_STACKS) |
---|
27 | return &Stacks[stackToAlloc++]; |
---|
28 | return NULL; |
---|
29 | } |
---|
30 | |
---|
31 | void StackDeallocator(void *stack) |
---|
32 | { |
---|
33 | StackDeallocated = stack; |
---|
34 | } |
---|
35 | |
---|
36 | rtems_task Init( |
---|
37 | rtems_task_argument ignored |
---|
38 | ) |
---|
39 | { |
---|
40 | rtems_status_code rc; |
---|
41 | rtems_id taskId; |
---|
42 | rtems_id taskId1; |
---|
43 | |
---|
44 | puts( "\n\n*** TEST OF STACK ALLOCATOR PLUGIN ***" ); |
---|
45 | |
---|
46 | puts( "Init - create task TA1 to use custom stack allocator - OK" ); |
---|
47 | rc = rtems_task_create( |
---|
48 | rtems_build_name( 'T', 'A', '1', ' ' ), |
---|
49 | 1, |
---|
50 | RTEMS_MINIMUM_STACK_SIZE, |
---|
51 | RTEMS_DEFAULT_MODES, |
---|
52 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
53 | &taskId |
---|
54 | ); |
---|
55 | directive_failed( rc, "rtems_task_create of TA1" ); |
---|
56 | |
---|
57 | puts( "Init - create task TA1 to have custom stack allocator fail" ); |
---|
58 | rc = rtems_task_create( |
---|
59 | rtems_build_name( 'F', 'A', 'I', 'L' ), |
---|
60 | 1, |
---|
61 | RTEMS_MINIMUM_STACK_SIZE, |
---|
62 | RTEMS_DEFAULT_MODES, |
---|
63 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
64 | &taskId1 |
---|
65 | ); |
---|
66 | fatal_directive_status( rc, RTEMS_UNSATISFIED, "rtems_task_create of FAIL" ); |
---|
67 | |
---|
68 | puts( "Init - delete task TA1 to use custom stack deallocator - OK" ); |
---|
69 | rc = rtems_task_delete( taskId ); |
---|
70 | directive_failed( rc, "rtems_task_delete of TA1" ); |
---|
71 | |
---|
72 | puts( "*** END OF OF STACK ALLOCATOR PLUGIN TEST ***" ); |
---|
73 | rtems_test_exit(0); |
---|
74 | } |
---|
75 | |
---|
76 | /* configuration information */ |
---|
77 | |
---|
78 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
79 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
80 | |
---|
81 | #define CONFIGURE_TASK_STACK_ALLOCATOR StackAllocator |
---|
82 | #define CONFIGURE_TASK_STACK_DEALLOCATOR StackDeallocator |
---|
83 | |
---|
84 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
85 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
86 | |
---|
87 | #define CONFIGURE_INIT |
---|
88 | #include <rtems/confdefs.h> |
---|
89 | |
---|
90 | /* global variables */ |
---|