186 lines
6.7 KiB
C
186 lines
6.7 KiB
C
#include "McuBspTimer.h"
|
|
|
|
static uint32_t gMcuBspTimerTick[MCU_BSP_TIMER_ALL_NUM] = {0};
|
|
|
|
static void McuBspTimer0aIntHandler(void);
|
|
static void McuBspTimer1aIntHandler(void);
|
|
static void McuBspTimer2aIntHandler(void);
|
|
static void McuBspTimer3aIntHandler(void);
|
|
static void McuBspTimer4aIntHandler(void);
|
|
static void McuBspTimer5aIntHandler(void);
|
|
static void McuBspTimer6aIntHandler(void);
|
|
static void McuBspTimer7aIntHandler(void);
|
|
|
|
int McuBspTimerInit(uint8_t TimerId, uint16_t PeriodMs)
|
|
{
|
|
if (TimerId >= MCU_BSP_TIMER_ALL_NUM) {
|
|
return -1;
|
|
}
|
|
if (TimerId == MCU_BSP_TIMER_0) {
|
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
|
|
TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC);
|
|
TimerLoadSet(TIMER0_BASE, TIMER_A, (SysFreqGet() / 1000) * PeriodMs);
|
|
IntEnable(INT_TIMER0A);
|
|
BSP_IntVectSet((CPU_INT08U)BSP_INT_ID_TMR0A, (CPU_FNCT_VOID)McuBspTimer0aIntHandler);
|
|
BSP_IntEn(BSP_INT_ID_TMR0A);
|
|
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
|
|
TimerEnable(TIMER0_BASE, TIMER_A);
|
|
} else if (TimerId == MCU_BSP_TIMER_1) {
|
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
|
|
TimerConfigure(TIMER1_BASE, TIMER_CFG_A_PERIODIC);
|
|
TimerLoadSet(TIMER1_BASE, TIMER_A, (SysFreqGet() / 1000) * PeriodMs);
|
|
IntEnable(INT_TIMER1A);
|
|
BSP_IntVectSet((CPU_INT08U)BSP_INT_ID_TMR1A, (CPU_FNCT_VOID)McuBspTimer1aIntHandler);
|
|
BSP_IntEn(BSP_INT_ID_TMR1A);
|
|
TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
|
|
TimerEnable(TIMER1_BASE, TIMER_A);
|
|
} else if (TimerId == MCU_BSP_TIMER_2) {
|
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
|
|
TimerConfigure(TIMER2_BASE, TIMER_CFG_A_PERIODIC);
|
|
TimerLoadSet(TIMER2_BASE, TIMER_A, (SysFreqGet() / 1000) * PeriodMs);
|
|
IntEnable(INT_TIMER2A);
|
|
BSP_IntVectSet((CPU_INT08U)BSP_INT_ID_TMR2A, (CPU_FNCT_VOID)McuBspTimer2aIntHandler);
|
|
BSP_IntEn(BSP_INT_ID_TMR2A);
|
|
TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT);
|
|
TimerEnable(TIMER2_BASE, TIMER_A);
|
|
} else if (TimerId == MCU_BSP_TIMER_3) {
|
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
|
|
TimerConfigure(TIMER3_BASE, TIMER_CFG_A_PERIODIC);
|
|
TimerLoadSet(TIMER3_BASE, TIMER_A, (SysFreqGet() / 1000) * PeriodMs);
|
|
IntEnable(INT_TIMER3A);
|
|
BSP_IntVectSet((CPU_INT08U)BSP_INT_ID_TMR3A, (CPU_FNCT_VOID)McuBspTimer3aIntHandler);
|
|
BSP_IntEn(BSP_INT_ID_TMR3A);
|
|
TimerIntEnable(TIMER3_BASE, TIMER_TIMA_TIMEOUT);
|
|
TimerEnable(TIMER3_BASE, TIMER_A);
|
|
} else if (TimerId == MCU_BSP_TIMER_4) {
|
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
|
|
TimerConfigure(TIMER4_BASE, TIMER_CFG_A_PERIODIC);
|
|
TimerLoadSet(TIMER4_BASE, TIMER_A, (SysFreqGet() / 1000) * PeriodMs);
|
|
IntEnable(INT_TIMER4A);
|
|
BSP_IntVectSet((CPU_INT08U)BSP_INT_ID_TMR4A, (CPU_FNCT_VOID)McuBspTimer4aIntHandler);
|
|
BSP_IntEn(BSP_INT_ID_TMR4A);
|
|
TimerIntEnable(TIMER4_BASE, TIMER_TIMA_TIMEOUT);
|
|
TimerEnable(TIMER4_BASE, TIMER_A);
|
|
} else if (TimerId == MCU_BSP_TIMER_5) {
|
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5);
|
|
TimerConfigure(TIMER5_BASE, TIMER_CFG_A_PERIODIC);
|
|
TimerLoadSet(TIMER5_BASE, TIMER_A, (SysFreqGet() / 1000) * PeriodMs);
|
|
IntEnable(INT_TIMER5A);
|
|
BSP_IntVectSet((CPU_INT08U)BSP_INT_ID_TMR5A, (CPU_FNCT_VOID)McuBspTimer5aIntHandler);
|
|
BSP_IntEn(BSP_INT_ID_TMR5A);
|
|
TimerIntEnable(TIMER5_BASE, TIMER_TIMA_TIMEOUT);
|
|
TimerEnable(TIMER5_BASE, TIMER_A);
|
|
} else if (TimerId == MCU_BSP_TIMER_6) {
|
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER6);
|
|
TimerConfigure(TIMER6_BASE, TIMER_CFG_A_PERIODIC);
|
|
TimerLoadSet(TIMER6_BASE, TIMER_A, (SysFreqGet() / 1000) * PeriodMs);
|
|
IntEnable(INT_TIMER6A);
|
|
BSP_IntVectSet((CPU_INT08U)BSP_INT_ID_TMR6A, (CPU_FNCT_VOID)McuBspTimer6aIntHandler);
|
|
BSP_IntEn(BSP_INT_ID_TMR6A);
|
|
TimerIntEnable(TIMER6_BASE, TIMER_TIMA_TIMEOUT);
|
|
TimerEnable(TIMER6_BASE, TIMER_A);
|
|
} else if (TimerId == MCU_BSP_TIMER_7) {
|
|
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER7);
|
|
TimerConfigure(TIMER7_BASE, TIMER_CFG_A_PERIODIC);
|
|
TimerLoadSet(TIMER7_BASE, TIMER_A, (SysFreqGet() / 1000) * PeriodMs);
|
|
IntEnable(INT_TIMER7A);
|
|
BSP_IntVectSet((CPU_INT08U)BSP_INT_ID_TMR7A, (CPU_FNCT_VOID)McuBspTimer7aIntHandler);
|
|
BSP_IntEn(BSP_INT_ID_TMR7A);
|
|
TimerIntEnable(TIMER7_BASE, TIMER_TIMA_TIMEOUT);
|
|
TimerEnable(TIMER7_BASE, TIMER_A);
|
|
} else {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int McuBspTimerTick(uint8_t TimerId, uint32_t *tick)
|
|
{
|
|
if ((TimerId > MCU_BSP_TIMER_ALL_NUM) || (tick == NULL)) {
|
|
return -1;
|
|
}
|
|
*tick = gMcuBspTimerTick[TimerId];
|
|
return 0;
|
|
}
|
|
|
|
static void McuBspTimer0aIntHandler(void)
|
|
{
|
|
CPU_SR_ALLOC();
|
|
OSIntEnter(); //通知系统进入OS中断
|
|
OS_ENTER_CRITICAL();
|
|
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
|
|
gMcuBspTimerTick[0]++;
|
|
OS_EXIT_CRITICAL();
|
|
OSIntExit();
|
|
}
|
|
static void McuBspTimer1aIntHandler(void)
|
|
{
|
|
CPU_SR_ALLOC();
|
|
OSIntEnter(); //通知系统进入OS中断
|
|
OS_ENTER_CRITICAL();
|
|
TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
|
|
gMcuBspTimerTick[1]++;
|
|
OS_EXIT_CRITICAL();
|
|
OSIntExit();
|
|
}
|
|
static void McuBspTimer2aIntHandler(void)
|
|
{
|
|
CPU_SR_ALLOC();
|
|
OSIntEnter(); //通知系统进入OS中断
|
|
OS_ENTER_CRITICAL();
|
|
TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT);
|
|
gMcuBspTimerTick[2]++;
|
|
OS_EXIT_CRITICAL();
|
|
OSIntExit();
|
|
}
|
|
static void McuBspTimer3aIntHandler(void)
|
|
{
|
|
CPU_SR_ALLOC();
|
|
OSIntEnter(); //通知系统进入OS中断
|
|
OS_ENTER_CRITICAL();
|
|
TimerIntClear(TIMER3_BASE, TIMER_TIMA_TIMEOUT);
|
|
gMcuBspTimerTick[3]++;
|
|
OS_EXIT_CRITICAL();
|
|
OSIntExit();
|
|
}
|
|
static void McuBspTimer4aIntHandler(void)
|
|
{
|
|
CPU_SR_ALLOC();
|
|
OSIntEnter(); //通知系统进入OS中断
|
|
OS_ENTER_CRITICAL();
|
|
TimerIntClear(TIMER4_BASE, TIMER_TIMA_TIMEOUT);
|
|
gMcuBspTimerTick[4]++;
|
|
OS_EXIT_CRITICAL();
|
|
OSIntExit();
|
|
}
|
|
static void McuBspTimer5aIntHandler(void)
|
|
{
|
|
CPU_SR_ALLOC();
|
|
OSIntEnter(); //通知系统进入OS中断
|
|
OS_ENTER_CRITICAL();
|
|
TimerIntClear(TIMER5_BASE, TIMER_TIMA_TIMEOUT);
|
|
gMcuBspTimerTick[5]++;
|
|
OS_EXIT_CRITICAL();
|
|
OSIntExit();
|
|
}
|
|
static void McuBspTimer6aIntHandler(void)
|
|
{
|
|
CPU_SR_ALLOC();
|
|
OSIntEnter(); //通知系统进入OS中断
|
|
OS_ENTER_CRITICAL();
|
|
TimerIntClear(TIMER6_BASE, TIMER_TIMA_TIMEOUT);
|
|
gMcuBspTimerTick[6]++;
|
|
OS_EXIT_CRITICAL();
|
|
OSIntExit();
|
|
}
|
|
static void McuBspTimer7aIntHandler(void)
|
|
{
|
|
CPU_SR_ALLOC();
|
|
OSIntEnter(); //通知系统进入OS中断
|
|
OS_ENTER_CRITICAL();
|
|
TimerIntClear(TIMER7_BASE, TIMER_TIMA_TIMEOUT);
|
|
gMcuBspTimerTick[7]++;
|
|
OS_EXIT_CRITICAL();
|
|
OSIntExit();
|
|
}
|