userdata.c

来自「M3355的源代码」· C语言 代码 · 共 255 行

C
255
字号
/*====================================================================
 *
 *  Copyright (C) 1997 Acer Labs, Inc.  All Rights Reserved.
 *                  
 *  File:   USERDATA.c  
 *                                           
 *  Contents: Functions for read User Data and write User Data 
 *            to Flash.
 *           
 * The following devices are supported in the code:
 *
 * ST
 * M29F800AT/M29F800AB
 * M29W800AT/M29W800AB
 *
 * MXIC
 * MX29F400T/MX29F400B
 *
 * AMD
 *
 *  History:
 *   Date           By         Reason
 *  ===========    =========   ======
 *  23-Nov-2001    Dick Ma     Created
 ********************************************************************/

#include <comsub.h>
#include <flash.h>
#include <iic.h>
#include <platform.h>

#define SIZE_OF_SETUP_PARA sizeof(Setup_Parameter)
#define SIZE_OF_USER_PARA	sizeof(Setup_Parameter)
#define SIZE_OF_OPTION_PARA	sizeof(EEPROM_OPTION_Parameter)


#if ( _USERDATA_TYPE==_USERDATA_TO_EEPROM_ )
/*******************************************************************************
 * Function: int Read_UserData();
 * 
 * Description: This function read User Data from IIC EEPROM.
 *
 * Pseudo Code:
 * Step 1: 
 *
 * Arguments: 
 * 
 * Return Value: 
*******************************************************************************/
int Read_UserData()
{
    return I2cReadEEPROM(START_EEP_OFFSET,(LPBYTE)&OSD_Setup_Parameter,SIZE_OF_SETUP_PARA);
}

/*******************************************************************************
 * Function: int Write_UserData();
 * 
 * Description: This function write User Data to IIC EEPROM.
 *
 * Pseudo Code:
 * Step 1: 
 *
 * Arguments: 
 * 
 * Return Value: 
*******************************************************************************/
int Write_UserData()
{
    return I2cWriteEEPROM(START_EEP_OFFSET,(LPBYTE)&OSD_Setup_Parameter,SIZE_OF_SETUP_PARA);
}

/*******************************************************************************
 * Function: int Read_UserPara();
 * Description: This function read User Parameter from IIC EEPROM.
*******************************************************************************/
int Read_UserPara()
{
    return I2cReadEEPROM(START_EEP_OFFSET+SIZE_OF_OPTION_PARA,(LPBYTE)&OSD_Setup_Parameter,SIZE_OF_USER_PARA);
}

/*******************************************************************************
 * Function: int Write_UserPara();
 * Description: This function write User Parameter from IIC EEPROM.
*******************************************************************************/
int Write_UserPara()
{
    return I2cWriteEEPROM(START_EEP_OFFSET+SIZE_OF_OPTION_PARA,(LPBYTE)&OSD_Setup_Parameter,SIZE_OF_USER_PARA);
}

/*******************************************************************************
 * Function: int Read_UserPara();
 * Description: This function read User Parameter from IIC EEPROM.
*******************************************************************************/
int Read_OptionPara()
{
    return I2cReadEEPROM(START_EEP_OFFSET,(LPBYTE)&EEP_Option_Parameter,SIZE_OF_OPTION_PARA);
}

/*******************************************************************************
 * Function: int Write_UserPara();
 * Description: This function write User Parameter from IIC EEPROM.
*******************************************************************************/
int Write_OptionPara()
{
    return I2cWriteEEPROM(START_EEP_OFFSET,(LPBYTE)&EEP_Option_Parameter,SIZE_OF_OPTION_PARA);
}

//030807-01lily:lastplay
#define BOOKMARK_START_OFFSET		(SIZE_OF_OPTION_PARA+SIZE_OF_SETUP_PARA+8)
#define SIZE_OF_DISCLASTPLAY		(sizeof(DISCLASTPLAY))

int Read_BookMark(DISCLASTPLAY *lpDes)
{
    int i;
    i=I2cReadEEPROM(BOOKMARK_START_OFFSET,(LPBYTE)lpDes,SIZE_OF_DISCLASTPLAY);
    return i;

}
int Write_BookMark(DISCLASTPLAY *lpSrc)
{
    int i;
    i=I2cWriteEEPROM(BOOKMARK_START_OFFSET,(LPBYTE)lpSrc,SIZE_OF_DISCLASTPLAY);
    return i;

}
//end 030807-01lily:lastplay

#if 0
//#else // user data to flash
/*******************************************************************************
* Function: int Read_UserData();
*
* Description: This function read User Data from Flash.
*
* Pseudo Code:
* Step 1:
*
* Arguments:
*
* Return Value:
*******************************************************************************/
int Read_UserData()
{
    int i;
    WORD wSetupParameter[SIZE_OF_SETUP_PARA/2+1];
    WORD wLast;
    DWORD dwDataOff;

    /* read userdata from last block */
    dwDataOff = BlockOffset[NUM_BLOCKS-1];
    for(i=0;i<(SIZE_OF_SETUP_PARA/2);i++)
    {
        wSetupParameter[i] = FlashRead( dwDataOff + i );
    }
    /* if the size of Setup_Parameter is odd, get low byte of last word */
    if ( SIZE_OF_SETUP_PARA % 2 )
    {
        wLast = FlashRead( dwDataOff + i );
        ( (LPBYTE) wSetupParameter )[i*2] = LoByte(wLast);
    }

    /* Adjust data boundary to WORD */
    for(i=0;i<SIZE_OF_SETUP_PARA;i++)
    {
        ( (LPBYTE) &OSD_Setup_Parameter )[i] = ( (LPBYTE) &wSetupParameter )[i];
    }

    return FLASH_SUCCESS;
}

/*******************************************************************************
* Function: int Write_UserData();
*
* Description: This function read User Data from Flash.
*
* Pseudo Code:
* Step 1:
*
* Arguments:
*
* Return Value:
*******************************************************************************/
int Write_UserData()
{
    int i, iRV;
    DWORD dwDataOff, dwNumWords;
    WORD wSetupParameter[SIZE_OF_SETUP_PARA/2+1];

    dis_dsp(); /*** Disable Task Dispatch ***/
    Dis_FlashCache();/*** Disable M6311 R/W Flash cache ***/

    /* Flash Reset */
    FlashReadReset();
    PRINTF("\nFlash Reset!\n");

    /* FlashBlockErase */
    PRINTF("\nFlashBlockErase Begin\n");

    iRV = FlashBlockErase( NUM_BLOCKS-1 );
    if(iRV < 0)
    {
        PRINTF("All Blocks Erase: %s\n", FlashErrorStr(iRV));
    }
    else if(iRV < NUM_BLOCKS)
    {
        PRINTF("Block %d is protected!\n", iRV);
    }
    else
    {
        PRINTF("Block invalid!\n");
    }
    if(iRV != FLASH_SUCCESS)
        return iRV;

    Ena_FlashCache();/*** Disable M6311 R/W Flash cache ***/
    ena_dsp();/*** Enable Task Dispatch ***/
    dly_tsk(500);
    dis_dsp(); /*** Disable Task Dispatch ***/
    Dis_FlashCache();/*** Disable M6311 R/W Flash cache ***/

    /* Flash Reset */
    FlashReadReset();
    PRINTF("Flash Reset!\n");
    /* Sample code of how to use FlashProgram */
    PRINTF("\nFlashProgram Begin\n");
    /********************************
    * Note: Using Word Address,
    *********************************/
    /* wirte userdata into last block */
    dwDataOff = BlockOffset[NUM_BLOCKS-1];
    dwNumWords = SIZE_OF_SETUP_PARA/2 + 1;
    /* Adjust data boundary to WORD */
    for(i=0;i<SIZE_OF_SETUP_PARA;i++)
    {
        ( (LPBYTE) &wSetupParameter )[i] = ( (LPBYTE) &OSD_Setup_Parameter )[i];
    }

    iRV = FlashProgram( dwDataOff, dwNumWords,  &wSetupParameter );
    if(iRV < 0)
    {
        PRINTF("Program %d: %s\n", i, FlashErrorStr(iRV));
    }
    else
    {
        PRINTF("Block %d is protected!\n", iRV);
    }

    Ena_FlashCache();/*** Disable M6311 R/W Flash cache ***/
    ena_dsp();/*** Enable Task Dispatch ***/

    return iRV;
}
#endif
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?