int ethernet_service(struct sim *s) { /* fpga --> tap */ ETH_SOURCE_ACK = 1; if(ETH_SOURCE_STB == 1) { s->eth_txbuffer[s->eth_txbuffer_len] = ETH_SOURCE_DATA; s->eth_txbuffer_len++; } else { if(s->eth_last_source_stb) { eth_write(s, s->eth_txbuffer, s->eth_txbuffer_len); s->eth_txbuffer_len = 0; } } s->eth_last_source_stb = ETH_SOURCE_STB; /* tap --> fpga */ if(s->eth_rxbuffer_len == 0) { ETH_SINK_STB = 0; s->eth_rxbuffer_pos = 0; s->eth_rxbuffer_len = eth_read(s, s->eth_rxbuffer); } else { if(s->eth_rxbuffer_pos < MAX(s->eth_rxbuffer_len, 60)) { ETH_SINK_STB = 1; ETH_SINK_DATA = s->eth_rxbuffer[s->eth_rxbuffer_pos]; s->eth_rxbuffer_pos++; } else { ETH_SINK_STB = 0; s->eth_rxbuffer_len = 0; memset(s->eth_rxbuffer, 0, 1532); } } }
int read_command(char** pkt){ if(DEBUG>10) std::cout<<"DEBUG[commands.cpp] read_command(*{NULL})"<<std::endl; *pkt=0; int n=eth_read(0); // testing >>> //std::cout<<"TESTING: read_command, copy wdat to rdat"<<std::endl; //n=24; //memcpy(rdat,wdat,4*n); //n=RAMPAGE_SIZE+4; //memcpy(rdat,(const void*)&wdat[nn],n); //rdat[3] = (rdat[3]&0xff) + 0xd0; //if(time(0)%10==0) rdat[10]++; //if(time(0)%15==0) rdat[2]++; //if(time(0)%2==0 && (rdat[0]&0xff) == 0xf3) rdat[2]++; // <<< testing if(n<=6){ if(DEBUG>10) std::cout<<"DEBUG[commands.cpp] read_command return -2 <== n="<<n<<" <= 6"<<std::endl; return -2; } *pkt = rdat; // currently just setting the pointer, but I may want to make a copy (otherwise I can just use rbuf) if(DEBUG>20){ std::cout<<"DEBUG[commands.cpp] read_command read in packet with "<<n<<" bytes:"<<std::endl; dumphex(n,*pkt); std::cout<<std::endl; } int num=0; if ((rdat[0]&0xff) == 0xf0 && (rdat[1]&0xff) == 0xf0) num=0; else if((rdat[0]&0xff) == 0xf1 && (rdat[1]&0xff) == 0xf1) num=1; else if((rdat[0]&0xff) == 0xf2 && (rdat[1]&0xff) == 0xf2) num=2; else if((rdat[0]&0xff) == 0xf3 && (rdat[1]&0xff) == 0xf3) num=3; // return packet for F3 will now start with f3f3 else if((rdat[0]&0xff) == 0xf5 && (rdat[1]&0xff) == 0xf5) num=5; else if((rdat[0]&0xff) == 0xf7 && (rdat[1]&0xff) == 0xf7) num=7; else if((rdat[0]&0xff) == 0xfd && (rdat[1]&0xff) == 0xfd) num=0xd; else if((rdat[0]&0xff) == 0xfe && (rdat[1]&0xff) == 0xfe) num=0xe; else num=-1; if(num==3){ // compare the address word from the header to the first word (-0xa000+0xd000) in the data if( (rdat[2]&0xff) != (rdat[4]&0xff) || (rdat[3]&0xff) != ((rdat[5]&0xff) - 0xa0 + 0xd0) ){ if(DEBUG>10){ std::cout<<"DEBUG[commands.cpp] Address words do not agree: "; dumphex(6,rdat); std::cout<<std::endl; } num = -num; } } if(DEBUG>10) std::cout<<"DEBUG[commands.cpp] read_command return "<<num<<std::endl; return num; }
int main(int argc,char *argv[]) { int n; char *tmp; char devname[12]; // check arguments if(argc != 2) return usage(argc, argv); // set and check device name tmp=argv[1]; if(strcmp(tmp,"1") && strcmp(tmp,"2")) return usage(argc, argv); sprintf(devname, "/dev/schar%s",tmp); printf("devname %s\n",devname); // open device eth_open(devname); eth_register_mac(); while(1){ // never ending loop, Ctrl-C to stop // receive data n=eth_read(0); if (n<=6) continue; printf(" nread %d \n",n); printf(" nrdat %d \n",nrdat); printf("Dump: \""); dumphex(n,rpkt); printf("\"\n"); printf("Use Ctrl-C to stop.\n"); } // close device eth_close(); return 0; }
static void eth_dw_isr(struct device *port) { struct eth_runtime *context = port->driver_data; uint32_t base_addr = context->base_addr; uint32_t int_status; int_status = eth_read(base_addr, REG_ADDR_STATUS); #ifdef CONFIG_SHARED_IRQ /* If using with shared IRQ, this function will be called * by the shared IRQ driver. So check here if the interrupt * is coming from the GPIO controller (or somewhere else). */ if ((int_status & STATUS_RX_INT) == 0) { return; } #endif eth_rx(port); /* Acknowledge the interrupt. */ eth_write(base_addr, REG_ADDR_STATUS, STATUS_NORMAL_INT | STATUS_RX_INT); }
static int eth_initialize(struct device *port) { struct eth_runtime *context = port->driver_data; const struct eth_config *config = port->config->config_info; uint32_t base_addr; union { struct { uint8_t bytes[6]; uint8_t pad[2]; } __attribute__((packed)); uint32_t words[2]; } mac_addr; if (!eth_setup(port)) return -EPERM; base_addr = context->base_addr; /* Read the MAC address from the device. */ mac_addr.words[1] = eth_read(base_addr, REG_ADDR_MACADDR_HI); mac_addr.words[0] = eth_read(base_addr, REG_ADDR_MACADDR_LO); net_set_mac(mac_addr.bytes, sizeof(mac_addr.bytes)); /* Initialize the frame filter enabling unicast messages */ eth_write(base_addr, REG_ADDR_MAC_FRAME_FILTER, MAC_FILTER_4_PM); /* Initialize transmit descriptor. */ context->tx_desc.tdes0 = 0; context->tx_desc.tdes1 = 0; context->tx_desc.buf1_ptr = (uint8_t *)context->tx_buf; context->tx_desc.tx_end_of_ring = 1; context->tx_desc.first_seg_in_frm = 1; context->tx_desc.last_seg_in_frm = 1; context->tx_desc.tx_end_of_ring = 1; /* Initialize receive descriptor. */ context->rx_desc.rdes0 = 0; context->rx_desc.rdes1 = 0; context->rx_desc.buf1_ptr = (uint8_t *)context->rx_buf; context->rx_desc.own = 1; context->rx_desc.first_desc = 1; context->rx_desc.last_desc = 1; context->rx_desc.rx_buf1_sz = UIP_BUFSIZE; context->rx_desc.rx_end_of_ring = 1; /* Install transmit and receive descriptors. */ eth_write(base_addr, REG_ADDR_RX_DESC_LIST, (uint32_t)&context->rx_desc); eth_write(base_addr, REG_ADDR_TX_DESC_LIST, (uint32_t)&context->tx_desc); eth_write(base_addr, REG_ADDR_MAC_CONF, /* Set the RMII speed to 100Mbps */ MAC_CONF_14_RMII_100M | /* Enable full-duplex mode */ MAC_CONF_11_DUPLEX | /* Enable transmitter */ MAC_CONF_3_TX_EN | /* Enable receiver */ MAC_CONF_2_RX_EN); eth_write(base_addr, REG_ADDR_INT_ENABLE, INT_ENABLE_NORMAL | /* Enable receive interrupts */ INT_ENABLE_RX); /* Mask all the MMC interrupts */ eth_write(base_addr, REG_MMC_RX_INTR_MASK, MMC_DEFAULT_MASK); eth_write(base_addr, REG_MMC_TX_INTR_MASK, MMC_DEFAULT_MASK); eth_write(base_addr, REG_MMC_RX_IPC_INTR_MASK, MMC_DEFAULT_MASK); eth_write(base_addr, REG_ADDR_DMA_OPERATION, /* Enable receive store-and-forward mode for simplicity. */ OP_MODE_25_RX_STORE_N_FORWARD | /* Enable transmit store-and-forward mode for simplicity. */ OP_MODE_21_TX_STORE_N_FORWARD | /* Place the transmitter state machine in the Running state. */ OP_MODE_13_START_TX | /* Place the receiver state machine in the Running state. */ OP_MODE_1_START_RX); SYS_LOG_INF("Enabled 100M full-duplex mode."); net_driver_ethernet_register_tx(eth_net_tx); config->config_func(port); return 0; }
void read_getwork(SOCKET s) { uint16_t size, offset, start_address; uint16_t state = 0; uint8_t a = 0, b = 0, c = 0, d = 0, e = 0; uint8_t *write_ptr; uint16_t write_len = 0; while(1) { size = (read_sock_reg(s, Sn_RX_RSR) << 8) | read_sock_reg(s, Sn_RX_RSR+1); if (size == 0) { if (established(s) == 1) continue; break; } offset = (read_sock_reg(s, Sn_RX_RD) << 8) | read_sock_reg(s, Sn_RX_RD+1); offset &= 0x7FF; // TODO: RXBUF_BASE + s << 8??? start_address = RXBUF_BASE + offset; a = b; b = c; c = d; d = e; eth_read(start_address, &e); printf("%c", e); offset = (read_sock_reg(s, Sn_RX_RD) << 8) | read_sock_reg(s, Sn_RX_RD+1); offset += 1; write_sock_reg(s, Sn_RX_RD, offset >> 8); write_sock_reg(s, Sn_RX_RD+1, offset & 0xFF); write_sock_reg(s, Sn_CR, RECV); /*if (write_len > 0 && ((e >= '0' && e <= '9') || (e >= 'a' && e <= 'f') || (e >= 'A' && e <= 'F')) ) { if (write_len & 1) { *write_ptr = (hex_to_nibble(d) << 4) | hex_to_nibble(e); write_ptr++; } write_len--; state++; } if(state == 152+64) break; if(a == 'a' && b == 't' && c == 'e' && d == '"' && e == ':') { write_ptr = midstate; write_len = 64; }*/ /*if(a == 'a' && b == 't' && c == 'a' && d == '"' && e == ':') { write_ptr = hdata; write_len = 152; }*/ } printf("\n\n"); //send(s, midstate, 32); //send(s, hdata, 76); }