예제 #1
0
/***********************************************************************
		module		:	[EEPROM]
		function		:	[EEPROM读]
  		return		:	[0:读取成功
  						-1:读取失败]
		comment	:	[全局普通函数]
		machine		:	[EH-0818]
		language	:	[CHN]
 		keyword		:	[EEPROM]
		date			:	[11/07/27]
 		author		:	[chen-zhengkai]
************************************************************************/
char eeprom_read(unsigned char* readBuffer, unsigned short sizelen, int romOffset)
{
	unsigned short idx = 0;
	char ret = 0;
	EEPROM_Init(EEPROM_ON);
	for (idx = 0; idx < sizelen; idx++) {
		if (EEPROM_Read_Byte(idx+romOffset, &readBuffer[idx])) {	//读取失败
			ret = -1;	//读取失败
			break;
		}
	}
	EEPROM_Init(EEPROM_OFF);
	return ret;
}
예제 #2
0
/* ----------------------------------------------------------------------------
 * Function      : void EEPROM_Read(uint32_t spi_interface,
 *                                  uint16_t address,
 *                                  uint8_t* buffer,
 *                                  uint32_t byte_count)
 * ----------------------------------------------------------------------------
 * Description   : Read a number of bytes starting at an address
 * Inputs        : - spi_interface  - Index of SPI interface; use 0, 1
 *                 - address        - EEPROM address
 *                 - buffer         - Memory to transfer read data
 *                 - byte_count     - Number of bytes to read
 * Outputs       : None
 * Assumptions   : byte_count is less than the buffer size
 * ------------------------------------------------------------------------- */
void EEPROM_Read(uint32_t spi_interface,
                 uint16_t address,
                 uint8_t* buffer,
                 uint32_t byte_count)
{
    /* Check if SPI interface exists. If interface is invalid, return. */
    if(spi_interface > (EEPROM_SPI_NUM_INTERFACE - 1))
    {
        return;
    }

    EEPROM_Read_Init(spi_interface, address);

    for( ; byte_count > 0; byte_count--)
    {
        *buffer = EEPROM_Read_Byte(spi_interface);
        buffer++;
    }

    EEPROM_Read_Done(spi_interface);
}
예제 #3
0
/* ----------------------------------------------------------------------------
 * Function      : uint32_t EEPROM_Read_Word(uint32_t spi_interface)
 * ----------------------------------------------------------------------------
 * Description   : Read a 32-bit word from the EEPROM
 * Inputs        : spi_interface   - Index of SPI interface; use 0, 1
 * Outputs       : data            - Word read (return 0xFFFFFFFF if the
 *                                   specified SPI interface is invalid)
 * Assumptions   : - EEPROM is initialized to an address
 *                 - EEPROM is selected by chip select
 * ------------------------------------------------------------------------- */
uint32_t EEPROM_Read_Word(uint32_t spi_interface)
{
    uint32_t i;
    uint32_t data = 0;

    /* Check if SPI interface exists. If interface is invalid, return
     * 0xFFFFFFFF. */
    if(spi_interface > (EEPROM_SPI_NUM_INTERFACE - 1))
    {
        return 0xFFFFFFFF;
    }

    for (i = 0; i < 4; i++)
    {
        ((uint8_t *)&data)[i] = EEPROM_Read_Byte(spi_interface);
    }

    return data;

    /* NOTE: Chip select is left low. */
}