X-Git-Url: https://git.llucax.com/z.facultad/66.09/etherled.git/blobdiff_plain/05000dec2685a88aaf9bd3c20c8861e62c94696c..6d441bbe709092d070c21b92aeeabfb82cb5982f:/src/dp8390.c?ds=inline diff --git a/src/dp8390.c b/src/dp8390.c index 946ebc7..30b3fb5 100644 --- a/src/dp8390.c +++ b/src/dp8390.c @@ -139,6 +139,8 @@ static void reset() */ bool netdev_init() { + byte i; + // Set IOR & IOW as they're active low. IOR = 1; IOW = 1; @@ -191,18 +193,11 @@ bool netdev_init() write_reg(RSAR0, 0u); // En la dirección 0x0000 write_reg(RSAR1, 0u); write_reg(CR, READ); // Comienza lectura - eth_addr_local[0] = read_reg(RDMA); - read_reg(RDMA); // Ignoramos porque viene como un word - eth_addr_local[1] = read_reg(RDMA); - read_reg(RDMA); // Ignoramos porque viene como un word - eth_addr_local[2] = read_reg(RDMA); - read_reg(RDMA); // Ignoramos porque viene como un word - eth_addr_local[3] = read_reg(RDMA); - read_reg(RDMA); // Ignoramos porque viene como un word - eth_addr_local[4] = read_reg(RDMA); - read_reg(RDMA); // Ignoramos porque viene como un word - eth_addr_local[5] = read_reg(RDMA); - read_reg(RDMA); // Ignoramos porque viene como un word + for (i = 0; i < ETH_ADDR_SIZE; ++i) + { + eth_addr_local[i] = read_reg(RDMA); + read_reg(RDMA); // Ignoramos porque viene como un word + } // Abort/ complete DMA operation. ABORT_DMA(STOP); @@ -226,12 +221,8 @@ bool netdev_init() write_reg(CURR, RX_PAGE_START + 1); // Set physical address - write_reg(PAR0, eth_addr_local[0]); - write_reg(PAR1, eth_addr_local[1]); - write_reg(PAR2, eth_addr_local[2]); - write_reg(PAR3, eth_addr_local[3]); - write_reg(PAR4, eth_addr_local[4]); - write_reg(PAR5, eth_addr_local[5]); + for (i = 0; i < ETH_ADDR_SIZE; ++i) + write_reg(PAR_BASE + i, eth_addr_local[i]); // Restart RTL8019AS. write_reg(CR, START); @@ -318,9 +309,6 @@ void netdev_send_end() */ byte netdev_recv_start() { - // Indicamos que no se leyó el paquete - persistent.next_pkt = 0; - // Check if the rx buffer has overflowed. if (read_reg(ISR) & OVW) { @@ -378,7 +366,6 @@ byte netdev_recv_start() // Check if last packet has been removed from rx buffer. if(bnry == current) { - print(0x0000); // Clear packet received interrupt flag. write_reg(ISR, PRX | RXE); return 0u; @@ -401,30 +388,26 @@ byte netdev_recv_start() buf_hdr.next = read_reg(RDMA); // Indicamos cual es el próximo paquete para cuando termine + // FIXME poner más lindo para que consuma menos memoria persistent.next_pkt = buf_hdr.next - 1; - printb(bnry, 0x03); - printb(current, 0x07); - printb(buf_hdr.next, 0x0f); - // Retrieve packet data length and subtract CRC bytes. buf_hdr.len = read_reg(RDMA) - sizeof(struct buf_hdr_t); // Si es muy grande, muy chico o hubo error, lo descartamos if ((buf_hdr.len < MIN_PACKET_LEN) || (buf_hdr.len > MAX_PACKET_LEN) || ((buf_hdr.status & 0x0F) != RXSOK) - || (current = read_reg(RDMA))) // Parte alta del tamaño + || read_reg(RDMA)) // Parte alta del tamaño { - printb(buf_hdr.next, 0x1f); - printb(buf_hdr.status, 0x3f); - printb(buf_hdr.len, 0x7f); - printb(current, 0xff); + // Abort/ complete DMA operation. + ABORT_DMA(START); + + // Advance boundary pointer to next packet start. + write_reg(BNRY, persistent.next_pkt); + return 0; } - // Abort/ complete DMA operation. - ABORT_DMA(START); - // Set remote DMA start address registers to packet data. write_reg(RSAR0, sizeof(struct buf_hdr_t)); write_reg(RSAR1, bnry); @@ -435,7 +418,7 @@ byte netdev_recv_start() // Initiate DMA transfer of packet data. write_reg(CR, READ); - + return buf_hdr.len; } return 0; @@ -464,10 +447,9 @@ uint16 netdev_recv_word() void netdev_recv_end() { // Abort/ complete DMA operation. - ABORT_DMA(STOP); + ABORT_DMA(START); // Advance boundary pointer to next packet start. - if (persistent.next_pkt) - write_reg(BNRY, persistent.next_pkt); + write_reg(BNRY, persistent.next_pkt); }