forked from trocache/RefKEIL
Interruptions are now generic, with a given function which does the trick
This commit is contained in:
parent
270263d97c
commit
5c8ef23fd2
4 changed files with 49 additions and 14 deletions
|
@ -1,6 +1,13 @@
|
||||||
#include "timerdriver.h"
|
#include "timerdriver.h"
|
||||||
#include "gpiodriver.h"
|
#include "gpiodriver.h"
|
||||||
|
|
||||||
|
void (* pFnc) (void); /* déclaration d’un pointeur de fonction */
|
||||||
|
|
||||||
|
void Init_Periph (void (* ptrFonction)(void))
|
||||||
|
{
|
||||||
|
pFnc = ptrFonction; /* affectation du pointeur */
|
||||||
|
}
|
||||||
|
|
||||||
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer)
|
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer)
|
||||||
{
|
{
|
||||||
//TIM1 uses the APB2ENR register from RCC. The others uses the APB1ENR, so we check this value.
|
//TIM1 uses the APB2ENR register from RCC. The others uses the APB1ENR, so we check this value.
|
||||||
|
@ -22,13 +29,6 @@ void MyTimer_ActiveIT(TIM_TypeDef * TimerX, uint8_t Prio)
|
||||||
NVIC->ISER[0] |= (0x1<<positionTimerIT);
|
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)
|
||||||
|
@ -83,3 +83,28 @@ uint8_t TimerIT2UInt(TIM_TypeDef * TimerX)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TIM1_CC_IRQHandler(void)
|
||||||
|
{
|
||||||
|
if (pFnc != 0)
|
||||||
|
(*pFnc) (); /* appel indirect de la fonction */
|
||||||
|
}
|
||||||
|
|
||||||
|
void TIM2_IRQHandler(void)
|
||||||
|
{
|
||||||
|
if (pFnc != 0)
|
||||||
|
(*pFnc) (); /* appel indirect de la fonction */
|
||||||
|
TIM2->SR &= ~(0x1<<UIF);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TIM3_IRQHandler(void)
|
||||||
|
{
|
||||||
|
if (pFnc != 0)
|
||||||
|
(*pFnc) (); /* appel indirect de la fonction */
|
||||||
|
}
|
||||||
|
|
||||||
|
void TIM4_IRQHandler(void)
|
||||||
|
{
|
||||||
|
if (pFnc != 0)
|
||||||
|
(*pFnc) (); /* appel indirect de la fonction */
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer);
|
||||||
int TimerX2Int(TIM_TypeDef * TimerX);
|
int TimerX2Int(TIM_TypeDef * TimerX);
|
||||||
uint8_t TimerIT2UInt(TIM_TypeDef * TimerX);
|
uint8_t TimerIT2UInt(TIM_TypeDef * TimerX);
|
||||||
void MyTimer_ActiveIT(TIM_TypeDef * TimerX, uint8_t Prio);
|
void MyTimer_ActiveIT(TIM_TypeDef * TimerX, uint8_t Prio);
|
||||||
|
void Init_Periph (void (* ptrFonction)(void));
|
||||||
|
|
||||||
#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))
|
||||||
|
|
|
@ -2,15 +2,24 @@
|
||||||
#include "../../Drivers/gpiodriver.h"
|
#include "../../Drivers/gpiodriver.h"
|
||||||
#include "../../Drivers/timerdriver.h"
|
#include "../../Drivers/timerdriver.h"
|
||||||
|
|
||||||
|
void ToggleLed(void)
|
||||||
|
{
|
||||||
|
MyGPIO_Toggle(GPIOA,5);
|
||||||
|
}
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led
|
MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led
|
||||||
MyTimer_Struct_TypeDef timer2 = {TIM3,499,7199};
|
MyTimer_Struct_TypeDef timer2 = {TIM2,499,7199}; //timer
|
||||||
|
|
||||||
|
//init & start LED, Timer
|
||||||
MyGPIO_Init(&led);
|
MyGPIO_Init(&led);
|
||||||
MyTimer_Base_Init(&timer2);
|
MyTimer_Base_Init(&timer2);
|
||||||
MyTimer_Base_Start(TIM3);
|
MyTimer_Base_Start(TIM2);
|
||||||
//Pour reset le timer : RCC_APB1RSTR
|
|
||||||
MyTimer_ActiveIT(TIM3,2);
|
//Init Interruption & Activate
|
||||||
|
Init_Periph(ToggleLed);
|
||||||
|
MyTimer_ActiveIT(TIM2,2);
|
||||||
do{
|
do{
|
||||||
}while(1) ;
|
}while(1) ;
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
<OPTFL>
|
<OPTFL>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>1</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<IsCurrentTarget>1</IsCurrentTarget>
|
<IsCurrentTarget>0</IsCurrentTarget>
|
||||||
</OPTFL>
|
</OPTFL>
|
||||||
<CpuCode>18</CpuCode>
|
<CpuCode>18</CpuCode>
|
||||||
<DebugOpt>
|
<DebugOpt>
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Key>DLGDARM</Key>
|
<Key>DLGDARM</Key>
|
||||||
<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>
|
<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=150,186,744,937,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>
|
||||||
|
@ -257,7 +257,7 @@
|
||||||
<OPTFL>
|
<OPTFL>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>1</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<IsCurrentTarget>0</IsCurrentTarget>
|
<IsCurrentTarget>1</IsCurrentTarget>
|
||||||
</OPTFL>
|
</OPTFL>
|
||||||
<CpuCode>18</CpuCode>
|
<CpuCode>18</CpuCode>
|
||||||
<DebugOpt>
|
<DebugOpt>
|
||||||
|
|
Loading…
Reference in a new issue