Revision 2b9a14a2 Target/Modules/PowerManagement_1-1/Boot/main.c
| Target/Modules/PowerManagement_1-1/Boot/main.c | ||
|---|---|---|
| 51 | 51 |
****************************************************************************************/ |
| 52 | 52 |
static void Init(void); |
| 53 | 53 |
|
| 54 |
static void initGpio(); |
|
| 55 |
static void initExti(); |
|
| 56 |
void configGpioForShutdown(); |
|
| 57 |
void systemPowerDown(); |
|
| 54 |
static void initGpio(void);
|
|
| 55 |
static void initExti(void);
|
|
| 56 |
void configGpioForShutdown(void);
|
|
| 57 |
void systemPowerDown(void);
|
|
| 58 | 58 |
|
| 59 |
ErrorStatus handleColdReset(); |
|
| 60 |
ErrorStatus handleSoftwareReset(); |
|
| 61 |
ErrorStatus handleUartDnWakeup(); |
|
| 62 |
ErrorStatus handlePathDcWakeup(); |
|
| 63 |
ErrorStatus handleTouchWakeup(); |
|
| 64 |
ErrorStatus handleIwdgWakeup(); |
|
| 59 |
ErrorStatus handleColdReset(void);
|
|
| 60 |
ErrorStatus handleSoftwareReset(void);
|
|
| 61 |
ErrorStatus handleUartDnWakeup(void);
|
|
| 62 |
ErrorStatus handlePathDcWakeup(void);
|
|
| 63 |
ErrorStatus handleTouchWakeup(void);
|
|
| 64 |
ErrorStatus handleIwdgWakeup(void);
|
|
| 65 | 65 |
|
| 66 |
static void indicateHibernate(); |
|
| 67 |
static void AdcSingleMeasurement(); |
|
| 66 |
static void indicateHibernate(void);
|
|
| 67 |
static void AdcSingleMeasurement(void);
|
|
| 68 | 68 |
|
| 69 | 69 |
ADC_TypeDef* setupADC(ADC_TypeDef* adc, const uint16_t low_th, const uint16_t high_th); |
| 70 | 70 |
uint16_t configIwdg(const uint16_t ms); |
| 71 | 71 |
|
| 72 | 72 |
ErrorStatus shutdownDisambiguationProcedure(const uint8_t type); |
| 73 |
void shutdownToTransportation(); |
|
| 74 |
void shutdownToDeepsleep(); |
|
| 75 |
void shutdownToHibernate(); |
|
| 76 |
void shutdownAndRestart(); |
|
| 73 |
void shutdownToTransportation(void);
|
|
| 74 |
void shutdownToDeepsleep(void);
|
|
| 75 |
void shutdownToHibernate(void);
|
|
| 76 |
void shutdownAndRestart(void);
|
|
| 77 | 77 |
|
| 78 | 78 |
volatile blBackupRegister_t backup_reg; |
| 79 | 79 |
|
| ... | ... | |
| 88 | 88 |
|
| 89 | 89 |
const blCallbackTable_t cbtable __attribute__ ((section ("_callback_table"))) = {
|
| 90 | 90 |
.magicNumber = BL_MAGIC_NUMBER, |
| 91 |
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 3},
|
|
| 91 |
.vBootloader = {BL_VERSION_ID_AMiRoBLT_Beta, BL_VERSION_MAJOR, BL_VERSION_MINOR, 4},
|
|
| 92 | 92 |
.vSSSP = {BL_VERSION_ID_SSSP, BL_SSSP_VERSION_MAJOR, BL_SSSP_VERSION_MINOR, 0},
|
| 93 | 93 |
.vCompiler = {BL_VERSION_ID_GCC, __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__}, // currently only GCC is supported
|
| 94 | 94 |
.cbShutdownHibernate = blCallbackShutdownHibernate, |
| ... | ... | |
| 166 | 166 |
|
| 167 | 167 |
setLed(BLT_FALSE); |
| 168 | 168 |
|
| 169 |
/* |
|
| 170 |
* Measure the current voltage of VSYS and enable the chargers if it was found to be > 9V. |
|
| 171 |
*/ |
|
| 172 |
AdcSingleMeasurement(); |
|
| 173 |
if ( (((float)(ADC_GetConversionValue(ADC1)) / (float)0x0FFF) * 3.3f * 5.33f) > 9.0f ) {
|
|
| 174 |
/* VSYS was found to be > 9V */ |
|
| 175 |
setLed(BLT_TRUE); |
|
| 176 |
GPIO_ResetBits(CHARGE_EN1_N_GPIO, CHARGE_EN1_N_PIN); |
|
| 177 |
GPIO_ResetBits(CHARGE_EN2_N_GPIO, CHARGE_EN2_N_PIN); |
|
| 178 |
} |
|
| 179 |
|
|
| 169 | 180 |
/* handle different wakeup/reset reasons */ |
| 170 | 181 |
ErrorStatus status = ERROR; |
| 171 | 182 |
if (backup_reg.wakeup_pri_reason & BL_WAKEUP_PRI_RSN_SFTRST) {
|
| ... | ... | |
| 314 | 325 |
/* |
| 315 | 326 |
* Initializes all GPIO used by the bootloader |
| 316 | 327 |
*/ |
| 317 |
static void initGpio() {
|
|
| 328 |
static void initGpio(void) {
|
|
| 318 | 329 |
GPIO_InitTypeDef gpio_init; |
| 319 | 330 |
|
| 320 | 331 |
/* |
| ... | ... | |
| 438 | 449 |
/* |
| 439 | 450 |
* Initialize all EXTI lines |
| 440 | 451 |
*/ |
| 441 |
static void initExti() {
|
|
| 452 |
static void initExti(void) {
|
|
| 442 | 453 |
/* configure EXTI lines */ |
| 443 | 454 |
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource0); // IR_INT1_N |
| 444 | 455 |
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource0); // CHARGE_STAT1A |
| ... | ... | |
| 504 | 515 |
/* |
| 505 | 516 |
* Final shutdown of the system to enter transportation mode. |
| 506 | 517 |
*/ |
| 507 |
void shutdownToTransportation() {
|
|
| 518 |
void shutdownToTransportation(void) {
|
|
| 508 | 519 |
/* configure some criticpal GPIOs as input |
| 509 | 520 |
* This is required, because otherwise some hardware might be powered through these signals */ |
| 510 | 521 |
configGpioForShutdown(); |
| ... | ... | |
| 546 | 557 |
/* |
| 547 | 558 |
* Final shutdown of the system to enter deepsleep mode. |
| 548 | 559 |
*/ |
| 549 |
void shutdownToDeepsleep() {
|
|
| 560 |
void shutdownToDeepsleep(void) {
|
|
| 550 | 561 |
/* configure some criticpal GPIOs as input |
| 551 | 562 |
* This is required, because otherwise some hardware might be powered through these signals */ |
| 552 | 563 |
configGpioForShutdown(); |
| ... | ... | |
| 586 | 597 |
/* |
| 587 | 598 |
* Final shutdown of the system to enter hibernate mode. |
| 588 | 599 |
*/ |
| 589 |
void shutdownToHibernate() {
|
|
| 600 |
void shutdownToHibernate(void) {
|
|
| 590 | 601 |
/* configure some criticpal GPIOs as input |
| 591 | 602 |
* This is required, because otherwise some hardware might be powered through these signals */ |
| 592 | 603 |
configGpioForShutdown(); |
| ... | ... | |
| 615 | 626 |
/* |
| 616 | 627 |
* Final shutdown of the system and restart. |
| 617 | 628 |
*/ |
| 618 |
void shutdownAndRestart() {
|
|
| 629 |
void shutdownAndRestart(void) {
|
|
| 619 | 630 |
/* configure some criticpal GPIOs as input |
| 620 | 631 |
* This is required, because otherwise some hardware might be powered through these signals */ |
| 621 | 632 |
configGpioForShutdown(); |
| ... | ... | |
| 645 | 656 |
* Configures some GPIO pins as inputs for safety reasons. |
| 646 | 657 |
* Under certain circumstances, these pins might power hardware that is supposed to be shut down. |
| 647 | 658 |
*/ |
| 648 |
void configGpioForShutdown() {
|
|
| 659 |
void configGpioForShutdown(void) {
|
|
| 649 | 660 |
/* setup the configuration */ |
| 650 | 661 |
GPIO_InitTypeDef gpio_init; |
| 651 | 662 |
gpio_init.GPIO_Mode = GPIO_Mode_IN; |
| ... | ... | |
| 687 | 698 |
/* |
| 688 | 699 |
* Disables all regulated voltages and finally cuts power to the rest of the system. |
| 689 | 700 |
*/ |
| 690 |
void systemPowerDown() {
|
|
| 701 |
void systemPowerDown(void) {
|
|
| 691 | 702 |
setLed(BLT_TRUE); |
| 692 | 703 |
|
| 693 | 704 |
/* make sure that all other modules are shut down */ |
| ... | ... | |
| 759 | 770 |
* If an attempt for an OS update is detected, flashing mode is entered. |
| 760 | 771 |
* Otherwise, the system will boot the OS. |
| 761 | 772 |
*/ |
| 762 |
ErrorStatus handleColdReset() {
|
|
| 773 |
ErrorStatus handleColdReset(void) {
|
|
| 763 | 774 |
/* activate system power and wait some time to ensure stable voltages */ |
| 764 | 775 |
setLed(BLT_TRUE); |
| 765 | 776 |
GPIO_SetBits(POWER_EN_GPIO, POWER_EN_PIN); |
| ... | ... | |
| 826 | 837 |
* - The reason is unknown. |
| 827 | 838 |
* This case will cause an error. |
| 828 | 839 |
*/ |
| 829 |
ErrorStatus handleSoftwareReset() {
|
|
| 840 |
ErrorStatus handleSoftwareReset(void) {
|
|
| 830 | 841 |
/* action depends on original shutdown reason */ |
| 831 | 842 |
switch (backup_reg.shutdown_pri_reason) {
|
| 832 | 843 |
case BL_SHUTDOWN_PRI_RSN_HIBERNATE: |
| ... | ... | |
| 880 | 891 |
* In this case, the system starts as after a cold reset. |
| 881 | 892 |
* this function is identical to handleTouchWakeup(). |
| 882 | 893 |
*/ |
| 883 |
ErrorStatus handleUartDnWakeup() {
|
|
| 894 |
ErrorStatus handleUartDnWakeup(void) {
|
|
| 884 | 895 |
return handleColdReset(); |
| 885 | 896 |
} /*** end of hanldeUartDnWakeup ***/ |
| 886 | 897 |
|
| ... | ... | |
| 889 | 900 |
* If the system was woken from deepsleep mode, it will enter hibernate mode to enable charging as long as the power plug is present. |
| 890 | 901 |
* In any other case, the system will just enter the previous low-power mode again. |
| 891 | 902 |
*/ |
| 892 |
ErrorStatus handlePathDcWakeup() {
|
|
| 903 |
ErrorStatus handlePathDcWakeup(void) {
|
|
| 893 | 904 |
/* reenter the previous low-power mode */ |
| 894 | 905 |
switch (backup_reg.shutdown_pri_reason) {
|
| 895 | 906 |
case BL_SHUTDOWN_PRI_RSN_HIBERNATE: |
| ... | ... | |
| 928 | 939 |
* In this case the system starts as after an cold reset. |
| 929 | 940 |
* This function is identical to handleUartDnWakeup(). |
| 930 | 941 |
*/ |
| 931 |
ErrorStatus handleTouchWakeup() {
|
|
| 942 |
ErrorStatus handleTouchWakeup(void) {
|
|
| 932 | 943 |
return handleColdReset(); |
| 933 | 944 |
} /*** end of handleTouchWakeup ***/ |
| 934 | 945 |
|
| ... | ... | |
| 938 | 949 |
* 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. |
| 939 | 950 |
* Otherwise, the system will configure the IWDG to wake the system again after five seconds and enter standby mode. |
| 940 | 951 |
*/ |
| 941 |
ErrorStatus handleIwdgWakeup() {
|
|
| 952 |
ErrorStatus handleIwdgWakeup(void) {
|
|
| 942 | 953 |
/* handle different situations, depending on the backup data */ |
| 943 | 954 |
if ((backup_reg.shutdown_pri_reason == BL_SHUTDOWN_PRI_RSN_HIBERNATE) || |
| 944 | 955 |
(backup_reg.shutdown_pri_reason == BL_SHUTDOWN_PRI_RSN_DEEPSLEEP)) {
|
| ... | ... | |
| 1146 | 1157 |
* Indicates the DiWheelDrive module to enter hibernate mode at wakeup. |
| 1147 | 1158 |
* This function should be called quite at the beginning of the according handleXXXReset/Wakeup() methods. |
| 1148 | 1159 |
*/ |
| 1149 |
static void indicateHibernate() {
|
|
| 1160 |
static void indicateHibernate(void) {
|
|
| 1150 | 1161 |
/* signal the DiWheelDrive to enter hibernate mode as well, so it will activate the charging pins */ |
| 1151 | 1162 |
GPIO_ResetBits(SYS_UART_DN_GPIO, SYS_UART_DN_PIN); |
| 1152 | 1163 |
msleep(10); // this must be that long, because the DiWheelDrive sleeps some time before evaluating any signals |
| ... | ... | |
| 1161 | 1172 |
/* |
| 1162 | 1173 |
*Performs a one-shot measurement of the VSYS voltage. |
| 1163 | 1174 |
*/ |
| 1164 |
static void AdcSingleMeasurement() {
|
|
| 1175 |
static void AdcSingleMeasurement(void) {
|
|
| 1165 | 1176 |
/* reset and initialize ADC for single-shot measurement */ |
| 1166 | 1177 |
// ADC_DeInit(); |
| 1167 | 1178 |
setupADC(ADC1, 0, 0); |
Also available in: Unified diff