From 6e0c1987025bc95526f6e9b68c360fde957b23ef Mon Sep 17 00:00:00 2001 From: Aleksander Taban Date: Tue, 16 Dec 2025 16:45:35 +0100 Subject: [PATCH] =?UTF-8?q?La=20version=20de=20horloge=20g=C3=A9n=C3=A9ral?= =?UTF-8?q?is=C3=A9e=20et=20maintenant=20disponible.=20Elle=20sera=20l'uni?= =?UTF-8?q?que=20pilote=20horloge,=20on=20n'utilisera=20plus=20Timer.c,=20?= =?UTF-8?q?qui=20est=20donc=20retir=C3=A9e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pilotes/Include/Timer.h | 8 ---- Pilotes/Source/Horloge.c | 83 +++++++++++++++++++++++++++++++--------- Pilotes/Source/Timer.c | 28 -------------- 3 files changed, 64 insertions(+), 55 deletions(-) delete mode 100644 Pilotes/Include/Timer.h delete mode 100644 Pilotes/Source/Timer.c diff --git a/Pilotes/Include/Timer.h b/Pilotes/Include/Timer.h deleted file mode 100644 index 48c46ec..0000000 --- a/Pilotes/Include/Timer.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef TIMER_H_ -#define TIMER_H_ -#include "stm32f10x.h" -// Config de timer -extern void MyTimer_Base_Init(TIM_TypeDef *Timer , unsigned short ValARR , unsigned short ValPSC ); -// Enable timers -void EnableTimer(TIM_TypeDef *Timer); -#endif diff --git a/Pilotes/Source/Horloge.c b/Pilotes/Source/Horloge.c index 4d2e30d..9f5dca0 100644 --- a/Pilotes/Source/Horloge.c +++ b/Pilotes/Source/Horloge.c @@ -2,18 +2,26 @@ #include "Horloge.h" static void (*TIM2_Appel)(void) = 0; +static void (*TIM3_Appel)(void) = 0; +static void (*TIM4_Appel)(void) = 0; void Timer_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Prescaler) { if (Timer == TIM1) { - RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; - } else if (Timer == TIM2) { - TIM2->CR1 |= TIM_CR1_CEN; - RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; - } else if (Timer == TIM3) { - RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; - } else if (Timer == TIM4) { - RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; + // On ne l'utilise JAMAIS!! + RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; + } + else if (Timer == TIM2) { + TIM2->CR1 |= TIM_CR1_CEN; + RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; + } + else if (Timer == TIM3) { + TIM3->CR1 |= TIM_CR1_CEN; + RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; + } + else if (Timer == TIM4) { + TIM3->CR1 |= TIM_CR1_CEN; + RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; } Timer->ARR |= Autoreload; Timer->PSC |= Prescaler; @@ -21,18 +29,8 @@ void Timer_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Pr } -//La fonction TIM2_IRQHandler existe déjà dans le processeur, on l'a juste redifint, tel qu'à chaque overflow on met un bit 1 dans GPIOA_ODR -void TIM2_IRQHandler(void) { //On redefinit le IRQHandler qui est déjà ecrit dans le code source - if (TIM2->SR & TIM_SR_UIF) { //On met le bit de overflow à un dès qu'on a overflow - TIM2->SR &= ~TIM_SR_UIF; //Remise à zero - - if (TIM2_Appel){TIM2_Appel();} - } -} - - void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void(*Interrupt_fonc)(void)) { //On veut créer une fonction qui envoie un signal au cas où il y a debordement, avec une prioritaire, 0 plus importante 15 moins importante - if (Timer == TIM2){ + if (Timer == TIM2) { TIM2_Appel = Interrupt_fonc; NVIC_EnableIRQ(TIM2_IRQn); @@ -40,6 +38,53 @@ void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void(*Interrupt_fonc)(void TIM2->DIER |= TIM_DIER_UIE; //Le registre DIER(Interrupt Enable Register) est mis au bit Update Interrupt, qui se commute lors d'un overflow TIM2->CR1 |= TIM_CR1_CEN; //Clock Enable } + else if (Timer == TIM3) { + TIM3_Appel = Interrupt_fonc; + + NVIC_EnableIRQ(TIM3_IRQn); + NVIC_SetPriority(TIM2_IRQn, Prio); + TIM3->DIER |= TIM_DIER_UIE; + TIM3->CR1 |= TIM_CR1_CEN; + } + else if (Timer == TIM4) { + TIM4_Appel = Interrupt_fonc; + + NVIC_EnableIRQ(TIM4_IRQn); + NVIC_SetPriority(TIM4_IRQn, Prio); + TIM4->DIER |= TIM_DIER_UIE; + TIM4->CR1 |= TIM_CR1_CEN; + } + else if (Timer == TIM1) { + // On n'utilise pas TIM1 + } + else { + // L'horloge n'existe pas + } +} + +//La fonction TIM2_IRQHandler existe déjà dans le processeur, on l'a juste redifint, tel qu'à chaque overflow on met un bit 1 dans GPIOA_ODR +void TIM2_IRQHandler(void) { //On redefinit le IRQHandler qui est déjà ecrit dans le code source + if (TIM2->SR & TIM_SR_UIF) { //On met le bit de overflow à un dès qu'on a overflow + TIM2->SR &= ~TIM_SR_UIF; //Remise à zero + if (TIM2_Appel){TIM2_Appel();} + } +} + +//La fonction TIM3_IRQHandler existe déjà dans le processeur, on l'a juste redifint, tel qu'à chaque overflow on met un bit 1 dans GPIOA_ODR +void TIM3_IRQHandler(void) { //On redefinit le IRQHandler qui est déjà ecrit dans le code source + if (TIM3->SR & TIM_SR_UIF) { //On met le bit de overflow à un dès qu'on a overflow + TIM3->SR &= ~TIM_SR_UIF; //Remise à zero + if (TIM3_Appel){TIM3_Appel();} + } +} + +//La fonction TIM4_IRQHandler existe déjà dans le processeur, on l'a juste redifint, tel qu'à chaque overflow on met un bit 1 dans GPIOA_ODR +void TIM4_IRQHandler(void) { //On redefinit le IRQHandler qui est déjà ecrit dans le code source + if (TIM4->SR & TIM_SR_UIF) { //On met le bit de overflow à un dès qu'on a overflow + TIM4->SR &= ~TIM_SR_UIF; //Remise à zero + if (TIM4_Appel){TIM4_Appel();} + } } + diff --git a/Pilotes/Source/Timer.c b/Pilotes/Source/Timer.c deleted file mode 100644 index e083f7f..0000000 --- a/Pilotes/Source/Timer.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include "Timer.h" - - -void MyTimer_Base_Init(TIM_TypeDef * Timer, unsigned short ValARR, unsigned short ValPSC) { // Configuration du timer -Timer -> PSC=(ValPSC); -Timer-> ARR = (ValARR); -Timer->EGR |= TIM_EGR_UG; -}; - - -void EnableTimer(TIM_TypeDef *Timer) { - if(Timer == TIM2){ - RCC -> APB1ENR |= RCC_APB1ENR_TIM2EN; - } - else if(Timer == TIM3){ - RCC -> APB1ENR |= RCC_APB1ENR_TIM3EN; - } - else if(Timer == TIM4){ - RCC -> APB1ENR |= RCC_APB1ENR_TIM4EN; - } - else if(Timer == TIM1){ - RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; - } - else{ - } -} -