Revision 2b9a14a2

View differences:

.gitignore
10 10
*.files
11 11
*.config
12 12
*.creator
13
*.user
13
*.creator.user*
14
*.cflags
15
*.cxxflags
14 16

  
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);
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