Unexpected Event: ADL_FCM_EVENT_MEM_RELEASE


#1

I am doing Data communication on UART2 and I am receiving ADL_FCM_EVENT_MEM_RELEASE event.

Documentation says that ADL_FCM_EVENT_MEM_RELEASE event is related to adl_fcmSendData function.

How is ADL_FCM_EVENT_MEM_RELEASE event related to adl_fcmSendData?

I am not expecting ADL to release the memory for me since the memory is on the stack.

(Reason for my curiosity: My 2 way data comm over UART2 stops after random number of exchanges with a PC)

Recv Handler (which also sends a message):

bool hnd_fcmData_U1 ( u16 DataSize, u8 * Data )
{
static int numRecv;
Message msg;
char outStr[255];

sprintf(outStr, "\r\n>> NumRecv %d hnd_fcmData_U1 %d\r\n", numRecv++, 
                    DataSize);
adl_atSendResponse ( ADL_AT_UNS, outStr); 

msg.type = 96;
msg.value = 98; 
adl_fcmSendData(UART2_Handle, &msg, sizeof(Message));

return TRUE;
}


#2

Hi schadha,

what you are trying to do here cannot work!

you may not use a local variable for sending data, because sending data will still happen after return from hnd_fcmData_U1 function. At that point, local variables are not in scope anymore and so the contents is undefined.

You could allocate a buffer dynamically (using a global pointer value) and when you get the ADL_FCM_EVENT_MEM_RELEASE you should release the memory. This event tells you that transmission of the buffer contents has been completed and the buffer is no longer required, so that you may release it.

Best Regards,
Jan


#3

adl_fcmSendData() does a local copy of your buffer, so you can give it a local variable.

adl_fcmSendDataExt() expects a preformatted buffer allocated with adl_memGet(), does not recopy it, and does adl_memRelease() it when sent. When releasing, it sends the MEM_RELEASE event to notify you; however, it’s already released, so you must not adl_memRelease() it yourself.

adl_fcmSendData() is just a wrapper around adl_fcmSendDataExt() which creates the preformatted buffer and fills it with your data. It causes a MEM_RELEASED event when that internal buffer is released, but that’s none of your business, you chouls ignore that event.


#4

Thanks for the correction!

But are you sure that it uses its own buffer, did you read that somewhere? See also: http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?t=1434 (pretty much at the end…)

Somebody reported that it works with releasing the buffer. But maybe the function doesn’t do anything if the pointer is already NULL…

Best Regards,
Jan