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.

MSP432E401Y: Arm-based microcontrollers forum

Part Number: MSP432E401Y
Other Parts Discussed in Thread: CC3220SF

In the UDP data communications (ethernet) in MSP432E401Y, I use the sendto() function. I was not able to operate transmission normally when going to let  carry it out in the new thread which flicked this out from a current thread.
I carried out the same thing in CC3220SF(WiFi), but was able to work normally here.
Please tell me what is bad.

/************************************
* server.c
* Contains BSD sockets code.
*************************************/

#include <string.h>
#include <stdint.h>
#include <stdio.h>

#include <pthread.h>
/* BSD support */
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netdb.h>

#include <ti/net/slnetutils.h>
#include <ti/display/Display.h>

#define UDPPORT "8611"

// ****** global variable *************************
uint32_t x=0;
int flag=0;
int SD = -1;
struct sockaddr_in clientAddr; // destination address from server
socklen_t clientaddrlen = sizeof(clientAddr); // the destination length
char rxBuffer[200]={0}; // Network receive memory
char txBuffer[1500]={0}; // Network send memory

extern Display_Handle dispH;
extern void fdOpenSession();
extern void fdCloseSession();
extern void *TaskSelf();
///////////////////////////////////////////////////////////////////////////
void myTimer(int tms)
{
volatile int i,j;
for(i=0;i<tms;++i) // 2000ms
{
j=12000; //
while(j>0){ --j; }
}
}
///////////////////////////////////////////////////////////////////////////

//*******mainTask thread function***********************************************
void* sendTask(void* arg)
{
int k,yy;

Display_printf(dispH, 0, 0, "******** hirose_server started**********");

while(flag>0)
{
for(k=0;k<16;++k) // make sending data
{
txBuffer[k]=(uint8_t)x++;
}
yy=sendto(SD, txBuffer, 16, 0,(struct sockaddr *)&clientAddr, clientaddrlen);

myTimer(2000);
Display_printf(dispH, 0, 0, "yy=%d .... x[15]=%d",yy,txBuffer[15]);
//--flag;
}
Display_printf(dispH, 0, 0, "******** hirose_server ended**********");

return NULL;
}

//*************************************************************************
void* server(void* arg)
{
int status;
struct addrinfo hints;
struct addrinfo *px;
char portNumber[]=UDPPORT; // PORT NO. (string)

Display_printf(dispH, 0, 0, "UDP Server example started");
fdOpenSession(TaskSelf()); // ??? but need!
Display_printf(dispH, 0, 0, "application portNumber = %s ",portNumber);

memset(&hints, 0, sizeof(hints)); // addrinfo
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE;

/* Obtain addresses suitable for binding to */
getaddrinfo(NULL, portNumber, &hints, &px); // ①make addrinfo struct
SD = socket(px->ai_family, px->ai_socktype, px->ai_protocol);// ②make soket
status = bind(SD, px->ai_addr, px->ai_addrlen); // ③bind the address


freeaddrinfo(px);
px = NULL;

Display_printf(dispH, 0, 0, "SD=%d: status=%d: Communication Start ",SD,status);


// Sever Operartion Start
while(1)
{
recvfrom(SD, rxBuffer, 20, 0,(struct sockaddr *)&clientAddr, &clientaddrlen);
// for the moment , parrot teturn ---> This is made!
sendto(SD, rxBuffer, 20, 0,(struct sockaddr *)&clientAddr, clientaddrlen);

if((strncmp(rxBuffer,"start",5)==0) && (flag==0))
{
flag=1;
// make a new thread
struct sched_param priParam;
priParam.sched_priority=8;
pthread_t thread;
pthread_attr_t attrs;
pthread_attr_init(&attrs);
pthread_attr_setschedparam(&attrs, &priParam);
//pthread_attr_setdetachstate(&attrs,1);
pthread_attr_setstacksize(&attrs, 2048);
pthread_create(&thread, &attrs, sendTask, NULL); // sendTask() thread call
// --->This can not work well. !!!!!!
// sendTask(NULL); //if there is it in this thread,it can work well as a function.
}

if((strncmp(rxBuffer,"stop",4)==0) && (flag==1))
{
flag=0;
Display_printf(dispH, 0, 0, "******** serverTask ended******** ");
}
}


// --------------------------------------------------------------------------------
fdCloseSession(TaskSelf());

return NULL;
}