X-Git-Url: https://git.llucax.com/z.facultad/66.09/etherled.git/blobdiff_plain/cbf2122a2f610a2b92f1dfcb0f554b4bf7c4757e..6d441bbe709092d070c21b92aeeabfb82cb5982f:/src/dp8390.c?ds=sidebyside diff --git a/src/dp8390.c b/src/dp8390.c index 6392307..30b3fb5 100644 --- a/src/dp8390.c +++ b/src/dp8390.c @@ -1,21 +1,11 @@ // vim: set et sw=4 sts=4 : +#include "debug.h" #include "eth.h" #include "dp8390.h" -#ifdef DEBUG -void sleep(unsigned char); -#ifdef SDCC -static xdata at 0x0080 byte leds0; -static xdata at 0x00c0 byte leds1; -#else -static byte xdata leds0 _at_ 0x0080; -static byte xdata leds1 _at_ 0x00c0; -#endif -#endif - /// Datos persistentes del módulo -static union +static union // Unión porque nunca se usan ambos juntos { byte send_len; ///> Tamaño del frame que será enviado byte next_pkt; ///> Próximo frame a obtener @@ -149,6 +139,8 @@ static void reset() */ bool netdev_init() { + byte i; + // Set IOR & IOW as they're active low. IOR = 1; IOW = 1; @@ -201,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); @@ -236,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); @@ -274,7 +255,7 @@ void netdev_send_start() write_reg(RBCR1, 0u); // Initiate DMA transfer of uip_buf & uip_appdata buffers to RTL8019AS. - write_reg(CR, WRITE | STA); + write_reg(CR, WRITE); } /** Escribe un byte al buffer de la placa de red para ser enviado @@ -327,7 +308,7 @@ void netdev_send_end() * @return Cantidad de bytes del frame leído */ byte netdev_recv_start() -{ +{ // Check if the rx buffer has overflowed. if (read_reg(ISR) & OVW) { @@ -344,17 +325,9 @@ byte netdev_recv_start() if (read_reg(BNRY) == current) { -#ifdef DEBUG - leds1 = ~0x01; - leds2 = ~read_reg(ISR); - sleep(5); - leds1 = ~0x02; - leds2 = ~read_reg(BNRY); - sleep(5); - leds1 = ~0x04; - leds2 = ~current; - sleep(5); -#endif + printb(read_reg(ISR), 0x01); + printb(read_reg(BNRY), 0x02); + printb(current, 0x04); reset(); } return 0u; @@ -400,7 +373,7 @@ byte netdev_recv_start() // Set remote DMA byte count registers to packet header length. write_reg(RBCR0, sizeof(struct buf_hdr_t)); - write_reg(RBCR1, 0u); + write_reg(RBCR1, 0x00); // Clear remote DMA complete interrupt status register bit. write_reg(ISR, RDC); @@ -412,7 +385,11 @@ byte netdev_recv_start() buf_hdr.status = read_reg(RDMA); // Save next packet pointer. - buf_hdr.next = persistent.next_pkt = read_reg(RDMA); + 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; // Retrieve packet data length and subtract CRC bytes. buf_hdr.len = read_reg(RDMA) - sizeof(struct buf_hdr_t); @@ -422,14 +399,15 @@ byte netdev_recv_start() || ((buf_hdr.status & 0x0F) != RXSOK) || read_reg(RDMA)) // Parte alta del tamaño { - ABORT_DMA(START); // Termina DMA - write_reg(BNRY, buf_hdr.next - 1); // Pasa al próximo frame + // 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); @@ -440,7 +418,7 @@ byte netdev_recv_start() // Initiate DMA transfer of packet data. write_reg(CR, READ); - + return buf_hdr.len; } return 0; @@ -472,6 +450,6 @@ void netdev_recv_end() ABORT_DMA(START); // Advance boundary pointer to next packet start. - write_reg(BNRY, persistent.next_pkt - 1); + write_reg(BNRY, persistent.next_pkt); }