20230201_1811_emb/1811Project_LPc/Src/Usr/Bsp/McuBspEeprom.c

53 lines
1.1 KiB
C
Raw Permalink Normal View History

#include "McuBspEeprom.h"
#include <cpu.h>
#include <os.h>
#include <bsp_int.h>
#include <bsp_sys.h>
#include <lib_def.h>
#include <os_cpu.h>
#include "driverlib/sysctl.h"
#include "driverlib/eeprom.h"
#include "driverlib/interrupt.h"
void McuBspEepromInit(void)
{
uint32_t ui32EEPROMInit;
SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_EEPROM0)) {
}
ui32EEPROMInit = EEPROMInit();
if(ui32EEPROMInit != EEPROM_INIT_OK) {
while (1) {
}
}
}
int8_t McuBspEepromSaveValue(uint32_t address, uint32_t *data, uint32_t datalen)
{
if (address % 4 !=0) {
return -1;
}
CPU_SR_ALLOC();
OS_ENTER_CRITICAL();
if (0 != EEPROMProgram(data, address, datalen)) {
EEPROMProgram (data, address, datalen);
}
OS_EXIT_CRITICAL();
return 0;
}
int8_t McuBspEepromReadValue(uint32_t address, uint32_t *data, uint32_t datalen)
{
if (address % 4 !=0) {
return -1;
}
CPU_SR_ALLOC();
OS_ENTER_CRITICAL();
EEPROMRead(data, address, datalen);
OS_EXIT_CRITICAL();
return 0;
}