X-Git-Url: https://git.llucax.com/z.facultad/66.09/etherled.git/blobdiff_plain/cbf2122a2f610a2b92f1dfcb0f554b4bf7c4757e..8f48e4df85125bfd22f8c93b5952deccc9f6af72:/src/dp8390.c?ds=inline diff --git a/src/dp8390.c b/src/dp8390.c index 6392307..642c36f 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 @@ -131,7 +121,7 @@ static void reset() SELECT_REG_PAGE(0); // Clear rx buffer overflow & packet received interrupt flags. - write_reg(ISR, PRX | OVW); + write_reg(ISR, OVW); // Re-itialise transmit configuration reg for normal operation. write_reg(TCR, MODE0); @@ -274,7 +264,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 +317,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 +334,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 +382,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 +394,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 +408,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); @@ -472,6 +459,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); }