NVM_BMK.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:22k
- /* **************************************************************************************
- * Copyright (c) 2001 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: "NVM_BMK.c" 05/27/03
- *
- * Description:
- * ============
- * NVM Bookmark
- *
- * Log:
- * ====
- * $Revision: 7 $
- * Last Modified by $Author: Johnk $ at $Modtime: 4/01/04 9:55p $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/Coremain/NVM_BMK.c $
- *
- * 7 4/01/04 10:57p Johnk
- * support HW POWER_ON_RESUME
- *
- * 6 03-06-17 14:59 Fwang
- * Add API -- NVM_BMK_Flush(). Optimize API parameters.
- *
- * 5 03-06-02 18:24 Fwang
- * Add API function for get available setting slot.
- * Optimize verifier.
- *
- * 4 03-05-28 11:18 Fwang
- * Add NVM_BMK_Get() to get bookmark
- * Support specified postion in NVM_BMK_SET()
- *
- * 3 03-05-28 9:40 Fwang
- * Set bookmark type in NVM_BMK_SET()
- *
- * 2 03-05-28 9:08 Fwang
- *
- * 1 03-05-27 22:47 Fwang
- * Creat
- ****************************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifndef EXINO2 //ZKR JK0331 : for power_on_resume in EEPROM
- #include "PlaycoreCoremainnvm_bmk.h"
- #ifdef HW_POWER_ON_RESUME
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceCore)
- #include "DebugDbgMain.h"
- #endif
- #include "PlaycorePSps.h"
- #include "PlaycoreScPadscmgr.h"
- #include "PlaycoreCoremaincoremain.h"
- #include "CPUCPU_API.h"
- #ifndef STORE_PS_DATA_IN_FLASH
- #include "eeprom.h"
- #endif
- #ifdef STORE_PS_DATA_IN_FLASH
- #define MK_FP(seg,ofs) ((void __seg *)(seg) + (void __near *)(ofs))
- static const BYTE huge *NVM_flash_base = MK_FP(PS_SEG, 0);
- #define BMK_FLASH_BASE_ADDR (NVM_flash_base + ((sizeof(NV_STORAGE) + 1)&0xfffe))
- #else
- #define BMK_EEPROM_BASE_ADDR (PS_OFFSET_ADDR+ ((sizeof(NV_STORAGE) + 1)&0xfffe))
- #endif
- #define BMK_SLOT_SIZE ((sizeof(NVM_GENERIC_BMK)+1)&0xfffe)
- #ifdef STORE_PS_DATA_IN_FLASH
- #define BMK_FLASH_SLOT_ADDR(slot) (BMK_FLASH_BASE_ADDR + slot*BMK_SLOT_SIZE)
- #else
- #define BMK_EEPROM_SLOT_ADDR(slot) (BMK_EEPROM_BASE_ADDR + slot*BMK_SLOT_SIZE)
- #endif
- static WORD sc_handle = NULL_HANDLE;
- static const WORD sc_buffer_size = NUM_OF_NVM_BMK * CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK));
- static BOOL (*p_IsMatch)(NVM_GENERIC_BMK*) = NULL;
- static void (*p_SetDiscMarker)(WORD handle) = NULL;
- static void (*p_BmkPlay)(NVM_GENERIC_BMK*) = NULL;
- static BMK_TYPE Current_BMK_Type = BMK_NONE;
- static BYTE __CalculateCheckSum(BYTE* buff, int size);
- static BYTE __CalculateCheckSum_sc(WORD sc, int size);
- #ifdef STORE_PS_DATA_IN_FLASH
- #ifdef _DEBUG
- static void __trace_sc(int slot)
- {
- int i;
- NVM_GENERIC_BMK bmk;
- BYTE *buffer = (BYTE*)&bmk;
- sc_GetBytes(sc_handle+slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), 0, sizeof(NVM_GENERIC_BMK), (BYTE*)&bmk);
- dbg_printf(("nSC Slot %d", slot));
- for (i=0; i<sizeof(NVM_GENERIC_BMK);)
- {
- dbg_printf(("n%3d: ", i));
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- }
- }
- static void __trace_flash(int slot)
- {
- int i;
- BYTE* buffer = (BYTE*)BMK_FLASH_SLOT_ADDR(slot);
- dbg_printf(("nFlash Slot %d", slot));
- for (i=0; i<sizeof(NVM_GENERIC_BMK);)
- {
- dbg_printf(("n%3d (%p): ", i, &buffer[i]));
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- dbg_printf((" 0x%2x", buffer[i])); i++;
- }
- }
- void NVM_BMK_DebugOut()
- {
- int i;
-
- for (i=0; i < NUM_OF_NVM_BMK; i++)
- {
- __trace_flash(i);
- }
- }
-
- #endif //_DEBUG
- #endif
- /**********************************************************************************
- * Purpose : Cache NVM bookmark
- * Input Parameters : None
- * Return Value : BOOL
- * Description : Allocate cache from Scpad and preload bookmark from NVM
- **********************************************************************************/
- BOOL NVM_BMK_Cache()
- {
- int i;
- #ifndef STORE_PS_DATA_IN_FLASH
- BYTE nvmdata[sizeof(NVM_GENERIC_BMK)];
- #endif
- //Allocate buffer from Scpad
- sc_handle = sc_Malloc(sc_buffer_size);
- if (NULL_HANDLE == sc_handle)
- return FALSE;
- //Cache NVM bookmark
- for( i = 0; i < NUM_OF_NVM_BMK ; i++ ){
- #ifdef STORE_PS_DATA_IN_FLASH
- sc_SetBytes( sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), 0, sizeof(NVM_GENERIC_BMK), (BYTE *)BMK_FLASH_SLOT_ADDR(i));
- #else
- eeprom_read( BMK_EEPROM_SLOT_ADDR(i),nvmdata, sizeof(NVM_GENERIC_BMK) );
- sc_SetBytes( sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), 0, sizeof(NVM_GENERIC_BMK), nvmdata);
- #endif
- }
- return TRUE;
- }
- /**********************************************************************************
- * Purpose : Uncache NVM bookmark
- * Input Parameters : None
- * Return Value : None
- * Description : Free Scpad cache
- **********************************************************************************/
- void NVM_BMK_UnCache()
- {
- if (NULL_HANDLE != sc_handle)
- {
- //Free Scpad cache
- sc_Free( sc_handle, sc_buffer_size );
- sc_handle = NULL_HANDLE;
- }
- }
- /**********************************************************************************
- * Purpose : Check if NVM bookmark is cached
- * Input Parameters : None
- * Return Value : True if bookmark is cached in Scpad
- * Description :
- **********************************************************************************/
- BOOL NVM_BMK_IsCached()
- {
- return (sc_handle != NULL_HANDLE);
- }
- /**********************************************************************************
- * Purpose : If bookmark of curren disc exits
- * Input Parameters : h_BmkSlot - slot position if hit
- * Return Value : True if exists
- * Description : Comapre fingure print of disc with bookmark.
- **********************************************************************************/
- BOOL NVM_BMK_hit(int *h_BmkSlot)
- {
- int i;
- #ifndef STORE_PS_DATA_IN_FLASH
- BMK_STORAGE bmk_storage;
- NVM_GENERIC_BMK *pGenric_bmk = &bmk_storage.bmk;
- #else
- NVM_GENERIC_BMK *pGenric_bmk;
- #endif
- if (NULL == p_IsMatch)
- return FALSE;
-
- for (i=0; i < NUM_OF_NVM_BMK; i++)
- {
- #ifdef STORE_PS_DATA_IN_FLASH
- pGenric_bmk = (NVM_GENERIC_BMK*)BMK_FLASH_SLOT_ADDR(i);
- #else
- eeprom_read( BMK_EEPROM_SLOT_ADDR(i),&(bmk_storage.data[0]), sizeof(NVM_GENERIC_BMK) );
- #endif
- if ( pGenric_bmk->bmk_type == Current_BMK_Type)
- {
- //Match with disc info
- if (p_IsMatch(pGenric_bmk))
- {
- if (h_BmkSlot != NULL)
- *h_BmkSlot = i;
- return TRUE;
- }
- }
- }
- return FALSE;
- }
- /**********************************************************************************
- * Purpose : To find a available slot
- * Input Parameters : h_BmkSlot - slot position
- * Return Value : None
- * Description : If no blank slot exists, replace the oldest one.
- **********************************************************************************/
- void NVM_BMK_Get_FreeSlot(int *h_BmkSlot)
- {
- int i, slot_id;
- #ifndef STORE_PS_DATA_IN_FLASH
- BMK_STORAGE bmk_storage;
- NVM_GENERIC_BMK *pGenric_bmk = &bmk_storage.bmk;
- #else
- NVM_GENERIC_BMK *pGenric_bmk;
- #endif
- BYTE oldest_age = 0;
- //Try to get a blank slot, otherwise return the oldest one.
- for (i=0; i < NUM_OF_NVM_BMK; i++)
- {
- #ifdef STORE_PS_DATA_IN_FLASH
- pGenric_bmk = (NVM_GENERIC_BMK*)BMK_FLASH_SLOT_ADDR(i);
- #else
- eeprom_read( BMK_EEPROM_SLOT_ADDR(i),&(bmk_storage.data[0]), sizeof(NVM_GENERIC_BMK) );
- #endif
- if ( pGenric_bmk->bmk_type == BMK_NONE)
- {
- //Found empty slot
- slot_id = i;
- break;
- }
- if (oldest_age <= pGenric_bmk->age)
- {
- oldest_age = pGenric_bmk->age;
- slot_id = i;
- }
- }
- *h_BmkSlot = slot_id;
- return;
- }
- /**********************************************************************************
- * Purpose : Save NVM bookmark
- * Input Parameters : bUpdateFlash - if NVM position exists in flash
- * Return Value : None
- * Description : Write cached bookmark back to NVM
- **********************************************************************************/
- #ifdef STORE_PS_DATA_IN_FLASH
- void NVM_BMK_Save(BOOL bUpdateFlash)
- #else
- void NVM_BMK_Save(void)
- #endif
- {
- int slot;
- #ifdef STORE_PS_DATA_IN_FLASH
- int offset;
- BYTE buff[2];
- unsigned short far *fp_uDestAddr;
- #else
- BYTE nvmdata[sizeof(NVM_GENERIC_BMK)];
- #endif
- if (NULL_HANDLE == sc_handle)
- return;
-
- #ifdef STORE_PS_DATA_IN_FLASH
- if ( bUpdateFlash ){
- //Update flash
- for (slot = 0; slot < NUM_OF_NVM_BMK; slot++)
- {
- for( offset = 0; offset < BMK_SLOT_SIZE; offset=offset+2 ){
- sc_GetBytes(sc_handle+slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset, 2, buff);
- fp_uDestAddr = BMK_FLASH_SLOT_ADDR(slot) + offset;
- Nor_Write((unsigned short huge *)fp_uDestAddr, (unsigned char far *)buff, 2);
- }
- }
- }else{
- //Update SRAM
- for (slot = 0; slot < NUM_OF_NVM_BMK; slot++)
- {
- sc_GetBytes(sc_handle+slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), 0, BMK_SLOT_SIZE, (BYTE*)BMK_FLASH_SLOT_ADDR(slot));
- }
- }
- #else
- for (slot = 0; slot < NUM_OF_NVM_BMK; slot++)
- {
- sc_GetBytes(sc_handle+slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), 0, BMK_SLOT_SIZE, nvmdata);
- eeprom_write( BMK_EEPROM_SLOT_ADDR(slot),nvmdata, sizeof(NVM_GENERIC_BMK) );
- }
- #endif
- }
- /**********************************************************************************
- * Purpose : Flush specified NVM bookmark
- * Input Parameters : position - specified slot. -1 means auto position
- * Return Value : None
- * Description :
- **********************************************************************************/
- void NVM_BMK_Flush( int position )
- {
- BYTE ucTemp;
- int offset, slot;
- const BYTE buff[4] = {0,0,0,0};
- NVM_GENERIC_BMK *pGenric_bmk;
-
- if ((position>=0) && (position<NUM_OF_NVM_BMK))
- {
- //Specified position
- slot = position;
- }else
- {
- //Find matched slot
- if ( FALSE == NVM_BMK_hit(&slot) )
- return;
- }
- if ( FALSE == NVM_BMK_Cache() )
- return;
-
- //Flush specified Scpad cache
- for (offset=0; offset<CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK));offset++)
- sc_SetBytes(sc_handle+slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset*BYTE_PER_CONTAINER, BYTE_PER_CONTAINER, buff);
- ucTemp = __CalculateCheckSum_sc(sc_handle+slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), sizeof(NVM_GENERIC_BMK)-1);
- offset = (int)&pGenric_bmk->checksum - (int)pGenric_bmk;
- sc_SetBytes(sc_handle+slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset, 1, &ucTemp);
-
- //Write back to NVM
- #ifdef STORE_PS_DATA_IN_FLASH
- core_save_NVM_setting_In_Flash((unsigned short far *)NVM_flash_base);
- #else
- NVM_BMK_Save();
- #endif
-
- NVM_BMK_UnCache();
- return;
- }
- /**********************************************************************************
- * Purpose : Flush all NVM bookmark
- * Input Parameters : None
- * Return Value : None
- * Description :
- **********************************************************************************/
- void NVM_BMK_FlushAll()
- {
- BYTE ucTemp;
- int i, offset;
- const BYTE buff[4] = {0,0,0,0};
- NVM_GENERIC_BMK *pGenric_bmk;
-
- if ( FALSE == NVM_BMK_Cache() )
- return;
-
- //Flush all Scpad cache
- for (i=0; i < NUM_OF_NVM_BMK; i++)
- {
- for (offset=0; offset<CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK));offset++)
- sc_SetBytes(sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset*BYTE_PER_CONTAINER, BYTE_PER_CONTAINER, buff);
- ucTemp = __CalculateCheckSum_sc(sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), sizeof(NVM_GENERIC_BMK)-1);
- offset = (int)&pGenric_bmk->checksum - (int)pGenric_bmk;
- sc_SetBytes(sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset, 1, &ucTemp);
- }
-
- //Write back to NVM
- #ifdef STORE_PS_DATA_IN_FLASH
- core_save_NVM_setting_In_Flash((unsigned short far *)NVM_flash_base);
- #else
- NVM_BMK_Save();
- #endif
-
- NVM_BMK_UnCache();
- return;
- }
- /**********************************************************************************
- * Purpose : Verify the consistence of NVM bookmark
- * Input Parameters : None
- * Return Value : None
- * Description : Flush NVM bookmark if contains error
- **********************************************************************************/
- void NVM_BMK_Verify()
- {
- int i, offset;
- BOOL bError = FALSE;
- #ifndef STORE_PS_DATA_IN_FLASH
- BMK_STORAGE bmk_storage;
- NVM_GENERIC_BMK *pGenric_bmk = &bmk_storage.bmk;
- #else
- NVM_GENERIC_BMK *pGenric_bmk;
- #endif
- const BYTE buff[4] = {0,0,0,0};
- BYTE temp;
- for (i=0; i<NUM_OF_NVM_BMK; i++)
- {
- #ifdef STORE_PS_DATA_IN_FLASH
- pGenric_bmk = (NVM_GENERIC_BMK*)BMK_FLASH_SLOT_ADDR(i);
- #else
- eeprom_read( BMK_EEPROM_SLOT_ADDR(i),&(bmk_storage.data[0]), sizeof(NVM_GENERIC_BMK) );
- #endif
- if ( pGenric_bmk->checksum != __CalculateCheckSum((BYTE*)pGenric_bmk, sizeof(NVM_GENERIC_BMK)-1) )
- {
- bError = TRUE;
- break;
- }
- }
- if (!bError)
- return;
-
- dbg_printf(("nNVM Bookmark check sume error! "));
- if ( FALSE == NVM_BMK_Cache() )
- return;
-
- for (i=0; i<NUM_OF_NVM_BMK; i++)
- {
- #ifdef STORE_PS_DATA_IN_FLASH
- pGenric_bmk = (NVM_GENERIC_BMK*)BMK_FLASH_SLOT_ADDR(i);
- #else
- eeprom_read( BMK_EEPROM_SLOT_ADDR(i),&(bmk_storage.data[0]), sizeof(NVM_GENERIC_BMK) );
- #endif
- if ( pGenric_bmk->checksum != __CalculateCheckSum((BYTE*)pGenric_bmk, sizeof(NVM_GENERIC_BMK)-1) )
- {
- //Flush cache
- for (offset=0; offset<CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK));offset++)
- sc_SetBytes(sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset*BYTE_PER_CONTAINER, BYTE_PER_CONTAINER, buff);
- temp = __CalculateCheckSum_sc(sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), sizeof(NVM_GENERIC_BMK)-1);
- offset = (int)&pGenric_bmk->checksum - (int)pGenric_bmk;
- sc_SetBytes(sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset, 1, &temp);
- #ifdef STORE_PS_DATA_IN_FLASH
- #ifdef _DEBUG
- dbg_printf(("nERR In "));
- __trace_flash(i);
- #endif
- #endif
- }
- }
- #ifdef STORE_PS_DATA_IN_FLASH
- core_save_NVM_setting_In_Flash((unsigned short far *)NVM_flash_base);
- #else
- NVM_BMK_Save();
- #endif
- NVM_BMK_UnCache();
- }
- /**********************************************************************************
- * Purpose : Hook callback navigator functiones
- * Input Parameters : bmk_type - bmk type according to Navigator
- * match_func - function to check disc figure print
- * set_func - function to set disc bookmark info
- * play_func - function to retore disc bookmark info
- * Return Value : None
- * Description :
- **********************************************************************************/
- void NVM_BMK_Hook(BMK_TYPE bmk_type, BOOL(*match_func)(NVM_GENERIC_BMK*), void(*set_func)(WORD), void(*play_func)(NVM_GENERIC_BMK*))
- {
- p_IsMatch = match_func;
- p_SetDiscMarker = set_func;
- p_BmkPlay = play_func;
- Current_BMK_Type = bmk_type;
- return;
- }
- /**********************************************************************************
- * Purpose : Unhook callback navigator functiones
- * Input Parameters : None
- * Return Value : None
- * Description :
- **********************************************************************************/
- void NVM_BMK_UnHook()
- {
- p_IsMatch = NULL;
- p_SetDiscMarker = NULL;
- p_BmkPlay = NULL;
- Current_BMK_Type = BMK_NONE;
- return;
- }
- /**********************************************************************************
- * Purpose : Get available slot position
- * Input Parameters : None
- * Return Value : available position
- * Description : Find available slot to set bookmark for the current disc
- **********************************************************************************/
- int NVM_BMK_AvailableSlot()
- {
- int slot = 0;
-
- //Find available slot
- if (!NVM_BMK_hit(&slot))
- {
- NVM_BMK_Get_FreeSlot(&slot);
- }
- return slot;
- }
- /**********************************************************************************
- * Purpose : Set NVM bookmark
- * Input Parameters : position - specified position. -1 for auto posisition
- * Return Value : None
- * Description : Save disc info to available NVM bookmark slot, and update age of each slot
- **********************************************************************************/
- void NVM_BMK_SET(int position)
- {
- BYTE ucTemp;
- int i, slot, offset;
- #ifndef STORE_PS_DATA_IN_FLASH
- BMK_STORAGE bmk_storage;
- NVM_GENERIC_BMK *pGenric_bmk = &bmk_storage.bmk;
- #else
- NVM_GENERIC_BMK *pGenric_bmk;
- #endif
-
- if (NULL == p_SetDiscMarker)
- return;
- if ( FALSE == NVM_BMK_Cache() )
- return;
- if ((position>=0) && (position<NUM_OF_NVM_BMK))
- {
- //Specified position
- slot = position;
- }else
- {
- //Find available slot
- slot = NVM_BMK_AvailableSlot();
- }
- //Set disc info
- p_SetDiscMarker( sc_handle + slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)) );
- //Set bookmark type
- ucTemp = Current_BMK_Type;
- offset = (int)&pGenric_bmk->bmk_type - (int)pGenric_bmk;
- sc_SetBytes(sc_handle+slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset, sizeof(BYTE), (BYTE *) &ucTemp);
- //Set age as zero
- ucTemp = 0;
- offset = (int)&pGenric_bmk->age - (int)pGenric_bmk;
- sc_SetBytes(sc_handle+slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset, sizeof(BYTE), &ucTemp);
- //Calculate check sum
- ucTemp = __CalculateCheckSum_sc(sc_handle + slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), sizeof(NVM_GENERIC_BMK)-1) ;
- offset =(int)& pGenric_bmk->checksum - (int)pGenric_bmk;
- sc_SetBytes(sc_handle + slot*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset, sizeof(BMK_TYPE), (BYTE *) &ucTemp);
- //Update the age counting of each slot
- for (i=0; i < NUM_OF_NVM_BMK; i++)
- {
- #ifdef STORE_PS_DATA_IN_FLASH
- pGenric_bmk = (NVM_GENERIC_BMK*)BMK_FLASH_SLOT_ADDR(i);
- #else
- eeprom_read( BMK_EEPROM_SLOT_ADDR(i),&(bmk_storage.data[0]), sizeof(NVM_GENERIC_BMK) );
- #endif
- if (BMK_NONE == pGenric_bmk->bmk_type) //Don't update blank slot
- continue;
- if (i == slot) //Don't update selected slot whose age is zero
- continue;
-
- if (pGenric_bmk->age < 0xFF) //Maxium limitation
- {
- //Increment age
- ucTemp = pGenric_bmk->age + 1;
- offset = (int)&pGenric_bmk->age - (int)pGenric_bmk;
- sc_SetBytes(sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset, sizeof(BYTE), &ucTemp);
- ucTemp = __CalculateCheckSum_sc(sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), sizeof(NVM_GENERIC_BMK)-1);
- offset = (int)&pGenric_bmk->checksum - (int)pGenric_bmk;
- sc_SetBytes(sc_handle+i*CONTAINER_COUNT(sizeof(NVM_GENERIC_BMK)), offset, 1, &ucTemp);
- }
- }
-
- //Write back to NVM
- #ifdef STORE_PS_DATA_IN_FLASH
- core_save_NVM_setting_In_Flash((unsigned short far *)NVM_flash_base);
- #else
- NVM_BMK_Save();
- #endif
- NVM_BMK_UnCache();
- return;
- }
- /**********************************************************************************
- * Purpose : Play from NVM bookmark
- * Input Parameters : None
- * Return Value : Whether found matched bookmark or not
- * Description : If bookmark of current disc exists, play from the bookmark.
- **********************************************************************************/
- BOOL NVM_BMK_Play()
- {
- int slot;
- #ifndef STORE_PS_DATA_IN_FLASH
- BMK_STORAGE bmk_storage;
- NVM_GENERIC_BMK *pGenric_bmk = &bmk_storage.bmk;
- #endif
- if (NULL == p_BmkPlay)
- return;
-
- #ifdef D_MEMORY_SETTING
- if (gps->memory_mode)
- {
- #endif
- if (NVM_BMK_hit(&slot))
- {
- //Bookmark play
- #ifdef STORE_PS_DATA_IN_FLASH
- p_BmkPlay( (NVM_GENERIC_BMK*)BMK_FLASH_SLOT_ADDR(slot) );
- #else
- eeprom_read( BMK_EEPROM_SLOT_ADDR(slot),&(bmk_storage.data[0]), sizeof(NVM_GENERIC_BMK) );
- p_BmkPlay(pGenric_bmk);
- #endif
- NVM_BMK_Flush(slot);
- return TRUE;
- }
- #ifdef D_MEMORY_SETTING
- }
- #endif
- return FALSE;
- }
- /**********************************************************************************
- * Purpose : Get bookmark info from NVM
- * Input Parameters : slot - postion
- * Return Value : pointer to NVM bookmark. NULL if not exists
- * Description :
- **********************************************************************************/
- #if 0
- NVM_GENERIC_BMK *NVM_BMK_Get(int slot)
- {
- NVM_GENERIC_BMK *pGenric_bmk;
-
- if ((slot>=0) && (slot<NUM_OF_NVM_BMK))
- {
- pGenric_bmk = BMK_FLASH_SLOT_ADDR(slot);
- if (pGenric_bmk->bmk_type != BMK_NONE)
- return pGenric_bmk;
- else
- return NULL;
- }
- else
- return NULL;
- }
- #endif
- /**********************************************************************************
- * Purpose : Calculate check sum of given buffer
- **********************************************************************************/
- static BYTE __CalculateCheckSum(BYTE* buff, int size)
- {
- int i;
- BYTE checksum=0;
- for (i=0; i< size; i++)
- {
- checksum += buff[i];
- }
- return checksum^0xFF;
- }
- /**********************************************************************************
- * Purpose : Calculate check sum of given Scpad buffer
- **********************************************************************************/
- static BYTE __CalculateCheckSum_sc(WORD sc, int size)
- {
- int i;
- BYTE temp;
- BYTE checksum = 0;
- for (i=0; i< size; i++)
- {
- sc_GetBytes(sc, i, 1, &temp);
- checksum += temp;
- }
- return checksum^0xFF;
- }
- #else
- void NVM_BMK_Verify()
- {
- }
- #pragma argsused
- void NVM_BMK_SET(int position)
- {
- }
- BOOL NVM_BMK_Play()
- {
- }
- #pragma argsused
- void NVM_BMK_Hook(BMK_TYPE bmk_type, BOOL(*match_func)(NVM_GENERIC_BMK*), void(*set_func)(WORD), void(*play_func)(NVM_GENERIC_BMK*))
- {
- }
- void NVM_BMK_UnHook()
- {
- }
- #endif //HW_POWER_ON_RESUME
- #endif //EXINO2