Compare commits

...

3 commits

Author SHA1 Message Date
Arnaud Vergnet
7e6eb879f1 add basic scheduler functions 2020-11-09 10:01:39 +01:00
Arnaud Vergnet
cdcf3a2f9d add encoder config 2020-11-09 10:01:18 +01:00
Arnaud Vergnet
6ded190d3d add gpio config 2020-11-09 10:01:00 +01:00
6 changed files with 86 additions and 13 deletions

View file

@ -1,11 +1,12 @@
#include "IncrementalEncoder.h" #include "IncrementalEncoder.h"
#include "Timer.h" #include "Timer.h"
#include "GPIO.h"
void IncrementalEncoder_conf(TIM_TypeDef * timer) void IncrementalEncoder_conf(TIM_TypeDef * timer, GPIO_TypeDef * gpio, int pin)
{ {
Timer_encoder_conf(timer); Timer_encoder_conf(timer);
// TODO GPIO config GPIO_conf(gpio, pin, LL_GPIO_MODE_INPUT, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_UP);
} }
void IncrementalEncoder_start(TIM_TypeDef * timer) void IncrementalEncoder_start(TIM_TypeDef * timer)

View file

@ -9,7 +9,7 @@
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4 * @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
* @retval None * @retval None
*/ */
void IncrementalEncoder_conf(TIM_TypeDef * timer); void IncrementalEncoder_conf(TIM_TypeDef * timer, GPIO_TypeDef * gpio, int pin);
/** /**
* @brief Démarre le codeur incrémental associé au timer donné * @brief Démarre le codeur incrémental associé au timer donné

21
Services/Scheduler.c Normal file
View file

@ -0,0 +1,21 @@
#include "Scheduler.h"
#include "Timer.h"
#include "stm32f1xx_ll_utils.h"
void (*it_callback_SysTick)(void);
void SysTick_Handler(void)
{
(*it_callback_SysTick)();
}
void Scheduler_conf(void (*it_callback) (void))
{
it_callback_SysTick = it_callback;
LL_Init1msTick(1000);
}
void Scheduler_start(void)
{
}

22
Services/Scheduler.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef SCHEDULER_H
#define SCHEDULER_H
#include "stm32f103xb.h"
/**
* @brief Configure l'horloge interne comme ordonanceur
* @note
* @param (void)* it_callback : Tache de fond à executer
* @retval None
*/
void Scheduler_conf(void (*it_callback) (void));
/**
* @brief Démarre ordonanceur
* @note
* @param None
* @retval None
*/
void Scheduler_start(void);
#endif

View file

@ -1,14 +1,20 @@
#include "Sail.h" #include "Sail.h"
#include "ServoMotor.h" #include "ServoMotor.h"
#include "IncrementalEncoder.h"
TIM_TypeDef * SAIL_TIMER = TIM4; TIM_TypeDef * MOTOR_TIMER = TIM4;
const int SAIL_CHANNEL = LL_TIM_CHANNEL_CH3; const int MOTOR_CHANNEL = LL_TIM_CHANNEL_CH3;
GPIO_TypeDef * SAIL_GPIO = GPIOB; GPIO_TypeDef * MOTOR_GPIO = GPIOB;
const int SAIL_PIN = LL_GPIO_PIN_8; const int MOTOR_PIN = LL_GPIO_PIN_8;
TIM_TypeDef * ENCODER_TIMER = TIM3;
GPIO_TypeDef * ENCODER_GPIO = GPIOA;
const int ENCODER_PIN = LL_GPIO_PIN_5;
void Sail_conf() void Sail_conf()
{ {
ServoMotor_conf(SAIL_TIMER, SAIL_CHANNEL, SAIL_GPIO, SAIL_PIN); ServoMotor_conf(MOTOR_TIMER, MOTOR_CHANNEL, MOTOR_GPIO, MOTOR_PIN);
IncrementalEncoder_conf(ENCODER_TIMER, ENCODER_GPIO, ENCODER_PIN);
} }
void Sail_background() void Sail_background()
@ -24,5 +30,6 @@ void Sail_reset()
void Sail_start() void Sail_start()
{ {
Timer_start(SAIL_TIMER); Timer_start(MOTOR_TIMER);
Timer_start(ENCODER_TIMER);
} }

View file

@ -21,17 +21,36 @@
#include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config #include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config
#include "Sail.h" #include "Sail.h"
#include "Scheduler.h"
void SystemClock_Config(void); void SystemClock_Config(void);
/* Private functions ---------------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/
int counter = 1;
void backgroundTask()
{
counter++;
Sail_background();
}
void configurePeripherals()
{
Sail_conf();
}
void startPeripherals()
{
Sail_start();
}
/** /**
* @brief Main program * @brief Main program
* @param None * @param None
* @retval None * @retval None
*/ */
int main(void) int main(void)
{ {
/* Configure the system clock to 72 MHz */ /* Configure the system clock to 72 MHz */
@ -43,9 +62,12 @@ int main(void)
// Lancement chronomètre // Lancement chronomètre
// Chrono_Start(); // Chrono_Start();
// time = Chrono_Read(); // time = Chrono_Read();
configurePeripherals();
startPeripherals();
Scheduler_conf(backgroundTask);
Scheduler_start();
Sail_conf();
Sail_start();
while (1) while (1)
{ {
} }