summaryrefslogtreecommitdiff
path: root/ttcp/init.c
blob: 4df07c9bbe36c7f34f9af48bd447d7ecd2e7e4bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * RTEMS configuration/initialization
 * 
 * This program may be distributed and used for any purpose.
 * I ask only that you:
 *      1. Leave this author information intact.
 *      2. Document any changes you make.
 *
 * W. Eric Norum
 * Saskatchewan Accelerator Laboratory
 * University of Saskatchewan
 * Saskatoon, Saskatchewan, CANADA
 * eric@skatter.usask.ca
 */

#include "../usercfg.h"

#include <bsp.h>

#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_EXECUTIVE_RAM_SIZE    (512*1024)
#define CONFIGURE_MAXIMUM_SEMAPHORES    20
#define CONFIGURE_MAXIMUM_TASKS         20
#define CONFIGURE_MAXIMUM_TIMERS        10
#define CONFIGURE_MAXIMUM_PERIODS       1
#define CONFIGURE_MICROSECONDS_PER_TICK 10486

#define CONFIGURE_INIT
rtems_task Init (rtems_task_argument argument);

#include <confdefs.h>

#include <stdio.h>
#include <rtems_ka9q.h>

#if (defined (USE_BOOTP))
#include <bootp.h>
#endif

volatile int ttcp_running;

/*
 * Suspend execution for the specified number of seconds
 */
static void
delay_task (int seconds)
{
	rtems_task_wake_after ((seconds * 1000000) / BSP_Configuration.microseconds_per_tick);
}

/*
 * Display the contents of several KA9Q tables
 */
void
show_ka9q_tables (void)
{
	printf ("\n****************** MALLOC Statistics ***************\n");
	malloc_dump ();
	printf ("\n****************** MBUF Statistics ***************\n");
	mbufstat ();
	mbufsizes ();
	printf ("\n****************** Routing Table ***************\n");
	rtems_ka9q_execute_command ("route");
	printf ("\n****************** ARP Table ***************\n");
	rtems_ka9q_execute_command ("arp");
	printf ("\n****************** Driver Statistics ***************\n");
	rtems_ka9q_execute_command ("ifconfig rtems");
	printf ("\n****************** Ip Statistics ***************\n");
	rtems_ka9q_execute_command ("ip status");
	printf ("\n****************** ICMP Statistics ***************\n");
	rtems_ka9q_execute_command ("icmp status");
	printf ("\n****************** UDP Statistics ***************\n");
	rtems_ka9q_execute_command ("udp status");
	printf ("\n****************** TCP Statistics ***************\n");
	rtems_ka9q_execute_command ("tcp status");
}

/*
 * RTEMS Startup Task
 */
rtems_task
Init (rtems_task_argument ignored)
{
	rtems_task_priority oldPri;
	rtems_mode old_mode;

#if (defined (m68040))
	/*
	 * Hook up FPSP
	 */
	M68kFPSPInstallExceptionHandlers ();

	/*
	 * Turn on instruction cache
	 */
	asm volatile ("cinva bc");
	asm volatile ("movec %0,itt0" : : "d" (0x00ffc004));
	asm volatile ("movec %0,dtt0" : : "d" (0x00ffc040));
	asm volatile ("cinva bc\n\t"
			"movec %0,cacr" : : "d" (0x80008000));
#endif

	ttcp_running = 0;

	/*
	 * Start KA9Q
	 */
	rtems_task_set_priority (RTEMS_SELF, 30, &oldPri);
	rtems_ka9q_start (30);

	/*
	 * Hook up drivers
	 */
	if (rtems_ka9q_execute_command ("attach rtems"
					/* " rbuf 24 tbuf 5" */
					" rbuf 100 tbuf 10"
#if !(defined (USE_BOOTP))
					" ip " MY_IP_ADDRESS
#endif
					" ether " MY_ETHERNET_ADDRESS))
		rtems_panic ("Can't attach Ethernet driver.\n");

#if (defined (TRACE_NETWORK_DRIVER))
	/*
	 * Turn on debugging
	 */
	puts( "Enabling debug mode of KA9Q" );
	if (rtems_ka9q_execute_command ("trace rtems input <stdout>")
	 || rtems_ka9q_execute_command ("trace rtems output <stdout>")
	 || rtems_ka9q_execute_command ("trace rtems ascii <stdout>"))
		rtems_panic ("Can't set tracing for Ethernet driver.\n");
#endif


	/*
	 * Configure the driver
	 */
	if (rtems_ka9q_execute_command ("ifconfig rtems broadcast 255.255.255.255"))
		rtems_panic ("Can't configure Ethernet driver.\n");

	/*
	 * Add the ethernet broadcast address to the ARP table.
	 */
	if (rtems_ka9q_execute_command ("arp add 255.255.255.255 ether FF:FF:FF:FF:FF:FF"))
		rtems_panic ("Can't add broadcast entry to ARP table.\n");

#if (defined (USE_BOOTP))
	{
	int i;
	/*
	 * Get BOOTP information
	 */
	for (i = 0 ; ; ) {
		if (rtems_ka9q_execute_command ("bootp") == 0)
			break;
		if (++i == 10)
			rtems_panic ("Can't get information from BOOTP server.\n");
		delay_task (i);
	}
	if (BootpFileName)
		printf ("BOOTP filename: `%s'\n", BootpFileName);
	else
		printf ("BOOTP -- No filename!\n");
	}
#else
	if (rtems_ka9q_execute_command ("ifconfig rtems netmask 255.255.255.0"))
		rtems_panic ("Can't set netmask.\n");
	if (rtems_ka9q_execute_command ("route add default rtems"))
		rtems_panic ("Can't add default route.\n");
	printf ("Routing table after adding default route\n");
	rtems_ka9q_execute_command ("route");
#endif
	/*
	 * Issue a gratuitous ARP request to update tables in
	 * other hosts on this network.
	 */
	if (rtems_ka9q_execute_command ("arp gratuitous rtems"))
		rtems_panic ("Can't send gratuitous ARP.\n");
	
	rtems_ka9q_execute_command ("tcp window");
	rtems_ka9q_execute_command ("tcp window 4096");
	rtems_ka9q_execute_command ("tcp window");

	/*
	 * Whew!
	 */
	printf ("NETWORK INITIALIZED!\n");

	/*
	 * Let other tasks preempt this one
	 */
	rtems_task_mode (RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &old_mode);

	/*
	 * See if sockets work properly
	 */
	test_network ();

	/*
	 * Wait for characters from console terminal
	 */
	do {
		rtems_task_wake_after( 1 );
	} while ( !ttcp_running );
        printf( "Now accepting input from the console\n" );
	for (;;) {
		switch (getchar ()) {
		case '\004':
			printf( "Exiting test\n" );
			return;

		case 's':
			/*
			 * Show what's been accomplished
			 */
			show_ka9q_tables ();
			break;
		}
	}
	exit (0);
}