User`s manual

V460 Series WinXP Embedded User’s Manual Getting Started
Using the Battery Backed-up SRAM
The V460 embedded computer has a 256 KB SRAM backed up by a battery for users to keep
important data, and provides a robust design to prevents unstable power sources from damaging
your system or your data. The data stored in this SRAM is available until the battery runs out of
power. You can use the standard file IO API to read and write data. Sample source code is given
below:
Writing Data to SRAM
// Persisted_SRAM_Write.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwBackSize = 0;
HANDLE hSRAM = NULL;
// open the SRAM device driver
hSRAM = CreateFile(L"\\\\.\\Sram", GENERIC_READ | GENERIC_WRITE,
0, // exclusive access, until the handle is closed
NULL, // no security
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, // no overlapped I/O
NULL); // null template
if (hSRAM == INVALID_HANDLE_VALUE)
{
printf("Can't open SRAM\n");
return 1;
}
// preparing data for write
char *data = "This is persisted data xxxxxx1234567";
DWORD nLen = strlen(data);
// write data into SRAM
WriteFile( hSRAM, data, nLen, &dwBackSize, NULL);
// close device driver handle
CloseHandle(hSRAM);
printf("** Done! You can now reboot your deivce, and try the Persisted_SRAM_Read program
to verify the data that is still can be read.\n");
return 0;
}
2-8