예제 #1
0
void uos_init (void)
{
	/* Configure 16 Mbyte of external Flash memory at nCS3. */
	MC_CSCON3 = MC_CSCON_WS (4);		/* Wait states  */

	/* Выделяем место для динамической памяти */
	extern unsigned __bss_end[];
#ifdef ELVEES_DATA_SDRAM
	/* Динамическая память в SDRAM */
	if (((unsigned) __bss_end & 0xF0000000) == 0x80000000)
		mem_init (&pool, (unsigned) __bss_end, 0x82000000);
	else
		mem_init (&pool, (unsigned) __bss_end, 0xa2000000);
#else
	/* Динамическая память в CRAM */
	extern unsigned _estack[];
	mem_init (&pool, (unsigned) __bss_end, (unsigned) _estack - 256);
#endif

	timer_init (&timer, KHZ, 20);

	/*
	 * Create a group of two locks: timer and eth.
	 */
	mutex_group_t *g = mutex_group_init (group, sizeof(group));
	mutex_group_add (g, &eth->netif.lock);
	mutex_group_add (g, &timer.decisec);

	arp = arp_init (arp_data, sizeof(arp_data), &ip);
	ip_init (&ip, &pool, 70, &timer, arp, g);

	/*
	 * Create interface eth0
	 */
	const unsigned char my_macaddr[] = { 0, 9, 0x94, 0xf1, 0xf2, 0xf3 };
	eth_init (eth, "eth0", 80, &pool, arp, my_macaddr);

	unsigned char my_ip[] = { 172, 0, 0, 18 };
	route_add_netif (&ip, &route, my_ip, 24, &eth->netif);
	
	h_udp_task = task_create (udp_task, 0, "udp", 65,	stack_udp, sizeof (stack_udp));
    init_trace();
}
예제 #2
0
void uos_init (void)
{
	printf (&debug, "\nCPU speed is %d MHz\n", KHZ/1000);

	/* Используем только внутреннюю память.
	 * Оставляем 256 байтов для задачи "idle". */
	extern unsigned __bss_end[], _estack[];
	mem_init (&pool, (unsigned) __bss_end, (unsigned) _estack - 256);

	timer_init (&timer, KHZ, 50);
	gpanel_init (&display, &font_fixed6x8);
	gpanel_clear (&display, 0);
	puts (&display, "Testing TCP.\r\n");

	/*
	 * Create a group of two locks: timer and eth.
	 */
	mutex_group_t *g = mutex_group_init (group, sizeof(group));
	mutex_group_add (g, &eth.netif.lock);
	mutex_group_add (g, &timer.decisec);

	arp = arp_init (arp_data, sizeof(arp_data), &ip);
	ip_init (&ip, &pool, 70, &timer, arp, g);

	/*
	 * Create interface eth0
	 */
	const unsigned char my_macaddr[] = { 0, 9, 0x94, 0xf1, 0xf2, 0xf3 };
	k5600bg1_init (&eth, "eth0", 80, &pool, arp, my_macaddr);

	unsigned char my_ip[] = { 192, 168, 20, 222 };
	route_add_netif (&ip, &route, my_ip, 24, &eth.netif);

	task_create (tcp_task, 0, "tcp", 20,
		stack_tcp, sizeof (stack_tcp));
//	task_create (poll_task, 0, "poll", 1,
//		stack_poll, sizeof (stack_poll));
	task_create (console_task, 0, "cons", 10,
		stack_console, sizeof (stack_console));
}
예제 #3
0
void main_task (void *data)
{
	buf_t *p, *r;
	unsigned char addr [4], *output;
	unsigned short port;
#if 1
	mutex_group_t *g;

	debug_printf ("\n\n*** Testing SNMP on UART 1 ***\n\n");

	arp = arp_init (arp_data, sizeof(arp_data), 0);

	/*
	 * Create a group of two locks: timer and eth.
	 */
	g = mutex_group_init (group, sizeof(group));
	mutex_group_add (g, &eth.netif.lock);
	mutex_group_add (g, &timer.decisec);
	ip = mem_alloc (&pool, sizeof (*ip));
	ip_init (ip, &pool, 70, &timer, arp, g);
	arp->ip = ip;

	/*
	 * Create interface eth0 144.206.181.251 / 255.255.255.0
	 */
	/* Reset чипа CS8900A заведен на порт G3.
	 * Он в прямой логике, надо подать туда 0. */
	outb_far (0x08, DDRG);
	clearb_far (3, PORTG);

	/* Добавляем один wait state, т.к. иначе cs8900 не успевает. */
	setb (SRW, MCUCR);
	cs8900_init (&eth, "eth0", 80, &pool, arp);
	route_add_netif (ip, &route, "\220\316\265\373", 24, &eth.netif);

	/*
	 * Add default route to 144.206.181.254
	 */
	route_add_gateway (ip, &default_route, "\0\0\0\0", 0, "\220\316\265\376");
	if (! default_route.netif)
		debug_printf ("test_snmp: no interface for default route!\n");

	snmp_init (&snmp, &pool, ip, snmp_tab, sizeof(snmp_tab),
		SNMP_SERVICE_REPEATER, "Testing SNMP",
		"1.3.6.1.4.1.20520.1.1");

#endif
	udp_socket (&sock, ip, 161);
	debug_printf ("test_snmp: mem available = %u bytes\n",
		mem_available (&pool));

	for (;;) {
		p = udp_recvfrom (&sock, addr, &port);
		debug_printf ("test_snmp: mem available = %u bytes\n",
			mem_available (&pool));

		r = buf_alloc (&pool, 1500, 50);
		if (! r) {
			debug_printf ("test_snmp: out of memory!\n");
			buf_free (p);
			continue;
		}

		output = snmp_execute (&snmp, p->payload, p->len, r->payload,
			r->len, addr);
		buf_free (p);
		if (! output) {
			buf_free (r);
			continue;
		}

		buf_add_header (r, - (output - r->payload));
		udp_sendto (&sock, r, addr, port);
	}
}
예제 #4
0
void uos_init (void)
{
	mutex_group_t *g;

	/* Baud 9600. */
	uart_init (&uart, 0, PRIO_UART, KHZ, 9600);
	timer_init (&timer, KHZ, 50);
	watchdog_alive ();

	/* Configure control pins. */
	control_link_led (0);
        gpio_config (PIN_DCD, 1);               /* P0 - output */
        gpio_config (PIN_CTS, 1);		/* P4 - output */
        gpio_config (PIN_LINK, 1);              /* P16 - output */
        gpio_config (PIN_DSR, 1);		/* P21 - output */

	configure_ram (RAM_START, RAM_START + RAM_SIZE, REFRESH_USEC, IO_START);
	mem_init (&pool, RAM_START, RAM_START + RAM_SIZE);
	watchdog_alive ();

	/* Configure Ethernet. */
	eth = mem_alloc (&pool, sizeof (eth_t));
	if (! eth) {
		debug_printf ("No memory for eth_t\n");
		uos_halt (1);
	}

	/*
	 * Create a group of two locks: timer and eth.
	 */
	g = mutex_group_init (group, sizeof(group));
	mutex_group_add (g, &eth->netif.lock);
	mutex_group_add (g, &timer.decisec);
	ip = mem_alloc (&pool, sizeof (*ip));
	if (! ip) {
		debug_printf ("No memory for ip_t\n");
		uos_halt (1);
	}
	arp = arp_init (arp_data, sizeof(arp_data), ip);
	ip_init (ip, &pool, PRIO_IP, &timer, arp, g);

	/*
	 * Create interface eth0 144.206.181.188 / 255.255.255.0
	 */
	eth_init (eth, "eth0", PRIO_ETH_RX, PRIO_ETH_TX, &pool, arp);
	route_add_netif (ip, &route, (unsigned char*) "\220\316\265\274",
		24, &eth->netif);

	/* Configure HDLC. */
	hdlc = mem_alloc (&pool, sizeof (hdlc_t));
	if (! hdlc) {
		debug_printf ("No memory for hdlc_t\n");
		uos_halt (1);
	}
	hdlc_init (hdlc, 0, "hdlc0", PRIO_HDLC_RX, PRIO_HDLC_TX,
		&pool, KHZ * 1000);
	hdlc->callback_receive = receive_hdlc;

	stack_console = mem_alloc (&pool, CONSOLE_STACKSZ);
	assert (stack_console != 0);
	task_create (main_console, 0, "console", PRIO_CONSOLE,
		stack_console, CONSOLE_STACKSZ);

	stack_poll = mem_alloc (&pool, POLL_STACKSZ);
	assert (stack_poll != 0);
	task_create (main_poll, 0, "poll", PRIO_POLL,
		stack_poll, POLL_STACKSZ);

	stack_telnet = mem_alloc (&pool, TELNET_STACKSZ);
	assert (stack_telnet != 0);
	task_create (main_telnet, 0, "telnet", PRIO_TELNET,
		stack_telnet, TELNET_STACKSZ);
}