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.

EK-TM4C1294XL: Ethernet recieve speed.

Part Number: EK-TM4C1294XL


Hi,

I have created TCP server and is receiving data from client successfully, same data is to be written to USB Drive that also works fine. My issue is that client is sending 4 Bytes buffer at speed rate >2.5Mbps (tested PC as a server using Hercules and Wireshark both), at same speed TM4C server is not receiving data. 

Regards

Khodidas

/*
 * Copyright (c) 2014-2015, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *    ======== tcpEcho.c ========
 *    Contains BSD sockets code.
 */
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART.h>
/* NDK BSD support */
#include <sys/socket.h>

/* Example/Board Header file */
#include "Board.h"

#include "inc/hw_memmap.h"
#include "inc/hw_adc.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "inc/hw_ints.h"
#include "driverlib/interrupt.h"
#include "inc/hw_sysctl.h"
#include "driverlib/sysctl.h"
#include "driverlib/ssi.h"
#include "driverlib/pin_map.h"


//****************************For USB************************//
//#include "usblib/usblib.h"
//#include "usblib/usbmsc.h"
//#include "usblib/host/usbhost.h"
//#include "usblib/host/usbhmsc.h"
#include <ti/drivers/USBMSCHFatFs.h>
#include "fatfs/src/ff.h"

//#include <ti/sysbios/fatfs/ff.h>
//#include <ti/sysbios/fatfs/diskio.h>.
  FILE src, dst;

  USBMSCHFatFs_Handle usbmschfatfsHandle;
  USBMSCHFatFs_Params usbmschfatfsParams;


#define USB_DRIVE_NUM 0
const char textarray[] = "0123456789abcdefghijklmnopqrstuvwxyz012\n";
const char  inputfilesd[]  = "input.txt";

static uint8_t usbServiceTaskStack[1024];

char read_buf[20];
unsigned int filesize,fresult;

unsigned int bytesWritten = 0;
//*********************************************************************//

UART_Handle      handle;
UART_Params myuart;


#define NUM_SSI_DATA    5

#define TCPPACKETSIZE 4
#define NUMTCPWORKERS 50
uint32_t bytesRcvd;


uint32_t adcBuffer2[9];
uint32_t pui32DataTx[NUM_SSI_DATA];
uint32_t pui32DataRx[NUM_SSI_DATA];
uint32_t ui32SysClock=0;
uint32_t ui32Index;
char buffer[TCPPACKETSIZE];

bool LOCK=false;


uint16_t counter;
int                clientfd;

void USB_INIT();

void ADC0IntHandler(void)
{
    // Clear interrupt Flag
    ADCIntClear(ADC0_BASE, 0);
    ADCSequenceDataGet(ADC0_BASE, 0, adcBuffer2);
    ADCProcessorTrigger(ADC0_BASE, 1);
    //ADCSequenceDataGet(ADC0_BASE, 0, adcBuffer2);
    ADCSequenceDataGet(ADC0_BASE, 1, &adcBuffer2[6]);
    ADCSequenceDataGet(ADC0_BASE, 1, &adcBuffer2[7]);
    ADCSequenceDataGet(ADC0_BASE, 1, &adcBuffer2[8]);
    if(adcBuffer2[8]>4000)
    {
     LOCK=true;
    }
}

void adc2_init(void)
 {

     uint32_t adcClock=0, adcDiv=0;
        // Enable the ADC0 peripheral
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);


        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
        GPIOPinTypeADC(GPIO_PORTD_BASE,  GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3| GPIO_PIN_2| GPIO_PIN_1 | GPIO_PIN_0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);



        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5| GPIO_PIN_1 | GPIO_PIN_2); //| GPIO_PIN_3);
        // Configure the ADC to use PLL at 480 MHz with Full rate devided by 30 to get 16 MHz
        ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 30);


        ADCSequenceDisable(ADC0_BASE, 0);
        ADCSequenceDisable(ADC0_BASE, 1);
        // Read the current ADC configuration
        adcClock=ADCClockConfigGet(ADC0_BASE, &adcDiv);
        // Hardware averageing: by a faktor of 2 -> 2,4,8,16,32,64
        ADCHardwareOversampleConfigure(ADC0_BASE, 8);
        // ADC voltage-lvl reference set to intern
        ADCReferenceSet(ADC0_BASE, ADC_REF_INT);
        ADCReferenceSet(ADC0_BASE, ADC_REF_INT);
        // ADC Sequencer config: Source ADC0, Sequencer 0, Trigger: always, priority: 0
        ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_ALWAYS, 0);
        ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);


        // ADC Sequencer step
        // 1. Source-ADC -> ADC0_BASE
        // 2. Source-Sequencer -> 0
        // 3. Sample-Value depends in the depth of the FIFO, by Sequencer 0 it is up to 7 (0-7)
        // 4. Config-> select input-channel AINx, interrupt specification
        //
        ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH1);
        ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH2);
        ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH8 |ADC_CTL_IE|ADC_CTL_END);

       // ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH4);
        //ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH5);

        ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH6);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH7);

        ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH12);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH13);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH14);
        ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH15 |ADC_CTL_IE|ADC_CTL_END );


        IntPrioritySet(INT_ADC0SS0, 0x00);

           // ADC0SS0 Interrupt source
           ADCIntRegister(ADC0_BASE, 0, ADC0IntHandler);

           // Register Interrupt to NVIC
           IntRegister(INT_ADC0SS0, ADC0IntHandler);

           // ADC0 enable
           ADCIntEnable(ADC0_BASE, 0);

           // Interrupt ADC0SS0 enable
           IntEnable(INT_ADC0SS0);

           // Enable Global Interrupts
           IntMasterEnable();

           ADCSequenceEnable(ADC0_BASE, 0);
           ADCSequenceEnable(ADC0_BASE, 1);

 }
void SPI_Init()
{
    // The SSI0 peripheral must be enabled for use.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    GPIOPinConfigure(GPIO_PA2_SSI0CLK);
    GPIOPinConfigure(GPIO_PA3_SSI0FSS);
    GPIOPinConfigure(GPIO_PA4_SSI0XDAT0);
    GPIOPinConfigure(GPIO_PA5_SSI0XDAT1);
    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2);
    // Configure and enable the SSI port for SPI master mode.  Use SSI0, system clock supply, idle clock level low and active low clock in
    // freescale SPI mode, master mode, 1MHz SSI frequency, and 8-bit data.
    // For SPI mode, you can set the polarity of the SSI clock when the SSI unit is idle.  You can also configure what clock edge you want to
    // capture data on.  Please reference the datasheet for more information on the different SPI modes.
    SSIConfigSetExpClk(SSI0_BASE, ui32SysClock, SSI_FRF_MOTO_MODE_0, SSI_MODE_SLAVE, 1000000, 8);

    // Enable the SSI0 module.
    SSIEnable(SSI0_BASE);
}
/*
 *  ======== tcpWorker ========
 *  Task to handle TCP connection. Can be multiple Tasks running
 *  this function.
 */
//Void tcpWorker(UArg arg0, UArg arg1)
//{
//    int  clientfd = (int)arg0;
//
//    ui32SysClock=SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000);
//
//    System_printf("tcpWorker: start clientfd = 0x%x\n", clientfd);
//
//
////    while (1)
////    {
////
////
////        pui32DataTx[0] = 's';
////        pui32DataTx[1] = 'p';
////        pui32DataTx[2] = 'I';
////        pui32DataTx[3] = 'S';
////        pui32DataTx[4] = '\n';
////   //     bytesRcvd = recv(clientfd, buffer, TCPPACKETSIZE, 0);
////        for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++)
////           {
////               // Send the data using the "blocking" put function.  This function
////               // will wait until there is room in the send FIFO before returning.
////               // This allows you to assure that all the data you send makes it into
////               // the send FIFO.
////               //
////               SSIDataPutNonBlocking(SSI0_BASE, pui32DataTx[ui32Index]);
////               //SSIDataGet(SSI0_BASE, &pui32DataRx[ui32Index]);
////               SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx[ui32Index]);
////           }
////
////
////         count++;
////
////
////       // bytesSent = send(clientfd, buffer, bytesRcvd, 0);
////
////    }
//    System_printf("tcpWorker stop clientfd = 0x%x\n", clientfd);
//
//    close(clientfd);
//}

/*
 *  ======== tcpHandler ========
 *  Creates new Task to handle new TCP connections.
 */
Void tcpHandler(UArg arg0, UArg arg1)
{
    int                status;

    int                server;
    struct sockaddr_in localAddr;
    struct sockaddr_in clientAddr;
    int                optval;
    int                optlen = sizeof(optval);
    socklen_t          addrlen = sizeof(clientAddr);
    Task_Handle        taskHandle;
    Task_Params        taskParams;
    Error_Block        eb;

    server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (server == -1) {
        System_printf("Error: socket not created.\n");
        goto shutdown;
    }


    memset(&localAddr, 0, sizeof(localAddr));
    localAddr.sin_family = AF_INET;
    localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    localAddr.sin_port = htons(arg0);

    status = bind(server, (struct sockaddr *)&localAddr, sizeof(localAddr));
    if (status == -1) {
        System_printf("Error: bind failed.\n");
        goto shutdown;
    }

    status = listen(server, NUMTCPWORKERS);
    if (status == -1) {
        System_printf("Error: listen failed.\n");
        goto shutdown;
    }

    optval = 1;
    if (setsockopt(server, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) {
        System_printf("Error: setsockopt failed\n");
        goto shutdown;
    }

    while ((clientfd = accept(server, (struct sockaddr *)&clientAddr, &addrlen)) != -1)
    {

        System_printf("tcpHandler: Creating thread clientfd = %d\n", clientfd);

        /* Init the Error_Block */
        Error_init(&eb);

        USB_INIT();

        /* addrlen is a value-result param, must reset for next accept call */
        addrlen = sizeof(clientAddr);
    }




    System_printf("Error: accept failed.\n");

shutdown:
    if (server > 0) {
        close(server);
    }
}




void USB_INIT()
{

       /* Variables for the CIO functions */

       USBMSCHFatFs_Params_init(&usbmschfatfsParams);
         usbmschfatfsParams.serviceTaskStackPtr = usbServiceTaskStack;
         usbmschfatfsParams.serviceTaskStackSize = sizeof(usbServiceTaskStack);
         usbmschfatfsHandle = USBMSCHFatFs_open(Board_USBMSCHFatFs0,
                                                USB_DRIVE_NUM,
                                               &usbmschfatfsParams);
         if (usbmschfatfsHandle == NULL) {
             System_abort("Error starting the USB Drive\n");
         }
         else {
             System_printf("Drive %u is mounted\n", USB_DRIVE_NUM);
         }

         /* Need to block until a USB Drive has been enumerated */
         if (!USBMSCHFatFs_waitForConnect(usbmschfatfsHandle, 100000)) {
             System_abort("No USB drive present, aborting...\n");
         }

         adc2_init();
         SPI_Init();


         fresult = f_open(&src, inputfilesd, FA_READ|FA_WRITE);
              if (fresult != FR_OK)
                {
                     System_printf("Creating a new file \"%s\"...", inputfilesd);
                         /* Open file for both reading and writing */
                         fresult = f_open(&src, inputfilesd, FA_CREATE_NEW|FA_READ|FA_WRITE);
                         if (fresult != FR_OK)
                         {
                             System_printf("Error: \"%s\" could not be created.\n",inputfilesd);
                                           System_printf("Aborting...\n");
                         }

                         fresult =    f_write(&src, textarray, strlen(textarray), &bytesWritten);
                         f_sync(&src);
                         f_close(&src);
                         /* Reset the internal file pointer */
                        // f_lseek(&src, 0);
                         System_printf("done\n");
                 }
                    else
                     {
                         char temp[100];
                        // f_read(&src, read_buf, strlen(read_buf), &bytesRead);

                         while(1)
                         {

                             counter++;
                             bytesRcvd = recv(clientfd, buffer, TCPPACKETSIZE, 0);
                            // sprintf(temp,"%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%lu,%d,%d,%d,%d \n",adcBuffer2[0],adcBuffer2[1],adcBuffer2[2],adcBuffer2[3],adcBuffer2[4],adcBuffer2[5],adcBuffer2[6],adcBuffer2[7],adcBuffer2[8],buffer[0],buffer[1],buffer[2],buffer[3]);
                             sprintf(temp,"%d,%d,%d,%d \n",buffer[0],buffer[1],buffer[2],buffer[3]);
                             fresult = f_write(&src,temp, strlen(temp),&bytesWritten);
                                 //bytesRcvd = recv(clientfd, buffer, TCPPACKETSIZE, 0);

                                 //if(counter>5000)
                             if(LOCK)
                                 {
                                     f_sync(&src);
                                     f_close(&src);
                                     break;
                                 }
                         }

                     }
                     USBMSCHFatFs_close(usbmschfatfsHandle);
                    //System_printf("Drive %u unmounted\n", USB_DRIVE_NUM);
}


/*
 *  ======== main ========
 */
int main(void)

{
    /* Call board init functions */
    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), 120000000);
    Board_initGeneral();
    Board_initGPIO();
    Board_initEMAC();
    Board_initUSBMSCHFatFs();
    Board_initUART();


    UART_Params_init(&myuart);
    handle = UART_open(0, &myuart);
   // UARTStdioConfig(0, 115200, ui32SysClock);
    UART_write(handle, "HELLO", 5);

    /* SysMin will only print to the console when you call flush or exit */
    System_flush();

    /* Start BIOS */
    BIOS_start();

    return (0);
}