source: network-demos/ttcp/init.c @ af0dafa

4.11netdemos-4-5-branchnetwork-demos-4-10-branchnetwork-demos-4-6-branchnetwork-demos-4-7-branchnetwork-demos-4-8-branchnetwork-demos-4-9-branchrtems-4-5-branch
Last change on this file since af0dafa was af0dafa, checked in by Joel Sherrill <joel.sherrill@…>, on 08/12/98 at 23:07:14

Added foreground task which can print KA9Q tables.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 * RTEMS configuration/initialization
3 *
4 * This program may be distributed and used for any purpose.
5 * I ask only that you:
6 *      1. Leave this author information intact.
7 *      2. Document any changes you make.
8 *
9 * W. Eric Norum
10 * Saskatchewan Accelerator Laboratory
11 * University of Saskatchewan
12 * Saskatoon, Saskatchewan, CANADA
13 * eric@skatter.usask.ca
14 */
15
16#include "../usercfg.h"
17
18#include <bsp.h>
19
20#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
21#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
22#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
23
24#define CONFIGURE_EXECUTIVE_RAM_SIZE    (512*1024)
25#define CONFIGURE_MAXIMUM_SEMAPHORES    20
26#define CONFIGURE_MAXIMUM_TASKS         20
27#define CONFIGURE_MAXIMUM_TIMERS        10
28#define CONFIGURE_MAXIMUM_PERIODS       1
29#define CONFIGURE_MICROSECONDS_PER_TICK 10486
30
31#define CONFIGURE_INIT
32rtems_task Init (rtems_task_argument argument);
33
34#include <confdefs.h>
35
36#include <stdio.h>
37#include <rtems_ka9q.h>
38
39#if (defined (USE_BOOTP))
40#include <bootp.h>
41#endif
42
43volatile int ttcp_running;
44
45/*
46 * Suspend execution for the specified number of seconds
47 */
48static void
49delay_task (int seconds)
50{
51        rtems_task_wake_after ((seconds * 1000000) / BSP_Configuration.microseconds_per_tick);
52}
53
54/*
55 * Display the contents of several KA9Q tables
56 */
57void
58show_ka9q_tables (void)
59{
60        printf ("\n****************** MALLOC Statistics ***************\n");
61        malloc_dump ();
62        printf ("\n****************** MBUF Statistics ***************\n");
63        mbufstat ();
64        mbufsizes ();
65        printf ("\n****************** Routing Table ***************\n");
66        rtems_ka9q_execute_command ("route");
67        printf ("\n****************** ARP Table ***************\n");
68        rtems_ka9q_execute_command ("arp");
69        printf ("\n****************** Driver Statistics ***************\n");
70        rtems_ka9q_execute_command ("ifconfig rtems");
71        printf ("\n****************** Ip Statistics ***************\n");
72        rtems_ka9q_execute_command ("ip status");
73        printf ("\n****************** ICMP Statistics ***************\n");
74        rtems_ka9q_execute_command ("icmp status");
75        printf ("\n****************** UDP Statistics ***************\n");
76        rtems_ka9q_execute_command ("udp status");
77        printf ("\n****************** TCP Statistics ***************\n");
78        rtems_ka9q_execute_command ("tcp status");
79}
80
81/*
82 * RTEMS Startup Task
83 */
84rtems_task
85Init (rtems_task_argument ignored)
86{
87        rtems_task_priority oldPri;
88        rtems_mode old_mode;
89
90#if (defined (m68040))
91        /*
92         * Hook up FPSP
93         */
94        M68kFPSPInstallExceptionHandlers ();
95
96        /*
97         * Turn on instruction cache
98         */
99        asm volatile ("cinva bc");
100        asm volatile ("movec %0,itt0" : : "d" (0x00ffc004));
101        asm volatile ("movec %0,dtt0" : : "d" (0x00ffc040));
102        asm volatile ("cinva bc\n\t"
103                        "movec %0,cacr" : : "d" (0x80008000));
104#endif
105
106        ttcp_running = 0;
107
108        /*
109         * Start KA9Q
110         */
111        rtems_task_set_priority (RTEMS_SELF, 30, &oldPri);
112        rtems_ka9q_start (30);
113
114        /*
115         * Hook up drivers
116         */
117        if (rtems_ka9q_execute_command ("attach rtems"
118                                        /* " rbuf 24 tbuf 5" */
119                                        " rbuf 100 tbuf 10"
120#if !(defined (USE_BOOTP))
121                                        " ip " MY_IP_ADDRESS
122#endif
123                                        " ether " MY_ETHERNET_ADDRESS))
124                rtems_panic ("Can't attach Ethernet driver.\n");
125
126#if (defined (TRACE_NETWORK_DRIVER))
127        /*
128         * Turn on debugging
129         */
130        puts( "Enabling debug mode of KA9Q" );
131        if (rtems_ka9q_execute_command ("trace rtems input <stdout>")
132         || rtems_ka9q_execute_command ("trace rtems output <stdout>")
133         || rtems_ka9q_execute_command ("trace rtems ascii <stdout>"))
134                rtems_panic ("Can't set tracing for Ethernet driver.\n");
135#endif
136
137
138        /*
139         * Configure the driver
140         */
141        if (rtems_ka9q_execute_command ("ifconfig rtems broadcast 255.255.255.255"))
142                rtems_panic ("Can't configure Ethernet driver.\n");
143
144        /*
145         * Add the ethernet broadcast address to the ARP table.
146         */
147        if (rtems_ka9q_execute_command ("arp add 255.255.255.255 ether FF:FF:FF:FF:FF:FF"))
148                rtems_panic ("Can't add broadcast entry to ARP table.\n");
149
150#if (defined (USE_BOOTP))
151        {
152        int i;
153        /*
154         * Get BOOTP information
155         */
156        for (i = 0 ; ; ) {
157                if (rtems_ka9q_execute_command ("bootp") == 0)
158                        break;
159                if (++i == 10)
160                        rtems_panic ("Can't get information from BOOTP server.\n");
161                delay_task (i);
162        }
163        if (BootpFileName)
164                printf ("BOOTP filename: `%s'\n", BootpFileName);
165        else
166                printf ("BOOTP -- No filename!\n");
167        }
168#else
169        if (rtems_ka9q_execute_command ("ifconfig rtems netmask 255.255.255.0"))
170                rtems_panic ("Can't set netmask.\n");
171        if (rtems_ka9q_execute_command ("route add default rtems"))
172                rtems_panic ("Can't add default route.\n");
173        printf ("Routing table after adding default route\n");
174        rtems_ka9q_execute_command ("route");
175#endif
176        /*
177         * Issue a gratuitous ARP request to update tables in
178         * other hosts on this network.
179         */
180        if (rtems_ka9q_execute_command ("arp gratuitous rtems"))
181                rtems_panic ("Can't send gratuitous ARP.\n");
182       
183        rtems_ka9q_execute_command ("tcp window");
184        rtems_ka9q_execute_command ("tcp window 4096");
185        rtems_ka9q_execute_command ("tcp window");
186
187        /*
188         * Whew!
189         */
190        printf ("NETWORK INITIALIZED!\n");
191
192        /*
193         * Let other tasks preempt this one
194         */
195        rtems_task_mode (RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &old_mode);
196
197        /*
198         * See if sockets work properly
199         */
200        test_network ();
201
202        /*
203         * Wait for characters from console terminal
204         */
205        do {
206                rtems_task_wake_after( 1 );
207        } while ( !ttcp_running );
208        printf( "Now accepting input from the console\n" );
209        for (;;) {
210                switch (getchar ()) {
211                case '\004':
212                        printf( "Exiting test\n" );
213                        return;
214
215                case 's':
216                        /*
217                         * Show what's been accomplished
218                         */
219                        show_ka9q_tables ();
220                        break;
221                }
222        }
223        exit (0);
224}
Note: See TracBrowser for help on using the repository browser.