DVBCore  17.9.0
Open Source DVB Engine
 All Data Structures Files Functions Typedefs Macros Pages
Macros | Functions
stbdbnvm.c File Reference

Non-volatile memory database functions. More...

#include <string.h>
#include <techtype.h>
#include <dbgfuncs.h>
#include "dba.h"
#include "dba_nvm.h"
#include "stbdbnvm.h"
#include "stbnvm.h"
#include "stbcsum.h"
#include "stbheap.h"

Macros

#define BLOCK_PAYLOAD_SIZE   20
 
#define FIRST_BLOCK_MASK   0x80
 
#define LINKED_BLOCK_MASK   0x40
 
#define RECID_BLOCK_MASK   0x3f
 

Functions

void STB_InitNVMAccess (U16BIT offset)
 Initialises parameters needed for NVM block access. More...
 
void STB_InitNVMMap (void)
 Initialises parameters needed for NVM block access (calcs num blocks if required)
 
BOOLEAN STB_CheckNVMDatabaseIntegrity (void)
 Reads each database block from NVM and checks its checksum. If the data has already been read into the RAM cache then the data will be checked from here, but this data has been read from NVM and is an exact copy, so the check is still valid. Note: It's assumed that STB_InitNVMAccess has already been called. More...
 
void STB_SetNVMAccessRAM (U8BIT *ram_ptr)
 Sets all DB NVM access to RAM block supplied instead of NVM (cancel if NULL). More...
 
U8BIT * STB_GetNVMAccessRAM (void)
 Returns the current RAM pointer used for DB NVM access. More...
 
U16BIT STB_GetNVMBlockCount (void)
 Returns total number of NVM database blocks. More...
 
U16BIT STB_GetNVMBlocksUsed (void)
 Returns total number of NVM database blocks in use. More...
 
U16BIT STB_GetNVMBlockSize (void)
 Returns the size of an NVM database block, in bytes. More...
 
U16BIT STB_GetNVMBlocksNeeded (U16BIT size)
 Returns number of NVM database blocks needed for specified number of bytes. More...
 
U16BIT STB_CreateNVMRecord (U8BIT rec_id, U16BIT size)
 Creates a record of the type given in NVM by overwriting invalid blocks. More...
 
void STB_DestroyNVMRecord (U16BIT block_no)
 Destroys NVM record by marking all NVM blocks used by the record as invalid. More...
 
void STB_SetNextNVMBlock (U16BIT block_no, U16BIT next_block)
 Repairs NVM linked list by pointing the NVM record starting at the specified block number to the record starting at the specified next block number. More...
 
U16BIT STB_GetNextNVMBlock (U16BIT block_no)
 Returns the block number of the next NVM record pointed to by the NVM record starting at the specified block number. More...
 
U16BIT STB_FindNVMRecordFromId (U8BIT rec_id, U16BIT last_blk)
 Finds next record of the type given in NVM. More...
 
void STB_NVMChanged (BOOLEAN state)
 
void STB_NVMFlushCache (BOOLEAN clear)
 Flush cached changes. More...
 
void STB_NVMSave (void)
 Saves the RAM cache data to NVM.
 
void STB_SetNVMRecordString (U16BIT block_no, U16BIT offset, U16BIT size, U8BIT *string)
 Writes the specified value into a field of a NVM record. More...
 
void STB_SetNVMRecordNumber (U16BIT block_no, U16BIT offset, U16BIT size, U32BIT value)
 Writes the specified value into a field of a NVM record. More...
 
U8BIT * STB_GetNVMRecordString (U16BIT block_no, U16BIT offset, U16BIT size)
 Reads string of a field from a NVM record. More...
 
U32BIT STB_GetNVMRecordNumber (U16BIT block_no, U16BIT offset, U16BIT size)
 Reads the specified value of a field from a NVM record. More...
 
void STB_WriteNVMData (U16BIT offset, U16BIT size, U8BIT *data_ptr)
 Writes the given data to NVM. More...
 
BOOLEAN STB_ReadNVMData (U16BIT offset, U16BIT size, U8BIT *data_ptr)
 Reads data from the NVM into the given buffer. More...
 

Detailed Description

Non-volatile memory database functions.

Date
06/09/2000

Function Documentation

BOOLEAN STB_CheckNVMDatabaseIntegrity ( void  )

Reads each database block from NVM and checks its checksum. If the data has already been read into the RAM cache then the data will be checked from here, but this data has been read from NVM and is an exact copy, so the check is still valid. Note: It's assumed that STB_InitNVMAccess has already been called.

Returns
TRUE if all checksums are valid, FALSE otherwise
U16BIT STB_CreateNVMRecord ( U8BIT  rec_id,
U16BIT  size 
)

Creates a record of the type given in NVM by overwriting invalid blocks.

Parameters
U8BITrec_id - the ID of the record to be created
U16BITsize - the size the record to be created (in bytes)
Returns
U16BIT - block number created if OK, else NVM_INVALID_BLOCK_ID.
void STB_DestroyNVMRecord ( U16BIT  block_no)

Destroys NVM record by marking all NVM blocks used by the record as invalid.

Parameters
U16BITblock_no - the first NVM block number of the record
U16BIT STB_FindNVMRecordFromId ( U8BIT  rec_id,
U16BIT  last_blk 
)

Finds next record of the type given in NVM.

Parameters
U8BITrec_id - the ID of the record
U16BITlast_blk - last block found (NVM_INVALID_BLOCK_ID if none)
Returns
U16BIT - block number found if OK, else NVM_INVALID_BLOCK_ID.
U16BIT STB_GetNextNVMBlock ( U16BIT  block_no)

Returns the block number of the next NVM record pointed to by the NVM record starting at the specified block number.

Parameters
U16BITblock_no - the NVM block number of the current record
Returns
U16BIT - the NVM block number of the next record.
U8BIT* STB_GetNVMAccessRAM ( void  )

Returns the current RAM pointer used for DB NVM access.

Returns
U8BIT* - pointer to RAM area
U16BIT STB_GetNVMBlockCount ( void  )

Returns total number of NVM database blocks.

Returns
U16BIT - number of blocks.
U16BIT STB_GetNVMBlockSize ( void  )

Returns the size of an NVM database block, in bytes.

Returns
size of block in bytes
U16BIT STB_GetNVMBlocksNeeded ( U16BIT  size)

Returns number of NVM database blocks needed for specified number of bytes.

Parameters
U16BITsize - the size (in bytes)
Returns
U16BIT - number of blocks.
U16BIT STB_GetNVMBlocksUsed ( void  )

Returns total number of NVM database blocks in use.

Returns
U16BIT - number of blocks.
U32BIT STB_GetNVMRecordNumber ( U16BIT  block_no,
U16BIT  offset,
U16BIT  size 
)

Reads the specified value of a field from a NVM record.

Parameters
U16BITblock_no - the first NVM block number of the record
U16BIToffset - field byte offset into the record
U16BITsize - field byte size in the record
Returns
U32BIT - the numeric value of the field.
U8BIT* STB_GetNVMRecordString ( U16BIT  block_no,
U16BIT  offset,
U16BIT  size 
)

Reads string of a field from a NVM record.

Parameters
U16BITblock_no - the first NVM block number of the record
U16BIToffset - field byte offset into the record
U16BITsize - field byte size in the record
Returns
U8BIT* - string of the field.
void STB_InitNVMAccess ( U16BIT  offset)

Initialises parameters needed for NVM block access.

Parameters
U16BIToffset - offset to NVM blocks in bytes
void STB_NVMFlushCache ( BOOLEAN  clear)

Flush cached changes.

Parameters
clearTRUE clear the cache after flushing cached changes, FALSE do not clear the cache
BOOLEAN STB_ReadNVMData ( U16BIT  offset,
U16BIT  size,
U8BIT *  data_ptr 
)

Reads data from the NVM into the given buffer.

Parameters
U16BIToffset - byte offset from which to read the data
U16BITsize - number of bytes of data to read
U8BIT*data_ptr - address of buffer to read data into
Returns
BOOLEAN - TRUE on success, else FALSE.
void STB_SetNextNVMBlock ( U16BIT  block_no,
U16BIT  next_block 
)

Repairs NVM linked list by pointing the NVM record starting at the specified block number to the record starting at the specified next block number.

Parameters
U16BITblock_no - the NVM block number of the current record
U16BITnext_block - the NVM block number of the next record
void STB_SetNVMAccessRAM ( U8BIT *  ram_ptr)

Sets all DB NVM access to RAM block supplied instead of NVM (cancel if NULL).

Parameters
U8BIT*ram_ptr - pointer to RAM area
void STB_SetNVMRecordNumber ( U16BIT  block_no,
U16BIT  offset,
U16BIT  size,
U32BIT  value 
)

Writes the specified value into a field of a NVM record.

Parameters
U16BITblock_no - the first NVM block number of the record
U16BIToffset - field bit offset into the record
U16BITsize - field bit size in the record
U32BITvalue - the numeric value of the field
void STB_SetNVMRecordString ( U16BIT  block_no,
U16BIT  offset,
U16BIT  size,
U8BIT *  string 
)

Writes the specified value into a field of a NVM record.

Parameters
U16BITblock_no - the first NVM block number of the record
U16BIToffset - field bit offset into the record
U16BITsize - field bit size in the record
U8BIT*string - the string value of the field
void STB_WriteNVMData ( U16BIT  offset,
U16BIT  size,
U8BIT *  data_ptr 
)

Writes the given data to NVM.

Parameters
U16BIToffset - byte offset at which to write the data
U16BITsize - number of bytes of data to write
U8BIT*data_ptr - pointer to the data to be written