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.

NDK2.0.0 run to UTL_HALT()

Other Parts Discussed in Thread: TMS320C6747

Dear Sir:
I have a problem when using NDK2.0.0 in my project.

CCS Version : Code Composer Studio 4.2.0.10018
Target CPU : TMS320C6747
Reference examples: NDK2.0.0\ti\ndk\example\network\client\evm6747\client.pjt

The DSP is connected to a PHY(act as a client) to communicate with the PC (act as a sever).
When I'm sending data in an infinite loop,after a few seconds , the programme run to a function called UTL_HALT().
What's the meaning and how to avoid the problem appears?

**** My program is following(Modified at conecho.c):***********************************

void MyEchoTcp()
{
SOCKET s;
struct sockaddr_in sin1;
char *pBuf = 0;
Int16 sendbytes;
int error = 0,status,size;
printf("\n== Start My TCP Echo Client Test ==\n");

/* Allocate the file environment for this task */
fdOpenSession( TaskSelf() );

if( !(pBuf = mmBulkAlloc( 1024 )) )
{
printf("failed allocate buffer ,leaving...\n");
goto leave;
}

s = socket(AF_INET, SOCK_STREAMNC, IPPROTO_TCP);
if( s == INVALID_SOCKET )
{
printf("failed socket create (%d),leaving...\n",fdError());
goto leave;
}

// Prepare address for connect
bzero( &sin1, sizeof(struct sockaddr_in) );
sin1.sin_family = AF_INET;
sin1.sin_len = sizeof( sin1 );
sin1.sin_addr.s_addr = 0xDD00A8C0;//IPAddr;
sin1.sin_port = htons(5908);

// Configure our Tx and Rx timeout to be 5 seconds
timeout.tv_sec = 5;
timeout.tv_usec = 0;

setsockopt( s , SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof( timeout ) );
setsockopt( s , SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof( timeout ) );

SocketValid = 0;

while(1)
{
// Connect socket
if ( connect( s, (PSA) &sin1, sizeof(sin1) ) < 0 )
{
LOG_printf(&myLog,"failed connect s (%d)\n",fdError());
LOG_printf(&myLog,"connect task sleep 2 s ... \n");
TaskSleep(2000);
continue;
}

SocketValid = 1;

while(SocketValid)
{
sendbytes = send( s, pBuf, 1024, 0 );//Line A
if( sendbytes < 0 )
{
LOG_printf(&myLog, "Failed sendto : (%d)\n",fdError());
switch(fdError())
{
case ENOTCONN:
SocketValid = 0;
break;
}
}
else
{
LOG_printf(&myLog, "Success send Bytes:(%d)",sendbytes);
TaskSleep(1);//Line B
}
}
}
leave:

if( pBuf )
mmBulkFree( pBuf );

fdCloseSession( TaskSelf() );

printf("== socket task end ==\n\n");

TaskExit();
}
******************************************************************************************
I have tried to modify some value in this program and get a few rules,that is
1. sendbytes = send( s, pBuf, N, 0 );//Line A, the program run to UTL_HALT() more quickly when N increase;
2. TaskSleep(N)//Line B,the program run to UTL_HALT() more quickly when N reduce;
3. When I set a breakpoint at Line A and sending 1024 bytes each time,when the program run to the breakpoint after 8 times,the program will run to UTL_HALT().
In my view,it seems that this problem has some relation to the TCP Transmit buffer size(the default size is 8192),Am I true?

Please give me some suggestions,thank you!

  • Hi Pan,

    Thanks for your post.

    To my knowledge, UTL_Halt( ) should be caused by memory leak and kindly ensure the memory usage of your application doesn't violate the desired limits at run time. Please check for sufficient memory while the DSP application at run time.

    Also, i think, this problem is highly related to NDK internal semaphore and task switching between tskNdkStackTest() and udp_sendTsk().

    There are some clues which you can trace out when the DSP application runs for a while, it would be halted by calling UTL_halt(),

    1.  You could not send UDP datagram continuously and stably if using keeping NDK with a NC_PRIORITY_LOW priority. Therefore you could change the NDK priority from NC_PRIORITY_LOW to NC_PRIORITY_HIGH by the following line:

    rc = NC_SystemOpen( NC_PRIORITY_HIGH, NC_OPMODE_INTERRUPT );

    2.       You could also analyze the DSP/BIOS->Message Log->Excution Graphic Details output:

    553765   SWI: begin KNL_swi (TSK scheduler) (0xe00cef58)

    553766   SWI: end   KNL_swi (TSK scheduler) (0xe00cef58) state = done

    553767   SWI: begin KNL_swi (TSK scheduler) (0xe00cef58)

    553768   SWI: end   KNL_swi (TSK scheduler) (0xe00cef58) state = done

    553769   SWI: begin KNL_swi (TSK scheduler) (0xe00cef58)

    553770   TSK: blocked tskNdkStackTest (0xe00ceddc) on <unknown handle> SEM

    553771   TSK: running dynamic TSK (0xe009624c)

    553772   SWI: end   KNL_swi (TSK scheduler) (0xe00cef58) state = done

    553773   SWI: begin KNL_swi (TSK scheduler) (0xe00cef58)

    553774   SWI: end   KNL_swi (TSK scheduler) (0xe00cef58) state = done

    553775   SWI: begin KNL_swi (TSK scheduler) (0xe00cef58)

    553776   SWI: end   KNL_swi (TSK scheduler) (0xe00cef58) state = done

    553777   SWI: begin KNL_swi (TSK scheduler) (0xe00cef58)

    553778   SWI: end   KNL_swi (TSK scheduler) (0xe00cef58) state = done

    553779   SYS abort called with message '*** TSK lock NOT CALLED IN TSK CONTEXT'

          Does the above indicate the UTL_Halt() failure is caused by task switching between tskNdkStackTest() and udp_sendTsk(), since the two is NDK scheduler tasks, we can do nothing to change this architecture.

    3.       If we change the data sending code as following:

    while(1){      

         opt = sendto(s,sendBuf,1280,0,(PSA)&addrto,sizeof(addrto));

            if(opt != 1280)

    { printf("send err ! ");break;}

    TSK_sleep(1);

    }

    The application will not enter UTL_Halt() and operate normally for a very long time (but not  sure whether it will be stable forever). However “TSK_sleep(1)” will dramatically degrade the UDP sending speed which is not acceptable for your application, I belive so.

    Thanks & regards,

    Sivaraj K

    -------------------------------------------------------------------------------------------------------

    Please click the Verify Answer button on this post if it answers your question.

    -------------------------------------------------------------------------------------------------------

  • Dear Sivaraj K:
    Thanks,I have tried your methods and find that
    1. changing the NDK priority from NC_PRIORITY_LOW to NC_PRIORITY_HIGH has no effect.
    2.the raw logs printed by RTAsystem is very similar to your example log.
    3.changing the data sending code as your suggestion has no effect.

    Fortunately,I modified my CMD file and change the .tsk section to SDRAM(it's original location : DSPL2RAM,and all other sections are in SDRAM ),my program never run to UTL_HALT() any more.It seems a little strange.
    As you see,the problem must highly related to NDK internal semaphore and task switching,but when I modify the location of the section,the problem seems to be solved. How to explain this?

    Thanks & regards,
    Pan
  • Hi Pan,

    Thanks for your update.

    We would be glad if you share the solution steps for this fix sothat, the E2E community members would be beneffited and it would help other if they see the same issue.

    We really appreciate your efforts and glad that your issue gets resolved.

    Thanks for your understanding.

    Thanks & regards,

    Sivaraj K

    -------------------------------------------------------------------------------------------------------

    Please click the Verify Answer button on this post if it answers your question.

    -------------------------------------------------------------------------------------------------------