44 #ifdef STB_NV_PRINT_REQUIRED 45 #define STB_NV_PRINT(x) DEBUG_PRINTX_CONDITIONAL(DEBUG_STB_NV) x 47 #define STB_NV_PRINT(x) 52 #define FORMAT_VERSION_NUM 1 53 #define FORMAT_ID_STRING "DTVKit NV" 54 #define FORMAT_ID_STRING_SIZE 10 61 U8BIT id_str[FORMAT_ID_STRING_SIZE];
63 U8BIT num_data_blocks;
69 U32BIT data_block_size;
84 static U32BIT stb_area_offset;
89 static U32BIT CalcNvmOffset(U32BIT offset);
90 static void MoveBlock(U32BIT src_addr, U32BIT dst_addr, U32BIT size);
91 static BOOLEAN LoadFormat(
void);
92 static void SaveFormat(
void);
96 static U32BIT CalcNvmOffset(U32BIT offset)
114 static void MoveBlock(U32BIT src_addr, U32BIT dst_addr, U32BIT bytes)
118 FUNCTION_START(MoveBlock);
126 if (temp_array != NULL)
135 FUNCTION_FINISH(MoveBlock);
149 static BOOLEAN LoadFormat(
void)
151 BOOLEAN ret_val = FALSE;
157 FUNCTION_START(LoadFormat);
163 if (strcmp((
char *)nvm_format.id_str, (
char *)FORMAT_ID_STRING) == 0)
166 if (nvm_format.version == FORMAT_VERSION_NUM)
173 for (i = 0, last_rec = NULL; (i < nvm_format.num_data_blocks) && ret_val; i++)
181 rec_ptr->next = NULL;
183 if (data_block_list == NULL)
185 data_block_list = rec_ptr;
189 last_rec->next = rec_ptr;
192 rec_ptr->prev = last_rec;
196 offset = CalcNvmOffset(offset +
sizeof(
S_DATA_BLOCK_REC) + rec_ptr->block.data_block_size);
206 stb_area_offset = offset;
211 FUNCTION_FINISH(LoadFormat);
225 static void SaveFormat(
void)
230 FUNCTION_START(SaveFormat);
233 strncpy((
char *)nvm_format.id_str, (
char *)FORMAT_ID_STRING, FORMAT_ID_STRING_SIZE);
234 nvm_format.version = FORMAT_VERSION_NUM;
241 nvm_format.dvb_area_offset = nvm_format.app_area_offset + nvm_format.app_area_size;
244 nvm_format.stb_area_offset = (nvm_format.dvb_area_offset + nvm_format.dvb_area_size);
257 for (rec_ptr = data_block_list; rec_ptr != NULL; rec_ptr = rec_ptr->next)
262 offset = CalcNvmOffset(offset +
sizeof(
S_DATA_BLOCK_REC) + rec_ptr->block.data_block_size);
265 stb_area_offset = offset;
268 FUNCTION_FINISH(SaveFormat);
290 memset(&nvm_format, 0,
sizeof(nvm_format));
311 for (rec_ptr = data_block_list; rec_ptr != NULL; rec_ptr = rec_ptr->next)
313 if (rec_ptr->block.data_block_id == data_block_id)
315 size = rec_ptr->block.data_block_size;
342 for (rec_ptr = data_block_list; rec_ptr != NULL; rec_ptr = rec_ptr->next)
344 if (rec_ptr->block.data_block_id == data_block_id)
346 ret_val =
STB_MEMReadNVM(rec_ptr->nvm_addr, num_bytes, dest_addr);
370 BOOLEAN block_changed;
377 for (rec_ptr = data_block_list, last_rec = NULL; rec_ptr != NULL; rec_ptr = rec_ptr->next)
379 if (rec_ptr->block.data_block_id == data_block_id)
387 block_changed = FALSE;
395 memset(rec_ptr, 0,
sizeof(*rec_ptr));
397 rec_ptr->block.data_block_id = data_block_id;
398 rec_ptr->block.data_block_size = num_bytes;
401 if (data_block_list == NULL)
403 data_block_list = rec_ptr;
407 last_rec->next = rec_ptr;
410 rec_ptr->prev = last_rec;
412 nvm_format.num_data_blocks++;
413 block_changed = TRUE;
421 if (rec_ptr->block.data_block_size != num_bytes)
423 block_changed = TRUE;
424 rec_ptr->block.data_block_size = num_bytes;
429 for (bptr = data_block_list, last_rec = NULL; bptr != NULL; bptr = bptr->next)
431 offset = CalcNvmOffset(offset +
sizeof(
S_DATA_BLOCK_REC) + bptr->block.data_block_size);
436 if (offset != stb_area_offset)
440 stb_area_offset = offset;
443 for (bptr = last_rec; (bptr != NULL) && (bptr != rec_ptr); bptr = bptr->prev)
446 offset = CalcNvmOffset(offset -
sizeof(
S_DATA_BLOCK_REC) - bptr->block.data_block_size);
447 MoveBlock(bptr->nvm_addr, offset,
sizeof(
S_DATA_BLOCK_REC) + bptr->block.data_block_size);
454 rec_ptr->nvm_addr = CalcNvmOffset(offset - rec_ptr->block.data_block_size);
514 ASSERT(dest_addr != NULL);
517 nvm_addr += stb_area_offset;
547 ASSERT(src_addr != NULL);
550 nvm_addr += stb_area_offset;
void * STB_GetMemory(U32BIT bytes)
Attempts to allocate memory from the heap.
void STB_NVMInitialise(void)
Initialises NVM control.
BOOLEAN STB_MEMWriteNVM(U32BIT addr, U32BIT bytes, U8BIT *src_addr)
Writes data to the NVM.
BOOLEAN STB_NVMSTBRead(U32BIT offset, U32BIT bytes, U8BIT *dest_addr)
Reads bytes from the given position of the STB area of NVM.
Header file - Function prototypes for NVM control.
U8BIT STB_CalcChecksum(U8BIT *data_ptr, U32BIT data_size)
Calculates the checksum to zero for the data block provided.
void STB_FreeMemory(void *addr)
Releases previously allocated heap memory.
BOOLEAN STB_NVMDataBlockRead(U32BIT data_block_id, U32BIT num_bytes, U8BIT *dest_addr)
Reads data bytes for the given data block from NVM.
U32BIT STB_NVMGetDataBlockSize(U32BIT data_block_id)
Returns the number of bytes of data stored for the given data block.
Debug functions header file.
U32BIT STB_MEMGetNVMOffset(void)
Returns any offset required in NVM to avoid private data.
U8BIT STB_MEMGetNVMAlign(void)
Returns the word alignment size of the NVM device.
U32BIT STB_MEMGetNVMSize(void)
Returns the size (capacity) of the NVM.
Header file - Function prototypes for NVM and Heap.
System Wide Global Technical Data Type Definitions.
Header file - Function prototypes for check sum calcs.
BOOLEAN STB_NVMSTBWrite(U32BIT offset, U32BIT bytes, U8BIT *src_addr)
Writes bytes into the given position of the STB area of NVM.
Header file - Function prototypes for heap memory.
BOOLEAN STB_NVMDataBlockWrite(U32BIT data_block_id, U32BIT num_bytes, U8BIT *src_addr)
Writes data bytes for the given data block to NVM.
BOOLEAN STB_MEMReadNVM(U32BIT addr, U32BIT bytes, U8BIT *dst_addr)
Read data from the NVM.
U32BIT STB_NVMGetSTBSize(void)
Returns size of STB database storage are (in bytes).