]> rtime.felk.cvut.cz Git - rtems-devel.git/blob - rtems-omk-template/appsmptest/init.c
0773fcef0494aa45cd3b088b603fffebae5f0169
[rtems-devel.git] / rtems-omk-template / appsmptest / init.c
1 /*  Init
2  *
3  *  This routine is the initialization task for this test program.
4  *  It is called from init_exec and has the responsibility for creating
5  *  and starting the tasks that make up the test.  If the time of day
6  *  clock is required for the test, it should also be set to a known
7  *  value by this function.
8  *
9  *  Input parameters:  NONE
10  *
11  *  Output parameters:  NONE
12  *
13  *  COPYRIGHT (c) 1989-1999.
14  *  On-Line Applications Research Corporation (OAR).
15  *
16  *  The license and distribution terms for this file may be
17  *  found in the file LICENSE in this distribution or at
18  *  http://www.rtems.com/license/LICENSE.
19  *
20  *  $Id: init.c,v 1.12.4.1 2003/09/04 18:46:30 joel Exp $
21  */
22
23 #define CONFIGURE_INIT
24 #include <system_def.h>
25 #include "system.h"
26 #include "app_def.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <rtems/error.h>
30 #include <rtems/monitor.h>
31 #include <rtems/shell.h>
32
33 #define CONFIGURE_SHELL_COMMANDS_INIT
34 #define CONFIGURE_SHELL_COMMANDS_ALL
35 #define CONFIGURE_SHELL_MOUNT_MSDOS
36
37 #include <rtems/shellconfig.h>
38
39 #define BUILD_VERSION_STRING(major,minor,patch) \
40         __XSTRING(major) "." __XSTRING(minor) "." __XSTRING(patch)
41
42 #define RTEMS_VER_CODE VER_CODE(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
43
44 #if RTEMS_VER_CODE < VER_CODE(4,7,99)
45   #define rtems_shell_add_cmd shell_add_cmd
46   #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
47                 shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,B19200 | CS8,m_forever)
48 #elif RTEMS_VER_CODE < VER_CODE(4,9,99)
49   #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
50           rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait)
51 #endif
52
53 void
54 bad_rtems_status(rtems_status_code status, int fail_level, const char *text)
55 {
56   printf("ERROR: %s status %s", text, rtems_status_text(status));
57   status = rtems_task_delete( RTEMS_SELF );
58 }
59
60 int testcmd_forshell(int argc, char **argv)
61 {
62   int i;
63   printf("Command %s called\n",argv[0]);
64   for(i=1;i<argc;i++)
65     if(argv[i])
66       printf("%s",argv[i]);
67   printf("\n");
68   return 0;
69 }
70
71 rtems_task Init(
72   rtems_task_argument ignored
73 )
74 {
75   rtems_status_code status;
76   cpu_set_t         cpuset;
77
78   printf( "\n\nRTEMS v "
79           BUILD_VERSION_STRING(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
80           "\n");
81
82   rtems_monitor_init(RTEMS_MONITOR_SUSPEND|RTEMS_MONITOR_GLOBAL);
83   /*rtems_capture_cli_init (0);*/
84
85   printf( "Starting application " SW_VER_ID " v "
86           BUILD_VERSION_STRING(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH)
87   "\n" );
88
89   Task_1_name = rtems_build_name( 'T', 'S', 'K', '1' );
90
91   status = rtems_task_create(
92      Task_1_name,
93      TASK_1_PRIORITY,
94      RTEMS_MINIMUM_STACK_SIZE+0x10000,
95      RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/,
96      RTEMS_DEFAULT_ATTRIBUTES,
97      &Task_1_id
98   );
99   check_rtems_status(status, 0, "rtems_task_create of Task_1");
100
101   CPU_ZERO(&cpuset);
102   CPU_SET(0, &cpuset);
103
104   status = rtems_task_set_affinity(
105     Task_1_id,
106     sizeof(cpuset),
107     &cpuset
108   );
109   check_rtems_status(status, 0, "rtems_task_set_affinity of Task_1");
110
111   status = rtems_task_start( Task_1_id, Task_1, (rtems_task_argument)1 );
112   check_rtems_status(status, 0, "rtems_task_start of Task_1\n");
113
114   Task_2_name = rtems_build_name( 'T', 'S', 'K', '2' );
115
116   status = rtems_task_create(
117      Task_2_name,
118      TASK_2_PRIORITY,
119      RTEMS_MINIMUM_STACK_SIZE+0x10000,
120      RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/,
121      RTEMS_DEFAULT_ATTRIBUTES,
122      &Task_2_id
123   );
124   check_rtems_status(status, 0, "rtems_task_create of Task_2");
125
126   CPU_ZERO(&cpuset);
127   CPU_SET(1, &cpuset);
128
129   status = rtems_task_set_affinity(
130     Task_2_id,
131     sizeof(cpuset),
132     &cpuset
133   );
134   check_rtems_status(status, 0, "rtems_task_set_affinity of Task_2");
135
136   status = rtems_task_start( Task_2_id, Task_1, (rtems_task_argument)2 );
137   check_rtems_status(status, 0, "rtems_task_start of Task_2\n");
138
139   rtems_shell_init("SHLL",RTEMS_MINIMUM_STACK_SIZE+0x1000,
140               SHELL_TASK_PRIORITY,"/dev/console",1,0, NULL);
141
142   rtems_shell_add_cmd("testcmd", "app",
143                 "test command for shell",
144                 testcmd_forshell);
145
146   //rtems_monitor_wakeup();
147
148   status = rtems_task_delete( RTEMS_SELF );
149
150   printf( "*** END OF TEST2 ***\n" );
151   exit( 0 );
152 }