]> rtime.felk.cvut.cz Git - rtems-devel.git/blob - rtems-omk-template/appnet/init.c
Switch network configuration in appnet test from BOOTP to DHCP.
[rtems-devel.git] / rtems-omk-template / appnet / 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 #include <rtems/rtems_bsdnet.h>
34
35 #include "networkconfig.h"
36
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
41 #include <string.h>
42 #include <unistd.h>
43
44 #define CONFIGURE_SHELL_COMMANDS_INIT
45 #define CONFIGURE_SHELL_COMMANDS_ALL
46 #define CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING
47 #define CONFIGURE_SHELL_MOUNT_MSDOS
48 #define CONFIGURE_SHELL_MOUNT_NFS
49
50 #include <rtems/shellconfig.h>
51
52 #define BUILD_VERSION_STRING(major,minor,patch) \
53         __XSTRING(major) "." __XSTRING(minor) "." __XSTRING(patch)
54
55 #define RTEMS_VER_CODE VER_CODE(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
56
57 #if RTEMS_VER_CODE < VER_CODE(4,7,99)
58   #define rtems_shell_add_cmd shell_add_cmd
59   #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
60                 shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,B19200 | CS8,m_forever)
61 #elif RTEMS_VER_CODE < VER_CODE(4,9,99)
62   #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
63           rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait)
64 #endif
65
66 void 
67 bad_rtems_status(rtems_status_code status, int fail_level, const char *text)
68 {
69   printf("ERROR: %s status %s", text, rtems_status_text(status));
70   status = rtems_task_delete( RTEMS_SELF );
71 }
72
73 int testcmd_forshell(int argc, char **argv)
74 {
75   int i;
76   printf("Command %s called\n",argv[0]);
77   for(i=1;i<argc;i++)
78     if(argv[i])
79       printf("%s",argv[i]);
80   printf("\n");
81   return 0;
82 }
83
84 rtems_task Init(
85   rtems_task_argument ignored
86 )
87 {
88   rtems_status_code status;
89
90   printf( "\n\nRTEMS v "
91           BUILD_VERSION_STRING(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
92           "\n");
93   
94   rtems_monitor_init(RTEMS_MONITOR_SUSPEND|RTEMS_MONITOR_GLOBAL);
95   /*rtems_capture_cli_init (0);*/
96
97   if (rtems_bsdnet_initialize_network() < 0)
98     printf( "Network initialization failed\n");
99   else
100     printf( "Network initialization OK\n");
101
102
103   printf( "Starting application " SW_VER_ID " v "
104           BUILD_VERSION_STRING(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH)
105           "\n" );
106
107   Task_1_name = rtems_build_name( 'T', 'S', 'K', '1' );
108     
109   status = rtems_task_create(
110      Task_1_name,
111      TASK_1_PRIORITY,
112      RTEMS_MINIMUM_STACK_SIZE+0x10000,
113      RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/,
114      RTEMS_DEFAULT_ATTRIBUTES,
115      &Task_1_id
116   );
117   check_rtems_status(status, 0, "rtems_task_create of Task_1");
118
119   status = rtems_task_start( Task_1_id, Task_1, 0 );
120   check_rtems_status(status, 0, "rtems_task_start of Task_1\n");
121
122   rtems_shell_init("SHLL",RTEMS_MINIMUM_STACK_SIZE+0x1000,
123               SHELL_TASK_PRIORITY,"/dev/console",1,0, NULL);
124
125   rtems_shell_add_cmd("testcmd", "app",
126                 "test command for shell",
127                 testcmd_forshell);
128
129   //rtems_monitor_wakeup();
130
131   status = rtems_task_delete( RTEMS_SELF );
132   
133   printf( "*** END OF TEST2 ***\n" );
134   exit( 0 );
135 }