Пример #1
0
void ethProcess()
{
	static uint32_t lastCheck = 0;

	if (ticks - lastCheck >= 1000) {
		lastCheck = ticks;

		TByteBuffer b;
		if (ethPrepareBuffer(&b, 2))
		{
			uint16_t type = 0x0000;
			BYTEBUFFER_APPEND(&b, type);
			ethSendPacket(&b);
			ethFreeBuffer(&b);
		}

		if (dodump)
			enc28j60Dump();
	}

	static uint32_t lastARPTime = 0;
	if (ticks - lastARPTime >= ARP_TMR_INTERVAL)
	{
		lastARPTime = ticks;
		etharp_tmr();
	}

	static uint32_t lastDHCPTime1 = 0;
	if (ticks - lastDHCPTime1 >= DHCP_COARSE_TIMER_MSECS)
	{
		lastDHCPTime1 = ticks;
		dhcp_coarse_tmr();
	}

	static uint32_t lastDHCPTime2 = 0;
	if (ticks - lastDHCPTime2 >= DHCP_FINE_TIMER_MSECS)
	{
		lastDHCPTime2 = ticks;
		dhcp_fine_tmr();
	}

	if (IO_IS_LOW(INT_ETH))
	{
		uint8_t eir = enc28j60ReadControl(EIR);
		myprintf("eir 0x%02x\r\n", eir);
		if (eir & EIR_LINKIF)
		{
			uint16_t phir = enc28j60ReadPhyWord(PHIR);
			if (phir & PHIR_PLNKIF)
			{
				uint16_t stat = enc28j60ReadPhyWord(PHSTAT2);
				if (stat & PHSTAT2_LSTAT) // link is up
				{
					myprintf("LINK UP\r\n");
					netif_set_up(&eth_netif);
					dhcp_start(&eth_netif);
				}
				else // link is down or was for a period
				{
					myprintf("LINK DOWN\r\n");
					dhcp_stop(&eth_netif);
					netif_set_down(&eth_netif);
				}
			}
			myprintf("phir: 0x%04x\r\n", phir);
		}
		enc28j60_if_input(&eth_netif);
	}
}
Пример #2
0
void ethProcess()
{
	static uint32_t lastCheck = 0;

	if (ticks - lastCheck >= 1000) {
		lastCheck = ticks;

		// TProvHeader header;
		// provPrepareHeader(&header);
		
		// header.type = PROVIDER_TYPE_CONTROL;
		// header.cmd = 0;
		// provSendPacket(&header, sizeof(header));

		if (dodump)
			enc28j60Dump();
	}

	static uint32_t lastARPTime = 0;
	if (ticks - lastARPTime >= ARP_TMR_INTERVAL)
	{
		lastARPTime = ticks;
		etharp_tmr();
	}

	static uint32_t lastDHCPTime1 = 0;
	if (ticks - lastDHCPTime1 >= DHCP_COARSE_TIMER_MSECS)
	{
		lastDHCPTime1 = ticks;
		dhcp_coarse_tmr();
	}

	static uint32_t lastDHCPTime2 = 0;
	if (ticks - lastDHCPTime2 >= DHCP_FINE_TIMER_MSECS)
	{
		lastDHCPTime2 = ticks;
		dhcp_fine_tmr();
	}

	if (IO_IS_LOW(INT_ETH))
	{
		uint8_t eir = enc28j60ReadControl(EIR);
		myprintf("eir 0x%02x\r\n", eir);
		if (eir & EIR_LINKIF)
		{
			uint16_t phir = enc28j60ReadPhyWord(PHIR);
			if (phir & PHIR_PLNKIF)
			{
				uint16_t stat = enc28j60ReadPhyWord(PHSTAT2);
				if (stat & PHSTAT2_LSTAT) // link is up
				{
					myprintf("LINK UP\r\n");
					netif_set_up(&eth_netif);
					dhcp_start(&eth_netif);
				}
				else // link is down or was for a period
				{
					myprintf("LINK DOWN\r\n");
					dhcp_stop(&eth_netif);
					netif_set_down(&eth_netif);
				}
			}
			myprintf("phir: 0x%04x\r\n", phir);
		}
		enc28j60_if_input(&eth_netif);
	}
}