A&D Storage service


#1

Hello, I’m looking for sample about using A&D Storage Service, the documentation only list the differents methode without example…


#2

The application download samples use A&D storage.


#3

thanks, but the example is full of bug! I can’t find download.h…
Did I need an Handler just for write and read data who I know the exact size?
Do you have an example of code just for reading and storing value of int?


#4

Could smoeone explain me how to read back my data (I finaly write it with adl_adWrite) but I can read it back withadl_adInfo, witch kind of pointer, or casting or something else is need to have my data back???


#5

Use the adl_adInfo_t structure type passed by reference to adl_adInfo. The pointer: void *data, gives you access to the data.


#6

Here it the problem! I don’t know how to back my data, I try
if info is an adl_adinfo struc…

int value = adl_adinfo.data => bad data
int value = (int)adl_adinfo.data => bad data
int value = &(adl_adinfo.data) => to grabe the data pointed by adl…data the same bad data…

witch kind of *.&-> I have to use please ?


#7

The only one you haven’t used (take a look to your C book):

int value = *((int *) adl_adinfo->data);

This gives you the value of the first integer stored. You must include the cast to integer, the original pointer “data” is defined as void!!! Most of compiler shall crash on compiling or in execution, if you dont include the cast.


#8

The worst, is that I tried int value = *(adl…data) but as you said it’s crash :’( shame on me, but thanks to you for help :wink:


#9

Me again, I can now read data and write most of them…
But I steal have a probem… :’(
I obtain adl_adwrite error -21 at the first cal in trace when I try this code:

#include "adl_global.h"

const u16 wm_apmCustomStackSize = 1024*3;

/*Struct des PIO de Mesure*/
struct PIO{
	char GPIOnumber;
	s32 GPIOHandle;
	adl_ioDefs_t GPIOConfig;
	adl_ioDefs_t GPIOToRead;
	s32 ReadCurrentValue;
	ascii LabelGPIO[10];
	unsigned short CmpGPIO;
	short UnitGPIO;
	bool OldValueGPIO;
	unsigned short SavedCmpGPIO;
	unsigned char Duree;
};
/*tableau de struct "PIO" contenat les GPIO à lire,compter*/
struct PIO TblEntree[5];


s32 AdEventHandle;
adl_adInfo_t infocell;

s32 celletatmodem = 0;
s32 celllabelpio19 = 1;
s32 cellunitpio19 = 2;
s32 cellcmppio19 = 3;
s32 celllabelpio20 = 4;
s32 cellunitpio20 = 5;
s32 cellcmppio20 = 6;
s32 celllabelpio23 = 7;
s32 cellunitpio23 = 8;
s32 cellcmppio23 = 9;
s32 celllabelpio26 = 10;
s32 cellunitpio26 = 11;
s32 cellcmppio26 = 12;
s32 celllabelpio27 = 13;
s32 cellunitpio27 = 14;
s32 cellcmppio27 = 15;

#define TAILLELABELPIO sizeof(ascii)*10
#define TAILLEUNITPIO sizeof(short)
#define TAILLECMPPIO sizeof(unsigned short)

#define TYPELABELPIO typeof(ascii)
#define TYPEUNITPIO typeof(short)
#define TYPECMPPIO typeof(unsigned short)

void info(void){
	adl_adState_t etatmem;
	adl_adGetState(&etatmem);
	TRACE (( 1, "totalmem = %d", etatmem.totalmem));
	TRACE (( 1, "freemem = %d", etatmem.freemem));
	TRACE (( 1, "numobjects = %d", etatmem.numobjects));
	TRACE (( 1, "numdelobjects = %d", etatmem.deletedmem));
}

void subscribe(void){
    celllabelpio19 = adl_adSubscribe(celllabelpio19,TAILLELABELPIO);
    cellunitpio19 = adl_adSubscribe(cellunitpio19,TAILLEUNITPIO);
    cellcmppio19 = adl_adSubscribe(cellcmppio19,TAILLECMPPIO);

    celllabelpio20 = adl_adSubscribe(celllabelpio20,TAILLELABELPIO);
    cellunitpio20 = adl_adSubscribe(cellunitpio20,TAILLEUNITPIO);
    cellcmppio20 = adl_adSubscribe(cellcmppio20,TAILLECMPPIO);

    celllabelpio23 = adl_adSubscribe(celllabelpio23,TAILLELABELPIO);
    cellunitpio23 = adl_adSubscribe(cellunitpio23,TAILLEUNITPIO);
    cellcmppio23 = adl_adSubscribe(cellcmppio23,TAILLECMPPIO);

    celllabelpio26 = adl_adSubscribe(celllabelpio26,TAILLELABELPIO);
    cellunitpio26 = adl_adSubscribe(cellunitpio26,TAILLEUNITPIO);
    cellcmppio26 = adl_adSubscribe(cellcmppio26,TAILLECMPPIO);

    celllabelpio27 = adl_adSubscribe(celllabelpio27,TAILLELABELPIO);
    cellunitpio27 = adl_adSubscribe(cellunitpio27,TAILLEUNITPIO);
    cellcmppio27 = adl_adSubscribe(cellcmppio27,TAILLECMPPIO);
}

void finalise(void){
	adl_adFinalise(celllabelpio19);
	adl_adFinalise(cellunitpio19);
	adl_adFinalise(cellcmppio19);
	adl_adFinalise(celllabelpio20);
	adl_adFinalise(cellunitpio20);
	adl_adFinalise(cellcmppio20);
	adl_adFinalise(celllabelpio23);
	adl_adFinalise(cellunitpio23);
	adl_adFinalise(cellcmppio23);
	adl_adFinalise(celllabelpio26);
	adl_adFinalise(cellunitpio26);
	adl_adFinalise(cellcmppio26);
	adl_adFinalise(celllabelpio27);
	adl_adFinalise(cellunitpio27);
	adl_adFinalise(cellcmppio27);
}

void delete(void){
	adl_adDelete(celllabelpio19);
	adl_adDelete(cellunitpio19);
	adl_adDelete(cellcmppio19);
	adl_adDelete(celllabelpio20);
	adl_adDelete(cellunitpio20);
	adl_adDelete(cellcmppio20);
	adl_adDelete(celllabelpio23);
	adl_adDelete(cellunitpio23);
	adl_adDelete(cellcmppio23);
	adl_adDelete(celllabelpio26);
	adl_adDelete(cellunitpio26);
	adl_adDelete(cellcmppio26);
	adl_adDelete(celllabelpio27);
	adl_adDelete(cellunitpio27);
	adl_adDelete(cellcmppio27);
}

void write(void){
	adl_adWrite(celllabelpio19,TAILLELABELPIO,&TblEntree[0].LabelGPIO);
	adl_adWrite(celllabelpio19,TAILLELABELPIO,&TblEntree[0].LabelGPIO);
	adl_adWrite(cellunitpio19,TAILLEUNITPIO,&TblEntree[0].UnitGPIO);
	adl_adWrite(cellcmppio19,TAILLECMPPIO,&TblEntree[0].CmpGPIO);

	adl_adWrite(celllabelpio20,TAILLELABELPIO,&TblEntree[1].LabelGPIO);
	adl_adWrite(cellunitpio20,TAILLEUNITPIO,&TblEntree[1].UnitGPIO);
	adl_adWrite(cellcmppio20,TAILLECMPPIO,&TblEntree[1].CmpGPIO);

	adl_adWrite(celllabelpio23,TAILLELABELPIO,&TblEntree[2].LabelGPIO);
	adl_adWrite(cellunitpio23,TAILLEUNITPIO,&TblEntree[2].UnitGPIO);
	adl_adWrite(cellcmppio23,TAILLECMPPIO,&TblEntree[2].CmpGPIO);

	adl_adWrite(celllabelpio26,TAILLELABELPIO,&TblEntree[3].LabelGPIO);
	adl_adWrite(cellunitpio26,TAILLEUNITPIO,&TblEntree[3].UnitGPIO);
	adl_adWrite(cellcmppio26,TAILLECMPPIO,&TblEntree[3].CmpGPIO);

	adl_adWrite(celllabelpio27,TAILLELABELPIO,&TblEntree[4].LabelGPIO);
	adl_adWrite(cellunitpio27,TAILLEUNITPIO,&TblEntree[4].UnitGPIO);
	adl_adWrite(cellcmppio27,TAILLECMPPIO,&TblEntree[4].CmpGPIO);
}

void AdEventsHandler( adl_adEvent_e Event, u32 Progress ){
	// Switch on event
	switch ( Event ){
		case ADL_AD_EVENT_FORMAT_INIT:{TRACE (( 1, "Format Initialisée" ));break;}
		case ADL_AD_EVENT_FORMAT_PROGRESS:{TRACE (( 1, "Format En Cours" ));break;};
		case ADL_AD_EVENT_FORMAT_DONE:{TRACE (( 1, "Format Finis" ));break;}
		case ADL_AD_EVENT_RECOMPACT_INIT:{TRACE (( 1, "Recompatage Initialisé" ));break;}
		case ADL_AD_EVENT_RECOMPACT_PROGRESS:{break;}
	    case ADL_AD_EVENT_RECOMPACT_DONE:{TRACE (( 1, "Recompatage Finis" ));break;}
	    case ADL_AD_EVENT_INSTALL:break;
	}
}

void TimerHandler ( u8 ID, void * Context ){
	adl_adState_t etatmem;
	adl_adGetState(&etatmem);
	if(etatmem.numdeleted >= 10){
		adl_adRecompact(AdEventHandle);
	}
}

void savemem(void){
	finalise();
	delete();
	subscribe();
	write();
}

void adl_main ( adl_InitType_e  InitType ){
    TRACE (( 1, "Embedded : Appli Init" ));
    AdEventHandle = adl_adEventSubscribe(AdEventsHandler);
    strcpy(TblEntree[0].LabelGPIO,"blop1");
    strcpy(TblEntree[1].LabelGPIO,"blop2");
    strcpy(TblEntree[2].LabelGPIO,"blop3");
    strcpy(TblEntree[3].LabelGPIO,"blop4");
    strcpy(TblEntree[4].LabelGPIO,"blop5");

    subscribe();
    savemem();
    adl_tmrSubscribe(TRUE,ADL_TMR_MN_TO_TICK(1),ADL_TMR_TYPE_TICK,TimerHandler);

}

So what -12 stand for, and where is my mistak ??

EDIT:
I got error only for adl_adWrite(celllabelpio19,TAILLELABELPIO,&TblEntree[0].LabelGPIO);
and if I comment it no more and the other steel works


#10

The error codes are described in the chapter titled “Error Codes” at the end of the ADL User Guide


#11

My bad is -21 meaning for Memory Full, so next question :slight_smile:
How the memory can be full, if the next write are done without error… and I did 3 time the same thing…

I did:

adl_adWrite(celllabelpio19,TAILLELABELPIO,&TblEntree[0].LabelGPIO);  -> return -21
adl_adWrite(cellunitpio19,TAILLEUNITPIO,&TblEntree[0].UnitGPIO);  -> return 0
adl_adWrite(cellcmppio19,TAILLECMPPIO,&TblEntree[0].CmpGPIO);  -> return 0

adl_adWrite(celllabelpio20,TAILLELABELPIO,&TblEntree[1].LabelGPIO);  -> return 0
adl_adWrite(cellunitpio20,TAILLEUNITPIO,&TblEntree[1].UnitGPIO);  -> return 0
adl_adWrite(cellcmppio20,TAILLECMPPIO,&TblEntree[1].CmpGPIO);  -> return 0

Moreover TblEntree[0].LabelGPIO and TblEntree[1].LabelGPIO contain the same quantity of data and have the same size…


#12

-21 means ADL_AD_RET_ERR_OVERFLOW.
You are triying to write two times on the same cell:

adl_adWrite(celllabelpio19,TAILLELABELPIO,&TblEntree[0].LabelGPIO);
   adl_adWrite(celllabelpio19,TAILLELABELPIO,&TblEntree[0].LabelGPIO);
   adl_adWrite(cellunitpio19,TAILLEUNITPIO,&TblEntree[0].UnitGPIO);
   adl_adWrite(cellcmppio19,TAILLECMPPIO,&TblEntree[0].CmpGPIO);

Be careful, adl_adWrite, writes AT THE END of the cell. It doesn’t over write. May flh functions are more indicated for your use.


#13

Hi I also think, I will move to Flash memory…

For my application, I’m looking to save and restore an array of 5 elements of this type of struct:

struct PIO{
	char GPIOnumber;
	s32 GPIOHandle;
	adl_ioDefs_t GPIOConfig;
	adl_ioDefs_t GPIOToRead;
	s32 ReadCurrentValue;
	ascii LabelGPIO[10];
	unsigned short CmpGPIO;
	short UnitGPIO;
	bool OldValueGPIO;
	unsigned short SavedCmpGPIO;
	unsigned char Duree;
};

and also some ascii array (of differents size …)
Have you any idea, example, help of how doing that?

Thanks in advance


#14

You can use it as follow:

PIO Data[5];

if(adl_flhSubscribe("Structure Objects", 5) == OK)
{
  //First subscription: Initialize flash
  ...
}
...
//Data writing
for (i=0; i<sizeof(Data); i++)
{
 adl_flhWrite("Structure Objects",0,sizeof(PIO),(u8 *) Data[i]);
}

Hope this helps


#15

Very Thanks to you fer.caballero !!!
It’s not exactly what I want but that help me a lot

Now all seem to work greatfully.