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.
9 * (C) 2015 Pavel Pisa <pisa@cmp.felk.cvut.cz>
11 * Based on RTEMS example test by
12 * On-Line Applications Research Corporation (OAR).
16 #define CONFIGURE_INIT
17 #include <system_def.h>
20 #include "appl_config.h"
24 #include <rtems/error.h>
25 #include <rtems/monitor.h>
26 #include <rtems/shell.h>
27 #include <rtems/untar.h>
29 #ifdef CONFIG_OC_APP_APPDL_NET
30 #include <rtems/rtems_bsdnet.h>
32 #include "networkconfig.h"
33 #endif /*CONFIG_OC_APP_APPDL_NET*/
35 #include <sys/types.h>
37 #ifdef CONFIG_OC_APP_APPDL_NET
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
41 #endif /*CONFIG_OC_APP_APPDL_NET*/
46 #define CONFIGURE_SHELL_COMMANDS_INIT
47 #define CONFIGURE_SHELL_COMMANDS_ALL
48 #define CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING
49 #define CONFIGURE_SHELL_MOUNT_MSDOS
50 #define CONFIGURE_SHELL_MOUNT_NFS
52 #include <rtems/shellconfig.h>
54 #define BUILD_VERSION_STRING(major,minor,patch) \
55 __XSTRING(major) "." __XSTRING(minor) "." __XSTRING(patch)
57 #define RTEMS_VER_CODE VER_CODE(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
59 #if RTEMS_VER_CODE < VER_CODE(4,7,99)
60 #define rtems_shell_add_cmd shell_add_cmd
61 #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
62 shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,B19200 | CS8,m_forever)
63 #elif RTEMS_VER_CODE < VER_CODE(4,9,99)
64 #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
65 rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait)
68 extern int _binary_rootfs_tarfile_start;
69 extern int _binary_rootfs_tarfile_size;
70 #define TARFILE_START _binary_rootfs_tarfile_start
71 #define TARFILE_SIZE _binary_rootfs_tarfile_size
73 #ifdef CONFIG_OC_APP_APPDL_TELNETD
74 #include <rtems/telnetd.h>
76 rtems_telnetd_config_table rtems_telnetd_config;
78 void run_telnetd_command(char *device_name, void *arg)
80 rtems_shell_env_t shell_env;
82 rtems_shell_dup_current_env(&shell_env);
83 shell_env.taskname = NULL;
84 shell_env.devname = device_name;
85 rtems_shell_main_loop(&shell_env);
87 #endif /*CONFIG_OC_APP_APPDL_TELNETD*/
90 bad_rtems_status(rtems_status_code status, int fail_level, const char *text)
92 printf("ERROR: %s status %s", text, rtems_status_text(status));
93 status = rtems_task_delete( RTEMS_SELF );
96 int testcmd_forshell(int argc, char **argv)
99 printf("Command %s called\n",argv[0]);
102 printf("%s",argv[i]);
107 typedef int (*call_t)(int argc, char* argv[]);
109 int dlopen_forshell(int argc, char **argv)
113 char * message = "loaded";
114 char *call_file_name;
115 char *call_symbol = NULL;
120 printf ("file to load not specified\n");
123 call_file_name = argv[1];
126 call_symbol = argv[2];
131 handle = dlopen (call_file_name, RTLD_NOW | RTLD_GLOBAL);
134 printf("dlopen failed: %s\n", dlerror());
138 if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) < 0)
139 message = "dlinfo error checking unresolved status";
141 message = "has unresolved externals";
143 if (call_symbol == NULL) {
144 printf ("handle: %p %s\n", handle, message);
148 call = dlsym (handle, call_symbol);
151 printf("dlsym failed: symbol %s not found\n", call_symbol);
155 call_ret = call(argc, argv);
161 rtems_task_argument ignored
164 rtems_status_code status;
166 printf( "\n\nRTEMS v "
167 BUILD_VERSION_STRING(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
170 rtems_monitor_init(RTEMS_MONITOR_SUSPEND|RTEMS_MONITOR_GLOBAL);
171 /*rtems_capture_cli_init (0);*/
173 #ifdef CONFIG_OC_APP_APPDL_NET
174 if (rtems_bsdnet_initialize_network() < 0)
175 printf( "Network initialization failed\n");
177 printf( "Network initialization OK\n");
178 #endif /*CONFIG_OC_APP_APPDL_NET*/
181 printf( "Starting application " SW_VER_ID " v "
182 BUILD_VERSION_STRING(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH)
185 status = Untar_FromMemory((unsigned char *)(&TARFILE_START), (long)&TARFILE_SIZE);
187 printf("Untar_FromMemory returned %s\n",rtems_status_text(status));
189 Task_1_name = rtems_build_name( 'T', 'S', 'K', '1' );
191 status = rtems_task_create(
194 RTEMS_MINIMUM_STACK_SIZE+0x10000,
195 RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/,
196 RTEMS_DEFAULT_ATTRIBUTES,
199 check_rtems_status(status, 0, "rtems_task_create of Task_1");
201 status = rtems_task_start( Task_1_id, Task_1, 0 );
202 check_rtems_status(status, 0, "rtems_task_start of Task_1\n");
204 rtems_shell_init("SHLL",RTEMS_MINIMUM_STACK_SIZE+0x1000,
205 SHELL_TASK_PRIORITY,"/dev/console",1,0, NULL);
207 rtems_shell_add_cmd("testcmd", "app",
208 "test command for shell",
211 rtems_shell_add_cmd("dlopen", "app",
212 "runtime load object and call contained function",
215 //rtems_monitor_wakeup();
217 #ifdef CONFIG_OC_APP_APPDL_TELNETD
218 rtems_telnetd_config.command = run_telnetd_command;
219 rtems_telnetd_config.arg = NULL;
220 rtems_telnetd_config.priority = SHELL_TASK_PRIORITY;
221 rtems_telnetd_config.stack_size = RTEMS_MINIMUM_STACK_SIZE+0x1000;
222 rtems_telnetd_config.login_check = NULL;
223 rtems_telnetd_config.keep_stdio = 0;
225 status = rtems_telnetd_initialize();
226 check_rtems_status(status, 0, "rtems_telnetd_initialize\n");
227 #endif /*CONFIG_OC_APP_APPDL_TELNETD*/
229 status = rtems_task_delete( RTEMS_SELF );
231 printf( "*** END OF APPDL ***\n" );