Hi Open AT Fan,
here is a small program that recreates always (at least on my system) an error ( -7 --> FFFFFFF9 -> WM_AD_OVERFLOW ) when writing to an A&D cell. Please note that the error DOES NOT OCCOUR THE FIRST TIME (when the cell ID does not exist and has to be created).
THIS IS SOMETHING SLIGHTLY different from the previous problem description (rc=249) I made, BUT it shows clearly that something is not going on very well.
The program tries to get the handle of the cell 1123: if any error, create it.
Then it it writes a string into cell using wm_adWrite. If the cell does not exist, create it and write. Everything works fine.
If the cell exists, the wm_adWrite function return -7 (out of memory ???) and this make no much sense to me.
Even if I converted all the job I made using the ADL stuff, please do not hesitate to tell me if I made blatant error or misunderstanding.
ThanX again for your help,
Carlo.
#include "wm_types.h"
#include "wm_apm.h"
/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStack                                                      */
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
#define wm_apmCustomStackSize   1024
u32 wm_apmCustomStack[ wm_apmCustomStackSize / 4 ];
#define MY_TIMER_ID			23
#define MY_TIMER_VALUE		50					// 5 seconds
char *WriteBuf = "This is the data to write ";
u32   WriteBufLen;
#ifdef __DEBUG_APP__
	#define			MYDEBUG(_X_)			MyDebug _X_
#else
	#define			MYDEBUG(_X_)
#endif // __DEBUG_APP__
/***************************************************************************/
/*  Local variables                                                        */
/***************************************************************************/
#ifdef __DEBUG_APP__
	static char DbgBuf[256];
#endif // __DEBUG_APP__
/***************************************************************************/
/*  Functions prototypes                                                   */
/***************************************************************************/
void Handle_WM_OS_TIMER_Msg ( wm_apmMsg_t * pMessage );
#ifdef __DEBUG_APP__
	void  MyDebug ( s8 Level, const char *Format, ... )
	{
		va_list	args;
		u16		Len;
	
		wm_memset( DbgBuf, 0, sizeof( DbgBuf ) );
		va_start( args, Format );
		Len = wm_vsprintf( DbgBuf, Format, args );
		wm_strcat( DbgBuf, "\r\n" );
		Len += 3;
		wm_atSendUnsolicitedExternalApp( Len, DbgBuf );
	//	++Len;
	//	wm_atSendRspExternalApp( Len, DbgBuf );
	//	wm_osDebugTrace( (u8)Level, DbgBuf );
	}
#endif // __DEBUG_APP__
s32 wm_apmAppliInit ( wm_apmInitType_e InitType )
{
    s32 sRc;
	
    MYDEBUG(( 1, "Embedded Application Task Init" ));
    sRc = wm_osStartTimer( MY_TIMER_ID, FALSE,  MY_TIMER_VALUE );
    MYDEBUG(( 1, "wm_osStartTimer(ID=%d, value=%d) rc=%d",
              MY_TIMER_ID, MY_TIMER_VALUE, sRc ));
    WriteBufLen = wm_strlen( WriteBuf );
    return OK;
}
s32 wm_apmAppliParser ( wm_apmMsg_t * pMessage )
{
    switch ( pMessage->MsgTyp )
    {
        case WM_OS_TIMER:
            MYDEBUG(( 1, "Parser: WM_OS_TIMER" ));
            Handle_WM_OS_TIMER_Msg( pMessage );
            break;
        case WM_AT_RESPONSE:
            MYDEBUG(( 1, "Parser: WM_AT_RESPONSE" ));
            break;
        case WM_AT_UNSOLICITED:
            MYDEBUG(( 1, "Parser: WM_AT_UNSOLICITED" ));
            break;
        case WM_AT_INTERMEDIATE:
            MYDEBUG(( 1, "Parser: WM_AT_INTERMEDIATE" ));
            break;
        case WM_AT_CMD_PRE_PARSER:
            MYDEBUG(( 1, "Parser: WM_AT_CMD_PRE_PARSER" ));
            break;
        case WM_AT_RSP_PRE_PARSER:
            MYDEBUG(( 1, "Parser: WM_AT_RSP_PRE_PARSER" ));
            break;
        case WM_OS_RELEASE_MEMORY:
            MYDEBUG(( 1, "Parser: WM_OS_RELEASE_MEMORY" ));
            break;
        case WM_FCM_RECEIVE_BLOCK:
            MYDEBUG(( 1, "Parser: WM_FCM_RECEIVE_BLOCK" ));
            break;
        case WM_FCM_OPEN_FLOW:
            MYDEBUG(( 1, "Parser: WM_FCM_OPEN_FLOW" ));
            break;
        case WM_FCM_CLOSE_FLOW:
            MYDEBUG(( 1, "Parser: WM_FCM_CLOSE_FLOW" ));
            break;
        case WM_FCM_RESUME_DATA_FLOW:
            MYDEBUG(( 1, "Parser: M_FCM_RESUME_DATA_FLOW" ));
            break;
        case WM_IO_SERIAL_SWITCH_STATE_RSP:
            MYDEBUG(( 1, "Parser: WM_IO_SERIAL_SWITCH_STATE_RSP" ));
            break;
        case WM_IO_UPDATE_INFO:
            MYDEBUG(( 1, "Parser: WM_IO_UPDATE_INFO" ));
            break;
        case WM_IO_PORT_UPDATE_INFO:
            MYDEBUG(( 1, "Parser: WM_IO_PORT_UPDATE_INFO" ));
            break;
        default :
            MYDEBUG(( 1, "Parser: Unknown Message Type" ));
            break;
  
    } /* switch (pMessage->MsgTyp) */
  
    return OK;
}
/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmTask                                                             */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
const wm_apmTask_t wm_apmTask[] =
{
	{ wm_apmCustomStackSize, wm_apmCustomStack, wm_apmAppliInit, wm_apmAppliParser },
	{ 0, (u32 *)NULL, NULL, NULL },		
	{ 0, (u32 *)NULL, NULL, NULL }		
};
void Handle_WM_OS_TIMER_Msg ( wm_apmMsg_t * pMessage )
{
    wm_adHandle_t Handle;
    s32 sRc;
    u32 CellID = 1123,
        Size   = 102400;
		
    if ( pMessage->Body.OSTimer.Ident == MY_TIMER_ID )
    {
       MYDEBUG(( 1, "OUR TIMER TIMER EXPIRED!!!" ));
       sRc = wm_adRetrieve( CellID, &Handle );
       MYDEBUG(( 1, "wm_adRetrieve( Cell ID=%u ) rc=%d", CellID, sRc ));
       if ( sRc < OK )
       { // suppose it does not exist 
          sRc = wm_adAllocate( CellID, Size, &Handle );
          MYDEBUG(( 1, "wm_adAllocate( Cell ID=%u, Size=%u ) rc=%d",
                    CellID, Size, sRc ));
       }
       if ( sRc >= OK )
       {
          sRc = wm_adWrite( &Handle, WriteBufLen, WriteBuf );
          MYDEBUG(( 1, "wm_adWrite( Cell ID=%u, Len=%u Data='%s' ) rc=%d",
                    CellID, WriteBufLen, WriteBuf, sRc ));
       }
       else
          MYDEBUG(( 1, "*** UNABLE TO RETRIEVE A&D STORAGE ***" ));
    }
    else
    {
       MYDEBUG(( 1, "WARNING: unknown Timer ID received (%d)",
                 pMessage->Body.OSTimer.Ident ));
    }
}