mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-04 15:20:16 +00:00
EEPROM fix
This commit is contained in:
parent
5b4db505c2
commit
9b94fd12d6
@ -5,6 +5,7 @@
|
|||||||
#include "RobotFunctions.h"
|
#include "RobotFunctions.h"
|
||||||
|
|
||||||
InfoBlock infoBlock;
|
InfoBlock infoBlock;
|
||||||
|
extern IWDG_HandleTypeDef hiwdg;
|
||||||
|
|
||||||
//*********************** EEPROM_INIT ********************************//
|
//*********************** EEPROM_INIT ********************************//
|
||||||
MemoryStatus EEPROM_INIT() {
|
MemoryStatus EEPROM_INIT() {
|
||||||
@ -152,6 +153,7 @@ MemoryStatus saveShot(unsigned char number, Shot *shot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MemoryStatus getShot(unsigned char number, Shot *shot) {
|
MemoryStatus getShot(unsigned char number, Shot *shot) {
|
||||||
|
HAL_IWDG_Refresh(&hiwdg);
|
||||||
if (FLASH_ReadBlock(START_ADR_SHOT, number, (uint8_t*) shot, SHOT_BLOCKSIZE)
|
if (FLASH_ReadBlock(START_ADR_SHOT, number, (uint8_t*) shot, SHOT_BLOCKSIZE)
|
||||||
!= EEPROM_OK) {
|
!= EEPROM_OK) {
|
||||||
return EEPROM_FAIL;
|
return EEPROM_FAIL;
|
||||||
@ -172,6 +174,7 @@ MemoryStatus delShot(unsigned char number) {
|
|||||||
MemoryStatus saveProg(unsigned char number, Program *prog) {
|
MemoryStatus saveProg(unsigned char number, Program *prog) {
|
||||||
MemoryStatus result = EEPROM_OK;
|
MemoryStatus result = EEPROM_OK;
|
||||||
for (uint16_t i = 0; i < prog->header.shotCount; ++i) {
|
for (uint16_t i = 0; i < prog->header.shotCount; ++i) {
|
||||||
|
HAL_IWDG_Refresh(&hiwdg);
|
||||||
Shot shot;
|
Shot shot;
|
||||||
MemoryStatus stat = getShot(prog->shots[i].id, &shot);
|
MemoryStatus stat = getShot(prog->shots[i].id, &shot);
|
||||||
if (!(stat == EEPROM_OK || stat == EEPROM_MISSING_ELEMENT)) {
|
if (!(stat == EEPROM_OK || stat == EEPROM_MISSING_ELEMENT)) {
|
||||||
@ -217,6 +220,7 @@ MemoryStatus delProg(unsigned char number) {
|
|||||||
MemoryStatus saveMacro(unsigned char number, Macro *macro) {
|
MemoryStatus saveMacro(unsigned char number, Macro *macro) {
|
||||||
MemoryStatus result = EEPROM_OK;
|
MemoryStatus result = EEPROM_OK;
|
||||||
for (uint16_t i = 0; i < macro->header.programmCount; ++i) {
|
for (uint16_t i = 0; i < macro->header.programmCount; ++i) {
|
||||||
|
HAL_IWDG_Refresh(&hiwdg);
|
||||||
Program prog;
|
Program prog;
|
||||||
MemoryStatus stat = getProg(macro->programs[i].id, &prog);
|
MemoryStatus stat = getProg(macro->programs[i].id, &prog);
|
||||||
if (!(stat == EEPROM_OK || stat == EEPROM_MISSING_ELEMENT)) {
|
if (!(stat == EEPROM_OK || stat == EEPROM_MISSING_ELEMENT)) {
|
||||||
@ -260,18 +264,22 @@ MemoryStatus delMacro(unsigned char number) {
|
|||||||
|
|
||||||
MemoryStatus EEPROM_EARSE() {
|
MemoryStatus EEPROM_EARSE() {
|
||||||
uint16_t addr = 0;
|
uint16_t addr = 0;
|
||||||
uint16_t old_addr = 0;
|
const uint16_t EEPROM_MAX_ADDR = 1024*32;
|
||||||
do {
|
do {
|
||||||
uint8_t Buf[255];
|
uint8_t Buf[64];
|
||||||
|
HAL_IWDG_Refresh(&hiwdg);
|
||||||
memset(Buf, 0x00, sizeof(Buf));
|
memset(Buf, 0x00, sizeof(Buf));
|
||||||
|
HAL_IWDG_Refresh(&hiwdg);
|
||||||
|
|
||||||
FLASH_WriteBlock(addr, 0, Buf, sizeof(Buf), sizeof(Buf));
|
FLASH_WriteBlock(addr, 0, Buf, sizeof(Buf), sizeof(Buf));
|
||||||
old_addr = addr;
|
|
||||||
addr += sizeof(Buf);
|
addr += sizeof(Buf);
|
||||||
} while (old_addr <= addr);
|
} while (addr < EEPROM_MAX_ADDR);
|
||||||
|
|
||||||
return EEPROM_OK;
|
return EEPROM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MemoryStatus FLASH_WriteBlock(uint16_t startAddr, uint8_t number,
|
MemoryStatus FLASH_WriteBlock(uint16_t startAddr, uint8_t number,
|
||||||
uint8_t *writeData, uint16_t dataSize, uint16_t blockSize) {
|
uint8_t *writeData, uint16_t dataSize, uint16_t blockSize) {
|
||||||
HAL_StatusTypeDef result;
|
HAL_StatusTypeDef result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user