1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 12:25:20 +03:00

Refactor / rename PERSISTENT_OBJECT_BOOTLOADER_REQUEST to PERSISTENT_OBJECT_RESET_REASON

This commit is contained in:
jflyper 2019-02-04 17:54:02 +09:00
parent af84f9e99d
commit 85cd4df2ea
6 changed files with 24 additions and 20 deletions

View file

@ -29,12 +29,19 @@ typedef enum {
PERSISTENT_OBJECT_MAGIC = 0, PERSISTENT_OBJECT_MAGIC = 0,
PERSISTENT_OBJECT_HSE_VALUE, PERSISTENT_OBJECT_HSE_VALUE,
PERSISTENT_OBJECT_OVERCLOCK_LEVEL, 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_HIGH, // high 32 bits of rtcTime_t
PERSISTENT_OBJECT_RTC_LOW, // low 32 bits of rtcTime_t PERSISTENT_OBJECT_RTC_LOW, // low 32 bits of rtcTime_t
PERSISTENT_OBJECT_COUNT, PERSISTENT_OBJECT_COUNT,
} persistentObjectId_e; } 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); void persistentObjectInit(void);
uint32_t persistentObjectRead(persistentObjectId_e id); uint32_t persistentObjectRead(persistentObjectId_e id);
void persistentObjectWrite(persistentObjectId_e id, uint32_t value); void persistentObjectWrite(persistentObjectId_e id, uint32_t value);

View file

@ -52,9 +52,6 @@ void checkForBootLoaderRequest(void);
bool isMPUSoftReset(void); bool isMPUSoftReset(void);
void cycleCounterInit(void); void cycleCounterInit(void);
#define BOOTLOADER_REQUEST_COOKIE 0xDEADBEEF
#define MSC_REQUEST_COOKIE 0xDDDD1010
void enableGPIOPowerUsageAndNoiseReductions(void); void enableGPIOPowerUsageAndNoiseReductions(void);
// current crystal frequency - 8 or 12MHz // current crystal frequency - 8 or 12MHz

View file

@ -41,7 +41,7 @@ void systemReset(void)
void systemResetToBootloader(void) void systemResetToBootloader(void)
{ {
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, BOOTLOADER_REQUEST_COOKIE); persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_BOOTLOADER_REQUEST);
__disable_irq(); __disable_irq();
NVIC_SystemReset(); NVIC_SystemReset();
@ -56,12 +56,12 @@ typedef struct isrVector_s {
void checkForBootLoaderRequest(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; return;
} }
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0); persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE);
extern isrVector_t system_isr_vector_table_base; extern isrVector_t system_isr_vector_table_base;

View file

@ -45,7 +45,7 @@ void systemReset(void)
void systemResetToBootloader(void) void systemResetToBootloader(void)
{ {
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, BOOTLOADER_REQUEST_COOKIE); persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_BOOTLOADER_REQUEST);
__disable_irq(); __disable_irq();
NVIC_SystemReset(); NVIC_SystemReset();
} }
@ -191,12 +191,12 @@ void(*bootJump)(void);
void checkForBootLoaderRequest(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; return;
} }
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0); persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE);
void (*SysMemBootJump)(void); void (*SysMemBootJump)(void);

View file

@ -125,8 +125,8 @@ uint8_t mscStart(void)
bool mscCheckBoot(void) bool mscCheckBoot(void)
{ {
const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST); const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON);
return bootModeRequest == MSC_REQUEST_COOKIE; return bootModeRequest == RESET_MSC_REQUEST;
// Note that we can't clear the persisent object after checking here. This is because // 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 // this function is called multiple times during initialization. So we clear on a reset
// out of MSC mode. // out of MSC mode.
@ -162,7 +162,7 @@ void mscWaitForButton(void)
void systemResetToMsc(int timezoneOffsetMinutes) void systemResetToMsc(int timezoneOffsetMinutes)
{ {
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, MSC_REQUEST_COOKIE); persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_MSC_REQUEST);
__disable_irq(); __disable_irq();
@ -177,7 +177,7 @@ void systemResetToMsc(int timezoneOffsetMinutes)
void systemResetFromMsc(void) void systemResetFromMsc(void)
{ {
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0); persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE);
__disable_irq(); __disable_irq();
NVIC_SystemReset(); NVIC_SystemReset();
} }

View file

@ -130,8 +130,8 @@ uint8_t mscStart(void)
bool mscCheckBoot(void) bool mscCheckBoot(void)
{ {
const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_BOOTMODE_REQUEST); const uint32_t bootModeRequest = persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON);
return bootModeRequest == MSC_REQUEST_COOKIE; return bootModeRequest == RESET_MSC_REQUEST;
// Note that we can't clear the persisent object after checking here. This is because // 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 // this function is called multiple times during initialization. So we clear on a reset
// out of MSC mode. // out of MSC mode.
@ -167,7 +167,7 @@ void mscWaitForButton(void)
void systemResetToMsc(int timezoneOffsetMinutes) void systemResetToMsc(int timezoneOffsetMinutes)
{ {
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, MSC_REQUEST_COOKIE); persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_MSC_REQUEST);
__disable_irq(); __disable_irq();
@ -182,7 +182,7 @@ void systemResetToMsc(int timezoneOffsetMinutes)
void systemResetFromMsc(void) void systemResetFromMsc(void)
{ {
persistentObjectWrite(PERSISTENT_OBJECT_BOOTMODE_REQUEST, 0); persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE);
__disable_irq(); __disable_irq();
NVIC_SystemReset(); NVIC_SystemReset();
} }