From 89850bfc2f6bf437076e24ad581b36f963c64fad Mon Sep 17 00:00:00 2001 From: Cavailles Kevin Date: Sat, 14 Nov 2020 16:13:49 +0100 Subject: [PATCH 01/14] =?UTF-8?q?main=20commenc=C3=A9=20+=20emetteur=5Frf?= =?UTF-8?q?=20chang=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- keil_project/Services/emetteur_rf.c | 9 +++-- keil_project/Services/emetteur_rf.h | 2 +- keil_project/Src/main.c | 61 ++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/keil_project/Services/emetteur_rf.c b/keil_project/Services/emetteur_rf.c index 31e5a1c..f796547 100644 --- a/keil_project/Services/emetteur_rf.c +++ b/keil_project/Services/emetteur_rf.c @@ -42,11 +42,14 @@ void emetteur_rf_init(void){ LL_USART_SetBaudRate(uart_port, periph_speed, baudrate); */} -void emetteur_send_bytes(USART_TypeDef * uart_port,char* buf, int len){ + + + +void emetteur_send_bytes(char* buf, int len){ for(int i = 0; i < len; i++){ LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_11); - LL_USART_TransmitData8(uart_port, buf[i]); - while(!LL_USART_IsActiveFlag_TXE(uart_port)); + LL_USART_TransmitData8(USART1, buf[i]); + while(!LL_USART_IsActiveFlag_TXE(USART1)); LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_11); } } diff --git a/keil_project/Services/emetteur_rf.h b/keil_project/Services/emetteur_rf.h index 295fe4b..7a4592d 100644 --- a/keil_project/Services/emetteur_rf.h +++ b/keil_project/Services/emetteur_rf.h @@ -8,7 +8,7 @@ #include "stm32f1xx_ll_gpio.h" void emetteur_rf_init(void); -void emetteur_send_bytes(USART_TypeDef * uart_port,char* buf, int len); +void emetteur_send_bytes(char* buf, int len); diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index 46d750c..01bbc70 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -21,6 +21,7 @@ #include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config #include "stm32f1xx_ll_bus.h" + #include "RFInput.h" #include "IncrEncoder.h" #include "DcMotor.h" @@ -28,6 +29,9 @@ #include "alimentation.h" #include "accelerometer.h" +#define CONTROL_LOOP_PERIOD 250 +#define MSG_TRANSFER_PERIOD 3000 + void SystemClock_Config(void); /* Private functions ---------------------------------------------------------*/ @@ -38,18 +42,18 @@ void SystemClock_Config(void); * @retval None */ -int val = 0; -int val2 = 0; + int counter = 0; -float level; -int level_enough; -double xx,yy; -int bon; +int battery_level_good = 0; +int angle_roulis_good = 0; +int angle_sail = 0; +int RF_Input_Duty = 0; +int TX_Flag = 0, CONTROL_LOOP_Flag = 0; + int main(void) { /* Configure the system clock to 72 MHz */ - SystemClock_Config(); - + SystemClock_Config(); //alimentation_init(); RF_INPUT_Init(); DC_MOTOR_Init(); @@ -59,20 +63,39 @@ int main(void) /* Infinite loop */ while (1) { - LL_mDelay(100); - //counter = (counter + 1) % 100; - //DC_MOTOR_SetSpeed(counter); - //val = RF_INPUT_GetPeriodUs(); - //val2 = RF_INPUT_GetDutyTimeUs(); - //SAIL_SetAngle(counter); - //level = get_battery_level(); - //level_enough = is_level_enough(); - xx = accelero_get_x(); - //yy = accelero_get_y(); - //bon = accelero_angle_bon(); + if(CONTROL_LOOP_Flag){ + battery_level_good = is_level_enough(); + angle_roulis_good = accelero_angle_bon(); + + if(!angle_roulis_good){ + SAIL_SetAngle(90); + DC_MOTOR_SetSpeed(0); + }else{ + angle_sail = INCR_ENCODER_GetAngle(); + SAIL_SetAngle(angle_sail/2); + RF_Input_Duty = RF_INPUT_GetDutyTimeRelative(); + DC_MOTOR_SetSpeed(RF_Input_Duty); + } + + CONTROL_LOOP_Flag = 0; + } + if(TX_Flag){ + + TX_Flag = 0; + } } } +void SysTick_Handler(void) +{ + if(counter % CONTROL_LOOP_PERIOD == 0){ + CONTROL_LOOP_Flag = 1; + } + if(counter % MSG_TRANSFER_PERIOD == 0){ + TX_Flag = 1; + } + counter = (counter+1) % (CONTROL_LOOP_PERIOD*MSG_TRANSFER_PERIOD) ; +} From 83cccf56689ea02b4c4f82b6f6b15e9b5025bd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sat, 14 Nov 2020 16:20:20 +0100 Subject: [PATCH 02/14] emmeteur send bytes foncotion --- keil_project/Services/emetteur_rf.c | 27 +++++++++++++++------------ keil_project/Services/emetteur_rf.h | 3 ++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/keil_project/Services/emetteur_rf.c b/keil_project/Services/emetteur_rf.c index 31e5a1c..db7b130 100644 --- a/keil_project/Services/emetteur_rf.c +++ b/keil_project/Services/emetteur_rf.c @@ -1,4 +1,7 @@ #include "emetteur_rf.h" +#include + +char buf[100]; void emetteur_rf_init(void){ @@ -34,19 +37,19 @@ void emetteur_rf_init(void){ LL_USART_Init(USART1,&My_LL_Usart_Init_Struct); LL_USART_Enable(USART1); - /*int periph_speed; - if (uart_port==USART1) periph_speed = 36000000; - if (uart_port==USART2) periph_speed = 72000000; - if (uart_port==USART3) periph_speed = 72000000; + } - LL_USART_SetBaudRate(uart_port, periph_speed, baudrate); -*/} - -void emetteur_send_bytes(USART_TypeDef * uart_port,char* buf, int len){ +void emetteur_send_bytes(char* buf, int len){ + + LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_11); for(int i = 0; i < len; i++){ - LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_11); - LL_USART_TransmitData8(uart_port, buf[i]); - while(!LL_USART_IsActiveFlag_TXE(uart_port)); - LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_11); + LL_USART_TransmitData8(USART1, buf[i]); + while(!LL_USART_IsActiveFlag_TXE(USART1)); } + LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_11); +} + +void emetteur_send_message(int rouli_bon, int alimentation_bon, float angle_voile){ + int len = sprintf(buf, "Alim bon: %d, Rouli bon: %d, Angle de voile: %2f\r\n", alimentation_bon, rouli_bon, angle_voile); + emetteur_send_bytes(buf, len); } diff --git a/keil_project/Services/emetteur_rf.h b/keil_project/Services/emetteur_rf.h index 787b8fb..c9c47b8 100644 --- a/keil_project/Services/emetteur_rf.h +++ b/keil_project/Services/emetteur_rf.h @@ -7,7 +7,8 @@ #include "stm32f1xx_ll_gpio.h" void emetteur_rf_init(void); -void emetteur_send_bytes(USART_TypeDef * uart_port,char* buf, int len); +void emetteur_send_bytes(char* buf, int len); +void emetteur_send_message(int rouli_bon, int alimentation_bon, float angle_voile); From 1b68b7f6d063857080115578072d4e233d9cbef5 Mon Sep 17 00:00:00 2001 From: Cavailles Kevin Date: Sat, 14 Nov 2020 16:31:08 +0100 Subject: [PATCH 03/14] main fini --- keil_project/Src/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index 01bbc70..413e264 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -28,6 +28,7 @@ #include "Sail.h" #include "alimentation.h" #include "accelerometer.h" +#include "emetteur_rf.h" #define CONTROL_LOOP_PERIOD 250 #define MSG_TRANSFER_PERIOD 3000 @@ -76,11 +77,10 @@ int main(void) RF_Input_Duty = RF_INPUT_GetDutyTimeRelative(); DC_MOTOR_SetSpeed(RF_Input_Duty); } - CONTROL_LOOP_Flag = 0; } if(TX_Flag){ - + emetteur_send_message(angle_roulis_good, battery_level_good, angle_sail); TX_Flag = 0; } } @@ -88,6 +88,7 @@ int main(void) void SysTick_Handler(void) { + if(counter % CONTROL_LOOP_PERIOD == 0){ CONTROL_LOOP_Flag = 1; } From b8ea95d7906f7b99746165d37c22b41f20836a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sat, 14 Nov 2020 16:29:49 +0100 Subject: [PATCH 04/14] incr_encoder angle calculation --- keil_project/Services/IncrEncoder.c | 25 ++++++++++++++++++++++--- keil_project/Services/IncrEncoder.h | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/keil_project/Services/IncrEncoder.c b/keil_project/Services/IncrEncoder.c index bc9f795..b9a8b9b 100644 --- a/keil_project/Services/IncrEncoder.c +++ b/keil_project/Services/IncrEncoder.c @@ -1,9 +1,17 @@ +#include +#include + #include "IncrEncoder.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_tim.h" +#define RESOLUTION 1 +#define ANGLE_DEBUT 45 +#define INCR_ENCODER_MID_VALUE 719 + + int index_passed = 0; int counts_per_revolution = 360; @@ -45,9 +53,9 @@ void INCR_ENCODER_Init(void){ encoder_init_struct.IC1Filter = LL_TIM_IC_FILTER_FDIV1 ; encoder_init_struct.IC2Filter = LL_TIM_IC_FILTER_FDIV1 ; - LL_TIM_ENCODER_Init(TIM3, &encoder_init_struct); + LL_TIM_ENCODER_Init(TIM3, &encoder_init_struct); - LL_TIM_EnableCounter(TIM3); + LL_TIM_EnableCounter(TIM3); LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); @@ -78,6 +86,7 @@ void INCR_ENCODER_Init(void){ } void EXTI9_5_IRQHandler(void){ + index_passed = 1; // reset counter = encoder position to 0 position LL_TIM_WriteReg(TIM3,CNT,0); @@ -94,5 +103,15 @@ int INCR_ENCODER_IsAbsolute(void) int INCR_ENCODER_GetAngle(void) { - return LL_TIM_ReadReg(TIM3,CNT); + int counter_value = LL_TIM_ReadReg(TIM3, CNT); + float vabs = abs(counter_value-INCR_ENCODER_MID_VALUE); + float vIEAngleDebut = INCR_ENCODER_MID_VALUE -(ANGLE_DEBUT*4); + float nbIncrements = 90/RESOLUTION; + + if(vabs > vIEAngleDebut) + { + return 0; + }else{ + return 90 - RESOLUTION*floor(vabs/(vIEAngleDebut/nbIncrements) ) ; + } }; diff --git a/keil_project/Services/IncrEncoder.h b/keil_project/Services/IncrEncoder.h index 3640e9f..7767b5e 100644 --- a/keil_project/Services/IncrEncoder.h +++ b/keil_project/Services/IncrEncoder.h @@ -1,5 +1,5 @@ #ifndef INCR_ENCODER -//codé par Kévin Cavailles et Jasper Güldenstein + /** */ void INCR_ENCODER_Init(void); From 65327ef87895217b6f9fa4a52762ca09c1851e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sat, 14 Nov 2020 16:53:25 +0100 Subject: [PATCH 05/14] en attente girouette --- keil_project/Src/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index 413e264..b572cc7 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -51,6 +51,7 @@ int angle_sail = 0; int RF_Input_Duty = 0; int TX_Flag = 0, CONTROL_LOOP_Flag = 0; +char wait_for_girouette[] = "En attente d'initialisation de la girouette\r\n"; int main(void) { /* Configure the system clock to 72 MHz */ @@ -61,6 +62,12 @@ int main(void) SAIL_Init(); accelero_init(); + while(!INCR_ENCODER_IsAbsolute()) + { + emetteur_send_bytes(wait_for_girouette, sizeof(wait_for_girouette)); + LL_mDelay(500); + } + /* Infinite loop */ while (1) { From 86dbc5ff39d2b5d4b3fe65d698fc6f5b943b99f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sat, 14 Nov 2020 16:56:13 +0100 Subject: [PATCH 06/14] add init uart in main --- keil_project/Src/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index b572cc7..ff8a595 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -56,11 +56,12 @@ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); - //alimentation_init(); + alimentation_init(); + accelero_init(); RF_INPUT_Init(); DC_MOTOR_Init(); SAIL_Init(); - accelero_init(); + emetteur_rf_init(); while(!INCR_ENCODER_IsAbsolute()) { From 6a8b0178c53e9012f2f351869373d493d35ce31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sun, 15 Nov 2020 14:46:59 +0100 Subject: [PATCH 07/14] renaming --- keil_project/Services/{emetteur_rf.c => RFOutput.c} | 0 keil_project/Services/{emetteur_rf.h => RFOutput.h} | 0 keil_project/Services/accelerometer.c | 2 +- keil_project/Services/alimentation.c | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename keil_project/Services/{emetteur_rf.c => RFOutput.c} (100%) rename keil_project/Services/{emetteur_rf.h => RFOutput.h} (100%) diff --git a/keil_project/Services/emetteur_rf.c b/keil_project/Services/RFOutput.c similarity index 100% rename from keil_project/Services/emetteur_rf.c rename to keil_project/Services/RFOutput.c diff --git a/keil_project/Services/emetteur_rf.h b/keil_project/Services/RFOutput.h similarity index 100% rename from keil_project/Services/emetteur_rf.h rename to keil_project/Services/RFOutput.h diff --git a/keil_project/Services/accelerometer.c b/keil_project/Services/accelerometer.c index 0e9be97..14141dc 100644 --- a/keil_project/Services/accelerometer.c +++ b/keil_project/Services/accelerometer.c @@ -1,4 +1,4 @@ -#include "accelerometer.h" +#include "Accelerometer.h" double x; double y; double angle; diff --git a/keil_project/Services/alimentation.c b/keil_project/Services/alimentation.c index e54e5df..ad89e86 100644 --- a/keil_project/Services/alimentation.c +++ b/keil_project/Services/alimentation.c @@ -1,4 +1,4 @@ -#include "alimentation.h" +#include "Alimentation.h" void alimentation_init(void){ From 58f3895a6ed52c973471612147cca6f2248f551e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sun, 15 Nov 2020 14:48:36 +0100 Subject: [PATCH 08/14] more renaming --- keil_project/Services/{accelerometer.c => Accelerometer.c} | 0 keil_project/Services/{accelerometer.h => Accelerometer.h} | 0 keil_project/Services/{alimentation.c => Alimentation.c} | 0 keil_project/Services/{alimentation.h => Alimentation.h} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename keil_project/Services/{accelerometer.c => Accelerometer.c} (100%) rename keil_project/Services/{accelerometer.h => Accelerometer.h} (100%) rename keil_project/Services/{alimentation.c => Alimentation.c} (100%) rename keil_project/Services/{alimentation.h => Alimentation.h} (100%) diff --git a/keil_project/Services/accelerometer.c b/keil_project/Services/Accelerometer.c similarity index 100% rename from keil_project/Services/accelerometer.c rename to keil_project/Services/Accelerometer.c diff --git a/keil_project/Services/accelerometer.h b/keil_project/Services/Accelerometer.h similarity index 100% rename from keil_project/Services/accelerometer.h rename to keil_project/Services/Accelerometer.h diff --git a/keil_project/Services/alimentation.c b/keil_project/Services/Alimentation.c similarity index 100% rename from keil_project/Services/alimentation.c rename to keil_project/Services/Alimentation.c diff --git a/keil_project/Services/alimentation.h b/keil_project/Services/Alimentation.h similarity index 100% rename from keil_project/Services/alimentation.h rename to keil_project/Services/Alimentation.h From 6c92b1ca1aa2b7a322f4da1ef8ffc2e64f49c065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sun, 15 Nov 2020 14:49:30 +0100 Subject: [PATCH 09/14] project file after renaming --- keil_project/MDK-ARM/Project.uvoptx | 126 +++++++++++---------------- keil_project/MDK-ARM/Project.uvprojx | 105 +++++++++++----------- 2 files changed, 100 insertions(+), 131 deletions(-) diff --git a/keil_project/MDK-ARM/Project.uvoptx b/keil_project/MDK-ARM/Project.uvoptx index fd59681..58b97a9 100644 --- a/keil_project/MDK-ARM/Project.uvoptx +++ b/keil_project/MDK-ARM/Project.uvoptx @@ -432,7 +432,7 @@ - 3 + 2 0 46 1 @@ -568,42 +568,6 @@ 2 2 1 - 1 - 0 - 0 - ..\Services\Chrono.c - Chrono.c - 0 - 0 - - - 2 - 3 - 1 - 0 - 0 - 0 - ..\Services\alimentation.c - alimentation.c - 0 - 0 - - - 2 - 4 - 1 - 0 - 0 - 0 - ..\Services\accelerometer.c - accelerometer.c - 0 - 0 - - - 2 - 5 - 1 0 0 0 @@ -614,19 +578,7 @@ 2 - 6 - 1 - 0 - 0 - 0 - ..\Services\emetteur_rf.c - emetteur_rf.c - 0 - 0 - - - 2 - 7 + 3 1 0 0 @@ -638,7 +590,7 @@ 2 - 8 + 4 1 0 0 @@ -650,7 +602,7 @@ 2 - 9 + 5 1 0 0 @@ -662,7 +614,7 @@ 2 - 10 + 6 1 0 0 @@ -672,6 +624,42 @@ 0 0 + + 2 + 7 + 1 + 0 + 0 + 0 + ..\Services\Accelerometer.c + Accelerometer.c + 0 + 0 + + + 2 + 8 + 1 + 0 + 0 + 0 + ..\Services\Alimentation.c + Alimentation.c + 0 + 0 + + + 2 + 9 + 1 + 0 + 0 + 0 + ..\Services\RFOutput.c + RFOutput.c + 0 + 0 + @@ -680,18 +668,6 @@ 0 0 0 - - 3 - 11 - 1 - 0 - 0 - 0 - ..\MyDrivers\MyTimer.c - MyTimer.c - 0 - 0 - @@ -702,7 +678,7 @@ 0 4 - 12 + 10 1 0 0 @@ -714,7 +690,7 @@ 4 - 13 + 11 1 0 0 @@ -726,7 +702,7 @@ 4 - 14 + 12 1 0 0 @@ -738,7 +714,7 @@ 4 - 15 + 13 1 0 0 @@ -750,7 +726,7 @@ 4 - 16 + 14 1 0 0 @@ -762,7 +738,7 @@ 4 - 17 + 15 1 0 0 @@ -774,7 +750,7 @@ 4 - 18 + 16 1 0 0 @@ -794,7 +770,7 @@ 0 5 - 19 + 17 5 0 0 @@ -814,7 +790,7 @@ 0 6 - 20 + 18 1 0 0 @@ -834,7 +810,7 @@ 0 7 - 21 + 19 2 0 0 diff --git a/keil_project/MDK-ARM/Project.uvprojx b/keil_project/MDK-ARM/Project.uvprojx index 4c9116f..aea7bbf 100644 --- a/keil_project/MDK-ARM/Project.uvprojx +++ b/keil_project/MDK-ARM/Project.uvprojx @@ -185,6 +185,7 @@ 0 0 0 + 0 0 0 8 @@ -351,7 +352,7 @@ 0 0 0 - 0 + 4 @@ -392,31 +393,11 @@ User Services - - Chrono.c - 1 - ..\Services\Chrono.c - - - alimentation.c - 1 - ..\Services\alimentation.c - - - accelerometer.c - 1 - ..\Services\accelerometer.c - DcMotor.c 1 ..\Services\DcMotor.c - - emetteur_rf.c - 1 - ..\Services\emetteur_rf.c - IncrEncoder.c 1 @@ -437,17 +418,25 @@ 1 ..\Services\Servo.c + + Accelerometer.c + 1 + ..\Services\Accelerometer.c + + + Alimentation.c + 1 + ..\Services\Alimentation.c + + + RFOutput.c + 1 + ..\Services\RFOutput.c + MyDrivers - - - MyTimer.c - 1 - ..\MyDrivers\MyTimer.c - - Drivers/STM32f1xx_LL_Driver @@ -703,6 +692,7 @@ 0 0 0 + 0 0 0 8 @@ -869,7 +859,7 @@ 0 0 0 - 0 + 4 @@ -910,31 +900,11 @@ User Services - - Chrono.c - 1 - ..\Services\Chrono.c - - - alimentation.c - 1 - ..\Services\alimentation.c - - - accelerometer.c - 1 - ..\Services\accelerometer.c - DcMotor.c 1 ..\Services\DcMotor.c - - emetteur_rf.c - 1 - ..\Services\emetteur_rf.c - IncrEncoder.c 1 @@ -955,17 +925,25 @@ 1 ..\Services\Servo.c + + Accelerometer.c + 1 + ..\Services\Accelerometer.c + + + Alimentation.c + 1 + ..\Services\Alimentation.c + + + RFOutput.c + 1 + ..\Services\RFOutput.c + MyDrivers - - - MyTimer.c - 1 - ..\MyDrivers\MyTimer.c - - Drivers/STM32f1xx_LL_Driver @@ -1058,4 +1036,19 @@ + + + + <Project Info> + + + + + + 0 + 1 + + + + From 6ec006ddd2497096b7ec3894e52acf530bec18e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sun, 15 Nov 2020 14:50:10 +0100 Subject: [PATCH 10/14] fixed includes --- keil_project/Services/RFOutput.c | 2 +- keil_project/Src/main.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/keil_project/Services/RFOutput.c b/keil_project/Services/RFOutput.c index db7b130..1b3cfba 100644 --- a/keil_project/Services/RFOutput.c +++ b/keil_project/Services/RFOutput.c @@ -1,4 +1,4 @@ -#include "emetteur_rf.h" +#include "RFOutput.h" #include char buf[100]; diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index ff8a595..41f67dd 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -26,9 +26,9 @@ #include "IncrEncoder.h" #include "DcMotor.h" #include "Sail.h" -#include "alimentation.h" -#include "accelerometer.h" -#include "emetteur_rf.h" +#include "Alimentation.h" +#include "Accelerometer.h" +#include "RFOutput.h" #define CONTROL_LOOP_PERIOD 250 #define MSG_TRANSFER_PERIOD 3000 From e125c339a04498ad47dff1983d0ff73ad97cffa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sun, 15 Nov 2020 14:51:48 +0100 Subject: [PATCH 11/14] removed outdated service chrono and outdated drivers --- keil_project/MyDrivers/MyTimer.c | 182 ------------------------------- keil_project/MyDrivers/MyTimer.h | 70 ------------ keil_project/MyDrivers/MyUart.c | 67 ------------ keil_project/MyDrivers/MyUart.h | 10 -- keil_project/Services/Chrono.c | 182 ------------------------------- keil_project/Services/Chrono.h | 107 ------------------ 6 files changed, 618 deletions(-) delete mode 100644 keil_project/MyDrivers/MyTimer.c delete mode 100644 keil_project/MyDrivers/MyTimer.h delete mode 100644 keil_project/MyDrivers/MyUart.c delete mode 100644 keil_project/MyDrivers/MyUart.h delete mode 100644 keil_project/Services/Chrono.c delete mode 100644 keil_project/Services/Chrono.h diff --git a/keil_project/MyDrivers/MyTimer.c b/keil_project/MyDrivers/MyTimer.c deleted file mode 100644 index e51d696..0000000 --- a/keil_project/MyDrivers/MyTimer.c +++ /dev/null @@ -1,182 +0,0 @@ -// TOUT A FAIRE !! // - -/* - indispensable pour pouvoir adresser les registres des périphériques. - Rem : OBLIGATION d'utiliser les définitions utiles contenues dans ce fichier (ex : TIM_CR1_CEN, RCC_APB1ENR_TIM2EN ...) - pour une meilleure lisibilité du code. - - Pour les masques, utiliser également les définitions proposée - Rappel : pour mettre à 1 , reg = reg | Mask (ou Mask est le représente le ou les bits à positionner à 1) - pour mettre à 0 , reg = reg&~ Mask (ou Mask est le représente le ou les bits à positionner à 0) - -*/ - -#include "MyTimer.h" -#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges -#include "stm32f1xx_ll_tim.h" - - -// variable pointeur de fonction permettant de mémoriser le callback à appeler depuis -// le handler d'IT -void (*Ptr_ItFct_TIM1)(void); -void (*Ptr_ItFct_TIM2)(void); -void (*Ptr_ItFct_TIM3)(void); -void (*Ptr_ItFct_TIM4)(void); - - - - -/** - * @brief Active l'horloge et règle l'ARR et le PSC du timer visé - * @note Fonction à lancer avant toute autre. Le timer n'est pas encore lancé (voir MyTimerStart) - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * int Arr : valeur à placer dans ARR - * int Psc : valeur à placer dans PSC - * @retval None - */ -void MyTimer_Conf(TIM_TypeDef * Timer,int Arr, int Psc) -{ - LL_TIM_InitTypeDef My_LL_Tim_Init_Struct; - - // Validation horloge locale - if (Timer==TIM1) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1); - else if (Timer==TIM2) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); - else if (Timer==TIM3) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3); - else LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4); - - // chargement structure Arr, Psc, Up Count - My_LL_Tim_Init_Struct.Autoreload=Arr; - My_LL_Tim_Init_Struct.Prescaler=Psc; - My_LL_Tim_Init_Struct.ClockDivision=LL_TIM_CLOCKDIVISION_DIV1; - My_LL_Tim_Init_Struct.CounterMode=LL_TIM_COUNTERMODE_UP; - My_LL_Tim_Init_Struct.RepetitionCounter=0; - - LL_TIM_Init(Timer,&My_LL_Tim_Init_Struct); - - - // Blocage IT - LL_TIM_DisableIT_UPDATE(Timer); - - - // Blocage Timer - LL_TIM_DisableCounter(Timer); - - - -} - - -/** - * @brief Démarre le timer considéré - * @note - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * @retval None - */ -void MyTimer_Start(TIM_TypeDef * Timer) -{ - LL_TIM_EnableCounter(Timer); -} - -/** - * @brief Arrêt le timer considéré - * @note - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * @retval None - */ -void MyTimer_Stop(TIM_TypeDef * Timer) -{ - LL_TIM_DisableCounter(Timer); -} - - -/** - * @brief Configure le Timer considéré en interruption sur débordement. - * @note A ce stade, les interruptions ne sont pas validés (voir MyTimer_IT_Enable ) - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * void (*IT_function) (void) : nom (adresse) de la fonction à lancer sur interruption - * int Prio : priorité associée à l'interruption - * @retval None - */ -void MyTimer_IT_Conf(TIM_TypeDef * Timer, void (*IT_function) (void),int Prio) -{ - // affectation de la fonction - if (Timer==TIM1) Ptr_ItFct_TIM1=IT_function; - else if (Timer==TIM2) Ptr_ItFct_TIM2=IT_function; - else if (Timer==TIM3) Ptr_ItFct_TIM3=IT_function; - else Ptr_ItFct_TIM4=IT_function; - - - // Blocage IT (il faudra la débloquer voir fct suivante) - LL_TIM_DisableIT_UPDATE(Timer); - - // validation du canal NVIC - IRQn_Type TIM_irq; - - if (Timer==TIM1) TIM_irq=TIM1_UP_IRQn; - else if (Timer==TIM2) TIM_irq=TIM2_IRQn; - else if (Timer==TIM3) TIM_irq=TIM3_IRQn; - else TIM_irq=TIM4_IRQn; - - NVIC_SetPriority(TIM_irq, Prio); - NVIC_EnableIRQ(TIM_irq); - - -} - - -/** - * @brief Autorise les interruptions - * @note - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * @retval None - */ -void MyTimer_IT_Enable(TIM_TypeDef * Timer) -{ - LL_TIM_EnableIT_UPDATE(Timer); -} - - -/** - * @brief Interdit les interruptions - * @note - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * @retval None - */ -void MyTimer_IT_Disable(TIM_TypeDef * Timer) -{ - LL_TIM_DisableIT_UPDATE(Timer); -} - - -/* -============ LES INTERRUPTIONS ================================= - -*/ - -void TIM1_UP_IRQHandler(void) -{ - // rabaisser le flag d'IT - LL_TIM_ClearFlag_UPDATE(TIM1); - (*Ptr_ItFct_TIM1)(); -} - -void TIM2_IRQHandler(void) -{ - // rabaisser le flag d'IT - LL_TIM_ClearFlag_UPDATE(TIM2); - (*Ptr_ItFct_TIM2)(); -} - -void TIM3_IRQHandler(void) -{ - // rabaisser le flag d'IT - LL_TIM_ClearFlag_UPDATE(TIM3); - (*Ptr_ItFct_TIM3)(); -} - -void TIM4_IRQHandler(void) -{ - // rabaisser le flag d'IT - LL_TIM_ClearFlag_UPDATE(TIM4); - (*Ptr_ItFct_TIM4)(); -} diff --git a/keil_project/MyDrivers/MyTimer.h b/keil_project/MyDrivers/MyTimer.h deleted file mode 100644 index f2fa06c..0000000 --- a/keil_project/MyDrivers/MyTimer.h +++ /dev/null @@ -1,70 +0,0 @@ -// RIEN A MODIFIER // - -#ifndef MY_TIMER_H -#define MY_TIMER_H - -/* -Driver pour Timer 1 à 4 du STM32F103RB - -*/ - -#include "stm32f103xb.h" - -/** - * @brief Active l'horloge et règle l'ARR et le PSC du timer visé - * @note Fonction à lancer avant toute autre. Le timer n'est pas encore lancé (voir MyTimerStart) - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * int Arr : valeur à placer dans ARR - * int Psc : valeur à placer dans PSC - * @retval None - */ -void MyTimer_Conf(TIM_TypeDef * Timer,int Arr, int Psc); - - -/** - * @brief Démarre le timer considéré - * @note - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * @retval None - */ -void MyTimer_Start(TIM_TypeDef * Timer); - - -/** - * @brief Arrêt le timer considéré - * @note - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * @retval None - */ -void MyTimer_Stop(TIM_TypeDef * Timer); - - -/** - * @brief Configure le Timer considéré en interruption sur débordement. - * @note A ce stade, les interruptions ne sont pas validés (voir MyTimer_IT_Enable ) - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * void (*IT_function) (void) : nom (adresse) de la fonction à lancer sur interruption - * int Prio : priorité associée à l'interruption - * @retval None - */ -void MyTimer_IT_Conf(TIM_TypeDef * Timer, void (*IT_function) (void),int Prio); - - -/** - * @brief Autorise les interruptions - * @note - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * @retval None - */ -void MyTimer_IT_Enable(TIM_TypeDef * Timer); - - -/** - * @brief Interdit les interruptions - * @note - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * @retval None - */ -void MyTimer_IT_Disable(TIM_TypeDef * Timer); - -#endif diff --git a/keil_project/MyDrivers/MyUart.c b/keil_project/MyDrivers/MyUart.c deleted file mode 100644 index b907c68..0000000 --- a/keil_project/MyDrivers/MyUart.c +++ /dev/null @@ -1,67 +0,0 @@ -#include "MyUart.h" -#include "stm32f1xx_ll_bus.h" -#include "stm32f1xx_ll_usart.h" -#include "stm32f1xx_ll_gpio.h" - -void MyUart_Conf(USART_TypeDef * uart_port, int baudrate){ - - LL_USART_InitTypeDef My_LL_Usart_Init_Struct; - - if (uart_port==USART1) { - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); - LL_GPIO_InitTypeDef tx; - tx.Mode = LL_GPIO_MODE_ALTERNATE; - tx.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - tx.Speed = LL_GPIO_SPEED_FREQ_LOW; - tx.Pin = LL_GPIO_PIN_9; - LL_GPIO_Init(GPIOA, &tx); - } - if (uart_port==USART2){ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2); - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); - LL_GPIO_InitTypeDef tx; - tx.Mode = LL_GPIO_MODE_ALTERNATE; - tx.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - tx.Pull = LL_GPIO_PULL_UP; - tx.Speed = LL_GPIO_SPEED_FREQ_LOW; - tx.Pin = LL_GPIO_PIN_2; - LL_GPIO_Init(GPIOA, &tx); - } - if (uart_port==USART3){ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3); - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC); - LL_GPIO_InitTypeDef tx; - tx.Mode = LL_GPIO_MODE_ALTERNATE; - tx.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - tx.Pull = LL_GPIO_PULL_UP; - tx.Speed = LL_GPIO_SPEED_FREQ_LOW; - tx.Pin = LL_GPIO_PIN_10; - LL_GPIO_Init(GPIOC, &tx); - } - - My_LL_Usart_Init_Struct.BaudRate = baudrate; - My_LL_Usart_Init_Struct.DataWidth = LL_USART_DATAWIDTH_8B ; - My_LL_Usart_Init_Struct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; - My_LL_Usart_Init_Struct.OverSampling = LL_USART_OVERSAMPLING_16; - My_LL_Usart_Init_Struct.Parity = LL_USART_PARITY_NONE; - My_LL_Usart_Init_Struct.StopBits = LL_USART_STOPBITS_1; - My_LL_Usart_Init_Struct.TransferDirection = LL_USART_DIRECTION_TX_RX ; - - LL_USART_Init(uart_port,&My_LL_Usart_Init_Struct); - LL_USART_Enable(uart_port); - - /*int periph_speed; - if (uart_port==USART1) periph_speed = 36000000; - if (uart_port==USART2) periph_speed = 72000000; - if (uart_port==USART3) periph_speed = 72000000; - - LL_USART_SetBaudRate(uart_port, periph_speed, baudrate); -*/} - -void MyUart_send_bytes(USART_TypeDef * uart_port,char* buf, int len){ - for(int i = 0; i < len; i++){ - LL_USART_TransmitData8(uart_port, buf[i]); - while(!LL_USART_IsActiveFlag_TXE(uart_port)); - } -} diff --git a/keil_project/MyDrivers/MyUart.h b/keil_project/MyDrivers/MyUart.h deleted file mode 100644 index 6641c92..0000000 --- a/keil_project/MyDrivers/MyUart.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef MYUART_H -#define MYUART_H - -#include "stm32f1xx_ll_usart.h" - -void MyUart_Conf(USART_TypeDef * uart_port, int baudrate); - -void MyUart_send_bytes(USART_TypeDef * uart_port,char* buf, int len); - -#endif \ No newline at end of file diff --git a/keil_project/Services/Chrono.c b/keil_project/Services/Chrono.c deleted file mode 100644 index a77a4df..0000000 --- a/keil_project/Services/Chrono.c +++ /dev/null @@ -1,182 +0,0 @@ -// A COMPLETER - -/* -Service permettant de chornométrer jusqu'à 59mn 59s 99 1/100 -Utilise un timer au choix (TIMER1 à TIMER4). -Utilise la lib MyTimers.h /.c -*/ - - - -#include "Chrono.h" -#include "MyTimer.h" -#include "stm32f1xx_ll_gpio.h" -#include "stm32f1xx_ll_bus.h" - -// variable privée de type Time qui mémorise la durée mesurée -static Time Chrono_Time; // rem : static rend la visibilité de la variable Chrono_Time limitée à ce fichier - -// variable privée qui mémorise pour le module le timer utilisé par le module -static TIM_TypeDef * Chrono_Timer=TIM1; // init par défaut au cas où l'utilisateur ne lance pas Chrono_Conf avant toute autre fct. - -// déclaration callback appelé toute les 10ms -void Chrono_Task_10ms(void); - -int running = 0; - -/** - * @brief Configure le chronomètre. - * @note A lancer avant toute autre fonction. - * @param Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * @retval None - */ -void Chrono_Conf(TIM_TypeDef * Timer) -{ - // Reset Time - Chrono_Time.Hund=0; - Chrono_Time.Sec=0; - Chrono_Time.Min=0; - - // Fixation du Timer - Chrono_Timer=Timer; - - Chrono_Conf_io(); - // Réglage Timer pour un débordement à 10ms - MyTimer_Conf(Chrono_Timer,999, 719); - - // Réglage interruption du Timer avec callback : Chrono_Task_10ms() - MyTimer_IT_Conf(Chrono_Timer, Chrono_Task_10ms,3); - - // Validation IT - MyTimer_IT_Enable(Chrono_Timer); - - -} - - -/** - * @brief Démarre le chronomètre. - * @note si la durée dépasse 59mn 59sec 99 Hund, elle est remise à zéro et repart - * @param Aucun - * @retval Aucun - */ -void Chrono_Start(void) -{ - MyTimer_Start(Chrono_Timer); - running = 1; -} - - -/** - * @brief Arrête le chronomètre. - * @note - * @param Aucun - * @retval Aucun - */ -void Chrono_Stop(void) -{ - MyTimer_Stop(Chrono_Timer); - running = 0; -} - - -/** - * @brief Remet le chronomètre à 0 - * @note - * @param Aucun - * @retval Aucun - */ -void Chrono_Reset(void) -{ - // Arrêt Chrono - MyTimer_Stop(Chrono_Timer); - - // Reset Time - Chrono_Time.Hund=0; - Chrono_Time.Sec=0; - Chrono_Time.Min=0; -} - - -/** - * @brief Renvoie l'adresse de la variable Time privée gérée dans le module Chrono.c - * @note - * @param Aucun - * @retval adresse de la variable Time - */ -Time * Chrono_Read(void) -{ - return &Chrono_Time; -} - - - - -/** - * @brief incrémente la variable privée Chron_Time modulo 60mn - * @note - * @param Aucun - * @retval Aucun - */ -void Chrono_Task_10ms(void) -{ - Chrono_Time.Hund++; - if (Chrono_Time.Hund==100) - { - Chrono_Time.Sec++; - Chrono_Time.Hund=0; - } - if (Chrono_Time.Sec==60) - { - Chrono_Time.Min++; - Chrono_Time.Sec=0; - } - if (Chrono_Time.Min==60) - { - Chrono_Time.Hund=0; - } - if ( Chrono_Time.Sec % 2) { - LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_10); - } else { - LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_10); - } - -} - -/** - * @brief configurer les 3 IO pour recevoir les 2 BP et la LED - */ -void Chrono_Conf_io(void) { - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC); - - LL_GPIO_InitTypeDef button_rouge_conf; - button_rouge_conf.Mode = LL_GPIO_MODE_FLOATING; - button_rouge_conf.Pin = LL_GPIO_PIN_8; - LL_GPIO_Init(GPIOC, &button_rouge_conf); - - - LL_GPIO_InitTypeDef button_bleu_conf; - button_bleu_conf.Mode = LL_GPIO_MODE_FLOATING; - button_bleu_conf.Pin = LL_GPIO_PIN_13; - LL_GPIO_Init(GPIOC, &button_bleu_conf); - - LL_GPIO_InitTypeDef led; - led.Mode = LL_GPIO_MODE_OUTPUT; - led.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - led.Speed = LL_GPIO_SPEED_FREQ_LOW; - led.Pin = LL_GPIO_PIN_10; - LL_GPIO_Init(GPIOC, &led); -} - -void Chrono_Background(void){ - if(LL_GPIO_IsInputPinSet(GPIOC, LL_GPIO_PIN_8)) { - if(running) { - Chrono_Stop(); - } else { - Chrono_Start(); - } - } - if(!(LL_GPIO_IsInputPinSet(GPIOC, LL_GPIO_PIN_13))) { // negative logic for blue button - Chrono_Reset(); - } -} diff --git a/keil_project/Services/Chrono.h b/keil_project/Services/Chrono.h deleted file mode 100644 index 4afdaa6..0000000 --- a/keil_project/Services/Chrono.h +++ /dev/null @@ -1,107 +0,0 @@ -// RIEN A MODIFIER // - -#ifndef CHRONO_H -#define CHRONO_H - -/* -Service permettant de chornométrer jusqu'à 59mn 59s 99 1/100 -Utilise un timer au choix (TIMER1 à TIMER4). -Utilise la lib MyTimers.h /.c -*/ - -#include "stm32f103xb.h" - -/* ===================================================================================== -Les fonctions qui gèrent les IO (ajout par rapport à l'activité 1) -=======================================================================================*/ - - -#define PinStart LL_GPIO_PIN_8 -#define PinStop LL_GPIO_PIN_6 -// à compléter pour la pin reset du chronometre -#define PinLED LL_GPIO_PIN_10 -#define GPIO_Pin GPIOC -#define GPIO_LED GPIOC - - - - - - -/** - * @brief polle les 3 entrées et gènère les actions à faire - * @note Fct à lancer en tâche de fond (non bloquante) - * @param None - * @retval None - */ - -void Chrono_Background(void); - -//=======================================================================================// - - - - -// Type de donnée utilisé dans le module - -typedef struct { - char Hund; - char Sec; - char Min; -} Time; - - - - -/** - * @brief Configure le chronomètre. - * @note A lancer avant toute autre fonction. - * @param TIM_TypeDef Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 - * @retval None - */ -void Chrono_Conf(TIM_TypeDef * Timer); - - - - - - -/** - * @brief Démarre le chronomètre. - * @note si la durée dépasse 59mn 59sec 99 cent, elle est remise à zéro et repart - * @param Aucun - * @retval Aucun - */ -void Chrono_Start(void); - - -/** - * @brief Arrête le chronomètre. - * @note - * @param Aucun - * @retval Aucun - */ -void Chrono_Stop(void); - - -/** - * @brief Remet le chronomètre à 0 - * @note - * @param Aucun - * @retval Aucun - */ -void Chrono_Reset(void); - - -/** - * @brief Renvoie l'adresse de la variable Time privée gérée dans le module Chrono.c - * @note - * @param Aucun - * @retval adresse de la variable Time - */ -Time * Chrono_Read(void); - -void Chrono_Conf_io(void); - -void Chrono_Background(void); -#endif From a7af1cad1e2c3b2ae53251d6eed2695f1cb96c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sun, 15 Nov 2020 14:56:09 +0100 Subject: [PATCH 12/14] rf_output renaming --- keil_project/Services/RFOutput.c | 12 ++++++------ keil_project/Services/RFOutput.h | 6 +++--- keil_project/Src/main.c | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/keil_project/Services/RFOutput.c b/keil_project/Services/RFOutput.c index 1b3cfba..42f2813 100644 --- a/keil_project/Services/RFOutput.c +++ b/keil_project/Services/RFOutput.c @@ -1,9 +1,9 @@ #include "RFOutput.h" #include -char buf[100]; +char RF_OUTPUT_buf[100]; -void emetteur_rf_init(void){ +void RF_OUTPUT_Init(void){ LL_USART_InitTypeDef My_LL_Usart_Init_Struct; @@ -39,7 +39,7 @@ void emetteur_rf_init(void){ } -void emetteur_send_bytes(char* buf, int len){ +void RF_OUTPUT_SendBytes(char* buf, int len){ LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_11); for(int i = 0; i < len; i++){ @@ -49,7 +49,7 @@ void emetteur_send_bytes(char* buf, int len){ LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_11); } -void emetteur_send_message(int rouli_bon, int alimentation_bon, float angle_voile){ - int len = sprintf(buf, "Alim bon: %d, Rouli bon: %d, Angle de voile: %2f\r\n", alimentation_bon, rouli_bon, angle_voile); - emetteur_send_bytes(buf, len); +void RF_OUTPUT_SendMessage(int rouli_bon, int alimentation_bon, float angle_voile){ + int len = sprintf(RF_OUTPUT_buf, "Alim bon: %d, Rouli bon: %d, Angle de voile: %2f\r\n", alimentation_bon, rouli_bon, angle_voile); + RF_OUTPUT_SendBytes(RF_OUTPUT_buf, len); } diff --git a/keil_project/Services/RFOutput.h b/keil_project/Services/RFOutput.h index 868e3a7..f9285df 100644 --- a/keil_project/Services/RFOutput.h +++ b/keil_project/Services/RFOutput.h @@ -7,9 +7,9 @@ #include "stm32f1xx_ll_usart.h" #include "stm32f1xx_ll_gpio.h" -void emetteur_rf_init(void); -void emetteur_send_bytes(char* buf, int len); -void emetteur_send_message(int rouli_bon, int alimentation_bon, float angle_voile); +void RF_OUTPUT_Init(void); +void RF_OUTPUT_SendBytes(char* buf, int len); +void RF_OUTPUT_SendMessage(int rouli_bon, int alimentation_bon, float angle_voile); diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index 41f67dd..83f7709 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -61,11 +61,11 @@ int main(void) RF_INPUT_Init(); DC_MOTOR_Init(); SAIL_Init(); - emetteur_rf_init(); + RF_OUTPUT_Init(); while(!INCR_ENCODER_IsAbsolute()) { - emetteur_send_bytes(wait_for_girouette, sizeof(wait_for_girouette)); + RF_OUTPUT_SendBytes(wait_for_girouette, sizeof(wait_for_girouette)); LL_mDelay(500); } @@ -88,7 +88,7 @@ int main(void) CONTROL_LOOP_Flag = 0; } if(TX_Flag){ - emetteur_send_message(angle_roulis_good, battery_level_good, angle_sail); + RF_OUTPUT_SendMessage(angle_roulis_good, battery_level_good, angle_sail); TX_Flag = 0; } } From ef3b6b03e2be036196fa34a7549f46c7c9d41637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sun, 15 Nov 2020 15:00:18 +0100 Subject: [PATCH 13/14] alimentation function renamingi and minor cleanup --- keil_project/Services/Alimentation.c | 98 +++++++++++++--------------- keil_project/Services/Alimentation.h | 6 +- keil_project/Src/main.c | 4 +- 3 files changed, 49 insertions(+), 59 deletions(-) diff --git a/keil_project/Services/Alimentation.c b/keil_project/Services/Alimentation.c index ad89e86..3e4d704 100644 --- a/keil_project/Services/Alimentation.c +++ b/keil_project/Services/Alimentation.c @@ -1,63 +1,53 @@ #include "Alimentation.h" -void alimentation_init(void){ - RCC -> CFGR |= (0x1<<15); - RCC-> CFGR &= ~ (0x1<<14); - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); - LL_APB1_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC); - - LL_GPIO_InitTypeDef pc2; - LL_ADC_InitTypeDef adc; - LL_ADC_REG_InitTypeDef adcReg; - - LL_GPIO_StructInit(&pc2); - pc2.Pin = LL_GPIO_PIN_0; - pc2.Mode = LL_GPIO_MODE_ANALOG; - LL_GPIO_Init(GPIOC, &pc2); +void ALIMENTATION_Init(void){ + RCC -> CFGR |= (0x1<<15); + RCC-> CFGR &= ~ (0x1<<14); + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); + LL_APB1_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC); + + LL_GPIO_InitTypeDef pc2; + LL_ADC_InitTypeDef adc; + LL_ADC_REG_InitTypeDef adcReg; + + LL_GPIO_StructInit(&pc2); + pc2.Pin = LL_GPIO_PIN_0; + pc2.Mode = LL_GPIO_MODE_ANALOG; + LL_GPIO_Init(GPIOC, &pc2); + + + adc.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; + adc.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE; + LL_ADC_Init(ADC1, &adc); + + adcReg.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE ; + adcReg.SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE; + adcReg.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; + adcReg.ContinuousMode = LL_ADC_REG_CONV_SINGLE; + adcReg.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE; - adc.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; - adc.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE; - LL_ADC_Init(ADC1, &adc); - - adcReg.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE ; - adcReg.SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE; - adcReg.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; - adcReg.ContinuousMode = LL_ADC_REG_CONV_SINGLE; - adcReg.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE; - - - LL_ADC_REG_Init(ADC1, &adcReg); - - /*LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_10, LL_ADC_SAMPLINGTIME_1CYCLE_5); - LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_11, LL_ADC_SAMPLINGTIME_1CYCLE_5); - - */ - LL_ADC_Enable(ADC1); - - //LL_ADC_EnableIT_EOS(ADC1); - //wait 0,2 µs, calibration is advised - //LL_ADC_StartCalibration(ADC1); - } -float u2; -unsigned int niv_batterie; + LL_ADC_REG_Init(ADC1, &adcReg); + LL_ADC_Enable(ADC1); +} + +float ALIMENTATION_GetBatteryLevel(void){ + float u2; float battery_level; - float get_battery_level(void){ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_12); - LL_ADC_REG_StartConversionSWStart(ADC1); - while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1); - battery_level = LL_ADC_REG_ReadConversionData12(ADC1); - u2 = (battery_level*3.3)/4095.0; - float level = u2*13.0; - return level; + LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_12); + LL_ADC_REG_StartConversionSWStart(ADC1); + while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1); + battery_level = LL_ADC_REG_ReadConversionData12(ADC1); + u2 = (battery_level*3.3)/4095.0; + float level = u2*13.0; + return level; } - int is_level_enough(void){ - if (get_battery_level()<(0.8*12)){ - return 0; - }else{ - return 1; - } +int ALIMENTATION_IsLevelEnough(void){ + if (ALIMENTATION_GetBatteryLevel()<(0.8*12)){ + return 0; + }else{ + return 1; } - \ No newline at end of file +} diff --git a/keil_project/Services/Alimentation.h b/keil_project/Services/Alimentation.h index 503541f..7effb3d 100644 --- a/keil_project/Services/Alimentation.h +++ b/keil_project/Services/Alimentation.h @@ -18,9 +18,9 @@ Les fonctions qui gèrent les IO (ajout par rapport à l'activité 1) =======================================================================================*/ -void alimentation_init(void); -float get_battery_level(void); -int is_level_enough(void); +void ALIMENTATION_Init(void); +float ALIMENTATION_GetBatteryLevel(void); +int ALIMENTATION_IsLevelEnough(void); #endif diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index 83f7709..f6e9dbc 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -56,7 +56,7 @@ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); - alimentation_init(); + ALIMENTATION_Init(); accelero_init(); RF_INPUT_Init(); DC_MOTOR_Init(); @@ -73,7 +73,7 @@ int main(void) while (1) { if(CONTROL_LOOP_Flag){ - battery_level_good = is_level_enough(); + battery_level_good = ALIMENTATION_IsLevelEnough(); angle_roulis_good = accelero_angle_bon(); if(!angle_roulis_good){ From 41f7b66f5d5705df90ea33ffd22943f44a2f2a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jasper=20G=C3=BCldenstein?= Date: Sun, 15 Nov 2020 15:11:51 +0100 Subject: [PATCH 14/14] renaming functions and minor cleanup --- keil_project/Services/Accelerometer.c | 40 ++++++--------------------- keil_project/Services/Accelerometer.h | 8 +++--- keil_project/Src/main.c | 23 ++++++--------- 3 files changed, 22 insertions(+), 49 deletions(-) diff --git a/keil_project/Services/Accelerometer.c b/keil_project/Services/Accelerometer.c index 14141dc..ac4bcb7 100644 --- a/keil_project/Services/Accelerometer.c +++ b/keil_project/Services/Accelerometer.c @@ -1,9 +1,6 @@ #include "Accelerometer.h" -double x; -double y; -double angle; -void accelero_init(void){ +void ACCELEROMETER_Init(void){ RCC -> CFGR |= (0x1<<15); RCC-> CFGR &= ~ (0x1<<14); LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1); @@ -23,7 +20,6 @@ void accelero_init(void){ pc1.Mode = LL_GPIO_MODE_ANALOG; LL_GPIO_Init(GPIOA, &pc1); - adc.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; adc.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE; @@ -35,55 +31,37 @@ void accelero_init(void){ adcReg.ContinuousMode = LL_ADC_REG_CONV_SINGLE; adcReg.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE; - LL_ADC_REG_Init(ADC1, &adcReg); - - /*LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_10, LL_ADC_SAMPLINGTIME_1CYCLE_5); - LL_ADC_SetChannelSamplingTime(ADC2, LL_ADC_CHANNEL_11, LL_ADC_SAMPLINGTIME_1CYCLE_5); - */ - LL_ADC_Enable(ADC1); - - //LL_ADC_EnableIT_EOS(ADC1); - //wait 0,2 µs, calibration is advised - //LL_ADC_StartCalibration(ADC1); } - -double accelero_get_x(void){ +double ACCELEROMETER_GetX(void){ LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_1); LL_ADC_REG_StartConversionSWStart(ADC1); - while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1){ - //__asm__"nope"; - } + while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1); double x= LL_ADC_REG_ReadConversionData12(ADC1); return x; } -double accelero_get_y(void){ +double ACCELEROMETER_GetY(void){ LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_11); LL_ADC_REG_StartConversionSWStart(ADC1); - while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1){ - //__asm__"nope"; - } + while (LL_ADC_IsActiveFlag_EOS(ADC1) != 1); double y = LL_ADC_REG_ReadConversionData12(ADC1); return y; } - -int accelero_angle_bon(void){ - x = accelero_get_x(); - y = accelero_get_y(); - angle = x/y; +int ACCELEROMETER_AngleGood(void){ + double x = ACCELEROMETER_GetX(); + double y = ACCELEROMETER_GetY(); + double angle = x/y; if (angle>tan(0.698132)){ return 0; }else { return 1; } - //le flag EOC n'est jamais mis à un .... // Soit la conversion est mal faite soit on n'utilise pas bien la simulation //soit on n'utilise pas bien isActiveFlag dans la boucle } - diff --git a/keil_project/Services/Accelerometer.h b/keil_project/Services/Accelerometer.h index 8389738..d05ce28 100644 --- a/keil_project/Services/Accelerometer.h +++ b/keil_project/Services/Accelerometer.h @@ -18,13 +18,13 @@ Les fonctions qui gèrent les IO (ajout par rapport à l'activité 1) =======================================================================================*/ -void accelero_init(void); +void ACCELEROMETER_Init(void); -double accelero_get_x(void); +double ACCELEROMETER_GetX(void); -double accelero_get_y(void); +double ACCELEROMETER_GetY(void); -int accelero_angle_bon(void); +int ACCELEROMETER_AngleGood(void); #endif diff --git a/keil_project/Src/main.c b/keil_project/Src/main.c index f6e9dbc..8655e79 100644 --- a/keil_project/Src/main.c +++ b/keil_project/Src/main.c @@ -37,13 +37,7 @@ void SystemClock_Config(void); /* Private functions ---------------------------------------------------------*/ -/** - * @brief Main program - * @param None - * @retval None - */ - - +// global variables for monitoring in keil int counter = 0; int battery_level_good = 0; int angle_roulis_good = 0; @@ -52,12 +46,18 @@ int RF_Input_Duty = 0; int TX_Flag = 0, CONTROL_LOOP_Flag = 0; char wait_for_girouette[] = "En attente d'initialisation de la girouette\r\n"; + +/** + * @brief Main program + * @param None + * @retval None + */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); ALIMENTATION_Init(); - accelero_init(); + ACCELEROMETER_Init(); RF_INPUT_Init(); DC_MOTOR_Init(); SAIL_Init(); @@ -69,12 +69,11 @@ int main(void) LL_mDelay(500); } - /* Infinite loop */ while (1) { if(CONTROL_LOOP_Flag){ battery_level_good = ALIMENTATION_IsLevelEnough(); - angle_roulis_good = accelero_angle_bon(); + angle_roulis_good = ACCELEROMETER_AngleGood(); if(!angle_roulis_good){ SAIL_SetAngle(90); @@ -107,10 +106,6 @@ void SysTick_Handler(void) } - - - - /** * @brief System Clock Configuration * The system Clock is configured as follow :