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.

RTOS: RTOS/TM4C1294NCPDT: UART with TCP/IP issue

Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

HelIo

I am working on TI-RTOS

I want to send and Received data over a Ethernet, i am using TCP echo example as a reference and have combined with it UART code.

Read data from uart and send data over a Ethernet worked successfully i want to Read data from uart and send data over a Ethernet as well as Received data from Ethernet and write it to uart
code as follows

/*
* ======== tcpEcho.c ========
* Contains BSD sockets code.
*/

#include <string.h>
#include <stdio.h>
#include <stdbool.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"

#define TCPPACKETSIZE 256
#define NUMTCPWORKERS 3


char charinput[100]={0};


int32_t i32Logindex=0;
/*
* ======== tcpWorker ========
* Task to handle TCP connection. Can be multiple Tasks running
* this function.
*/
Void tcpWorker(UArg arg0, UArg arg1)
{
int32_t i32Clientfd = (int32_t)arg0;
UART_Handle uart;
UART_Params uartParams;

/*******UART 0 parameters initialization*************/
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 9600;

/***************Open UART 0**************************/
uart = UART_open(Board_UART0,&uartParams);

System_printf("tcpWorker: start clientfd = 0x%x\n", i32Clientfd);

// while(1)
//{
/********read data on UART 0****************/
UART_read(uart,&charinput,sizeof(charinput));

/******send data over the Ethernet**********/
send(i32Clientfd,charinput,sizeof(charinput),0);

// }

}

/*
* ======== tcpHandler ========
* Creates new Task to handle new TCP connections.
*/
Void tcpHandler(UArg arg0, UArg arg1)
{
int32_t i32Status;
int32_t i32Clientfd;
int32_t i32Server;
struct sockaddr_in localAddr;
struct sockaddr_in clientAddr;
int32_t i32Optval;
int32_t i32Optlen = sizeof(i32Optval);
socklen_t addrlen = sizeof(clientAddr);
Task_Handle taskHandle;
Task_Params taskParams;
Error_Block eb;

i32Server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (i32Server == -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);

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

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

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

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

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

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

/* Initialize the defaults and set the parameters. */
Task_Params_init(&taskParams);
taskParams.arg0 = (UArg)i32Clientfd;
taskParams.stackSize = 1280;
taskHandle = Task_create((Task_FuncPtr)tcpWorker, &taskParams, &eb);
if (taskHandle == NULL) {
System_printf("Error: Failed to create new Task\n");
close(i32Clientfd);
}

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

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

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

/*
* ======== main ========
*/
int main(void)
{
/* Call board init functions */
Board_initGeneral();
Board_initGPIO();
Board_initEMAC();
Board_initUART();

System_printf("Starting the TCP Echo example\nSystem provider is set to "
"SysMin. Halt the target to view any SysMin contents in"
" ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();

/* Start BIOS */
BIOS_start();

return (0);
}

please give some suggestion

Thank you