Flash Objects


#1

Hi there

I am trying to run the following application in TMT and TE.

#include "adl_global.h"
/***************************************************************************/
/*	Pre-defined constants												   */		
/***************************************************************************/
#define MAX_OBJ_NO		5
/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStack                                                      */
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );
/***************************************************************************/
/*  Local variables                                                        */
/***************************************************************************/
ascii Flash_Handle[] = "Handle"; // The flash objects stored are identified by this handle. 
s32 FlashID_Count;
s8 Return_Status;
u8 MyFlashObjCount = 0;
u16 MyFlashID = 0;
u16 FlhID[MAX_OBJ_NO]; // This array contains the Flash ID's of the flash objects.
u32 MemAvailableInFlash;
s32 MyFlashLen;
u8 MyData[] = "1001";

void adl_main ( adl_InitType_e InitType )
{
	u8 Index;
	s8 FlashReadStatus;
	s8 FlashWriteStatus;
	ascii MyResponse[100];
	
	TRACE (( 1, "Embedded Application : Main" ));
 	
	/* Subscribe for 5 flash objects. MAX_OBJ_NO is defined as 5. */
	Return_Status = adl_flhSubscribe(Flash_Handle, MAX_OBJ_NO);

	/* Get the ID count at the given handle and send it as response */
	FlashID_Count = adl_flhGetIDCount(Flash_Handle); 
	wm_sprintf(MyResponse,"ID's subscribed: %d\r\n",FlashID_Count);
	adl_atSendResponse(ADL_AT_UNS, MyResponse);

	/* Get free flash memory available and send it as response*/
	MemAvailableInFlash = adl_flhGetFreeMem();
	wm_sprintf(MyResponse,"Flash size: %u[No data written yet]\r\n",MemAvailableInFlash);
	adl_atSendResponse(ADL_AT_UNS, MyResponse);	
	
	/* Only if Memory is available in flash and if MyFlashObjCount is less than 5 */
	while(MemAvailableInFlash && (MyFlashObjCount < MAX_OBJ_NO))
	{
		MyFlashLen = adl_flhExist(Flash_Handle, MyFlashID);
		if(!MyFlashLen)
		{
			FlhID[MyFlashObjCount] = MyFlashID; // Store the allocated flash ID's in the array
			MyFlashObjCount++;
			FlashWriteStatus = adl_flhWrite( 
				Flash_Handle,	// Flash handle
				MyFlashID,		// ID of the flash object we are writing into
				(4 + 1),		// Length of flash object("1001")(Null terminator included)
				MyData);		// Pointer to data array.
			if(FlashWriteStatus != 0)
			{
				wm_sprintf(MyResponse,"Flash write failed. Error code: %d",FlashWriteStatus);
				TRACE((1,MyResponse));
				return; // Exit from adl_main().
			}

			MemAvailableInFlash = adl_flhGetFreeMem();
			wm_sprintf(MyResponse,"Flash Size: %u\r\n",MemAvailableInFlash);
			adl_atSendResponse(
				ADL_AT_UNS,  // This indicates that the response is an unsolicited message
				MyResponse); // This is the reponse string.		
			
			MyData[3] = MyData[3] + 1; // Incrementing the last digit to create a sequence.
			// MyData will consequently hold 1001, 1002, 1003 & 1004 sequentially.
		}
		MyFlashID++;
	}
/*	wm_sprintf(MyResponse,"No: of ID's subscribed: %u\r\n",MyFlashObjCount);
	adl_atSendResponse(ADL_AT_UNS, // This indicates that the response is an unsolicited message
		MyResponse);			   // This is the reponse string.		
*/ // This we are already performing by the API.
	//** Reading all the flash objects and then erase them as soon as they are read.
	for(Index = 0; Index < MAX_OBJ_NO; Index ++)
	{
		FlashReadStatus = adl_flhRead(
			Flash_Handle,	// Flash handle.
			FlhID[Index],	// ID of the flash object we are reading from.
			(4 + 1) ,		// Length of flash object(Null terminator included)
			MyData);		// Pointer to data array.

		if(FlashReadStatus != 0)
		{
			wm_sprintf(MyResponse,"Flash read failed. Error code: %d",FlashReadStatus);
			TRACE((1,MyResponse));
			return; // Exit from adl_main().
		}

		 
		wm_sprintf(MyResponse,"Data[%u] = %s\r\n",Index, MyData);
		adl_atSendResponse(
			ADL_AT_UNS,		// This indicates that the response is an unsolicited message.
			MyResponse);	// This is the reponse string.		
		
		/* Erase flash object at 'FlhID[Index]' and identified by 'Flash_Handle'. */
		if(OK == adl_flhErase(Flash_Handle,		// Handle of the subscribed set of objects.
							  FlhID[Index]));	// ID of flash object to be erased.
		
	}
	
	MemAvailableInFlash = adl_flhGetFreeMem();
	wm_sprintf(MyResponse,"Flash size: %u\r\n",MemAvailableInFlash);
	adl_atSendResponse(ADL_AT_UNS,	// This indicates that the response is an unsolicited message.
		MyResponse);				// This is the reponse string.		
	



}

I think that I am missing something here. What command do I use to get the count of subscribed flash ID, size of the free flash memory and all. The application ends at the TRACE((1, “Embedded Application:Main”")) because I do not know what commands must be issued to get this other information.

Regards,

Gugulethu

my question is, how do I getp


#2

I realised that i did not read all the information on the TE regarding the flash. I have found my mistake.

Kind Regards,

Gugulethu