I setup a project about network at tms320c6748evm boards.Just network is ok, it can receive and send data! Then I insert a function When net received data.The function is fft(),but when pc run into DSPF_sp_cfftr4_dif(x_asm, w, N) ,the program will be endless loop ,cannot back .
please help me! Thanks!
void DataServer()
{
SOCKET stcp = INVALID_SOCKET;
SOCKET stcpactive = INVALID_SOCKET;
SOCKET stcpbusy;
struct sockaddr_in sin1;
struct timeval timeout; // Timeout struct for select
int size,tmp;
// Allocate the file environment for this task
fdOpenSession( TaskSelf() );
// Create the main TCP listen socket
stcp = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if( stcp == INVALID_SOCKET )
goto leave;
// Set Port = 8000, leaving IP address = Any
bzero( &sin1, sizeof(struct sockaddr_in) );
sin1.sin_family = AF_INET;
sin1.sin_len = sizeof( sin1 );
sin1.sin_port = htons(8000);
// Bind socket
if ( bind( stcp, (PSA) &sin1, sizeof(sin1) ) < 0 )
goto leave;
// Start listening
if ( listen( stcp, 1) < 0 )
goto leave;
// Configure our timeout to be 60 seconds
timeout.tv_sec = 60;
timeout.tv_usec = 0;
printf("DataSrv Initialized\n");
// Run until task is destroyed by the system
for(;;)
{
fd_set ibits, obits, xbits;
int cnt;
// Clear the select flags
FD_ZERO(&ibits);
FD_ZERO(&obits);
FD_ZERO(&xbits);
// We examine the main TCP, UDP, and active TCP (if any)
FD_SET(stcp, &ibits);
// Wait for socket activity
if( stcpactive == INVALID_SOCKET )
{
// Wait without timeout
tmp = fdSelect( 4, &ibits, &obits, &xbits, 0 );
}
else
{
// Wait for set timeout - abort active connection on no activity
FD_SET(stcpactive, &ibits);
tmp = fdSelect( 4, &ibits, &obits, &xbits, &timeout );
if( tmp <= 0 )
{
fdClose( stcpactive );
stcpactive = INVALID_SOCKET;
}
}
if( tmp < 0 )
goto leave;
// Check for a new TCP connection
if( FD_ISSET(stcp, &ibits) )
{
// We have a new connection. Assign it so sbusy at
// first...
size = sizeof( sin1 );
stcpbusy = accept( stcp, (PSA)&sin1, &size );
// If the active socket is free use it, else print out
// a busy message
if( stcpactive == INVALID_SOCKET )
stcpactive = stcpbusy;
else
fdClose( stcpbusy );
}
// Check for new data on active TCP connection
if( stcpactive != INVALID_SOCKET && FD_ISSET(stcpactive, &ibits) )
{
// There is data available on the active connection
while(1)
{
bzero(&buf_in,1024);
cnt = (int)recv( stcpactive, (int16_t *)&buf_in, 2048, 0 );
if(cnt<=0)
break;
fft(&buf_in,&buf_out,1024); // the function
if( send( stcpactive, buf_out, 2048, 0 ) < 0 )
{
fdClose( stcpactive );
stcpactive = INVALID_SOCKET;
}
}
leave: printf("DataSrv Fatal Error\n"); // This task is killed by the system - here, we block
fdClose( stcpactive );
stcpactive = INVALID_SOCKET;
}
}
// We only get here on an error - close the sockets
if( stcp != INVALID_SOCKET )
fdClose( stcp );
TaskBlock( TaskSelf() );
}
#pragma DATA_ALIGN(x_asm, 8);
#pragma DATA_ALIGN(w, 8);
#define N (1024)
float x_asm[N * 2];
float w[N * 2];
void fft (int16_t * input, float *output,int16_t n)
{
int i,t;
float rs,is,om;
memset (x_asm, 0x55, sizeof (x_asm));
for (i = 0; i < N; i++)
{
x_asm[2 * i] =(float)input[i];
x_asm[2 * i + 1] =0;
}
gen_twiddle(w, N);
DSPF_sp_cfftr4_dif(x_asm, w, N);
bit_rev(x_asm, N);
for (i=0; i<N; i++)
{ rs=x_asm[2*i]*x_asm[2*i];
is=x_asm[2*i+1]*x_asm[2*i+1];
t=(i==0 ? N:(N>>1));
om=(rs+is)/t;
output[i] = sqrt(om);
}
}