Module sécurité fait (presque fini, manque les calculs rouli)
This commit is contained in:
parent
ac6130ec3a
commit
643c601172
6 changed files with 338 additions and 77 deletions
|
@ -3539,7 +3539,6 @@ __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,
|
||||
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
|
||||
|
|
|
@ -305,7 +305,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGDARM</Key>
|
||||
<Name>(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)</Name>
|
||||
<Name>(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)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -344,7 +344,7 @@
|
|||
<Type>0</Type>
|
||||
<LineNumber>99</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134218720</Address>
|
||||
<Address>134218780</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
|
@ -360,27 +360,22 @@
|
|||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>Chrono_Time</ItemText>
|
||||
<ItemText>USART1</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>1</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>USART1</ItemText>
|
||||
<ItemText>res10,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>2</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>res,0x0A</ItemText>
|
||||
<ItemText>level,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>3</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>res10,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>res12,0x0A</ItemText>
|
||||
<ItemText>danger,0x0A</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<Tracepoint>
|
||||
|
@ -391,7 +386,7 @@
|
|||
<periodic>1</periodic>
|
||||
<aLwin>1</aLwin>
|
||||
<aCover>0</aCover>
|
||||
<aSer1>0</aSer1>
|
||||
<aSer1>1</aSer1>
|
||||
<aSer2>0</aSer2>
|
||||
<aPa>0</aPa>
|
||||
<viewmode>1</viewmode>
|
||||
|
@ -429,7 +424,7 @@
|
|||
<Wi>
|
||||
<IntNumber>0</IntNumber>
|
||||
<FirstString>((TIM_TypeDef *)(0x40000000UL + 0x00000000UL))->CNT</FirstString>
|
||||
<SecondString>FF0000000000000000000000000000000000594000000000000000000000000000000000282854494D5F54797065446566202A292830783430303030303030554C202B2030783030303030303030554C29292D3E434E5400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000001000000000000000000F03F1000000000000000000000000000000000000000B6020008</SecondString>
|
||||
<SecondString>FF0000000000000000000000000000000000594000000000000000000000000000000000282854494D5F54797065446566202A292830783430303030303030554C202B2030783030303030303030554C29292D3E434E5400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000001000000000000000000F03F1900000000000000000000000000000000000000B6020008</SecondString>
|
||||
</Wi>
|
||||
</LogicAnalyzers>
|
||||
<DebugDescription>
|
||||
|
@ -660,6 +655,30 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Src\Securite.c</PathWithFileName>
|
||||
<FilenameWithoutPath>Securite.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>19</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Src\Securite.h</PathWithFileName>
|
||||
<FilenameWithoutPath>Securite.h</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
|
@ -670,7 +689,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileNumber>20</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -682,7 +701,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>19</FileNumber>
|
||||
<FileNumber>21</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -710,7 +729,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>20</FileNumber>
|
||||
<FileNumber>22</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -730,7 +749,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>21</FileNumber>
|
||||
<FileNumber>23</FileNumber>
|
||||
<FileType>2</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
|
|
@ -472,6 +472,16 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Src\AntiChavirement.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Securite.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Src\Securite.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Securite.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Src\Securite.h</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -983,6 +993,16 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Src\AntiChavirement.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Securite.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Src\Securite.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Securite.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Src\Securite.h</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
225
Src/Securite.c
Normal file
225
Src/Securite.c
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
55
Src/Securite.h
Normal file
55
Src/Securite.h
Normal file
|
@ -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
|
Loading…
Reference in a new issue