reducing code duplication

This commit is contained in:
rusefillc 2021-02-06 00:18:47 -05:00
parent 94130c41a0
commit a093a839be
3 changed files with 43 additions and 88 deletions

View File

@ -330,3 +330,46 @@ bool isValidSerialRxPin(brain_pin_e pin) {
} }
#endif /*EFI_AUX_SERIAL*/ #endif /*EFI_AUX_SERIAL*/
BOR_Level_t BOR_Get(void) {
FLASH_OBProgramInitTypeDef FLASH_Handle;
/* Read option bytes */
HAL_FLASHEx_OBGetConfig(&FLASH_Handle);
/* Return BOR value */
return (BOR_Level_t) FLASH_Handle.BORLevel;
}
BOR_Result_t BOR_Set(BOR_Level_t BORValue) {
if (BOR_Get() == BORValue) {
return BOR_Result_Ok;
}
FLASH_OBProgramInitTypeDef FLASH_Handle;
FLASH_Handle.BORLevel = (uint32_t)BORValue;
FLASH_Handle.OptionType = OPTIONBYTE_BOR;
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_OBProgram(&FLASH_Handle);
HAL_StatusTypeDef status = HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();
if (status != HAL_OK) {
return BOR_Result_Error;
}
return BOR_Result_Ok;
}
void baseMCUInit(void) {
// looks like this holds a random value on start? Let's set a nice clean zero
DWT->CYCCNT = 0;
BOR_Set(BOR_Level_1); // one step above default value
}

View File

@ -77,16 +77,6 @@ EXTERNC int getRemainingStack(thread_t *otp) {
#endif /* GNU / IAR */ #endif /* GNU / IAR */
void baseMCUInit(void) {
// looks like this holds a random value on start? Let's set a nice clean zero
DWT->CYCCNT = 0;
/**
* BOR (Brown Out Reset) is a way to reset microcontroller if target voltage is below voltage we set. When this happens, MCU is in reset state until voltage comes above selected voltage.
*/
BOR_Set(BOR_Level_1); // one step above default value
}
void _unhandled_exception(void) { void _unhandled_exception(void) {
/*lint -restore*/ /*lint -restore*/
@ -356,42 +346,6 @@ void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) {
#endif /* HAL_USE_SPI */ #endif /* HAL_USE_SPI */
BOR_Level_t BOR_Get(void) {
FLASH_OBProgramInitTypeDef FLASH_Handle;
/* Read option bytes */
HAL_FLASHEx_OBGetConfig(&FLASH_Handle);
/* Return BOR value */
return (BOR_Level_t) FLASH_Handle.BORLevel;
}
BOR_Result_t BOR_Set(BOR_Level_t BORValue) {
if (BOR_Get() == BORValue) {
return BOR_Result_Ok;
}
FLASH_OBProgramInitTypeDef FLASH_Handle;
FLASH_Handle.BORLevel = (uint32_t)BORValue;
FLASH_Handle.OptionType = OPTIONBYTE_BOR;
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_OBProgram(&FLASH_Handle);
HAL_StatusTypeDef status = HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();
if (status != HAL_OK) {
return BOR_Result_Error;
}
return BOR_Result_Ok;
}
#if EFI_CAN_SUPPORT #if EFI_CAN_SUPPORT
static bool isValidCan1RxPin(brain_pin_e pin) { static bool isValidCan1RxPin(brain_pin_e pin) {

View File

@ -75,12 +75,6 @@ EXTERNC int getRemainingStack(thread_t *otp) {
#endif /* GNU / IAR */ #endif /* GNU / IAR */
void baseMCUInit(void) {
// looks like this holds a random value on start? Let's set a nice clean zero
DWT->CYCCNT = 0;
BOR_Set(BOR_Level_1); // one step above default value
}
void _unhandled_exception(void) { void _unhandled_exception(void) {
/*lint -restore*/ /*lint -restore*/
@ -345,42 +339,6 @@ void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) {
#endif /* HAL_USE_SPI */ #endif /* HAL_USE_SPI */
BOR_Level_t BOR_Get(void) {
FLASH_OBProgramInitTypeDef FLASH_Handle;
/* Read option bytes */
HAL_FLASHEx_OBGetConfig(&FLASH_Handle);
/* Return BOR value */
return (BOR_Level_t) FLASH_Handle.BORLevel;
}
BOR_Result_t BOR_Set(BOR_Level_t BORValue) {
if (BOR_Get() == BORValue) {
return BOR_Result_Ok;
}
FLASH_OBProgramInitTypeDef FLASH_Handle;
FLASH_Handle.BORLevel = (uint32_t)BORValue;
FLASH_Handle.OptionType = OPTIONBYTE_BOR;
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_OBProgram(&FLASH_Handle);
HAL_StatusTypeDef status = HAL_FLASH_OB_Launch();
HAL_FLASH_OB_Lock();
if (status != HAL_OK) {
return BOR_Result_Error;
}
return BOR_Result_Ok;
}
#if EFI_CAN_SUPPORT #if EFI_CAN_SUPPORT
static bool isValidCan1RxPin(brain_pin_e pin) { static bool isValidCan1RxPin(brain_pin_e pin) {