// 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
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);
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
* @return Cantidad de bytes del frame leído
*/
byte netdev_recv_start()
-{
+{
// Check if the rx buffer has overflowed.
if (read_reg(ISR) & OVW)
{
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;
// 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);
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);
|| ((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);
ABORT_DMA(START);
// Advance boundary pointer to next packet start.
- write_reg(BNRY, persistent.next_pkt - 1);
+ write_reg(BNRY, persistent.next_pkt);
}