Commit 2b9a14a2 authored by Thomas Schöpping's avatar Thomas Schöpping
Browse files

The PowerManagement bootloaders will now measure VSYS and enable charging on every initialization.

parent 591c0fd3
......@@ -10,5 +10,7 @@ Host/Source/SerialBoot/build/
*.files
*.config
*.creator
*.user
*.creator.user*
*.cflags
*.cxxflags
......@@ -51,29 +51,29 @@
****************************************************************************************/
static void Init(void);
static void initGpio();
static void initExti();
void configGpioForShutdown();
void systemPowerDown();
static void initGpio(void);
static void initExti(void);
void configGpioForShutdown(void);
void systemPowerDown(void);
ErrorStatus handleColdReset();
ErrorStatus handleSoftwareReset();
ErrorStatus handleUartDnWakeup();
ErrorStatus handlePathDcWakeup();
ErrorStatus handleTouchWakeup();
ErrorStatus handleIwdgWakeup();
ErrorStatus handleColdReset(void);
ErrorStatus handleSoftwareReset(void);
ErrorStatus handleUartDnWakeup(void);
ErrorStatus handlePathDcWakeup(void);
ErrorStatus handleTouchWakeup(void);
ErrorStatus handleIwdgWakeup(void);
static void indicateHibernate();
static void AdcSingleMeasurement();
static void indicateHibernate(void);
static void AdcSingleMeasurement(void);
ADC_TypeDef* setupADC(ADC_TypeDef* adc, const uint16_t low_th, const uint16_t high_th);
uint16_t configIwdg(const uint16_t ms);
ErrorStatus shutdownDisambiguationProcedure(const uint8_t type);
void shutdownToTransportation();
void shutdownToDeepsleep();
void shutdownToHibernate();
void shutdownAndRestart();
void shutdownToTransportation(void);
void shutdownToDeepsleep(void);
void shutdownToHibernate(void);
void shutdownAndRestart(void);
volatile blBackupRegister_t backup_reg;
......@@ -88,7 +88,7 @@ void blCallbackHandleShutdownRequest(void);
const blCallbackTable_t cbtable __attribute__ ((section ("_callback_table"))) = {
.magicNumber = BL_MAGIC_NUMBER,
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 3},
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 4},
.vSSSP = {BL_VERSION_ID_SSSP, BL_SSSP_VERSION_MAJOR, BL_SSSP_VERSION_MINOR, 0},
.vCompiler = {BL_VERSION_ID_GCC, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__}, // currently only GCC is supported
.cbShutdownHibernate = blCallbackShutdownHibernate,
......@@ -166,6 +166,17 @@ void main(void)
setLed(BLT_FALSE);
/*
* Measure the current voltage of VSYS and enable the chargers if it was found to be > 9V.
*/
AdcSingleMeasurement();
if ( (((float)(ADC_GetConversionValue(ADC1)) / (float)0x0FFF) * 3.3f * 5.33f) > 9.0f ) {
/* VSYS was found to be > 9V */
setLed(BLT_TRUE);
GPIO_ResetBits(CHARGE_EN1_N_GPIO, CHARGE_EN1_N_PIN);
GPIO_ResetBits(CHARGE_EN2_N_GPIO, CHARGE_EN2_N_PIN);
}
/* handle different wakeup/reset reasons */
ErrorStatus status = ERROR;
if (backup_reg.wakeup_pri_reason & BL_WAKEUP_PRI_RSN_SFTRST) {
......@@ -314,7 +325,7 @@ static void Init(void)
/*
* Initializes all GPIO used by the bootloader
*/
static void initGpio() {
static void initGpio(void) {
GPIO_InitTypeDef gpio_init;
/*
......@@ -438,7 +449,7 @@ static void initGpio() {
/*
* Initialize all EXTI lines
*/
static void initExti() {
static void initExti(void) {
/* configure EXTI lines */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource0); // IR_INT1_N
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource0); // CHARGE_STAT1A
......@@ -504,7 +515,7 @@ ErrorStatus shutdownDisambiguationProcedure(const uint8_t type) {
/*
* Final shutdown of the system to enter transportation mode.
*/
void shutdownToTransportation() {
void shutdownToTransportation(void) {
/* configure some criticpal GPIOs as input
* This is required, because otherwise some hardware might be powered through these signals */
configGpioForShutdown();
......@@ -546,7 +557,7 @@ void shutdownToTransportation() {
/*
* Final shutdown of the system to enter deepsleep mode.
*/
void shutdownToDeepsleep() {
void shutdownToDeepsleep(void) {
/* configure some criticpal GPIOs as input
* This is required, because otherwise some hardware might be powered through these signals */
configGpioForShutdown();
......@@ -586,7 +597,7 @@ void shutdownToDeepsleep() {
/*
* Final shutdown of the system to enter hibernate mode.
*/
void shutdownToHibernate() {
void shutdownToHibernate(void) {
/* configure some criticpal GPIOs as input
* This is required, because otherwise some hardware might be powered through these signals */
configGpioForShutdown();
......@@ -615,7 +626,7 @@ void shutdownToHibernate() {
/*
* Final shutdown of the system and restart.
*/
void shutdownAndRestart() {
void shutdownAndRestart(void) {
/* configure some criticpal GPIOs as input
* This is required, because otherwise some hardware might be powered through these signals */
configGpioForShutdown();
......@@ -645,7 +656,7 @@ void shutdownAndRestart() {
* Configures some GPIO pins as inputs for safety reasons.
* Under certain circumstances, these pins might power hardware that is supposed to be shut down.
*/
void configGpioForShutdown() {
void configGpioForShutdown(void) {
/* setup the configuration */
GPIO_InitTypeDef gpio_init;
gpio_init.GPIO_Mode = GPIO_Mode_IN;
......@@ -687,7 +698,7 @@ void configGpioForShutdown() {
/*
* Disables all regulated voltages and finally cuts power to the rest of the system.
*/
void systemPowerDown() {
void systemPowerDown(void) {
setLed(BLT_TRUE);
/* make sure that all other modules are shut down */
......@@ -759,7 +770,7 @@ uint16_t configIwdg(const uint16_t ms) {
* If an attempt for an OS update is detected, flashing mode is entered.
* Otherwise, the system will boot the OS.
*/
ErrorStatus handleColdReset() {
ErrorStatus handleColdReset(void) {
/* activate system power and wait some time to ensure stable voltages */
setLed(BLT_TRUE);
GPIO_SetBits(POWER_EN_GPIO, POWER_EN_PIN);
......@@ -826,7 +837,7 @@ ErrorStatus handleColdReset() {
* - The reason is unknown.
* This case will cause an error.
*/
ErrorStatus handleSoftwareReset() {
ErrorStatus handleSoftwareReset(void) {
/* action depends on original shutdown reason */
switch (backup_reg.shutdown_pri_reason) {
case BL_SHUTDOWN_PRI_RSN_HIBERNATE:
......@@ -880,7 +891,7 @@ ErrorStatus handleSoftwareReset() {
* In this case, the system starts as after a cold reset.
* this function is identical to handleTouchWakeup().
*/
ErrorStatus handleUartDnWakeup() {
ErrorStatus handleUartDnWakeup(void) {
return handleColdReset();
} /*** end of hanldeUartDnWakeup ***/
......@@ -889,7 +900,7 @@ ErrorStatus handleUartDnWakeup() {
* If the system was woken from deepsleep mode, it will enter hibernate mode to enable charging as long as the power plug is present.
* In any other case, the system will just enter the previous low-power mode again.
*/
ErrorStatus handlePathDcWakeup() {
ErrorStatus handlePathDcWakeup(void) {
/* reenter the previous low-power mode */
switch (backup_reg.shutdown_pri_reason) {
case BL_SHUTDOWN_PRI_RSN_HIBERNATE:
......@@ -928,7 +939,7 @@ ErrorStatus handlePathDcWakeup() {
* In this case the system starts as after an cold reset.
* This function is identical to handleUartDnWakeup().
*/
ErrorStatus handleTouchWakeup() {
ErrorStatus handleTouchWakeup(void) {
return handleColdReset();
} /*** end of handleTouchWakeup ***/
......@@ -938,7 +949,7 @@ ErrorStatus handleTouchWakeup() {
* If VSYS is found to be high enough to charge the batteries, the system will stay active until VSYS drops or an EXTI event occurs.
* Otherwise, the system will configure the IWDG to wake the system again after five seconds and enter standby mode.
*/
ErrorStatus handleIwdgWakeup() {
ErrorStatus handleIwdgWakeup(void) {
/* handle different situations, depending on the backup data */
if ((backup_reg.shutdown_pri_reason == BL_SHUTDOWN_PRI_RSN_HIBERNATE) ||
(backup_reg.shutdown_pri_reason == BL_SHUTDOWN_PRI_RSN_DEEPSLEEP)) {
......@@ -1146,7 +1157,7 @@ ErrorStatus handleIwdgWakeup() {
* Indicates the DiWheelDrive module to enter hibernate mode at wakeup.
* This function should be called quite at the beginning of the according handleXXXReset/Wakeup() methods.
*/
static void indicateHibernate() {
static void indicateHibernate(void) {
/* signal the DiWheelDrive to enter hibernate mode as well, so it will activate the charging pins */
GPIO_ResetBits(SYS_UART_DN_GPIO, SYS_UART_DN_PIN);
msleep(10); // this must be that long, because the DiWheelDrive sleeps some time before evaluating any signals
......@@ -1161,7 +1172,7 @@ static void indicateHibernate() {
/*
*Performs a one-shot measurement of the VSYS voltage.
*/
static void AdcSingleMeasurement() {
static void AdcSingleMeasurement(void) {
/* reset and initialize ADC for single-shot measurement */
// ADC_DeInit();
setupADC(ADC1, 0, 0);
......
......@@ -51,29 +51,29 @@
****************************************************************************************/
static void Init(void);
static void initGpio();
static void initExti();
void configGpioForShutdown();
void systemPowerDown();
static void initGpio(void);
static void initExti(void);
void configGpioForShutdown(void);
void systemPowerDown(void);
ErrorStatus handleColdReset();
ErrorStatus handleSoftwareReset();
ErrorStatus handleUartDnWakeup();
ErrorStatus handlePathDcWakeup();
ErrorStatus handleTouchWakeup();
ErrorStatus handleIwdgWakeup();
ErrorStatus handleColdReset(void);
ErrorStatus handleSoftwareReset(void);
ErrorStatus handleUartDnWakeup(void);
ErrorStatus handlePathDcWakeup(void);
ErrorStatus handleTouchWakeup(void);
ErrorStatus handleIwdgWakeup(void);
static void indicateHibernate();
static void AdcSingleMeasurement();
static void indicateHibernate(void);
static void AdcSingleMeasurement(void);
ADC_TypeDef* setupADC(ADC_TypeDef* adc, const uint16_t low_th, const uint16_t high_th);
uint16_t configIwdg(const uint16_t ms);
ErrorStatus shutdownDisambiguationProcedure(const uint8_t type);
void shutdownToTransportation();
void shutdownToDeepsleep();
void shutdownToHibernate();
void shutdownAndRestart();
void shutdownToTransportation(void);
void shutdownToDeepsleep(void);
void shutdownToHibernate(void);
void shutdownAndRestart(void);
volatile blBackupRegister_t backup_reg;
......@@ -88,7 +88,7 @@ void blCallbackHandleShutdownRequest(void);
const blCallbackTable_t cbtable __attribute__ ((section ("_callback_table"))) = {
.magicNumber = BL_MAGIC_NUMBER,
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 3},
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 4},
.vSSSP = {BL_VERSION_ID_SSSP, BL_SSSP_VERSION_MAJOR, BL_SSSP_VERSION_MINOR, 0},
.vCompiler = {BL_VERSION_ID_GCC, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__}, // currently only GCC is supported
.cbShutdownHibernate = blCallbackShutdownHibernate,
......@@ -166,6 +166,17 @@ void main(void)
setLed(BLT_FALSE);
/*
* Measure the current voltage of VSYS and enable the chargers if it was found to be > 9V.
*/
AdcSingleMeasurement();
if ( (((float)(ADC_GetConversionValue(ADC1)) / (float)0x0FFF) * 3.3f * 5.33f) > 9.0f ) {
/* VSYS was found to be > 9V */
setLed(BLT_TRUE);
GPIO_ResetBits(CHARGE_EN1_N_GPIO, CHARGE_EN1_N_PIN);
GPIO_ResetBits(CHARGE_EN2_N_GPIO, CHARGE_EN2_N_PIN);
}
/* handle different wakeup/reset reasons */
ErrorStatus status = ERROR;
if (backup_reg.wakeup_pri_reason & BL_WAKEUP_PRI_RSN_SFTRST) {
......@@ -314,7 +325,7 @@ static void Init(void)
/*
* Initializes all GPIO used by the bootloader
*/
static void initGpio() {
static void initGpio(void) {
GPIO_InitTypeDef gpio_init;
/*
......@@ -446,7 +457,7 @@ static void initGpio() {
/*
* Initialize all EXTI lines
*/
static void initExti() {
static void initExti(void) {
/* configure EXTI lines */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource0); // IR_INT1_N
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource0); // CHARGE_STAT1A
......@@ -512,7 +523,7 @@ ErrorStatus shutdownDisambiguationProcedure(const uint8_t type) {
/*
* Final shutdown of the system to enter transportation mode.
*/
void shutdownToTransportation() {
void shutdownToTransportation(void) {
/* configure some criticpal GPIOs as input
* This is required, because otherwise some hardware might be powered through these signals */
configGpioForShutdown();
......@@ -554,7 +565,7 @@ void shutdownToTransportation() {
/*
* Final shutdown of the system to enter deepsleep mode.
*/
void shutdownToDeepsleep() {
void shutdownToDeepsleep(void) {
/* configure some criticpal GPIOs as input
* This is required, because otherwise some hardware might be powered through these signals */
configGpioForShutdown();
......@@ -594,7 +605,7 @@ void shutdownToDeepsleep() {
/*
* Final shutdown of the system to enter hibernate mode.
*/
void shutdownToHibernate() {
void shutdownToHibernate(void) {
/* configure some criticpal GPIOs as input
* This is required, because otherwise some hardware might be powered through these signals */
configGpioForShutdown();
......@@ -623,7 +634,7 @@ void shutdownToHibernate() {
/*
* Final shutdown of the system and restart.
*/
void shutdownAndRestart() {
void shutdownAndRestart(void) {
/* configure some criticpal GPIOs as input
* This is required, because otherwise some hardware might be powered through these signals */
configGpioForShutdown();
......@@ -653,7 +664,7 @@ void shutdownAndRestart() {
* Configures some GPIO pins as inputs for safety reasons.
* Under certain circumstances, these pins might power hardware that is supposed to be shut down.
*/
void configGpioForShutdown() {
void configGpioForShutdown(void) {
/* setup the configuration */
GPIO_InitTypeDef gpio_init;
gpio_init.GPIO_Mode = GPIO_Mode_IN;
......@@ -695,7 +706,7 @@ void configGpioForShutdown() {
/*
* Disables all regulated voltages and finally cuts power to the rest of the system.
*/
void systemPowerDown() {
void systemPowerDown(void) {
setLed(BLT_TRUE);
/* make sure that all other modules are shut down */
......@@ -767,7 +778,7 @@ uint16_t configIwdg(const uint16_t ms) {
* If an attempt for an OS update is detected, flashing mode is entered.
* Otherwise, the system will boot the OS.
*/
ErrorStatus handleColdReset() {
ErrorStatus handleColdReset(void) {
/* activate system power and wait some time to ensure stable voltages */
setLed(BLT_TRUE);
GPIO_SetBits(POWER_EN_GPIO, POWER_EN_PIN);
......@@ -834,7 +845,7 @@ ErrorStatus handleColdReset() {
* - The reason is unknown.
* This case will cause an error.
*/
ErrorStatus handleSoftwareReset() {
ErrorStatus handleSoftwareReset(void) {
/* action depends on original shutdown reason */
switch (backup_reg.shutdown_pri_reason) {
case BL_SHUTDOWN_PRI_RSN_HIBERNATE:
......@@ -888,7 +899,7 @@ ErrorStatus handleSoftwareReset() {
* In this case, the system starts as after a cold reset.
* this function is identical to handleTouchWakeup().
*/
ErrorStatus handleUartDnWakeup() {
ErrorStatus handleUartDnWakeup(void) {
return handleColdReset();
} /*** end of hanldeUartDnWakeup ***/
......@@ -897,7 +908,7 @@ ErrorStatus handleUartDnWakeup() {
* If the system was woken from deepsleep mode, it will enter hibernate mode to enable charging as long as the power plug is present.
* In any other case, the system will just enter the previous low-power mode again.
*/
ErrorStatus handlePathDcWakeup() {
ErrorStatus handlePathDcWakeup(void) {
/* reenter the previous low-power mode */
switch (backup_reg.shutdown_pri_reason) {
case BL_SHUTDOWN_PRI_RSN_HIBERNATE:
......@@ -936,7 +947,7 @@ ErrorStatus handlePathDcWakeup() {
* In this case the system starts as after an cold reset.
* This function is identical to handleUartDnWakeup().
*/
ErrorStatus handleTouchWakeup() {
ErrorStatus handleTouchWakeup(void) {
return handleColdReset();
} /*** end of handleTouchWakeup ***/
......@@ -946,7 +957,7 @@ ErrorStatus handleTouchWakeup() {
* If VSYS is found to be high enough to charge the batteries, the system will stay active until VSYS drops or an EXTI event occurs.
* Otherwise, the system will configure the IWDG to wake the system again after five seconds and enter standby mode.
*/
ErrorStatus handleIwdgWakeup() {
ErrorStatus handleIwdgWakeup(void) {
/* handle different situations, depending on the backup data */
if ((backup_reg.shutdown_pri_reason == BL_SHUTDOWN_PRI_RSN_HIBERNATE) ||
(backup_reg.shutdown_pri_reason == BL_SHUTDOWN_PRI_RSN_DEEPSLEEP)) {
......@@ -1154,7 +1165,7 @@ ErrorStatus handleIwdgWakeup() {
* Indicates the DiWheelDrive module to enter hibernate mode at wakeup.
* This function should be called quite at the beginning of the according handleXXXReset/Wakeup() methods.
*/
static void indicateHibernate() {
static void indicateHibernate(void) {
/* signal the DiWheelDrive to enter hibernate mode as well, so it will activate the charging pins */
GPIO_ResetBits(SYS_UART_DN_GPIO, SYS_UART_DN_PIN);
msleep(10); // this must be that long, because the DiWheelDrive sleeps some time before evaluating any signals
......@@ -1169,7 +1180,7 @@ static void indicateHibernate() {
/*
*Performs a one-shot measurement of the VSYS voltage.
*/
static void AdcSingleMeasurement() {
static void AdcSingleMeasurement(void) {
/* reset and initialize ADC for single-shot measurement */
// ADC_DeInit();
setupADC(ADC1, 0, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment