📄 drvtimer.c
字号:
bIsTimer3Used = FALSE;
bIsSetTime3Event = FALSE;
break;
}
default:
{
return E_DRVTIMER_CHANNEL ;
}
}
return E_SUCCESS;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvTIMER_SetTimerEvent */
/* */
/* Parameters: */
/* ch - [in] */
/* E_TIMER_CHANNEL, it could be E_TMR0/E_TMR1/E_TMR2/E_TMR3 */
/* uInterruptTicks - [in] */
/* Number of timer interrupt occurred */
/* pTimerCallback - [in] */
/* The function pointer of the interrupt callback function */
/* parameter - [in] */
/* A parameter of the callback function */
/* */
/* Returns: */
/* uTimerEventNo The timer event number */
/* E_DRVTIMER_EVENT_FULL The timer event is full */
/* Description: */
/* Install the interrupt callback function of the specified timer channel. */
/* And trigger timer callback functuion when interrupt occur specified times. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvTIMER_SetTimerEvent(E_TIMER_CHANNEL ch, uint32_t uInterruptTicks, TIMER_CALLBACK pTimerCallback, uint32_t parameter)
{
volatile int32_t i;
int32_t uTimerEventNo = 0;
switch (ch)
{
case E_TMR0:
{
if (uTime0EventCount >= TIMER_EVENT_COUNT)
return E_DRVTIMER_EVENT_FULL;
bIsSetTime0Event = TRUE;
uTime0EventCount++;
for (i=0; i<TIMER_EVENT_COUNT; i++)
{
if (tTime0Event[i].active == FALSE)
{
tTime0Event[i].active = TRUE;
tTime0Event[i].initTick = uInterruptTicks;
tTime0Event[i].curTick = uInterruptTicks;
tTime0Event[i].funPtr = (TIMER_CALLBACK)pTimerCallback;
tTime0Event[i].transParam = parameter;
uTimerEventNo = i;
break;
}
}
break;
}
case E_TMR1:
{
if (uTime1EventCount >= TIMER_EVENT_COUNT)
return E_DRVTIMER_EVENT_FULL;
bIsSetTime1Event = TRUE;
uTime1EventCount++;
for (i=0; i<TIMER_EVENT_COUNT; i++)
{
if (tTime1Event[i].active == FALSE)
{
tTime1Event[i].active = TRUE;
tTime1Event[i].initTick = uInterruptTicks;
tTime1Event[i].curTick = uInterruptTicks;
tTime1Event[i].funPtr = (TIMER_CALLBACK)pTimerCallback;
tTime1Event[i].transParam = parameter;
uTimerEventNo = i;
break;
}
}
break;
}
case E_TMR2:
{
if (uTime2EventCount >= TIMER_EVENT_COUNT)
return E_DRVTIMER_EVENT_FULL;
bIsSetTime2Event = TRUE;
uTime2EventCount++;
for (i=0; i<TIMER_EVENT_COUNT; i++)
{
if (tTime2Event[i].active == FALSE)
{
tTime2Event[i].active = TRUE;
tTime2Event[i].initTick = uInterruptTicks;
tTime2Event[i].curTick = uInterruptTicks;
tTime2Event[i].funPtr = (TIMER_CALLBACK)pTimerCallback;
tTime2Event[i].transParam = parameter;
uTimerEventNo = i;
break;
}
}
break;
}
case E_TMR3:
{
if (uTime3EventCount >= TIMER_EVENT_COUNT)
return E_DRVTIMER_EVENT_FULL;
bIsSetTime3Event = TRUE;
uTime3EventCount++;
for (i=0; i<TIMER_EVENT_COUNT; i++)
{
if (tTime3Event[i].active == FALSE)
{
tTime3Event[i].active = TRUE;
tTime3Event[i].initTick = uInterruptTicks;
tTime3Event[i].curTick = uInterruptTicks;
tTime3Event[i].funPtr = (TIMER_CALLBACK)pTimerCallback;
tTime3Event[i].transParam = parameter;
uTimerEventNo = i;
break;
}
}
break;
}
default:
{
break;
}
}
return uTimerEventNo;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvTIMER_ClearTimerEvent */
/* */
/* Parameters: */
/* ch - [in] */
/* E_TIMER_CHANNEL, it could be E_TMR0/E_TMR1/E_TMR2/E_TMR3 */
/* uTimerEventNo - [in] */
/* The timer event number */
/* Returns: */
/* None */
/* Description: */
/* Clear the timer event of the specified timer channel. */
/*---------------------------------------------------------------------------------------------------------*/
void DrvTIMER_ClearTimerEvent(E_TIMER_CHANNEL ch, uint32_t uTimerEventNo)
{
switch (ch)
{
case E_TMR0:
{
tTime0Event[uTimerEventNo].active = FALSE;
uTime0EventCount--;
if (uTime0EventCount == 0)
{
bIsSetTime0Event = FALSE;
}
break;
}
case E_TMR1:
{
tTime1Event[uTimerEventNo].active = FALSE;
uTime1EventCount--;
if (uTime1EventCount == 0)
{
bIsSetTime1Event = FALSE;
}
break;
}
case E_TMR2:
{
tTime2Event[uTimerEventNo].active = FALSE;
uTime2EventCount--;
if (uTime2EventCount == 0)
{
bIsSetTime2Event = FALSE;
}
break;
}
case E_TMR3:
{
tTime3Event[uTimerEventNo].active = FALSE;
uTime3EventCount--;
if (uTime3EventCount == 0)
{
bIsSetTime3Event = FALSE;
}
break;
}
default:
{
break;
}
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvTIMER_EnableInt */
/* */
/* Parameters: */
/* ch - [in] */
/* E_TIMER_CHANNEL, it could be E_TMR0/E_TMR1/E_TMR2/E_TMR3 */
/* Returns: */
/* E_SUCCESS Operation successful */
/* E_DRVTIMER_CHANNEL Invalid Timer channel */
/* Description: */
/* This function is used to enable the specified timer interrupt. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvTIMER_EnableInt(E_TIMER_CHANNEL ch)
{
TIMER_T * tTMR;
switch (ch)
{
case E_TMR0:
case E_TMR1:
case E_TMR2:
case E_TMR3:
{
tTMR = (TIMER_T *)((uint32_t)TIMER0 + CH_OFFSET[ch]);
tTMR->TCSR.IE = 1;
NVIC_SetPriority((IRQn_Type)((uint32_t)TMR0_IRQn + (uint32_t)ch), (1<<__NVIC_PRIO_BITS) - 2);
NVIC_EnableIRQ((IRQn_Type)((uint32_t)TMR0_IRQn + (uint32_t)ch));
return E_SUCCESS ;
}
default:
{
return E_DRVTIMER_CHANNEL ;
}
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvTIMER_DisableInt */
/* */
/* Parameters: */
/* ch - [in] */
/* E_TIMER_CHANNEL, it could be E_TMR0/E_TMR1/E_TMR2/E_TMR3 */
/* Returns: */
/* E_SUCCESS Operation successful */
/* E_DRVTIMER_CHANNEL Invalid Timer channel */
/* Description: */
/* This function is used to disable the specified timer interrupt */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvTIMER_DisableInt(E_TIMER_CHANNEL ch)
{
TIMER_T * tTMR;
switch (ch)
{
case E_TMR0:
case E_TMR1:
case E_TMR2:
case E_TMR3:
{
tTMR = (TIMER_T *)((uint32_t)TIMER0 + CH_OFFSET[ch]);
tTMR->TCSR.IE = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -