Forum Discussion

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

Not able to send ethernet frame from FPGA to windows PC

Hello,

I have an altera de2-115 fpga, it has two ehernet port. My aim is to send ethernet frame from my pc to fpga, then the fpga should send the same frame to another pc. i am using osinato for frame genration. i can see the frame received on fpga but it is not transmitting to the other PC.

When i received the frame on fpga i used a fro loop to copy receive frame to transmit frame

for(i=0;i<=1518;i++)

tx_frame=rx_frame;

then i used three lines of code for transmit but on wireshark i can see nothing

alt_avalon_sgdma_construct_mem_to_stream_desc( &tx_descriptor, &tx_descriptor_end, (alt_u32 *)tx_frame, 1518, 0, 1, 1, 0 );

// Set up non-blocking transfer of sgdma transmit descriptor

alt_avalon_sgdma_do_async_transfer( sgdma_tx_dev, &tx_descriptor );

// Wait until transmit descriptor transfer is complete

while (alt_avalon_sgdma_check_descriptor_status(&tx_descriptor) != 0)

;

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    #include <altera_avalon_sgdma.h>

    # include <altera_avalon_sgdma_descriptor.h>

    # include <altera_avalon_sgdma_regs.h>

    # include "sys/alt_stdio.h"

    # include "sys/alt_irq.h"

    # include <unistd.h>

    // Function Prototypes

    void rx_ethernet_isr (void *context);

    //void tx_ethernet_isr (void *context);

    //void tx_ethernet_isr (void *context);

    // Global Variables

    unsigned int i=0;

    // Create a transmit frame char=1 byte

    unsigned char tx_frame[1518] = { 0 };

    // Create a receive frame

    unsigned char rx_frame[1518] = { 0 };

    // Create sgdma transmit and receive devices

    alt_sgdma_dev * sgdma_tx_dev;

    alt_sgdma_dev * sgdma_rx_dev;

    // Allocate descriptors in the descriptor_memory (onchip memory)

    alt_sgdma_descriptor tx_descriptor __attribute__ (( section ( ".descriptor_memory" )));

    alt_sgdma_descriptor tx_descriptor_end __attribute__ (( section ( ".descriptor_memory" )));

    alt_sgdma_descriptor rx_descriptor __attribute__ (( section ( ".descriptor_memory" )));

    alt_sgdma_descriptor rx_descriptor_end __attribute__ (( section ( ".descriptor_memory" )));

    /********************************************************************************

    * This program demonstrates use of the Ethernet in the DE2-115 board.

    *

    * It performs the following:

    * 1. Records input text and transmits the text via Ethernet after Enter is

    * pressed

    * 2. Displays text received via Ethernet frame on the JTAG UART

    ********************************************************************************/

    int main(void)

    {

    // Open the sgdma transmit device

    sgdma_tx_dev = alt_avalon_sgdma_open ("/dev/sgdma_tx");

    if (sgdma_tx_dev == NULL) {

    alt_printf ("Error: could not open scatter-gather dma transmit device\n");

    return -1;

    } else alt_printf ("Opened scatter-gather dma transmit device\n");

    // Open the sgdma receive device

    sgdma_rx_dev = alt_avalon_sgdma_open ("/dev/sgdma_rx");

    if (sgdma_rx_dev == NULL) {

    alt_printf ("Error: could not open scatter-gather dma receive device\n");

    return -1;

    } else alt_printf ("Opened scatter-gather dma receive device\n");

    // Set interrupts for the sgdma receive device

    alt_avalon_sgdma_register_callback( sgdma_rx_dev, (alt_avalon_sgdma_callback) rx_ethernet_isr, 0x00000014, NULL );

    // Create sgdma receive descriptor

    alt_avalon_sgdma_construct_stream_to_mem_desc( &rx_descriptor, &rx_descriptor_end, (alt_u32 *)rx_frame, 0, 0 );

    // Set up non-blocking transfer of sgdma receive descriptor

    alt_avalon_sgdma_do_async_transfer( sgdma_rx_dev, &rx_descriptor );

    // Triple-speed Ethernet MegaCore base address

    volatile int * tse = (int *) 0x00102000;

    // Initialize the MAC address

    //*(tse + 3) = 0x116E6001;

    //*(tse + 4) = 0x00000F02;

    // Specify the addresses of the PHY devices to be accessed through MDIO interface

    *(tse + 0x0F) = 0x10;

    *(tse + 0x10) = 0x11;

    // Write to register 20 of the PHY chip for Ethernet port 0 to set up line loopback

    *(tse + 0x94) = 0x4000;

    // Write to register 16 of the PHY chip for Ethernet port 1 to enable automatic crossover for all modes("| = OR")

    *(tse + 0xB0) = *(tse + 0xB0) | 0x0060;

    // Write to register 20 of the PHY chip for Ethernet port 2 to set up delay for input/output clk

    *(tse + 0xB4) = *(tse + 0xB4) | 0x0082;

    // Software reset the second PHY chip and wait

    *(tse + 0xA0) = *(tse + 0xA0) | 0x8000;

    while ( *(tse + 0xA0) & 0x8000 )

    ;

    // Enable read and write transfers, gigabit Ethernet operation, and CRC forwarding

    *(tse + 2) = *(tse + 2) | 0x000000CB;

    alt_avalon_sgdma_construct_mem_to_stream_desc( &tx_descriptor, &tx_descriptor_end, (alt_u32 *)tx_frame, 60, 0, 1, 1, 0 );

    // Set up non-blocking transfer of sgdma transmit descriptor

    alt_avalon_sgdma_do_async_transfer( sgdma_tx_dev, &tx_descriptor );

    // Wait until transmit descriptor transfer is complete

    while (alt_avalon_sgdma_check_descriptor_status(&tx_descriptor) != 0)

    ;

    return 0;

    }

    /****************************************************************************************

    * Subroutine to read incoming Ethernet frames

    ****************************************************************************************/

    void rx_ethernet_isr (void *context)

    {

    // Wait until receive descriptor transfer is complete

    while (alt_avalon_sgdma_check_descriptor_status(&rx_descriptor) != 0);

    // Create new receive sgdma descriptor

    alt_avalon_sgdma_construct_stream_to_mem_desc( &rx_descriptor, &rx_descriptor_end, (alt_u32 *)rx_frame, 0, 0 );

    // Set up non-blocking transfer of sgdma receive descriptor

    alt_avalon_sgdma_do_async_transfer( sgdma_rx_dev, &rx_descriptor );

    for(i=0;i<=1518;i++)

    tx_frame=rx_frame;

    for (i=0;i<=25;i++)

    alt_printf("%x",rx_frame[i]);

    alt_printf("\n");

    alt_printf("%x",rx_frame[25]);

    alt_printf("\n");

    }

    This is the complete code
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    If you're trying to use the SGDMA in Ethernet IP to receive and then transmit data, you've done only 50% of it. You can't do a loopback of RxD to TxD simply by doing

    tx_buffer = rx_buffer.

    What you've done here is only copy the contents of the Rx buffer to the Tx buffer. You seem to have created the rx_descriptors and used the Rx send function correctly. But you didn't do the same for the Tx. You need to uncomment the Tx buffers, descriptors and functions. Get the Rx Data to the rx_buffer as you've done, and in the for loop copy the buffer contents to tx_buffer. Then use the Tx descriptors functions , program the Tx_Desc and call the Tx send data function. This will now send the received data via the Tx lines over the Ethernet and you should be able to see the data at the other terminal.

    Do keep in mind to account for the Tx buffer size, filling it up too soon will cause data loss.