Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

LWIP, LAN91C111, and DMA

I've searched the forums and cannot find anything that tells exactly how to modify the data transfer to use DMA. From what I can tell, this is correct (it is writing to the SMSC chip), but it plain doesn't work.

The low_level_output function in altera_avalon_lan91c111.c has some special code so it can do 32-bit data transfers. I've modified this to use bytes for simplicity purposes and to make it simple to match the DMA mode.

So, the modified non-DMA transfer using bytes is as follows (this works 100%):

   for (i=0;i<q->len;i++) {
       IOWR_ALTERA_AVALON_LAN91C111_DATA_BYTE( dev->base_addr,
                                         *(alt_u8*)(q->payload+i));     
    }

My DMA implementation of the same is:

   IOWR_ALTERA_AVALON_DMA_CONTROL(DMA_BASE, ALTERA_AVALON_DMA_CONTROL_BYTE_MSK +
                                            ALTERA_AVALON_DMA_CONTROL_LEEN_MSK +
                                            ALTERA_AVALON_DMA_CONTROL_WCON_MSK);
   IOWR_ALTERA_AVALON_DMA_RADDRESS(DMA_BASE, (int)(q->payload));
   IOWR_ALTERA_AVALON_DMA_WADDRESS(DMA_BASE, (int)IOADDR_ALTERA_AVALON_LAN91C111_DATA(dev->base_addr));
   IOWR_ALTERA_AVALON_DMA_LENGTH(DMA_BASE, q->len);
   alt_dcache_flush_all();   // Flush the cache to ensure the DMA transaction gets the latest data
   IOWR_ALTERA_AVALON_DMA_CONTROL(DMA_BASE, ALTERA_AVALON_DMA_CONTROL_BYTE_MSK +
                                            ALTERA_AVALON_DMA_CONTROL_LEEN_MSK +
                                            ALTERA_AVALON_DMA_CONTROL_WCON_MSK +
                                            ALTERA_AVALON_DMA_CONTROL_GO_MSK);
   while (IORD_ALTERA_AVALON_DMA_STATUS(DMA_BASE) & ALTERA_AVALON_DMA_STATUS_BUSY_MSK);    

So, the DMA transaction does occur and complete, but the Ethernet functions fail.

I&#39;ve checked that the DMA does transfer the number of bytes (well I&#39;ve checked short transactions, but haven&#39;t counted the 500 or so bytes that are normally sent).

Any ideas? Thanks in advance...