]> rtime.felk.cvut.cz Git - rtems-devel.git/blob - rtems-omk-template/appdl/init.c
0b798d90fe688e061e0ba35b7326196d88e0885d
[rtems-devel.git] / rtems-omk-template / appdl / 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 "appl_config.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <rtems/error.h>
31 #include <rtems/monitor.h>
32 #include <rtems/shell.h>
33 #include <rtems/untar.h>
34
35 #ifdef CONFIG_OC_APP_APPDL_NET
36 #include <rtems/rtems_bsdnet.h>
37
38 #include "networkconfig.h"
39 #endif /*CONFIG_OC_APP_APPDL_NET*/
40
41 #include <sys/types.h>
42
43 #ifdef CONFIG_OC_APP_APPDL_NET
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
47 #endif /*CONFIG_OC_APP_APPDL_NET*/
48
49 #include <string.h>
50 #include <unistd.h>
51
52 #define CONFIGURE_SHELL_COMMANDS_INIT
53 #define CONFIGURE_SHELL_COMMANDS_ALL
54 #define CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING
55 #define CONFIGURE_SHELL_MOUNT_MSDOS
56 #define CONFIGURE_SHELL_MOUNT_NFS
57
58 #include <rtems/shellconfig.h>
59
60 #define BUILD_VERSION_STRING(major,minor,patch) \
61         __XSTRING(major) "." __XSTRING(minor) "." __XSTRING(patch)
62
63 #define RTEMS_VER_CODE VER_CODE(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
64
65 #if RTEMS_VER_CODE < VER_CODE(4,7,99)
66   #define rtems_shell_add_cmd shell_add_cmd
67   #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
68                 shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,B19200 | CS8,m_forever)
69 #elif RTEMS_VER_CODE < VER_CODE(4,9,99)
70   #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
71           rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait)
72 #endif
73
74 extern int _binary_rootfs_tarfile_start;
75 extern int _binary_rootfs_tarfile_size;
76 #define TARFILE_START _binary_rootfs_tarfile_start
77 #define TARFILE_SIZE _binary_rootfs_tarfile_size
78
79 #ifdef CONFIG_OC_APP_APPDL_TELNETD
80 #include <rtems/telnetd.h>
81
82 rtems_telnetd_config_table rtems_telnetd_config;
83
84 void run_telnetd_command(char *device_name,  void *arg)
85 {
86   rtems_shell_env_t shell_env;
87
88   rtems_shell_dup_current_env(&shell_env);
89   shell_env.taskname = NULL;
90   shell_env.devname = device_name;
91   rtems_shell_main_loop(&shell_env);
92 }
93 #endif /*CONFIG_OC_APP_APPDL_TELNETD*/
94
95 void 
96 bad_rtems_status(rtems_status_code status, int fail_level, const char *text)
97 {
98   printf("ERROR: %s status %s", text, rtems_status_text(status));
99   status = rtems_task_delete( RTEMS_SELF );
100 }
101
102 int testcmd_forshell(int argc, char **argv)
103 {
104   int i;
105   printf("Command %s called\n",argv[0]);
106   for(i=1;i<argc;i++)
107     if(argv[i])
108       printf("%s",argv[i]);
109   printf("\n");
110   return 0;
111 }
112
113 rtems_task Init(
114   rtems_task_argument ignored
115 )
116 {
117   rtems_status_code status;
118
119   printf( "\n\nRTEMS v "
120           BUILD_VERSION_STRING(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
121           "\n");
122   
123   rtems_monitor_init(RTEMS_MONITOR_SUSPEND|RTEMS_MONITOR_GLOBAL);
124   /*rtems_capture_cli_init (0);*/
125
126  #ifdef CONFIG_OC_APP_APPDL_NET
127   if (rtems_bsdnet_initialize_network() < 0)
128     printf( "Network initialization failed\n");
129   else
130     printf( "Network initialization OK\n");
131  #endif /*CONFIG_OC_APP_APPDL_NET*/
132
133
134   printf( "Starting application " SW_VER_ID " v "
135           BUILD_VERSION_STRING(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH)
136           "\n" );
137
138   status = Untar_FromMemory((unsigned char *)(&TARFILE_START), (long)&TARFILE_SIZE);
139
140   printf("Untar_FromMemory returned %s\n",rtems_status_text(status));
141
142   Task_1_name = rtems_build_name( 'T', 'S', 'K', '1' );
143
144   status = rtems_task_create(
145      Task_1_name,
146      TASK_1_PRIORITY,
147      RTEMS_MINIMUM_STACK_SIZE+0x10000,
148      RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/,
149      RTEMS_DEFAULT_ATTRIBUTES,
150      &Task_1_id
151   );
152   check_rtems_status(status, 0, "rtems_task_create of Task_1");
153
154   status = rtems_task_start( Task_1_id, Task_1, 0 );
155   check_rtems_status(status, 0, "rtems_task_start of Task_1\n");
156
157   rtems_shell_init("SHLL",RTEMS_MINIMUM_STACK_SIZE+0x1000,
158               SHELL_TASK_PRIORITY,"/dev/console",1,0, NULL);
159
160   rtems_shell_add_cmd("testcmd", "app",
161                 "test command for shell",
162                 testcmd_forshell);
163
164   //rtems_monitor_wakeup();
165
166  #ifdef CONFIG_OC_APP_APPDL_TELNETD
167   rtems_telnetd_config.command = run_telnetd_command;
168   rtems_telnetd_config.arg = NULL;
169   rtems_telnetd_config.priority = SHELL_TASK_PRIORITY;
170   rtems_telnetd_config.stack_size = RTEMS_MINIMUM_STACK_SIZE+0x1000;
171   rtems_telnetd_config.login_check = NULL;
172   rtems_telnetd_config.keep_stdio = 0;
173
174   status = rtems_telnetd_initialize();
175   check_rtems_status(status, 0, "rtems_telnetd_initialize\n");
176  #endif /*CONFIG_OC_APP_APPDL_TELNETD*/
177
178   status = rtems_task_delete( RTEMS_SELF );
179
180   printf( "*** END OF TEST2 ***\n" );
181   exit( 0 );
182 }