From 85cd4df2eae9a272dd8aed60f14987ac8f33ea5b Mon Sep 17 00:00:00 2001 From: jflyper Date: Mon, 4 Feb 2019 17:54:02 +0900 Subject: [PATCH] Refactor / rename PERSISTENT_OBJECT_BOOTLOADER_REQUEST to PERSISTENT_OBJECT_RESET_REASON --- src/main/drivers/persistent.h | 9 ++++++++- src/main/drivers/system.h | 3 --- src/main/drivers/system_stm32f4xx.c | 8 ++++---- src/main/drivers/system_stm32f7xx.c | 8 ++++---- src/main/drivers/usb_msc_f4xx.c | 8 ++++---- src/main/drivers/usb_msc_f7xx.c | 8 ++++---- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/main/drivers/persistent.h b/src/main/drivers/persistent.h index c47f804ea..656a058ac 100644 --- a/src/main/drivers/persistent.h +++ b/src/main/drivers/persistent.h @@ -29,12 +29,19 @@ typedef enum { PERSISTENT_OBJECT_MAGIC = 0, PERSISTENT_OBJECT_HSE_VALUE, PERSISTENT_OBJECT_OVERCLOCK_LEVEL, - PERSISTENT_OBJECT_BOOTMODE_REQUEST, + PERSISTENT_OBJECT_RESET_REASON, PERSISTENT_OBJECT_RTC_HIGH, // high 32 bits of rtcTime_t PERSISTENT_OBJECT_RTC_LOW, // low 32 bits of rtcTime_t PERSISTENT_OBJECT_COUNT, } persistentObjectId_e; +// Values for PERSISTENT_OBJECT_RESET_REASON +#define RESET_NONE 0 +#define RESET_BOOTLOADER_REQUEST 1 // Boot loader invocation was requested +#define RESET_BOOTLOADER_POST 2 // Reset after boot loader activity +#define RESET_MSC_REQUEST 3 // MSC invocation was requested +#define RESET_FORCED 4 // Reset due to unknown reset reason + void persistentObjectInit(void); uint32_t persistentObjectRead(persistentObjectId_e id); void persistentObjectWrite(persistentObjectId_e id, uint32_t value); diff --git a/src/main/drivers/system.h b/src/main/drivers/system.h index 8c2ba5a68..285aefdfb 100644 --- a/src/main/drivers/system.h +++ b/src/main/drivers/system.h @@ -52,9 +52,6 @@ void checkForBootLoaderRequest(void); bool isMPUSoftReset(void); void cycleCounterInit(void); -#define BOOTLOADER_REQUEST_COOKIE 0xDEADBEEF -#define MSC_REQUEST_COOKIE 0xDDDD1010 - void enableGPIOPowerUsageAndNoiseReductions(void); // current crystal frequency - 8 or 12MHz diff --git a/src/main/drivers/system_stm32f4xx.c b/src/main/drivers/system_stm32f4xx.c index cab9560a9..0cbf60662 100644 --- a/src/main/drivers/system_stm32f4xx.c +++ b/src/main/drivers/system_stm32f4xx.c @@ -41,7 +41,7 @@ void systemReset(void) void systemResetToBootloader(void) { - persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, BOOTLOADER_REQUEST_COOKIE); + persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_BOOTLOADER_REQUEST); __disable_irq(); NVIC_SystemReset(); @@ -56,12 +56,12 @@ typedef struct isrVector_s { void checkForBootLoaderRequest(void) { - uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST); + uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON); - if (bootloaderRequest != BOOTLOADER_REQUEST_COOKIE) { + if (bootloaderRequest != RESET_BOOTLOADER_REQUEST) { return; } - persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0); + persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE); extern isrVector_t system_isr_vector_table_base; diff --git a/src/main/drivers/system_stm32f7xx.c b/src/main/drivers/system_stm32f7xx.c index 7668ddbdc..c519c63a9 100644 --- a/src/main/drivers/system_stm32f7xx.c +++ b/src/main/drivers/system_stm32f7xx.c @@ -45,7 +45,7 @@ void systemReset(void) void systemResetToBootloader(void) { - persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, BOOTLOADER_REQUEST_COOKIE); + persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_BOOTLOADER_REQUEST); __disable_irq(); NVIC_SystemReset(); } @@ -191,12 +191,12 @@ void(*bootJump)(void); void checkForBootLoaderRequest(void) { - uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST); + uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON); - if (bootloaderRequest != BOOTLOADER_REQUEST_COOKIE) { + if (bootloaderRequest != RESET_BOOTLOADER_REQUEST) { return; } - persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0); + persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE); void (*SysMemBootJump)(void); diff --git a/src/main/drivers/usb_msc_f4xx.c b/src/main/drivers/usb_msc_f4xx.c index 8c4c3c25c..19234ea6c 100644 --- a/src/main/drivers/usb_msc_f4xx.c +++ b/src/main/drivers/usb_msc_f4xx.c @@ -125,8 +125,8 @@ uint8_t mscStart(void) bool mscCheckBoot(void) { - const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST); - return bootModeRequest == MSC_REQUEST_COOKIE; + const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON); + return bootModeRequest == RESET_MSC_REQUEST; // Note that we can't clear the persisent object after checking here. This is because // this function is called multiple times during initialization. So we clear on a reset // out of MSC mode. @@ -162,7 +162,7 @@ void mscWaitForButton(void) void systemResetToMsc(int timezoneOffsetMinutes) { - persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, MSC_REQUEST_COOKIE); + persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_MSC_REQUEST); __disable_irq(); @@ -177,7 +177,7 @@ void systemResetToMsc(int timezoneOffsetMinutes) void systemResetFromMsc(void) { - persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0); + persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE); __disable_irq(); NVIC_SystemReset(); } diff --git a/src/main/drivers/usb_msc_f7xx.c b/src/main/drivers/usb_msc_f7xx.c index 90c73c550..980eea4f9 100644 --- a/src/main/drivers/usb_msc_f7xx.c +++ b/src/main/drivers/usb_msc_f7xx.c @@ -130,8 +130,8 @@ uint8_t mscStart(void) bool mscCheckBoot(void) { - const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST); - return bootModeRequest == MSC_REQUEST_COOKIE; + const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON); + return bootModeRequest == RESET_MSC_REQUEST; // Note that we can't clear the persisent object after checking here. This is because // this function is called multiple times during initialization. So we clear on a reset // out of MSC mode. @@ -167,7 +167,7 @@ void mscWaitForButton(void) void systemResetToMsc(int timezoneOffsetMinutes) { - persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, MSC_REQUEST_COOKIE); + persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_MSC_REQUEST); __disable_irq(); @@ -182,7 +182,7 @@ void systemResetToMsc(int timezoneOffsetMinutes) void systemResetFromMsc(void) { - persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0); + persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE); __disable_irq(); NVIC_SystemReset(); }