From e8f3c49127f0cd878119d6f1292a9d5d06dfa4ff Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 24 Apr 2019 11:32:40 +0200 Subject: [PATCH] software/libnet/microudp: rearrange send_packet, add comments and remove txlen padding --- litex/soc/software/libnet/microudp.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/litex/soc/software/libnet/microudp.c b/litex/soc/software/libnet/microudp.c index 955340fe..3a02f7f9 100644 --- a/litex/soc/software/libnet/microudp.c +++ b/litex/soc/software/libnet/microudp.c @@ -114,14 +114,20 @@ typedef union { unsigned char raw[ETHMAC_SLOT_SIZE]; } ethernet_buffer; +static unsigned int rxslot; static unsigned int rxlen; static ethernet_buffer *rxbuffer; + +static unsigned int txslot; static unsigned int txlen; static ethernet_buffer *txbuffer; static void send_packet(void) { - unsigned int txslot; + /* wait buffer to be available */ + while(!(ethmac_sram_reader_ready_read())); + + /* fill txbuffer */ #ifndef HW_PREAMBLE_CRC unsigned int crc; crc = crc32(&txbuffer->raw[8], txlen-8); @@ -131,7 +137,6 @@ static void send_packet(void) txbuffer->raw[txlen+3] = (crc & 0xff000000) >> 24; txlen += 4; #endif - txlen += 4; //FIXME: padding? #ifdef DEBUG_MICROUDP_TX int j; @@ -141,13 +146,14 @@ static void send_packet(void) printf("\n"); #endif + /* fill slot, length and send */ + ethmac_sram_reader_slot_write(txslot); ethmac_sram_reader_length_write(txlen); ethmac_sram_reader_start_write(1); - while(!(ethmac_sram_reader_ready_read())); - txslot = ethmac_sram_reader_slot_read(); - txbuffer = (ethernet_buffer *)(ETHMAC_BASE + ETHMAC_SLOT_SIZE * (ETHMAC_RX_SLOTS + txslot)); + + /* update txslot / txbuffer */ txslot = (txslot+1)%ETHMAC_TX_SLOTS; - ethmac_sram_reader_slot_write(txslot); + txbuffer = (ethernet_buffer *)(ETHMAC_BASE + ETHMAC_SLOT_SIZE * (ETHMAC_RX_SLOTS + txslot)); } static unsigned char my_mac[6]; @@ -415,17 +421,17 @@ void microudp_start(const unsigned char *macaddr, unsigned int ip) for(i=0;i<6;i++) cached_mac[i] = 0; - ethmac_sram_reader_slot_write(0); - txbuffer = (ethernet_buffer *)(ETHMAC_BASE + ETHMAC_SLOT_SIZE * ETHMAC_RX_SLOTS); - + txslot = 0; + ethmac_sram_reader_slot_write(txslot); + txbuffer = (ethernet_buffer *)(ETHMAC_BASE + ETHMAC_SLOT_SIZE * (ETHMAC_RX_SLOTS + txslot)); - rxbuffer = (ethernet_buffer *)ETHMAC_BASE; + rxslot = 0; + rxbuffer = (ethernet_buffer *)(ETHMAC_BASE + ETHMAC_SLOT_SIZE * rxslot); rx_callback = (udp_callback)0; } void microudp_service(void) { - unsigned int rxslot; if(ethmac_sram_writer_ev_pending_read() & ETHMAC_EV_SRAM_WRITER) { rxslot = ethmac_sram_writer_slot_read(); rxbuffer = (ethernet_buffer *)(ETHMAC_BASE + ETHMAC_SLOT_SIZE * rxslot); -- 2.30.2