EEPROM tests

This commit is contained in:
2024-09-10 01:40:51 +03:00
parent c85e6aca95
commit beb5ed6be3
3 changed files with 86 additions and 24 deletions

View File

@ -4,6 +4,21 @@
#include "Print.h"
MemoryStatus saveInfoBlock(InfoBlock *infoBlock) {
return FLASH_WriteBlock(START_ADR_STAT, 0, (uint8_t *)infoBlock, sizeof(InfoBlock));
}
MemoryStatus getInfoBlock(InfoBlock *infoBlock) {
MemoryStatus status = FLASH_ReadBlock(START_ADR_STAT, 0, (uint8_t *)infoBlock, sizeof(InfoBlock));
if (status != EEPROM_OK) {
return EEPROM_FAIL;
}
return EEPROM_OK;
}
MemoryStatus saveShot(unsigned char number, Shot* shot)
{
if (FLASH_WriteBlock(START_ADR_SHOT, number, (uint8_t*)shot, SHOT_BLOCKSIZE) == EEPROM_OK) {
@ -116,7 +131,10 @@ MemoryStatus FLASH_WriteBlock(uint16_t startAddr, uint8_t number, uint8_t *write
result = HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), Buf, (dataSize + 2), 10);
HAL_Delay(1);
return result;
if(result != HAL_OK){
return EEPROM_FAIL;
}
return EEPROM_OK;
}
MemoryStatus FLASH_ReadBlock(uint16_t startAddr, uint8_t number, uint8_t *readData, uint8_t dataSize)
@ -137,7 +155,10 @@ MemoryStatus FLASH_ReadBlock(uint16_t startAddr, uint8_t number, uint8_t *readDa
result = HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), blockAddr, 2, 10);
HAL_Delay(1);
result = HAL_I2C_Master_Receive(&hi2c1, (AT24C_ADRESS << 1), readData, dataSize, 10);
result = HAL_I2C_Master_Receive(&hi2c1, (AT24C_ADRESS << 1) | 1, readData, dataSize, 10);
HAL_Delay(1);
return result;
if(result != HAL_OK){
return EEPROM_FAIL;
}
return EEPROM_OK;
}