move flash addr in to mpu_util (#1123)

* move flash addr in to mpu_util

* this _may_ work

* don't use offsetof

* proper header + defines
This commit is contained in:
Matthew Kennedy 2020-02-04 18:36:38 -08:00 committed by GitHub
parent bc8ad6ba9d
commit 52c710bb62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 32 deletions

View File

@ -105,16 +105,6 @@
#define EFI_INTERNAL_FLASH TRUE
/**
* Flex Non Volatile Memory is faster than flash
* It also has smaller pages so it takes less time to erase
*
* There is no remote access to FlexNVM meaning that we cannot erase settings externally
*/
#define FLASH_ADDR 0x10000000 // FlexNVM
#define FLASH_ADDR_SECOND_COPY 0x10008000
/**
* Usually you need shaft position input, but maybe you do not need it?
*/
@ -406,7 +396,7 @@
#define EFI_PRINT_ERRORS_AS_WARNINGS TRUE
#define EFI_PRINT_MESSAGES_TO_TERMINAL TRUE
#define EFI_ACTIVE_CONFIGURATION_IN_FLASH (FLASH_ADDR + offsetof(persistent_config_container_s, persistentConfiguration.engineConfiguration))
#define EFI_ACTIVE_CONFIGURATION_IN_FLASH
//#define PWM_PHASE_MAX_COUNT 122

View File

@ -142,7 +142,8 @@ static fuel_table_t alphaNfuel = {
* todo: place this field next to 'engineConfiguration'?
*/
#ifdef EFI_ACTIVE_CONFIGURATION_IN_FLASH
engine_configuration_s & activeConfiguration = *(engine_configuration_s *)EFI_ACTIVE_CONFIGURATION_IN_FLASH;
#include "flash.h"
engine_configuration_s & activeConfiguration = reinterpret_cast<persistent_config_container_s*>(getFlashAddrFirstCopy())->persistentConfiguration.engineConfiguration;
// we cannot use this activeConfiguration until we call rememberCurrentConfiguration()
bool isActiveConfigurationVoid = true;
#else

View File

@ -40,10 +40,6 @@ extern engine_configuration_s *engineConfiguration;
* todo: an ideal solution would be to define this address in the .ld / .icf mapping file
*/
#ifndef FLASH_ADDR
#define FLASH_ADDR 0x080E0000
#endif
#define PERSISTENT_SIZE sizeof(persistent_config_container_s)
/**
@ -52,9 +48,6 @@ extern engine_configuration_s *engineConfiguration;
* In order to preserve at least one copy of the tune in case of electrical issues address of second configuration copy
* should be in a different sector of flash since complete flash sectors are erased on write.
*/
#ifndef FLASH_ADDR_SECOND_COPY
#define FLASH_ADDR_SECOND_COPY 0x080C0000
#endif
crc_t flashStateCrc(persistent_config_container_s *state) {
return calc_crc((const crc_t*) &state->persistentConfiguration, sizeof(persistent_config_s));
@ -87,12 +80,12 @@ void writeToFlashNow(void) {
crc_t crcResult = flashStateCrc(&persistentState);
persistentState.value = crcResult;
scheduleMsg(logger, "Reseting flash: size=%d", PERSISTENT_SIZE);
flashErase(FLASH_ADDR, PERSISTENT_SIZE);
flashErase(getFlashAddrFirstCopy(), PERSISTENT_SIZE);
scheduleMsg(logger, "Flashing with CRC=%d", crcResult);
efitimems_t nowMs = currentTimeMillis();
int result = flashWrite(FLASH_ADDR, (const char *) &persistentState, PERSISTENT_SIZE);
flashErase(FLASH_ADDR_SECOND_COPY, PERSISTENT_SIZE);
flashWrite(FLASH_ADDR_SECOND_COPY, (const char *) &persistentState, PERSISTENT_SIZE);
int result = flashWrite(getFlashAddrFirstCopy(), (const char *) &persistentState, PERSISTENT_SIZE);
flashErase(getFlashAddrSecondCopy(), PERSISTENT_SIZE);
flashWrite(getFlashAddrSecondCopy(), (const char *) &persistentState, PERSISTENT_SIZE);
scheduleMsg(logger, "Flash programmed in %dms", currentTimeMillis() - nowMs);
bool isSuccess = result == FLASH_RETURN_SUCCESS;
if (isSuccess) {
@ -135,10 +128,10 @@ static persisted_configuration_state_e doReadConfiguration(flashaddr_t address,
*/
persisted_configuration_state_e readConfiguration(Logging * logger) {
efiAssert(CUSTOM_ERR_ASSERT, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "read f", PC_ERROR);
persisted_configuration_state_e result = doReadConfiguration(FLASH_ADDR, logger);
persisted_configuration_state_e result = doReadConfiguration(getFlashAddrFirstCopy(), logger);
if (result != PC_OK) {
printMsg(logger, "Reading second configuration copy");
result = doReadConfiguration(FLASH_ADDR_SECOND_COPY, logger);
result = doReadConfiguration(getFlashAddrSecondCopy(), logger);
}
if (result == CRC_FAILED) {

View File

@ -7,13 +7,6 @@
#include "global.h"
/**
* @brief Number of sectors in the flash memory.
*/
#if !defined(FLASH_SECTOR_COUNT)
#define FLASH_SECTOR_COUNT 12
#endif
/* Error codes */
/** @brief Flash operation successful */
@ -73,6 +66,9 @@ typedef uint8_t flashsector_t;
*/
size_t flashSectorSize(flashsector_t sector);
uintptr_t getFlashAddrFirstCopy(void);
uintptr_t getFlashAddrSecondCopy(void);
/**
* @brief Get the beginning address of @p sector.
* @param sector Sector to retrieve the beginning address of.

View File

@ -241,5 +241,21 @@ size_t flashSectorSize(flashsector_t sector) {
return 0;
}
/**
* Flex Non Volatile Memory is faster than flash
* It also has smaller pages so it takes less time to erase
*
* There is no remote access to FlexNVM meaning that we cannot erase settings externally
*/
uintptr_t getFlashAddrFirstCopy() {
return 0x10000000;
}
uintptr_t getFlashAddrSecondCopy() {
return 0x10008000;
}
#endif /* EFI_PROD_CODE */

View File

@ -439,5 +439,13 @@ size_t flashSectorSize(flashsector_t sector) {
return 0;
}
uintptr_t getFlashAddrFirstCopy() {
return 0x080E0000;
}
uintptr_t getFlashAddrSecondCopy() {
return 0x080C0000;
}
#endif /* EFI_PROD_CODE */

View File

@ -428,3 +428,10 @@ size_t flashSectorSize(flashsector_t sector) {
return 0;
}
uintptr_t getFlashAddrFirstCopy() {
return 0x08100000;
}
uintptr_t getFlashAddrSecondCopy() {
return 0x08140000;
}