previous page next page reference home emBASIC home page

BgMem

16 Backed up storage access

BgMEM (from “Background memory”) has been implemented to have a disk replacement for the storage of data structures. These data files reside in battery backed up RAM and can hold variables between power outages. BgMEM offers LIFO, FIFO, Ring Buffer, and Random access.
In compliance to the requirements of real time systems, BgMEM offers fixed size “files” and fixed sized record only.


16.1 BGMWrite

INT BGMWrite (LWORD bgm, CHAR Array, WORD len)
Writes a record to the file that is referenced by bgm.

Bgm – Handle of BGMEM. See BGMOpen and BGMCreate
Array – reference to array data to stored
Len – data length, bytes

Return value: Number of bytes written or error code. If the value is smaller than 0, it is an error code.

 

16.2 BGMRead

int BGMRead (LWORD bgm, CHAR Array, WORD len)
Reads a record from the file that is referenced by bgm.

Bgm – Handle of BGMEM. See BGMOpen and BGMCreate
Array – reference to array data to read
Len – data length, bytes

Return value: Number of bytes read or error code. If the value is smaller than 0, it is an error code.

 

16.3 BGMWriteRandom

int BGMWriteRandom (LWORD bgm, CHAR Array, WORD len, LONG pos)
Writes a record to the file that is referenced by bgm. This function is suitable for random files only. The record is inserted at the position given in pos.
Bgm – Handle of BGMEM. See BGMOpen and BGMCreate
Array – reference to array data to stored
Len – data length, bytes
Pos - position of record in file.

Return value: Number of bytes written or error code. If the value is smaller than 0, it is an error code.

 

16.4 BGMReadRandom

int BGMReadRandom (LWORD bgm, CHAR Array, WORD len, LONG pos)
Reads a record from the file that is referenced by bgm. This function is suitable for random files only. The record is copied from the position given in pos.
Bgm – Handle of BGMEM. See BGMOpen and BGMCreate
Array – reference to array data to read
Len – data length, bytes
Pos - position of record in file.

Return value: Number of bytes read or error code. If the value is smaller than 0, it is an error code.

 

16.5 BGMLockRecord

long BGMLockRecord (LWORD bgm, LONG first, WORD records)
Inhibits write access of other tasks to records of a random file. Use of this function on FIFO, LIFO or ring files is ignored.
Bgm – Handle of BGMEM. See BGMOpen and BGMCreate
First - Number of first record to lock
Records - Number of records to be locked. All records can be locked, even those not yet used.

Return value: TRUE Lock successful
FALSE Record(s) could not be locked

16.6 BGMUNLockRecord

BGMUnLockRecord (LWORD bgm)
Cancels a lock previously installed.

Bgm – Handle of BGMEM. See BGMOpen and BGMCreate


16.7 BGMReadDir

LONG BGMReadDir (WORD seq, STRING buffer)
Serves to inspect all available files

Seq - A sequential number
Buffer – Pointer to string

Return: error code


16.8 BGMCreate

LWORD BGMCreate (string name, WORD records, WORD size, INT mode)
Creates a file. Caution: If a file of the same name exists, it gets cleared and all data is lost.

Name - File name, max. 32 characters. “$_-.” , “A”..“Z”, “0"..”9"
Records - Number of records in the file: 0 < records < 65536
Size - Size of records in bytes: 0 < records < 65536
Mode – File type

Return: handle of BGMEM file

16.9 BGMRemove

LONG BGMRemove (string name)
Clears a file.

Name – file name.

Return: error code


16.10 BGMOpen

LWORD BGMOpen (string name, INT wr)
Open a file, get a reference (a handle) on it.

name: Name of the file.
wr: TRUE means often for read and write
FALSE means open for read only

Return: handle of BGMEM file


16.11 BGMInit

LWORD BGMInit (LWORD size, INT fmt)
Create or initialize a file. This function is used by the SYSMON function “format”

size: Size of the BgMEM memory
fmt: $BGM_CMD_GETSIZE Just find out the size of BgMEM and return
$BGM_CMD_SETSIZE Change the size of BGMEM by writing size (in kBytes) to
EEPROM word 15. Thereafter a RESET is executed automatically!
$BGM_CMD_FORMAT Format BgMEM. This should be done always after changing the size of BgMEM.

Return value: Size of BgMEM or 0 if no BgMEM available