|
|
Typical Usage:
(Examples of a typical usage of the component in user code.
For more information please
see the page Component Code
Typical Usage.)
In our examples we expect that there is an empty flash sector at 0xE000 address. It is also expected, that affected FLASH memory area is not protected. Please refer to CPU datasheet for details about protection. The user has to properly choose the address in the flash for writing the data and ensure that sector that will be over-written does not contain an application code or data, because the whole sector may be erased and lost. This can be done for example, by decreasing the size of the area where the code is stored by the size of one or more sectors that will be used for user's data. To adjust the allocation sizes, open the build options tab in CPU inspector. Typical usage examples:
(1)
MAIN.C
byte Data;
void main(void)
{
/* Erase whole sector - necessary only if Write mode property is set to "Write" */
IFsh1_EraseSector(0xE000);
/* Write number 28 to address 0xE000 */
IntF1_SetByteFlash(0xE000, 28);
/* Read contents of internal FLASH array on address
0xE000 and write it to variable Data */
IntF1_GetByteFlash(0xE000, &Data);
}
Note: Address of FLASH is meant as absolute address, not index in FLASH array.
(2)
MAIN.C
void main(void)
{
// Fill virtual page with actual data content of address 0xE000
IntF1_GetPage(0xE000);
// Write number 23 to first cell of page
IntF1_SetBytePage(0, 23);
// Write number 255 to second cell
IntF1_SetBytePage(1, 255);
// Store data content of virtual page to FLASH on address 0xE630
IntF1_SetPage(0xE630);
}
Note: Method SetBytePage/GetBytePage use index 0 to PageSize-1
(3)
EVENTS.C
#define MASK_ADDR_OFFSET (IntF1_AREA_0_SECTOR_SIZE - 1)
static byte LocBuffer[IntF1_AREA_0_SECTOR_SIZE];
void IntF1_OnSaveBuffer(IntF1_TAddress Addr, word Size)
{
byte * Buf = &LocBuffer[Addr & MASK_ADDR_OFFSET];
while (Size--) {
(void)IntF1_GetByteFlash(Addr, Buf);
Addr++;
Buf++;
} /* while Size */
}
void IntF1_OnRestoreBuffer(IntF1_TAddress Addr, word Size)
{
(void)IntF1_RestoreToFlash(Addr, &LocBuffer[Addr & MASK_ADDR_OFFSET], Size);
}
MAIN.C
void main(void)
{
IntF1_SetByteFlash(0xE000, 0); /* clear */
IntF1_SetByteFlash(0xE000, 1); /* sector erase operation will be required */
}
(4)
MAIN.C
const byte tab []@0xE000={
1,2,3,4,5
};
void main(void)
{
// rewrite first byte of constant variable tab
IFsh1_SetByteFlash(IFsh1_DataPtr2Addr(tab),55);
}
|