#include "eeprom.h"
/*
* The user must implement the three extern-declared functions below
* in order for the compiler to be able to automatically write to the
* EEPROM memory when __eeprom variables are assigned to.
*/
/*
* Wait for the last data EEPROM operation to finish. Return 0 if the
* operation failed, otherwise non-zero. You may want to handle
* errors here, since the utility functions below simply ignore
* errors, aborting multi-write operations early.
*/
int eeprom_wait_for_last_operation(void)
{
FLASH_Status_TypeDef status = FLASH_WaitForLastOperation(FLASH_MemType_Data);
return !!(status & ( FLASH_Status_Successful_Operation));
}
/*
* Write one byte to the data EEPROM memory.
*/
void eeprom_program_byte(unsigned char __near * dst, unsigned char v)
{
FLASH_ProgramByte((u32)dst, (u8)v);
}
/*
* Write one 4-byte long word to the data EEPROM memory. The address
* must be 4-byte aligned.
*/
void eeprom_program_long(unsigned char __near * dst, unsigned long v)
{
FLASH_ProgramWord((u32)dst, (u32)v);
}
void eeprom_init(void)
{
}
/**************************************************************************
* 函数名:eeprom_BufferWrite
* 描述 :使用字节写命令写多个字节的数据到EEPROM
* 输入 :- pBuffer:指向要写入EEPROM中的数据的指针
* - WriteAddr:将写入的EEPROM的地址
* - NumByteToWrite:要写入EEPROM的字节数
* 调用 :外部调用
*************************************************************************/
void eeprom_BufferWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite)
{
while (NumByteToWrite--) /* 计数 */
{
FLASH_ProgramByte((uint32_t)WriteAddr,(uint8_t)*pBuffer);
pBuffer++;
WriteAddr++;
}
}
/*******************************************************************************
* 函数名 : eeprom_BufferRead
* 描述 : 从FLASH读取NumByteToRead字节的数据.
* 输入 : - pBuffer : 存放从FLASH读取的数据的缓冲区的指针
* - ReadAddr : 从FLASH的该地址处读数据
* - NumByteToRead : 要读取的字节数
*******************************************************************************/
void eeprom_BufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead)
{
while (NumByteToRead--) /* 计数 */
{
/* 读一个字节的数据 */
*pBuffer = FLASH_ReadByte(ReadAddr);
pBuffer++;
ReadAddr++;
}
}