Revision 2b9a14a2 Target/Modules/PowerManagement_1-2/Boot/main.c
Target/Modules/PowerManagement_1-2/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 |
/* |
... | ... | |
446 | 457 |
/* |
447 | 458 |
* Initialize all EXTI lines |
448 | 459 |
*/ |
449 |
static void initExti() { |
|
460 |
static void initExti(void) {
|
|
450 | 461 |
/* configure EXTI lines */ |
451 | 462 |
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource0); // IR_INT1_N |
452 | 463 |
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource0); // CHARGE_STAT1A |
... | ... | |
512 | 523 |
/* |
513 | 524 |
* Final shutdown of the system to enter transportation mode. |
514 | 525 |
*/ |
515 |
void shutdownToTransportation() { |
|
526 |
void shutdownToTransportation(void) {
|
|
516 | 527 |
/* configure some criticpal GPIOs as input |
517 | 528 |
* This is required, because otherwise some hardware might be powered through these signals */ |
518 | 529 |
configGpioForShutdown(); |
... | ... | |
554 | 565 |
/* |
555 | 566 |
* Final shutdown of the system to enter deepsleep mode. |
556 | 567 |
*/ |
557 |
void shutdownToDeepsleep() { |
|
568 |
void shutdownToDeepsleep(void) {
|
|
558 | 569 |
/* configure some criticpal GPIOs as input |
559 | 570 |
* This is required, because otherwise some hardware might be powered through these signals */ |
560 | 571 |
configGpioForShutdown(); |
... | ... | |
594 | 605 |
/* |
595 | 606 |
* Final shutdown of the system to enter hibernate mode. |
596 | 607 |
*/ |
597 |
void shutdownToHibernate() { |
|
608 |
void shutdownToHibernate(void) {
|
|
598 | 609 |
/* configure some criticpal GPIOs as input |
599 | 610 |
* This is required, because otherwise some hardware might be powered through these signals */ |
600 | 611 |
configGpioForShutdown(); |
... | ... | |
623 | 634 |
/* |
624 | 635 |
* Final shutdown of the system and restart. |
625 | 636 |
*/ |
626 |
void shutdownAndRestart() { |
|
637 |
void shutdownAndRestart(void) {
|
|
627 | 638 |
/* configure some criticpal GPIOs as input |
628 | 639 |
* This is required, because otherwise some hardware might be powered through these signals */ |
629 | 640 |
configGpioForShutdown(); |
... | ... | |
653 | 664 |
* Configures some GPIO pins as inputs for safety reasons. |
654 | 665 |
* Under certain circumstances, these pins might power hardware that is supposed to be shut down. |
655 | 666 |
*/ |
656 |
void configGpioForShutdown() { |
|
667 |
void configGpioForShutdown(void) {
|
|
657 | 668 |
/* setup the configuration */ |
658 | 669 |
GPIO_InitTypeDef gpio_init; |
659 | 670 |
gpio_init.GPIO_Mode = GPIO_Mode_IN; |
... | ... | |
695 | 706 |
/* |
696 | 707 |
* Disables all regulated voltages and finally cuts power to the rest of the system. |
697 | 708 |
*/ |
698 |
void systemPowerDown() { |
|
709 |
void systemPowerDown(void) {
|
|
699 | 710 |
setLed(BLT_TRUE); |
700 | 711 |
|
701 | 712 |
/* make sure that all other modules are shut down */ |
... | ... | |
767 | 778 |
* If an attempt for an OS update is detected, flashing mode is entered. |
768 | 779 |
* Otherwise, the system will boot the OS. |
769 | 780 |
*/ |
770 |
ErrorStatus handleColdReset() { |
|
781 |
ErrorStatus handleColdReset(void) {
|
|
771 | 782 |
/* activate system power and wait some time to ensure stable voltages */ |
772 | 783 |
setLed(BLT_TRUE); |
773 | 784 |
GPIO_SetBits(POWER_EN_GPIO, POWER_EN_PIN); |
... | ... | |
834 | 845 |
* - The reason is unknown. |
835 | 846 |
* This case will cause an error. |
836 | 847 |
*/ |
837 |
ErrorStatus handleSoftwareReset() { |
|
848 |
ErrorStatus handleSoftwareReset(void) {
|
|
838 | 849 |
/* action depends on original shutdown reason */ |
839 | 850 |
switch (backup_reg.shutdown_pri_reason) { |
840 | 851 |
case BL_SHUTDOWN_PRI_RSN_HIBERNATE: |
... | ... | |
888 | 899 |
* In this case, the system starts as after a cold reset. |
889 | 900 |
* this function is identical to handleTouchWakeup(). |
890 | 901 |
*/ |
891 |
ErrorStatus handleUartDnWakeup() { |
|
902 |
ErrorStatus handleUartDnWakeup(void) {
|
|
892 | 903 |
return handleColdReset(); |
893 | 904 |
} /*** end of hanldeUartDnWakeup ***/ |
894 | 905 |
|
... | ... | |
897 | 908 |
* If the system was woken from deepsleep mode, it will enter hibernate mode to enable charging as long as the power plug is present. |
898 | 909 |
* In any other case, the system will just enter the previous low-power mode again. |
899 | 910 |
*/ |
900 |
ErrorStatus handlePathDcWakeup() { |
|
911 |
ErrorStatus handlePathDcWakeup(void) {
|
|
901 | 912 |
/* reenter the previous low-power mode */ |
902 | 913 |
switch (backup_reg.shutdown_pri_reason) { |
903 | 914 |
case BL_SHUTDOWN_PRI_RSN_HIBERNATE: |
... | ... | |
936 | 947 |
* In this case the system starts as after an cold reset. |
937 | 948 |
* This function is identical to handleUartDnWakeup(). |
938 | 949 |
*/ |
939 |
ErrorStatus handleTouchWakeup() { |
|
950 |
ErrorStatus handleTouchWakeup(void) {
|
|
940 | 951 |
return handleColdReset(); |
941 | 952 |
} /*** end of handleTouchWakeup ***/ |
942 | 953 |
|
... | ... | |
946 | 957 |
* 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. |
947 | 958 |
* Otherwise, the system will configure the IWDG to wake the system again after five seconds and enter standby mode. |
948 | 959 |
*/ |
949 |
ErrorStatus handleIwdgWakeup() { |
|
960 |
ErrorStatus handleIwdgWakeup(void) {
|
|
950 | 961 |
/* handle different situations, depending on the backup data */ |
951 | 962 |
if ((backup_reg.shutdown_pri_reason == BL_SHUTDOWN_PRI_RSN_HIBERNATE) || |
952 | 963 |
(backup_reg.shutdown_pri_reason == BL_SHUTDOWN_PRI_RSN_DEEPSLEEP)) { |
... | ... | |
1154 | 1165 |
* Indicates the DiWheelDrive module to enter hibernate mode at wakeup. |
1155 | 1166 |
* This function should be called quite at the beginning of the according handleXXXReset/Wakeup() methods. |
1156 | 1167 |
*/ |
1157 |
static void indicateHibernate() { |
|
1168 |
static void indicateHibernate(void) {
|
|
1158 | 1169 |
/* signal the DiWheelDrive to enter hibernate mode as well, so it will activate the charging pins */ |
1159 | 1170 |
GPIO_ResetBits(SYS_UART_DN_GPIO, SYS_UART_DN_PIN); |
1160 | 1171 |
msleep(10); // this must be that long, because the DiWheelDrive sleeps some time before evaluating any signals |
... | ... | |
1169 | 1180 |
/* |
1170 | 1181 |
*Performs a one-shot measurement of the VSYS voltage. |
1171 | 1182 |
*/ |
1172 |
static void AdcSingleMeasurement() { |
|
1183 |
static void AdcSingleMeasurement(void) {
|
|
1173 | 1184 |
/* reset and initialize ADC for single-shot measurement */ |
1174 | 1185 |
// ADC_DeInit(); |
1175 | 1186 |
setupADC(ADC1, 0, 0); |
Also available in: Unified diff