This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/EK-TM4C1294XL: EK-TM4c1294NCPDT

Part Number: EK-TM4C1294XL

Tool/software: TI C/C++ Compiler

I am working on enet_uip and it is working when i sends UDP packets via Packet sender. 

What i want to do now is to send a Packet from the PC  to the Microcontroller with Port Number 2048 but then send back a packet with different packet word length on port 2049 back to PC from Microcontroller. 

So it should work like this. 

PC -> MC  (UDP packet on Port 2048 with message e.g Test_0)

but it should sent back packet now using Swap function where the MAC and IP addresses are swapped.

MC -> PC (UDP packet on Port 2049 with different message length like Test_12345)

What i have done is that the Swap function is working where i can swap the MAC and IP address in order to send back the packet from MC -> PC 

But what i don't get is how to implement this in my Echo main function. 

Any suggestions regarding this?????

  • Dear Charles, 

    Examples looks good, but still i am confused of how to implement this in my actual code. 

    I am attaching below my code. Might be if you can give me some hint. 

    The Echo implementation: 

    //
    // Main Application Loop.
    //
    i32PeriodicTimer = 0;
    i32ARPTimer = 0;
    while(true)
    {
    //
    // Wait for an event to occur. This can be either a System Tick event,
    // or an RX Packet event.
    //
    while(!g_ui32Flags)
    {
    }

    //
    // If SysTick, Clear the SysTick interrupt flag and increment the
    // timers.
    //
    if(HWREGBITW(&g_ui32Flags, FLAG_SYSTICK) == 1)
    {
    HWREGBITW(&g_ui32Flags, FLAG_SYSTICK) = 0;
    i32PeriodicTimer += SYSTICKMS;
    i32ARPTimer += SYSTICKMS;
    }

    //
    // Check for an RX Packet and read it.
    //
    if(HWREGBITW(&g_ui32Flags, FLAG_RXPKT))
    {
    //
    // Clear the RX Packet event flag.
    //
    HWREGBITW(&g_ui32Flags, FLAG_RXPKT) = 0;

    // Get the packet and set uip_len for uIP stack usage.
    //
    uip_len = (unsigned short)PacketReceive(EMAC0_BASE, uip_buf,
    sizeof(g_pui8UIPBuffer));

    //
    // Process incoming IP packets here.
    //
    if(BUF->type == htons(UIP_ETHTYPE_IP))
    {
    // check if UDP protocol used
    if (IPBUF->proto == 0x11) {

    // swap MAC addresses

    MACaddr[0] = IPBUF->ethhdr.src.addr[0];
    MACaddr[1] = IPBUF->ethhdr.src.addr[1];
    MACaddr[2] = IPBUF->ethhdr.src.addr[2];
    MACaddr[3] = IPBUF->ethhdr.src.addr[3];
    MACaddr[4] = IPBUF->ethhdr.src.addr[4];
    MACaddr[5] = IPBUF->ethhdr.src.addr[5];

    IPBUF->ethhdr.src.addr[0] = IPBUF->ethhdr.dest.addr[0];
    IPBUF->ethhdr.src.addr[1] = IPBUF->ethhdr.dest.addr[1];
    IPBUF->ethhdr.src.addr[2] = IPBUF->ethhdr.dest.addr[2];
    IPBUF->ethhdr.src.addr[3] = IPBUF->ethhdr.dest.addr[3];
    IPBUF->ethhdr.src.addr[4] = IPBUF->ethhdr.dest.addr[4];
    IPBUF->ethhdr.src.addr[5] = IPBUF->ethhdr.dest.addr[5];

    IPBUF->ethhdr.dest.addr[0] = MACaddr[0];
    IPBUF->ethhdr.dest.addr[1] = MACaddr[1];
    IPBUF->ethhdr.dest.addr[2] = MACaddr[2];
    IPBUF->ethhdr.dest.addr[3] = MACaddr[3];
    IPBUF->ethhdr.dest.addr[4] = MACaddr[4];
    IPBUF->ethhdr.dest.addr[5] = MACaddr[5];

    // swap IP address

    IPBUF->destipaddr[0] = IPBUF->srcipaddr[0];
    IPBUF->destipaddr[1] = IPBUF->srcipaddr[1];
    IPBUF->srcipaddr [0] = uip_hostaddr[0];
    IPBUF->srcipaddr [1] = uip_hostaddr[1];
    }
    else {
    uip_len = 0;
    }
    PacketTransmit(EMAC0_BASE, uip_buf, uip_len);
    uip_len = 0;

    }

    First of all i have to send the packet

    from the PC to MC on Port 2048 with some message, 

    and then i will toggle the source and destination address in order to send the packet back from

    MC to PC using a different Port which for e.g 2049 with different message length. 

    I am a bit confused, should i define in the echo the port number because i am using packet sender for it. 

    What i need is to run the main loop which first sends a packet from Point A to B and then wait during which i can send a packet from Point B to A another Packet. 

    How should i proceed with this???

  • Hi,

      I think the below post which contains a complete example will be helpful. I will also suggest you use the wireshark to see the network traffic when sending/receiving data to the client. The example setup the client to listen on port 23. You can change to 2048.  I'm not sure why you need to toggle the source and dest addresses. Why don't use look at the example first. It is a echo example. The client just echoes back whatever it received from the server using the sendto() API. 

    https://e2e.ti.com/support/microcontrollers/other/f/908/t/723207

  • In the enet_uip example: 

    1. uIP uses a single buffer, but the MAC needs a minimum of 3 receive descriptors to operate

    #define NUM_TX_DESCRIPTORS 3
    #define NUM_RX_DESCRIPTORS 3

    I don't get why MAC hardware need a minimum of 3 receive descriptors??

    2. How the intterupt handler for SysTick interrupt works 

    void
    SysTickIntHandler(void)
    {
    //
    // Increment the system tick count.
    //
    g_ui32TickCounter++;

    //
    // Indicate that a SysTick interrupt has occurred.
    //
    HWREGBITW(&g_ui32Flags, FLAG_SYSTICK) = 1;

    I don't get what this HWREGBITW and the equal to 1 means in this case?? and also how is the interrupt called ?

    3. Then there is a function  void EthernetIntHandler(void)  I have not seen this function to be used in main. Can you explain when and how it works?

  • Hello,

      Did you have a chance to run the example as attached in the other post that I referred? The example shows a simple data transfer based on LwIP UDP. 

    Atif Saeed said:

    1. uIP uses a single buffer, but the MAC needs a minimum of 3 receive descriptors to operate

    I'm not sure about the 3. Did you change to 1 and see how it works? Also why don't you want to use the LwIP but rather the uIP? My guess for three descriptors is to support forward linked descriptor list. For details about descriptors you can find description in the datasheet in the Ethernet chapter. However, these are all very low level details that people hardly need to know what happens behind the scene. The TCP/IP stack and the Ethernet drivers abstracts the hardware details. 

    Atif Saeed said:

    I don't get what this HWREGBITW and the equal to 1 means in this case?? and also how is the interrupt called ?

    The HWREGBITW is a function to set a bit high. The FLAG_SYSTICK is #defined as 0. Therefore, the HWREGBITW(&g_ui32Flags, FLAG_SYSTICK) = 1 will set the bit 0 of the g_ui32Flags register to 1.

    Atif Saeed said:
    3. Then there is a function  void EthernetIntHandler(void)  I have not seen this function to be used in main.

    The EthernetIntHandler is the ISR for the Ethernet module. Check the startup_ccs.c file and search for EthernetIntHandler and you will find the EthernetIntHandler is placed in the interrupt vector table corresponding to the Ethernet module. When an Ethernet interrupt happens, the processor will jump to the EthernetIntHandler ISR. The EthernetIntHandler ISR is in the enet_uip.c. 

      If you don't know how interrupt works, I will suggest you play with the example <TivaWare_Installation>/examples/boards/ek-tm4c1294xl/interrupts example. 

      

  • Hi Charles, 

    Yes i went throught the LwIP UDP example. 

    Actually i started couple of weeks ago with uIP therefore i am using this example. 

    Second i don't see any DMA in the LwIP where i should be able to Receive packet and transmit packet and no buffers. Correct me if i am wrong. In LwIP what it is doing is receving the packets and sending it back to specified port and a new IP. 

    Third, what i want to do is that i have send the packet and the packet is received and copied to the buffer. Now the packet is in the buffer,

    I want to do know is to extend the payload in the buffer and change the length before transmitting it back from the MC to PC. 

    Packet received and stored in the uIP_buf and transmitted from PC to MC. 

    For example a photo attached: UDP packet 

    1. Source port

    2. Destination port. 

    3. Length

    4. Check sum 

    5. Data 

    this can be seen in my picture. 

    Now this payload (buffer data) is in microcontroller software and i want to only change the payload of the data packet and specify the port number on which i want to send. And then transmit it back to the PC. 

    Before Transmitting the packet the buffer should have only the data and the length change e.g from (Test_0) to (Test_4321_echo)  plus the port number.

    Can you help me how should i approach to this problem. I tried some example but don't works.

  • Hi,

      I don't think continuing with the uIP is the best option for you. I see people who are not using the RTOS will use the LwIP. People who are using the RTOS will us the TI-RTOS NDK for TCP/IP stack. As you can see in the enet_uip. c example, it is quite low level that requires you to setup the tx/rx descriptors. I think you will be better off using the LwIP. If you had the chance to try the UDP example based off LwIP I referenced to, it is much easier. 

      There are some uIP examples provided by Adam Dunkels who is the brain behind both the LwIP and uIP.  Please see below. 

    This paper written by Adam Dunkels also contains some examples on how to send data to the network. 

    http://www.dunkels.com/adam/download/uip-doc-0.6.pdf

    Here is another uip question on StackOverFlow that may help.

    https://stackoverflow.com/questions/25102977/send-udp-on-specific-connection-in-%c2%b5ip/25448350#25448350