Added second version of timerdriver : Interruption handling v1

This commit is contained in:
Yohan Boujon 2023-03-21 16:07:40 +01:00
parent 952cabdbbe
commit 270263d97c
5 changed files with 57 additions and 22 deletions

View file

@ -1,4 +1,5 @@
#include "timerdriver.h" #include "timerdriver.h"
#include "gpiodriver.h"
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer) void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer)
{ {
@ -13,6 +14,21 @@ void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer)
Timer->Timer->PSC = Timer->PSC; Timer->Timer->PSC = Timer->PSC;
} }
void MyTimer_ActiveIT(TIM_TypeDef * TimerX, uint8_t Prio)
{
uint8_t positionTimerIT = TimerIT2UInt(TimerX);
TimerX->DIER |= (0x1<<UIE);
NVIC->IP[positionTimerIT] |= (Prio << 0x4);
NVIC->ISER[0] |= (0x1<<positionTimerIT);
}
void TIM2_IRQHandler(void)
{
MyGPIO_Toggle(GPIOA,5);
//we reset the flag
TIM2->SR &= ~(0x1<<UIF);
}
int TimerX2Int(TIM_TypeDef * TimerX) int TimerX2Int(TIM_TypeDef * TimerX)
{ {
if(TimerX == TIM1) if(TimerX == TIM1)
@ -47,4 +63,23 @@ int TimerX2Int(TIM_TypeDef * TimerX)
}*/ else { }*/ else {
return -1; return -1;
}; };
} }
uint8_t TimerIT2UInt(TIM_TypeDef * TimerX)
{
if(TimerX == TIM1)
{
return TIM1_CC_IRQn;
} else if(TimerX == TIM2)
{
return TIM2_IRQn;
} else if(TimerX == TIM3)
{
return TIM3_IRQn;
} else if(TimerX == TIM4)
{
return 30;
} else {
return 0;
}
}

View file

@ -2,7 +2,9 @@
#define TIMERDRIVER_H #define TIMERDRIVER_H
#include "stm32f10x.h" #include "stm32f10x.h"
#define CEN 0x0 #define CEN 0x0
#define UIE 0x0
#define UIF 0x0
typedef struct { typedef struct {
TIM_TypeDef * Timer; //TIM1 -> TIM4 TIM_TypeDef * Timer; //TIM1 -> TIM4
@ -12,6 +14,8 @@ typedef struct {
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer); void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer);
int TimerX2Int(TIM_TypeDef * TimerX); int TimerX2Int(TIM_TypeDef * TimerX);
uint8_t TimerIT2UInt(TIM_TypeDef * TimerX);
void MyTimer_ActiveIT(TIM_TypeDef * TimerX, uint8_t Prio);
#define MyTimer_Base_Start(Timer) (Timer->CR1 |= (0x01<<CEN)) #define MyTimer_Base_Start(Timer) (Timer->CR1 |= (0x01<<CEN))
#define MyTimer_Base_Stop(Timer) (Timer->CR1 &= ~(0x01<<CEN)) #define MyTimer_Base_Stop(Timer) (Timer->CR1 &= ~(0x01<<CEN))

View file

@ -4,15 +4,14 @@
int main (void) int main (void)
{ {
int returnValue;
MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led
MyTimer_Struct_TypeDef timer2 = {TIM2,499,7199}; MyTimer_Struct_TypeDef timer2 = {TIM3,499,7199};
MyGPIO_Init(&led); MyGPIO_Init(&led);
MyTimer_Base_Init(&timer2); MyTimer_Base_Init(&timer2);
MyTimer_Base_Start(TIM2); MyTimer_Base_Start(TIM3);
//Pour reset le timer : RCC_APB1RSTR //Pour reset le timer : RCC_APB1RSTR
MyTimer_ActiveIT(TIM3,2);
do{ do{
returnValue = TIM2->CNT;
}while(1) ; }while(1) ;
} }

View file

@ -125,7 +125,7 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>DLGDARM</Key> <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=-1,-1,-1,-1,0)(120=486,94,907,521,1)(121=464,533,885,960,1)(122=875,109,1296,536,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=-1,-1,-1,-1,0)(131=21,94,615,845,1)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,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=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name> <Name>(1010=895,198,1271,755,1)(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=-1,-1,-1,-1,0)(120=486,94,907,521,1)(121=464,533,885,960,1)(122=875,109,1296,536,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=-1,-1,-1,-1,0)(131=1326,229,1920,980,1)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,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=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>

View file

@ -10,14 +10,13 @@
<TargetName>Simulé</TargetName> <TargetName>Simulé</TargetName>
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<pArmCC>6190000::V6.19::ARMCLANG</pArmCC> <pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
<pCCUsed>6190000::V6.19::ARMCLANG</pCCUsed> <uAC6>0</uAC6>
<uAC6>1</uAC6>
<TargetOption> <TargetOption>
<TargetCommonOption> <TargetCommonOption>
<Device>STM32F103RB</Device> <Device>STM32F103RB</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F1xx_DFP.2.4.0</PackID> <PackID>Keil.STM32F1xx_DFP.2.3.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL> <PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu> <Cpu>IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec> <FlashUtilSpec></FlashUtilSpec>
@ -187,7 +186,6 @@
<RvdsVP>0</RvdsVP> <RvdsVP>0</RvdsVP>
<RvdsMve>0</RvdsMve> <RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp> <RvdsCdeCp>0</RvdsCdeCp>
<nBranchProt>0</nBranchProt>
<hadIRAM2>0</hadIRAM2> <hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2> <hadIROM2>0</hadIROM2>
<StupSel>8</StupSel> <StupSel>8</StupSel>
@ -315,7 +313,7 @@
</ArmAdsMisc> </ArmAdsMisc>
<Cads> <Cads>
<interw>1</interw> <interw>1</interw>
<Optim>2</Optim> <Optim>1</Optim>
<oTime>0</oTime> <oTime>0</oTime>
<SplitLS>0</SplitLS> <SplitLS>0</SplitLS>
<OneElfS>1</OneElfS> <OneElfS>1</OneElfS>
@ -324,7 +322,7 @@
<PlainCh>0</PlainCh> <PlainCh>0</PlainCh>
<Ropi>0</Ropi> <Ropi>0</Ropi>
<Rwpi>0</Rwpi> <Rwpi>0</Rwpi>
<wLevel>3</wLevel> <wLevel>2</wLevel>
<uThumb>0</uThumb> <uThumb>0</uThumb>
<uSurpInc>0</uSurpInc> <uSurpInc>0</uSurpInc>
<uC99>0</uC99> <uC99>0</uC99>
@ -423,7 +421,7 @@
<TargetCommonOption> <TargetCommonOption>
<Device>STM32F103RB</Device> <Device>STM32F103RB</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F1xx_DFP.2.4.0</PackID> <PackID>Keil.STM32F1xx_DFP.2.3.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL> <PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu> <Cpu>IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec> <FlashUtilSpec></FlashUtilSpec>
@ -593,7 +591,6 @@
<RvdsVP>0</RvdsVP> <RvdsVP>0</RvdsVP>
<RvdsMve>0</RvdsMve> <RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp> <RvdsCdeCp>0</RvdsCdeCp>
<nBranchProt>0</nBranchProt>
<hadIRAM2>0</hadIRAM2> <hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2> <hadIROM2>0</hadIROM2>
<StupSel>8</StupSel> <StupSel>8</StupSel>
@ -824,15 +821,15 @@
<RTE> <RTE>
<apis/> <apis/>
<components> <components>
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.6.0" condition="ARMv6_7_8-M Device"> <component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.4.0" condition="ARMv6_7_8-M Device">
<package name="CMSIS" schemaVersion="1.7.7" url="http://www.keil.com/pack/" vendor="ARM" version="5.9.0"/> <package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.7.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Réel"/> <targetInfo name="Réel"/>
<targetInfo name="Simulé"/> <targetInfo name="Simulé"/>
</targetInfos> </targetInfos>
</component> </component>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"> <component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS">
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Réel"/> <targetInfo name="Réel"/>
<targetInfo name="Simulé"/> <targetInfo name="Simulé"/>
@ -843,7 +840,7 @@
<file attr="config" category="header" name="RTE_Driver\Config\RTE_Device.h" version="1.1.2"> <file attr="config" category="header" name="RTE_Driver\Config\RTE_Device.h" version="1.1.2">
<instance index="0">RTE\Device\STM32F103RB\RTE_Device.h</instance> <instance index="0">RTE\Device\STM32F103RB\RTE_Device.h</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/> <component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Réel"/> <targetInfo name="Réel"/>
<targetInfo name="Simulé"/> <targetInfo name="Simulé"/>
@ -852,7 +849,7 @@
<file attr="config" category="source" condition="STM32F1xx MD ARMCC" name="Device\Source\ARM\startup_stm32f10x_md.s" version="1.0.1"> <file attr="config" category="source" condition="STM32F1xx MD ARMCC" name="Device\Source\ARM\startup_stm32f10x_md.s" version="1.0.1">
<instance index="0">RTE\Device\STM32F103RB\startup_stm32f10x_md.s</instance> <instance index="0">RTE\Device\STM32F103RB\startup_stm32f10x_md.s</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/> <component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Réel"/> <targetInfo name="Réel"/>
<targetInfo name="Simulé"/> <targetInfo name="Simulé"/>
@ -861,7 +858,7 @@
<file attr="config" category="source" name="Device\Source\system_stm32f10x.c" version="1.0.1"> <file attr="config" category="source" name="Device\Source\system_stm32f10x.c" version="1.0.1">
<instance index="0">RTE\Device\STM32F103RB\system_stm32f10x.c</instance> <instance index="0">RTE\Device\STM32F103RB\system_stm32f10x.c</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/> <component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.3.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Réel"/> <targetInfo name="Réel"/>
<targetInfo name="Simulé"/> <targetInfo name="Simulé"/>