Browse Source

add timer[3-6] to lib/timer.c

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 5 years ago
parent
commit
80367cdc12
  1. 16
      lib/config.h
  2. 85
      lib/timer.c
  3. 16
      lib/timer.h

16
lib/config.h

@ -78,6 +78,22 @@ extern "C" {
#define TARGET_HAS_TIM3 0
#endif
#ifndef TARGET_HAS_TIM4
#define TARGET_HAS_TIM4 0
#endif
#ifndef TARGET_HAS_TIM5
#define TARGET_HAS_TIM5 0
#endif
#ifndef TARGET_HAS_TIM6
#define TARGET_HAS_TIM6 0
#endif
#ifndef TARGET_HAS_TIM7
#define TARGET_HAS_TIM7 0
#endif
/* for command handler */
#ifndef TARGET_CMD_BUFSIZE
#define TARGET_CMD_BUFSIZE (256)

85
lib/timer.c

@ -98,6 +98,11 @@ static void __attribute__((unused)) tim_isr(struct timer *tm)
}
}
static void __attribute__((unused)) tim_rcc_setup(struct timer *tm)
{
RCC_APB1PeriphClockCmd(tm->rcc, ENABLE);
}
#if (TARGET_HAS_TIM1)
static void tim1_setup(struct timer *tm)
{
@ -120,15 +125,10 @@ void TIM1_UP_TIM10_IRQHandler()
#endif
#if (TARGET_HAS_TIM2)
static void tim2_setup(struct timer *tm)
{
RCC_APB1PeriphClockCmd(tm->rcc, ENABLE);
}
struct timer timer1 = {
.name = "TIM2",
.tim = TIM2,
.setup = tim2_setup,
.setup = tim_rcc_setup,
.rcc = RCC_APB1Periph_TIM2,
.irq = TIM2_IRQn,
.irq_priority = -1,
@ -141,15 +141,10 @@ void TIM2_IRQHandler()
#endif
#if (TARGET_HAS_TIM3)
static void tim3_setup(struct timer *tm)
{
RCC_APB1PeriphClockCmd(tm->rcc, ENABLE);
}
struct timer timer2 = {
.name = "TIM1",
.name = "TIM3",
.tim = TIM3,
.setup = tim3_setup,
.setup = tim_rcc_setup,
.rcc = RCC_APB1Periph_TIM3,
.irq = TIM3_IRQn,
.irq_priority = -1,
@ -161,3 +156,67 @@ void TIM3_IRQHandler()
}
#endif
#if (TARGET_HAS_TIM4)
struct timer timer3 = {
.name = "TIM4",
.tim = TIM4,
.setup = tim_rcc_setup,
.rcc = RCC_APB1Periph_TIM4,
.irq = TIM4_IRQn,
.irq_priority = -1,
};
void TIM4_IRQHandler()
{
tim_isr(&timer3);
}
#endif
#if (TARGET_HAS_TIM5)
struct timer timer4 = {
.name = "TIM5",
.tim = TIM5,
.setup = tim_rcc_setup,
.rcc = RCC_APB1Periph_TIM5,
.irq = TIM5_IRQn,
.irq_priority = -1,
};
void TIM5_IRQHandler()
{
tim_isr(&timer4);
}
#endif
#if (TARGET_HAS_TIM6)
struct timer timer5 = {
.name = "TIM6",
.tim = TIM6,
.setup = tim_rcc_setup,
.rcc = RCC_APB1Periph_TIM6,
.irq = TIM6_DAC_IRQn,
.irq_priority = -1,
};
void TIM6_DAC_IRQHandler()
{
tim_isr(&timer5);
}
#endif
#if (TARGET_HAS_TIM7)
struct timer timer6 = {
.name = "TIM7",
.tim = TIM7,
.setup = tim_rcc_setup,
.rcc = RCC_APB1Periph_TIM7,
.irq = TIM7_IRQn,
.irq_priority = -1,
};
void TIM7_IRQHandler()
{
tim_isr(&timer6);
}
#endif

16
lib/timer.h

@ -29,5 +29,21 @@ extern struct timer timer1;
extern struct timer timer2;
#endif
#if (TARGET_HAS_TIM4)
extern struct timer timer3;
#endif
#if (TARGET_HAS_TIM5)
extern struct timer timer4;
#endif
#if (TARGET_HAS_TIM6)
extern struct timer timer5;
#endif
#if (TARGET_HAS_TIM7)
extern struct timer timer6;
#endif
#endif

Loading…
Cancel
Save