commit de pauline

This commit is contained in:
Noel Jumin 2023-03-22 18:06:33 +01:00
parent f6f5a3eab5
commit 7bd8d23d41
6 changed files with 172 additions and 129 deletions

View file

@ -1,36 +1,14 @@
#ifndef MYTIMER_H
#define MYTIMER_H
#ifndef MYADC_H
#define MYADC_H
#include "stm32f10x.h"
#include "GPIO.h"
typedef struct
{
TIM_TypeDef * Timer ; // TIM1 à TIM4
unsigned short ARR;
unsigned short PSC;
}MyTimer_Struct_TypeDef;
/*
*****************************************************************************************
* @brief
* @param -> Paramètre sous forme dune structure (son adresse) contenant les
informations de base
* @Note -> Fonction à lancer systématiquement avant daller plus en détail dans les
conf plus fines (PWM, codeur inc...)
*************************************************************************************************
*/
void MyTimer_Base_Init (MyTimer_Struct_TypeDef * Timer);
/*
*****************************************************************************************
* @brief
* @param -> - TIM_TypeDef * Timer : Timer concerne
- char Prio : de 0 a 15
* @Note -> La fonction MyTimer_Base_Init doit avoir ete lancee au prealable
*************************************************************************************************
*/
void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void));
#define MyTimer_Base_Start(Timer) (Timer->CR1 |= 0x01)
#define MyTimer_Base_Stop(Timer) (Timer->CR1 &= ~0x01)
ADC_TypeDef * ADC;
char channel;
} MyADC_Struct_TypeDef;
void MyADC_init(MyADC_Struct_TypeDef* myADC);
#endif

View file

@ -1,92 +1,137 @@
#include "TIMER.h"
#include "ADC.h"
/*periode_timer=peridoe_horloge*prescaler*resolution
debordement stocké dans registre UIF
fixer val prescaler+ autoreload(equivalent resolution)
demarrage timer => CEN=1*/
void (*ptr_func)(void);
void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer)
void MyADC_init(MyADC_Struct_TypeDef* myADC)
{
if(Timer->Timer==TIM1)
MyGPIO_Struct_TypeDef Port_ADC;
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6;
if(myADC->ADC==ADC1)
{
RCC->APB2ENR |= 0x01<<11;
RCC->APB2ENR |= 0x01<<9;
ADC1->CR2|= 0x01; // on active l'adc
ADC1->SQR1&= ~(0x0F<<20);// 1 convertion
ADC2->SQR3&= ~0x1F;// on met 0 la séquance 1
ADC1->SQR3|= myADC->channel;// on indique le channel a convertir
}
else if (Timer->Timer==TIM2)
else if(myADC->ADC==ADC2)
{
RCC->APB1ENR |= 0x01;
RCC->APB2ENR |= 0x01<<8;
ADC2->CR2|= 0x01; // on active l'adc
ADC2->SQR1&= ~(0x0F<<20);// 1 convertion
ADC2->SQR3&= ~0x1F;// on met 0 la séquance 1
ADC2->SQR3|= myADC->channel;// on indique le channel a convertir
}
else if (Timer->Timer==TIM3)
{
RCC->APB1ENR |= 0x01<<1;
}
else if (Timer->Timer==TIM4)
{
RCC->APB1ENR |= 0x01<<2;
}
Timer->Timer->ARR=Timer->ARR;
Timer->Timer->PSC=Timer->PSC;
}
void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void))
{
int num_tim;
ptr_func=IT_function;
Timer->DIER |= 0x01;
if(Timer==TIM1)
{
num_tim=TIM1_UP_IRQn;
}
else if(Timer==TIM2)
{
num_tim=TIM2_IRQn;
}
else if(Timer==TIM3)
{
num_tim=TIM3_IRQn;
}
else if(Timer==TIM4)
{
num_tim=TIM4_IRQn;
}
NVIC->ISER[0] |= 0x01<<num_tim;
NVIC->IP[num_tim] |= Prio << 4;
switch (myADC->channel)
{
case 0:
Port_ADC.GPIO=GPIOA;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=0;
MyGPIO_Init(&Port_ADC);
break;
case 1:
Port_ADC.GPIO=GPIOA;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=1;
MyGPIO_Init(&Port_ADC);
break;
case 2:
Port_ADC.GPIO=GPIOA;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=2;
MyGPIO_Init(&Port_ADC);
break;
case 3:
Port_ADC.GPIO=GPIOA;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=3;
MyGPIO_Init(&Port_ADC);
break;
case 4:
Port_ADC.GPIO=GPIOA;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=4;
MyGPIO_Init(&Port_ADC);
break;
case 5:
Port_ADC.GPIO=GPIOA;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=5;
MyGPIO_Init(&Port_ADC);
break;
case 6:
Port_ADC.GPIO=GPIOA;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=6;
MyGPIO_Init(&Port_ADC);
break;
case 7:
Port_ADC.GPIO=GPIOA;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=7;
MyGPIO_Init(&Port_ADC);
break;
case 8:
Port_ADC.GPIO=GPIOB;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=0;
MyGPIO_Init(&Port_ADC);
break;
case 9:
Port_ADC.GPIO=GPIOB;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=1;
MyGPIO_Init(&Port_ADC);
break;
case 10:
Port_ADC.GPIO=GPIOC;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=0;
MyGPIO_Init(&Port_ADC);
break;
case 11:
Port_ADC.GPIO=GPIOC;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=1;
MyGPIO_Init(&Port_ADC);
break;
case 12:
Port_ADC.GPIO=GPIOC;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=2;
MyGPIO_Init(&Port_ADC);
break;
case 13:
Port_ADC.GPIO=GPIOC;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=3;
MyGPIO_Init(&Port_ADC);
break;
case 14:
Port_ADC.GPIO=GPIOC;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=4;
MyGPIO_Init(&Port_ADC);
break;
case 15:
Port_ADC.GPIO=GPIOC;
Port_ADC.GPIO_Conf=In_Analog;
Port_ADC.GPIO_Pin=5;
MyGPIO_Init(&Port_ADC);
break;
}
}
void TIM2_IRQHandler (void)
{
if(ptr_func!=0)
int conversion(MyADC_Struct_TypeDef* myADC)
{
(*ptr_func)();
}
TIM2->SR &= ~(1<<0) ;
if()
{
}
ADC1->CR2 |= ADC_CR2_ADON; // lancement de la conversion
While(!(ADC1->SR & ADC_SR_EOC) ) {} // attente de la fin de conversion
ADC1->SR &= ~ADC_SR_EOC; // validation de la conversion
return ADC1->DR & ~((0x0F) << 12); // retour de la conversion
}
void TIM3_IRQHandler (void)
{
if(ptr_func!=0)
{
(*ptr_func)();
}
TIM3->SR &= ~(1<<0) ;
}
void TIM4_IRQHandler (void)
{
if(ptr_func!=0)
{
(*ptr_func)();
}
TIM4->SR &= ~(1<<0) ;
}
void TIM1_UP_IRQHandler (void) // à vérifier
{
if(ptr_func!=0)
{
(*ptr_func)();
}
TIM1->SR &= ~(1<<0) ;
}

View file

@ -5,7 +5,10 @@ debordement stock
fixer val prescaler+ autoreload(equivalent resolution)
demarrage timer => CEN=1*/
void (*ptr_func)(void);
void (*ptr1_func)(void);
void (*ptr2_func)(void);
void (*ptr3_func)(void);
void (*ptr4_func)(void);
void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer)
{
@ -32,23 +35,26 @@ void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer)
void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void))
{
int num_tim;
ptr_func=IT_function;
Timer->DIER |= 0x01;
if(Timer==TIM1)
{
num_tim=TIM1_UP_IRQn;
num_tim=TIM1_UP_IRQn;
ptr1_func=IT_function;
}
else if(Timer==TIM2)
{
num_tim=TIM2_IRQn;
ptr2_func=IT_function;
}
else if(Timer==TIM3)
{
num_tim=TIM3_IRQn;
ptr3_func=IT_function;
}
else if(Timer==TIM4)
{
num_tim=TIM4_IRQn;
ptr4_func=IT_function;
}
NVIC->ISER[0] |= 0x01<<num_tim;
NVIC->IP[num_tim] |= Prio << 4;
@ -57,36 +63,36 @@ void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void)
void TIM2_IRQHandler (void)
{
if(ptr_func!=0)
if(ptr2_func!=0)
{
(*ptr_func)();
(*ptr2_func)();
}
TIM2->SR &= ~(1<<0) ;
}
void TIM3_IRQHandler (void)
{
if(ptr_func!=0)
if(ptr3_func!=0)
{
(*ptr_func)();
(*ptr3_func)();
}
TIM3->SR &= ~(1<<0) ;
}
void TIM4_IRQHandler (void)
{
if(ptr_func!=0)
if(ptr4_func!=0)
{
(*ptr_func)();
(*ptr4_func)();
}
TIM4->SR &= ~(1<<0) ;
}
void TIM1_UP_IRQHandler (void) // à vérifier
{
if(ptr_func!=0)
if(ptr1_func!=0)
{
(*ptr_func)();
(*ptr1_func)();
}
TIM1->SR &= ~(1<<0) ;
}

View file

@ -13,19 +13,11 @@ MyTimer_Struct_TypeDef timer2;
int main ( void )
{
PA5.GPIO=GPIOA;
PA5.GPIO_Conf=Out_Ppull;
PA5.GPIO_Pin=5;
MyGPIO_Init(&PA5);
timer2.Timer=TIM2;
timer2.ARR=35999; //pour avoir 500ms
timer2.PSC=1000;
MyTimer_Base_Init(&timer2);
MyTimer_ActiveIT(timer2.Timer,1, &Mafonction_IT);
MyTimer_Base_Start(timer2.Timer);
while(1)
{
}
}

View file

@ -430,6 +430,18 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>1</GroupNumber>
<FileNumber>4</FileNumber>
<FileType>1</FileType>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\Drivers\Src\ADC.c</PathWithFileName>
<FilenameWithoutPath>ADC.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>

View file

@ -398,6 +398,11 @@
<FileType>1</FileType>
<FilePath>..\Drivers\Src\TIMER.c</FilePath>
</File>
<File>
<FileName>ADC.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\Src\ADC.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -800,6 +805,11 @@
<FileType>1</FileType>
<FilePath>..\Drivers\Src\TIMER.c</FilePath>
</File>
<File>
<FileName>ADC.c</FileName>
<FileType>1</FileType>
<FilePath>..\Drivers\Src\ADC.c</FilePath>
</File>
</Files>
</Group>
<Group>