diff --git a/LLDrivers/inc/stm32f1xx_ll_adc.h b/LLDrivers/inc/stm32f1xx_ll_adc.h
index b8cd276..0c0304a 100644
--- a/LLDrivers/inc/stm32f1xx_ll_adc.h
+++ b/LLDrivers/inc/stm32f1xx_ll_adc.h
@@ -3539,8 +3539,7 @@ __STATIC_INLINE uint32_t LL_ADC_INJ_ReadConversionData32(ADC_TypeDef *ADCx, uint
__STATIC_INLINE uint16_t LL_ADC_INJ_ReadConversionData12(ADC_TypeDef *ADCx, uint32_t Rank)
{
register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, __ADC_MASK_SHIFT(Rank, ADC_INJ_JDRX_REGOFFSET_MASK));
-
- return (uint16_t)(READ_BIT(*preg,
+ return (uint16_t)(READ_BIT(*preg,
ADC_JDR1_JDATA)
);
}
@@ -3581,8 +3580,7 @@ __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_JEOS(ADC_TypeDef *ADCx)
/* end of unitary conversion. */
/* Flag noted as "JEOC" is corresponding to flag "JEOS" */
/* in other STM32 families). */
- return (READ_BIT(ADCx->SR, LL_ADC_FLAG_JEOS) == (LL_ADC_FLAG_JEOS));
-}
+ return (READ_BIT(ADCx->SR, LL_ADC_FLAG_JEOS) == (LL_ADC_FLAG_JEOS));}
/**
* @brief Get flag ADC analog watchdog 1 flag
diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx
index ecc3a2c..0893976 100644
--- a/MDK-ARM/Project.uvoptx
+++ b/MDK-ARM/Project.uvoptx
@@ -305,7 +305,7 @@
0
DLGDARM
- (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=120,153,415,450,0)(120=-1,-1,-1,-1,0)(121=-1,-1,-1,-1,0)(122=896,89,1317,516,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=248,17,842,768,0)(131=521,17,1115,768,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=251,288,699,702,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=229,0,832,751,0)(151=-1,-1,-1,-1,0)
+ (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=120,153,415,450,0)(120=-1,-1,-1,-1,0)(121=-1,-1,-1,-1,0)(122=896,89,1317,516,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=248,17,842,768,0)(131=521,17,1115,768,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=251,288,699,702,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=60,0,663,751,0)(151=-1,-1,-1,-1,0)
0
@@ -344,7 +344,7 @@
0
99
1
- 134218720
+ 134218780
0
0
0
@@ -360,27 +360,22 @@
0
1
- Chrono_Time
+ USART1
1
1
- USART1
+ res10,0x0A
2
1
- res,0x0A
+ level,0x0A
3
1
- res10,0x0A
-
-
- 4
- 1
- res12,0x0A
+ danger,0x0A
@@ -391,7 +386,7 @@
1
1
0
- 0
+ 1
0
0
1
@@ -429,7 +424,7 @@
0
((TIM_TypeDef *)(0x40000000UL + 0x00000000UL))->CNT
- FF0000000000000000000000000000000000594000000000000000000000000000000000282854494D5F54797065446566202A292830783430303030303030554C202B2030783030303030303030554C29292D3E434E5400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000001000000000000000000F03F1000000000000000000000000000000000000000B6020008
+ FF0000000000000000000000000000000000594000000000000000000000000000000000282854494D5F54797065446566202A292830783430303030303030554C202B2030783030303030303030554C29292D3E434E5400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000001000000000000000000F03F1900000000000000000000000000000000000000B6020008
@@ -660,6 +655,30 @@
0
0
+
+ 2
+ 18
+ 1
+ 0
+ 0
+ 0
+ ..\Src\Securite.c
+ Securite.c
+ 0
+ 0
+
+
+ 2
+ 19
+ 5
+ 0
+ 0
+ 0
+ ..\Src\Securite.h
+ Securite.h
+ 0
+ 0
+
@@ -670,7 +689,7 @@
0
3
- 18
+ 20
1
0
0
@@ -682,7 +701,7 @@
3
- 19
+ 21
1
0
0
@@ -710,7 +729,7 @@
0
5
- 20
+ 22
1
0
0
@@ -730,7 +749,7 @@
0
6
- 21
+ 23
2
0
0
diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx
index b7bdda7..a6279eb 100644
--- a/MDK-ARM/Project.uvprojx
+++ b/MDK-ARM/Project.uvprojx
@@ -472,6 +472,16 @@
1
..\Src\AntiChavirement.c
+
+ Securite.c
+ 1
+ ..\Src\Securite.c
+
+
+ Securite.h
+ 5
+ ..\Src\Securite.h
+
@@ -983,6 +993,16 @@
1
..\Src\AntiChavirement.c
+
+ Securite.c
+ 1
+ ..\Src\Securite.c
+
+
+ Securite.h
+ 5
+ ..\Src\Securite.h
+
diff --git a/Src/AntiChavirement.c b/Src/AntiChavirement.c
index c69e161..b0ef40a 100644
--- a/Src/AntiChavirement.c
+++ b/Src/AntiChavirement.c
@@ -61,59 +61,3 @@ void ConfAntiChavirement(){
//Activation de l'ADC (???)
LL_ADC_Enable(ADC1);
}
-
-
-void SystemClock_Config(void)
-{
- /* Set FLASH latency */
- LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
-
- /* Enable HSE oscillator */
- // ********* Commenter la ligne ci-dessous pour MCBSTM32 *****************
- // ********* Conserver la ligne si Nucléo*********************************
- LL_RCC_HSE_EnableBypass();
- LL_RCC_HSE_Enable();
- while(LL_RCC_HSE_IsReady() != 1)
- {
- };
-
- /* Main PLL configuration and activation */
- LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9);
-
- LL_RCC_PLL_Enable();
- while(LL_RCC_PLL_IsReady() != 1)
- {
- };
-
- /* Sysclk activation on the main PLL */
- LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
- LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
- while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
- {
- };
-
- /* Set APB1 & APB2 prescaler*/
- LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
- LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
-
- /* Set systick to 1ms in using frequency set to 72MHz */
- LL_Init1msTick(72000000); // utile lorsqu'on utilise la fonction LL_mDelay
-
- /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
- LL_SetSystemCoreClock(72000000);
-}
-int res10;
-int res12;
-
-int main(){
- SystemClock_Config();
-
- ConfAntiChavirement();
-
- while(1){
- LL_ADC_INJ_StartConversionSWStart(ADC1);
- while(!LL_ADC_IsActiveFlag_JEOS(ADC1)){}
- res10 = LL_ADC_INJ_ReadConversionData12(ADC1,LL_ADC_INJ_RANK_1);
- res12 = LL_ADC_INJ_ReadConversionData12(ADC1,LL_ADC_INJ_RANK_2);
- }
-}
diff --git a/Src/Securite.c b/Src/Securite.c
new file mode 100644
index 0000000..6ec87c4
--- /dev/null
+++ b/Src/Securite.c
@@ -0,0 +1,225 @@
+#include "Securite.h"
+
+
+// Seuil represente la valeur (en %) en dessous de laquelle le niveau de batterie est consideree faible
+#define Seuil (20)
+
+// Seuil represente la valeur de l'angle au dessus de laquelle le chavirement est trop prononcé
+#define SeuilAngle (40)
+
+
+int drapeauRecupSecurite = 0; // Flag qui est mis à 1 toute les 10 sec pour recuperer niveau batterie/rouli et envoi régulier
+int drapeauDangerBatterie = 0; //Flag qui est mis à 1 toute les 10 sec si batterie faible --> envoie message alarme
+int drapeauDangerRouli = 0; //Flag qui est mis à 1 toute les 10 sec si rouli pas bon --> envoie message alarme
+
+
+void ConfSecurite(){
+ //On est pas sûrs pour ADC 1, voir datasheet page 28
+
+ //Faire les horloges
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC);
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
+
+
+ //On configure les PINS
+ LL_GPIO_SetPinMode(GPIOC,LL_GPIO_PIN_0,LL_GPIO_MODE_ANALOG);
+ LL_GPIO_SetPinMode(GPIOC,LL_GPIO_PIN_2,LL_GPIO_MODE_ANALOG);
+
+
+ //ON se met en mode scan enable pour pouvoir à chaque trigger aller chercher sur plusieur voies.
+ LL_ADC_SetSequencersScanMode(ADC1,LL_ADC_SEQ_SCAN_ENABLE);
+
+ //Permet de faire en sorte d'aller chercher 2 voies (2 rangs) à chaque trigger
+ LL_ADC_INJ_SetSequencerLength(ADC1,LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS);
+
+ //Permet de ne pas avoir d'intérruption dans le scan
+ LL_ADC_INJ_SetSequencerDiscont(ADC1,LL_ADC_INJ_SEQ_DISCONT_DISABLE);
+
+ //A chaque trigger, on va donc avoir voies de rang 1 puis de rang 2 de scannées
+
+ //On met le rang 1 pour la voie 10 (accéléro)
+ LL_ADC_INJ_SetSequencerRanks(ADC1,LL_ADC_INJ_RANK_1,LL_ADC_CHANNEL_10);
+
+ //On met rang 2 pour la voie 12 (surveillance batterie)
+ LL_ADC_INJ_SetSequencerRanks(ADC1,LL_ADC_INJ_RANK_2,LL_ADC_CHANNEL_12);
+
+ //Permet d'avoirdes registres indépendants pour chaque voie (chaque rangs en fait, au max 4 + 1 pour les regular)
+ LL_ADC_INJ_SetTrigAuto(ADC1,LL_ADC_INJ_TRIG_INDEPENDENT);
+
+
+ //Sampling time voie 10 et 12, à changer peut-être
+ LL_ADC_SetChannelSamplingTime(ADC1,LL_ADC_CHANNEL_10,LL_ADC_SAMPLINGTIME_28CYCLES_5);
+
+ LL_ADC_SetChannelSamplingTime(ADC1,LL_ADC_CHANNEL_12,LL_ADC_SAMPLINGTIME_28CYCLES_5);
+
+
+
+ LL_ADC_INJ_SetTriggerSource(ADC1,LL_ADC_INJ_TRIG_SOFTWARE); //permet d'enable le trigger de l'adc par le software
+
+
+
+ LL_ADC_StartCalibration(ADC1);
+
+
+ //Tant que calibration par terminée on enable pas
+ while(LL_ADC_IsCalibrationOnGoing(ADC1)){
+ }
+
+ //Activation de l'ADC (???)
+ LL_ADC_Enable(ADC1);
+}
+
+/**
+ * @brief Recuperer le niveau de batterie
+ * @note ADC1 -> Channel 12 (Rang 2)
+ * @param None
+ * @retval niveau de batterie en pourcentage
+ */
+int RecupNiveauBatterie(void){
+ // Lancement de la conversion
+ LL_ADC_INJ_StartConversionSWStart(ADC1);
+ // Attente de la fin de conversion
+ while(!LL_ADC_IsActiveFlag_JEOS(ADC1)){}
+ // R?cuperation de la valeur apres conversion
+ int NiveauBatterie = LL_ADC_INJ_ReadConversionData12(ADC1,LL_ADC_INJ_RANK_2);
+ // Valeur code sur 12 bits : 0 a 4095 ; on veut Niveau de batterie en pourcentage
+ return NiveauBatterie * 100 / 4095 ;
+}
+
+
+/**
+ * @brief Met le flag de dangerBatterie à 1 si batterie faible.
+ * @note
+ * @param un entier representant le niveau de batterie en pourcentage
+ * @retval
+ */
+void CalculDangerNiveauBatterie(int niveau){
+ if ( niveau <= Seuil)
+ {
+ drapeauDangerBatterie = 1;
+ }
+ else
+ {
+ drapeauDangerBatterie = 0 ;
+ }
+}
+
+
+ /*
+ * @brief Mets le flag drapeauDangerRouli a 1 si l angle de rouli est mauvais
+ * @note Si le voilier prend un angle de roulis supe´rieur a` 40° -> MSG de danger + voiles sont imme´diatement rela^che´es
+ * @param un entier representant l angle de rouli
+ * @retval NONE
+ */
+void CalculerDangerChavirement(int gamma){
+ if ( gamma >= SeuilAngle)
+ {
+ drapeauDangerRouli = 1;
+ TendreVoile(90); //On lache les voiles si danger de chavirement
+ }
+ else
+ {
+ drapeauDangerRouli = 0 ;
+ }
+}
+
+/*
+ * @brief Recuperer l angle de rouli
+ * @note ADC1 -> Channel 10 (Rang 1)
+ * @param None
+ * @retval angle de rouli
+ */
+int RecupRouli(){
+ // Lancement de la conversion
+ LL_ADC_INJ_StartConversionSWStart(ADC1);
+ // Attente de la fin de conversion
+ while(!LL_ADC_IsActiveFlag_JEOS(ADC1)){}
+ // R?cuperation de la valeur apres conversion
+ int NiveauChavirement = LL_ADC_INJ_ReadConversionData12(ADC1,LL_ADC_INJ_RANK_1);
+ return 0; // Trouver le calcul de l'angle
+}
+
+void SystemClock_Config(void)
+{
+ /* Set FLASH latency */
+ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
+
+ /* Enable HSE oscillator */
+ // ********* Commenter la ligne ci-dessous pour MCBSTM32 *****************
+ // ********* Conserver la ligne si Nucléo*********************************
+ LL_RCC_HSE_EnableBypass();
+ LL_RCC_HSE_Enable();
+ while(LL_RCC_HSE_IsReady() != 1)
+ {
+ };
+
+ /* Main PLL configuration and activation */
+ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9);
+
+ LL_RCC_PLL_Enable();
+ while(LL_RCC_PLL_IsReady() != 1)
+ {
+ };
+
+ /* Sysclk activation on the main PLL */
+ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
+ LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
+ while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
+ {
+ };
+
+ /* Set APB1 & APB2 prescaler*/
+ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
+ LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
+
+ /* Set systick to 1ms in using frequency set to 72MHz */
+ LL_Init1msTick(72000000); // utile lorsqu'on utilise la fonction LL_mDelay
+
+ /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
+ LL_SetSystemCoreClock(72000000);
+}
+
+int res10;
+int level ;
+int danger;
+int rouli;
+
+//Dans le main voilier.c en theorie
+int main(){
+ SystemClock_Config();
+ ConfSecurite();
+
+
+ while(1){
+
+ /* Envoi message toute les 3 sec sur l'Allure et la tension voile */
+ if (drapeauTransimission){
+ //Envoi message régulier
+ drapeauTransmission = 0;
+ }
+
+ /* Recuperation toute les 10 sec niveau batterie et angle chavirement, puis calcul des dangers */
+ if (drapeauRecupSecurite){
+ level = RecupNiveauBatterie();
+ CalculDangerNiveauBatterie( level );
+ rouli = RecupRouli()
+ CalculerDanger(rouli);
+ drapeauRecupSecurite = 0;
+ }
+
+ /*Si batterie faible après recup (toute les 10 sec), envoi alerte batterie faible */
+ if (drapeauDangerBatterie){
+ char * msgBatterie = "Batterie faible";
+ EnvoiExcpetionnel(msgBatterie);
+ drapeauDangerBatterie = 0;
+ }
+
+ /*Si angle chavirement pas bon après recup (toute les 10 sec), envoi alerte chavirement */
+ if (drapeauDangerRouli){
+ char * msgRouli = "Bateau chavire !";
+ EnvoiExcpetionnel(msgRouli);
+ drapeauDangerRouli = 0;
+ }
+
+ }
+}
diff --git a/Src/Securite.h b/Src/Securite.h
new file mode 100644
index 0000000..6ab7aa0
--- /dev/null
+++ b/Src/Securite.h
@@ -0,0 +1,55 @@
+#ifndef ANTI_CHAVIREMENT_H
+#define ANTI_CHAVIREMENT_H
+
+#include "stm32f103xb.h"
+#include "stm32f1xx_ll_adc.h"
+#include "stm32f1xx_ll_gpio.h"
+#include "stm32f1xx_ll_bus.h"
+#include "stm32f1xx_ll_utils.h" // utile dans la fonction SystemClock_Config
+#include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config
+#include "stm32f1xx_ll_rcc.h" // utile dans la fonction SystemClock_Config
+
+
+
+/**
+ * @brief
+ * @note
+ * @param
+ * @retval
+ */
+void CalculerDanger(int gamma);
+
+/**
+ * @brief
+ * @note
+ * @param
+ * @retval
+ */
+int RecupRouli();
+
+
+/**
+ * @brief
+ * @note
+ * @param
+ * @retval
+ */
+int RecupNiveauBatterie(void);
+
+/**
+ * @brief
+ * @note A lancer en 1er avant tout
+ * @param
+ * @retval
+ */
+void confSecurite(void);
+
+/**
+ * @brief
+ * @note
+ * @param
+ * @retval
+ */
+void CalculDangerNiveauBatterie(int niveau );
+
+#endif