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.

Concerto control card working as TCP/IP Client

Hi everybody,

I'm trying to use my concerto control card with the F28M35H51C device as a client in a Client-Server system connected through ethernet (in this case the server is my PC). I started from enet_uip example, but in this example the concerto control card works as a server. Once I have tested successfully the enet_uip example i tried to change it to work as a client; here is the main function code:

int
main(void)
{
    uip_ipaddr_t ipaddr;
    static struct uip_eth_addr sTempAddr;
    long lPeriodicTimer, lARPTimer;
    unsigned long ulUser0, ulUser1;
    unsigned long ulTemp;
    int command_word;

    // Disable Protection
    HWREG(SYSCTL_MWRALLOW) =  0xA5A5A5A5;


    // Sets up PLL, M3 running at 75MHz and C28 running at 150MHz
    SysCtlClockConfigSet(SYSCTL_USE_PLL | (SYSCTL_SPLLIMULT_M & 0xF) |
                         SYSCTL_SYSDIV_1 | SYSCTL_M3SSDIV_2 |
                         SYSCTL_XCLKDIV_4);

#ifdef _FLASH
// Copy time critical code and Flash setup code to RAM
// This includes the following functions:  InitFlash();
// The  RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart
// symbols are created by the linker. Refer to the device .cmd file.
    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);

// Call Flash Initialization to setup flash waitstates
// This function must reside in RAM
    FlashInit();
#endif

    PinoutSet();

    // Enable clock supply for the following peripherals
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);

    // Disable clock supply for the watchdog modules
    SysCtlPeripheralDisable(SYSCTL_PERIPH_WDOG1);
    SysCtlPeripheralDisable(SYSCTL_PERIPH_WDOG0);

    // Adjust the pointer to be aligned on an odd half word address so that
    // DMA can be used.
    uip_buf = (u8_t *)(((unsigned long)ucUIPBuffer + 3) & 0xfffffffe);

    // Enable the uDMA controller and set up the control table base.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    uDMAEnable();
    uDMAControlBaseSet(g_sDMAControlTable);

    // Configure the DMA TX channel
    uDMAChannelAttributeDisable(UDMA_CHANNEL_ETH0TX, UDMA_ATTR_ALL);
    uDMAChannelControlSet(UDMA_CHANNEL_ETH0TX,
                          UDMA_SIZE_32 | UDMA_SRC_INC_32 |
                          UDMA_DST_INC_NONE | UDMA_ARB_8);

    // Set user/company specific MAC octets
    // (for this code we are using A8-63-F2-00-00-80)
    // 0x00 MACOCT3 MACOCT2 MACOCT1
    ulUser0 = 0x00F263A8;

    // 0x00 MACOCT6 MACOCT5 MACOCT4
    ulUser1 = 0x00800000;

    // User needs to program user specific MAC address into Flash
    // and read it on power up
    if((ulUser0 == 0xffffffff) || (ulUser1 == 0xffffffff))
    {
        // We should never get here.  This is an error if the MAC address has
        // not been programmed into the device.  Exit the program.
        while(1)
        {
        }
    }

    // Enable and Reset the Ethernet Controller.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);
    SysCtlPeripheralReset(SYSCTL_PERIPH_ETH);

    // Configure SysTick for a periodic interrupt.
    SysTickPeriodSet(SysCtlClockGet(SYSTEM_CLOCK_SPEED) / SYSTICKHZ);
    SysTickEnable();
    IntRegister(FAULT_SYSTICK, SysTickIntHandler);
    SysTickIntEnable();

    // Configure the DMA channel for Ethernet receive.
    uDMAChannelAttributeDisable(UDMA_CHANNEL_ETH0RX, UDMA_ATTR_ALL);
    uDMAChannelControlSet(UDMA_CHANNEL_ETH0RX,
                          UDMA_SIZE_32 | UDMA_SRC_INC_NONE |
                          UDMA_DST_INC_32 | UDMA_ARB_8);

    // Initialize the Ethernet Controller and disable all Ethernet Controller
    // interrupt sources.
    EthernetIntDisable(ETH_BASE, (ETH_INT_PHY | ETH_INT_MDIO |
                                  ETH_INT_RXER | ETH_INT_RXOF |
                                  ETH_INT_TX | ETH_INT_TXER | ETH_INT_RX));
    ulTemp = EthernetIntStatus(ETH_BASE, false);
    EthernetIntClear(ETH_BASE, ulTemp);

    // Initialize the Ethernet Controller for operation.
    EthernetInitExpClk(ETH_BASE, SysCtlClockGet(SYSTEM_CLOCK_SPEED));

    // Configure the Ethernet Controller for normal operation.
    // - Full Duplex
    // - TX CRC Auto Generation
    // - TX Padding Enabled
    EthernetConfigSet(ETH_BASE, (ETH_CFG_TX_DPLXEN | ETH_CFG_TX_CRCEN |
                                 ETH_CFG_TX_PADEN));

    // Wait for the link to become active.
    while((EthernetPHYRead(ETH_BASE, PHY_MR1) & 0x0004) == 0)
    {
    }

    // Enable the Ethernet Controller.
    EthernetEnable(ETH_BASE);

    // Enable and register the Ethernet interrupt.
    IntRegister(INT_ETH, EthernetIntHandler);
    IntEnable(INT_ETH);
#ifndef REV_0_SILICON
    IntRegister(INT_UDMA, EthernetIntHandler);
    IntEnable(INT_UDMA);
#endif
    // Enable the Ethernet RX Packet interrupt source.
    EthernetIntEnable(ETH_BASE, ETH_INT_RX);

    // Enable all processor interrupts.
    IntMasterEnable();

    // Initialize the uIP TCP/IP stack.
    uip_init();
#ifdef USE_STATIC_IP
    uip_ipaddr(ipaddr, DEFAULT_IPADDR0, DEFAULT_IPADDR1, DEFAULT_IPADDR2,
               DEFAULT_IPADDR3);
    uip_sethostaddr(ipaddr);
    ShowIPAddress(ipaddr);
    uip_ipaddr(ipaddr, DEFAULT_NETMASK0, DEFAULT_NETMASK1, DEFAULT_NETMASK2,
               DEFAULT_NETMASK3);
    uip_setnetmask(ipaddr);
#else
    uip_ipaddr(ipaddr, 0, 0, 0, 0);
    uip_sethostaddr(ipaddr);
    uip_ipaddr(ipaddr, 0, 0, 0, 0);
    uip_setnetmask(ipaddr);
#endif

    // Convert the 24/24 split MAC address from ram into a 32/16 split MAC
    // address needed to program the hardware registers, then program the MAC
    // address into the Ethernet Controller registers.
    sTempAddr.addr[0] = ((ulUser0 >>  0) & 0xff);
    sTempAddr.addr[1] = ((ulUser0 >>  8) & 0xff);
    sTempAddr.addr[2] = ((ulUser0 >> 16) & 0xff);
    sTempAddr.addr[3] = ((ulUser1 >>  0) & 0xff);
    sTempAddr.addr[4] = ((ulUser1 >>  8) & 0xff);
    sTempAddr.addr[5] = ((ulUser1 >> 16) & 0xff);

    // Program the hardware with it's MAC address (for filtering).
    EthernetMACAddrSet(ETH_BASE, (unsigned char *)&sTempAddr);
    uip_setethaddr(sTempAddr);


#ifndef USE_STATIC_IP

    // Initialize the DHCP Client Application.
    dhcpc_init(&sTempAddr.addr[0], 6);
    dhcpc_request();
#endif


    // Main Application Loop.

    lPeriodicTimer = 0;
    lARPTimer = 0;
    uip_ipaddr(&ipaddr, 169, 254, 42, 86);
uip_connect(&ipaddr, HTONS(80));
if(uip_connected()){
    while(true)
    {
    }
}
else{
	for(;;){}
}
}


I can see in the debugger that the host is not connected because the application falls in the infinite for loop.

To see what is happening on the ethernet port I'm using the software WireShark and i can see some traffic on the ethernet port, (PC is sending some packets, but destination IP is not the IP of concerto). Do you have any idea of how I can solve that? Or are there some examples of  how Concerto works as client? 

Thank you in advance and regards,

Filipp

  • We currently don't have any example that shows concerto as a client. You may have to dig further into the uIP stack to use Concerto as a client.
    ThanksNoah
  • Thank you Noah, if you have any suggestions please let me know.

    Kinds regards,

    Filippo

  • I've read the uIP library files more carefully, and it looks as if the library doesn't interact with the device driver(or the commands to the device driver are not visible in the uip code), but operates a simple control on internal code structures. So what should I do to connect to another server device. Can I use the uIP stack or I have to implement a TCP/IP library by myself? I'm sorry but I'm surprised that a company like Texas Instruments hasn't released a minimum documentation on how to use the libraries provided with its products.

    Regards,
    Filippo
  • It is more than two weeks that I'm trying to implement a simple TCP/IP client with no result. I have tried to use the webclient app in thirdy_part/uip-1.0/apps/webclient and i tried to modify the uip_enet example to use it. I have modified the uip-conf.h file, but the compiler doesn't compile. I'm going crazy, could you tell me at least if I can use this uip library to implement a TCP/IP client or if I'm just wasting my time?
    Help me please. It would be really appreciated.

    Thank you in advance and regards
    Filippo
  • Filippo,
    The uIP stack has provision for client application. However, we currently don't have any examples to showcase that.
    ThanksNoah
  • Thank you Mr Noah,
    could you answer me please a last question? Are the functions uip_connect(), uip_send() etc mapped with the ethernet peripheral? It seems they are not, in fact if I execute a uip_connect() nothing hapeens on ethernet port. But if it is so i didn't understand how they work in the enet_uip example. In the enet_uip example packets are sent by the routine EthernetPacketPutDMA, but when the host sends a SYN to connect to us, how is done the three way handshaking? I can't find out this from the code.
    Thank you in advance,
    Filippo
  • Hi Flippo,

    Let me see if I can get someone who can give a quick response. If not give me few days I will get back to you.

    Thanks

    Noah

  • Thank you very much Mr Noah, it would be very useful for me.

    Best regards,
    Filippo
  • Filippo,
    You are correct, the uip functions are not mapped to the Ethernet drivers. The main link is the data buffer. When a packet arrives the EthernetPacketGetDMA() function gets the packets in uip_buff and uip_input() is invoked to process the function.
    ThanksNoah
  • Thank you very much Mr Noah,
    and what about the uip_connect() function? How does it control the three way handshaking? Should I use it to connect to a remote device?

    Kind regards,
    Filippo