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.

AM3357: NIMU_send does not free memory when there is no network

Part Number: AM3357

Hi,
I am using the following products for my project:
Code Composer Studio 7.3.0
NDK 2.26.00.08
SYS/BIOS 6.52.00.12
am335x PDK 1.0.9

I have created application.
This have several tasks, some of them do communicate or its standby.(one of which is UDP and two are TCP)
If run this application for a while, them may suddenly lose communication.
At this time, the memory (PBMQ_free in pbm.c) is empty and will not be replenished.

It seems that the cause is do not free memory(PBM_free in pbm.c) when NIMU_send is send failure(TxFree variable is set to 0).

When TxFree variable is set to 0, NIMU_senddoes not free memory(packet data) even though it does not send data, and reports that it success of sent(return 0).
The memory of the packet dequeued from PBMQ_free disappears somewhere and does not return to PBMQ_free.
(A similar NIMU_ICSS_send (in nimu_icssEth.c) enqueues a packet to pNimuIcssEmacPrivData-> pdi.PBMQ_tx regardless of the success or failure of the sent, and the packet's memory are always released by the end of the function.)
I fixed NIMU_send to report a error of sent (return -1) when TxFree variable is set to 0. This will cause NIMUSendPacket, which is calling NIMU_send, to free memory.
This fixes makes the application work fine, but does it cause anything wrong?

The code below is NIMU_send with fixed.


/**
* @b NIMU_send
* @n
* The function is the interface routine invoked by the NDK stack to
* pass packets to the driver.
*
* @param[in] ptr_net_device
* NETIF_DEVICE structure pointer.
* @param[in] hPkt
* Packet to be sent out on wire.
*
* @retval
* Success - 0
* @retval
* Error - <0
*/
static int_fast32_t NIMU_send (NETIF_DEVICE* ptr_net_device, PBM_Handle hPkt); /* misra warning */
static int_fast32_t NIMU_send (NETIF_DEVICE* ptr_net_device, PBM_Handle hPkt)
{
CPSW_EMAC_DATA* ptr_pvt_data;

/* Get the pointer to the private data */
ptr_pvt_data = (CPSW_EMAC_DATA *)ptr_net_device->pvt_data;

/* Make sure the driver does not transmit packet less than min. as per the
* Ethernet standards. */
if( PBM_getValidLen(hPkt) < 60U )
{
PBM_setValidLen (hPkt, 60U );
}
/* We do not do any packet size checks here. If the packet
* is too big to fit in the MTU configured on the peripheral,
* then the driver/CSL layer catches the error.
*/

if(ptr_pvt_data->pdi.TxFree )
{
/* Enqueue the packet and send it for transmission. */
PBMQ_enq (&ptr_pvt_data->pdi.PBMQ_tx, hPkt);

/* Pass the packet to the controller if the transmitter is free. */
CpswHwPktTxNext(&ptr_pvt_data->pdi);
}
/* fixed point */
else{
/* Packet has not transmitted. */
return -1;
}

/* Packet has been successfully transmitted. */
return 0;
}


Thank you.