![]() |
| Home |
|
|
Using Non-Volatile MemoryThere are two methods how an application can use non-volatile memory. The simplest method is to declare a read/write device Region and a structure type containing all data to be placed in that region. At run time, initialize a pointer to that structure with the address of the region. Example (in the application's configuration file):Region NVRAM Start Size Device ReadWrite In the application's source code:
typedef struct {
int AnInteger;
} NVRAMData;
void main(void)
{
const RTAppSection * S = RTLocateSection(1, RT_ST_REGION, "NVRAM");
if (S != NULL)
{
NVRAMData * pNVRAMData = (NVRAMData*) S->SectionAddr;
printf("NRAMData %p->%i\n", pNVRAMData, pNVRAMData->AnInteger);
pNVRAMData->AnInteger++;
}
else
printf("can't find NVRAM region\n");
}
The other method places all data to reside in non-volatile memory in a separate data segment/section and Locates that Section or NTSection to a device Region. To use this method, the compiler must support placing data into a named section. Microsoft Visual C++ supports this through the #pragma bss_seg(...) directive. Example (in the application's configuration file):Region NVRAM Start Size Device ... Locate NTSection .nvram VMem->NVRam In the application's source code:
#pragma bss_seg(".nvram") // start to put data in section .nvram
int AnInteger;
#pragma bss_seg() // restore default section name
void main(void)
{
printf("NRAMData: %i\n", AnInteger);
AnInteger++;
}
|