mbed-os github
Dependencies: ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep
Fork of ARNSRS_testDFU by
Diff: main.cpp
- Revision:
- 59:fd64ca9dae27
- Parent:
- 58:694d4d00407c
- Child:
- 60:e2922f9e309c
diff -r 694d4d00407c -r fd64ca9dae27 main.cpp --- a/main.cpp Fri Jun 29 09:40:02 2018 +0000 +++ b/main.cpp Fri Jun 29 15:50:15 2018 +0000 @@ -28,7 +28,7 @@ //Pin de test des alims #define PIN_V_PILES_ANALOG PA_1 -#define PIN_V_PILE_DIGI PC_3 +#define PIN_V_PILES_DIGI PC_3 #define PIN_V_USB_DIGI PA_0 //#define OUTPUT(...) { NVIC_DisableIRQ(USART3_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART3_IRQn);} @@ -142,9 +142,6 @@ //Boolean du status de l'appareil, en mode SECU ou nominal bool EN_MODE_SECU = false; -//Test des alim -//DigitalIn V_PILES_DIGI(PIN_V_PILES_DIGI); - //Test voltage piles AnalogIn V_PILES_ANALOG(PIN_V_PILES_ANALOG); @@ -153,7 +150,7 @@ float VPiles_val = 1; bool flag_USB = false; -bool flag_Pile = false; +bool flag_Piles = false; //Commande à envoyer à l'IHM //0 -> Marche @@ -162,7 +159,7 @@ int Commande_IHM = 0; //Interruption pin -InterruptIn vpile_off_on(PIN_V_PILE_DIGI); +InterruptIn vpiles_off_on(PIN_V_PILES_DIGI); InterruptIn vusb_off_on(PIN_V_USB_DIGI); //Pin enable du régulateur 5 v @@ -197,14 +194,11 @@ void Au_Dodo() { - buzzer.beep(1000,0.3); - wait_ms(500); - buzzer.beep(1000,0.3); - wait(1); - + E5V = 0; - E3V = 0; - + //E3V = 0; + + /* //Mise en veille HAL_PWREx_EnablePullUpPullDownConfig() ; HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0); @@ -223,7 +217,7 @@ HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW); HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_HIGH); } - if (flag_Pile) { + if (flag_Piles) { HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH); HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_LOW); } @@ -233,43 +227,40 @@ WRITE_REG( RTC->BKP31R, 0x1 ); //Enter shutdown mode HAL_PWREx_EnterSHUTDOWNMode(); + */ + + //Mise en veille + HAL_PWREx_EnablePullUpPullDownConfig() ; + HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0); + HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0 + // Clear wake up Flag + __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1); + // Enable wakeup pin WKUP2 + HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // high est la valeur par défaut + // Set RTC back-up register RTC_BKP31R to indicate + //later on that system has entered shutdown mode + WRITE_REG( RTC->BKP31R, 0x1 ); + //Enter shutdown mode + HAL_PWREx_EnterSHUTDOWNMode(); } void USB_unpluged() { DEBUG(" La prise USB a été débranchée.\n"); - + + buzzer.beep(1000,0.3); + wait_ms(500); + buzzer.beep(1000,0.3); + wait(1); + //Arrêt des enregistrements FLAG_REC = false; - /* - //Mise en veille de l'IHM - Commande_IHM = 1; - IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM); - FLAG_DISPLAY = false; - Commande_IHM = 0; - - DigitalOut Screen(PC_4); - Screen = 0; - */ - - E3V = 0; - - /* + UTILS::UnMount_Flash(); + //Enregistrement position des servos sans mettre en sécu - int Pos_P = Servo_Poumon.getPulses(); - UTILS::Store_A_Val((float)Pos_P, "Servo_Poumon.sys"); - DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", Pos_P); - - int Pos_F = Servo_Fuite.getPulses(); - UTILS::Store_A_Val((float)Pos_F, "Servo_Fuite.sys"); - DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", Pos_F); - */ - - UTILS::UnMount_Flash(); - UTILS::EffacePage(2, 31, 1); - //Enregistrement position des servos sans mettre en sécu + uint64_t Pos_P = Servo_Poumon.getPulses(); UTILS::Write(VOLET_POUMON_ADDR, Pos_P); DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", (int) Pos_P); @@ -277,70 +268,54 @@ uint64_t Pos_F = Servo_Fuite.getPulses(); UTILS::Write(VOLET_FUITE_ADDR, Pos_F); DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", (int) Pos_F); - - /* - __disable_irq(); - - thread_Secu.terminate(); - - wait(300); - - thread_Head.terminate(); - - wait(300); - - thread_Volets_POUMON.terminate(); - - wait(300); - - thread_Volets_FUITE.terminate(); - - wait(300); - - //ejection de la flash pour pas crasher le system de fichiers - UTILS::UnMount_Flash(); - */ + + //Mise en veille de l'IHM + Commande_IHM = 1; + IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM); + FLAG_DISPLAY = false; + Commande_IHM = 0; + //Mise en veille + DEBUG(" Mise en veille...\r\n"); + //wait(1); Au_Dodo(); } -void FLASH_set_boot_bank(int bank) +void PILES_unpluged() { - //HAL_DeInit(); - FLASH_OBProgramInitTypeDef OBInit; - /* Set BFB2 bit to enable boot from Flash Bank2 */ - /* Allow Access to the Flash control registers and user Flash. */ - HAL_FLASH_Unlock(); - /* Clear OPTVERR bit set on virgin samples. */ - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR); - /* Allow Access to the option bytes sector. */ - HAL_FLASH_OB_Unlock(); - /* Get the Dual boot configuration status. */ - HAL_FLASHEx_OBGetConfig(&OBInit); + DEBUG(" Les piles ont été débranchées.\n"); + + buzzer.beep(1000,0.3); + wait_ms(500); + buzzer.beep(1000,0.3); wait(1); - /* Enable/Disable dual boot feature */ - OBInit.OptionType = OPTIONBYTE_USER; - OBInit.USERType = OB_USER_BFB2; - switch (bank) { - case 1: - OBInit.USERConfig = OB_BFB2_DISABLE; - break; - case 2: - OBInit.USERConfig = OB_BFB2_ENABLE; - break; + + //Arrêt des enregistrements + FLAG_REC = false; + + UTILS::UnMount_Flash(); + + //Enregistrement position des servos sans mettre en sécu + UTILS::EffacePage(2, 31, 1); + + uint64_t Pos_P = Servo_Poumon.getPulses(); + UTILS::Write(VOLET_POUMON_ADDR, Pos_P); + DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", (int) Pos_P); - } - HAL_FLASHEx_OBProgram (&OBInit); - wait(1); - if(HAL_FLASHEx_OBProgram (&OBInit) != HAL_OK) { - DEBUG(" Impossible de changer BFB2.\n"); - } else { - DEBUG(" BFB2 a été changé.\n"); - } - - HAL_FLASH_OB_Launch(); - HAL_FLASH_OB_Lock(); - DEBUG(" Fin routine BFB2.\n"); + uint64_t Pos_F = Servo_Fuite.getPulses(); + UTILS::Write(VOLET_FUITE_ADDR, Pos_F); + DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", (int) Pos_F); + + //Mise en veille de l'IHM + Commande_IHM = 1; + IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM); + FLAG_DISPLAY = false; + Commande_IHM = 0; + + //Mise en veille + DEBUG(" Mise en veille...\r\n"); + //wait(1); + Au_Dodo(); } void Affichage() @@ -606,18 +581,10 @@ if (0 == strcmp(com, "secu")) { Mode_SECU(); } else if (0 == strcmp(com, "PING")) { - /*FLAG_PID = 0; - FLAG_AFF = false; - FLAG_WINDEV = false; - control_Servo.setMode(MANUAL_MODE); Commande_IHM = 1; IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM); FLAG_DISPLAY = false; - Commande_IHM = 0; - wait(300); - Au_Dodo(); - */ - E3V = 0; + Commande_IHM = 0; } else if (0 == strcmp(com, "ARNSRS_ID")) { OUTPUT(" Changement de l'ID de l'appareil pour le N°: %s\r\n", numb); //UTILS::Store_A_Val(atoi(numb), "ARNSRS_ID"); @@ -717,14 +684,14 @@ char filename[20]; UTILS::Get_File_Size(&serialMonit, numb); } else if (0 == strcmp(com, "calib_p")) { + volet_poumon_Position = 0; + Servo_Poumon.reset(); Consigne_poumon = HOME_SERVO_POUMON; - volet_poumon_Position = HOME_SERVO_POUMON; - Servo_Poumon.reset(); OUTPUT(" Volet poumon Calibré.\r\n"); } else if (0 == strcmp(com, "calib_f")) { + volet_fuite_Position = 0; + Servo_Fuite.reset(); Consigne_fuite = HOME_SERVO_FUITE; - volet_fuite_Position = HOME_SERVO_FUITE; - Servo_Fuite.reset(); OUTPUT(" Volet fuite Calibré.\r\n"); } else if (0 == strcmp(com, "sleep")) { Stop_Sequence(); @@ -774,8 +741,8 @@ FLAG_REC = false; Mode_SECU(); UTILS::UnMount_Flash(); - UTILS::EffacePage(2, 30, 1); - UTILS::Write(ID_ARNSRS_ADDR, (uint64_t) 11111); + UTILS::EffacePage(2, 29, 1); + UTILS::Write(DFU_ADDR, 0xDEADBEEF); wait(1); NVIC_SystemReset(); } else if (0 == strcmp(com, "PID")) { @@ -843,12 +810,10 @@ } - int main() { HAL_Init(); - __HAL_RCC_PWR_CLK_ENABLE(); HAL_PWR_EnableBkUpAccess(); @@ -858,7 +823,7 @@ E3V = 1; if (PIN_V_USB_DIGI) flag_USB = true; - if (PIN_V_PILE_DIGI) flag_Pile = true; + if (PIN_V_PILES_DIGI) flag_Piles = true; UTILS::PVD_Config(); @@ -960,6 +925,8 @@ OTU_Ticker.attach(&Calcul_OTU, 60); vusb_off_on.fall(&USB_unpluged); + + vpiles_off_on.fall(&PILES_unpluged); buzzer.beep(1000,0.3); wait_ms(500);