#include "basic_io.h" #include "test.h" #include "LCD.h" #include "DM9000A.C" #include #include "system.h" #include "altera_avalon_pio_regs.h" #define MAX_ETH 1024 #define NONE_TYPE 0 #define ARP_TYPE 1 #define IP_TYPE 2 #define ET_PRE 0x08 #define ET_IP 0x00 #define ET_ARP 0x06 #define PIO_READ IORD_ALTERA_AVALON_PIO_DATA #define PIO_WRITE IOWR_ALTERA_AVALON_PIO_DATA //unsigned int aaa,rx_len,i,packet_num; //unsigned char RXT[68]; unsigned const char broadcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; unsigned const char my_mac[] = {0x01,0x60,0x6E,0x11,0x02,0x0F}; void ethernet_interrupts() { int i; unsigned int rp_err, rx_len, type, data, ip_len; unsigned char RXT[MAX_ETH], mac_addr[6]; type = NONE_TYPE; printf("ethernet interrupt...\n"); rp_err=ReceivePacket (RXT,&rx_len); if(!rp_err) { //good debug info may be to print this whole ethernet packet here before processing it printf("receiving packet... (len %d)\n",rx_len); for(i=0;i> 8) & 0xFF; TXT[1] = (mac_addr_h) & 0xFF; TXT[2] = (mac_addr_l >> 24) & 0xFF; TXT[3] = (mac_addr_l >> 16) & 0xFF; TXT[4] = (mac_addr_l >> 8) & 0xFF; TXT[5] = (mac_addr_l) & 0xFF; //now set the src addr - which is always our addr for(i=0; i<6; i++) { TXT[i+6] = my_mac[i]; } //now set ether type to ip TXT[12] = ET_PRE; TXT[13] = ET_IP; //now fill in with data ti = 14;//start after the ehter type len = PIO_READ(CPU_IP_LENGTH_BASE); for (i=0; i> 24) & 0xFF; TXT[ti++] = (data >> 16) & 0xFF; TXT[ti++] = (data >> 8) & 0xFF; TXT[ti++] = data & 0xFF; } //read all data, finish handshake PIO_WRITE(CPU_IP_DONE_BASE, 1); while(PIO_READ(CPU_IP_READY_BASE)); PIO_WRITE(CPU_IP_DONE_BASE, 0); //send packet TODO make sure ti is correct here //print TXT before sending? printf("transmitting...\n"); TransmitPacket(TXT,ti); } if (PIO_READ(CPU_ARP_READY_BASE)) { printf("trying to send an arp packet\n"); //first get and set the dest addr mac_addr_h = PIO_READ(CPU_ARP_MAC_H_BASE); mac_addr_l = PIO_READ(CPU_ARP_MAC_L_BASE); TXT[0] = (mac_addr_h >> 8) & 0xFF; TXT[1] = (mac_addr_h) & 0xFF; TXT[2] = (mac_addr_l >> 24) & 0xFF; TXT[3] = (mac_addr_l >> 16) & 0xFF; TXT[4] = (mac_addr_l >> 8) & 0xFF; TXT[5] = (mac_addr_l) & 0xFF; //now set the src addr - which is always our addr for(i=0; i<6; i++) { TXT[i+6] = my_mac[i]; } //now set ether type to arp TXT[12] = ET_PRE; TXT[13] = ET_ARP; //now fill in with data ti = 14;//start after the ether type for (i=0; i<7; i++) { PIO_WRITE(CPU_ARP_INDEX_BASE, i); //TODO this should be fine, but make sure it is reading right data for index here data = PIO_READ(CPU_ARP_DATA_BASE); //printf("send arp: %08x\n",data); TXT[ti++] = (data >> 24) & 0xFF; TXT[ti++] = (data >> 16) & 0xFF; TXT[ti++] = (data >> 8) & 0xFF; TXT[ti++] = data & 0xFF; } //read all data, finish handshake PIO_WRITE(CPU_ARP_DONE_BASE, 1); while(PIO_READ(CPU_ARP_READY_BASE)); PIO_WRITE(CPU_ARP_DONE_BASE, 0); //send packet TODO make sure ti is correct here //print TXT before sending? //for(i=0; i