Commit d19ce431 authored by 张金硕's avatar 张金硕

🐞 fix:修改RTE_TIM40.c的QAC问题

parent d6b4d355
...@@ -222,57 +222,72 @@ void RTE_Calc_Freq(uint8_t u8ch) ...@@ -222,57 +222,72 @@ void RTE_Calc_Freq(uint8_t u8ch)
uint16_t u16TSR; uint16_t u16TSR;
uint8_t u8RollingCh = 0; uint8_t u8RollingCh = 0;
switch (u8ch) if((u8ch < 0) || (u8ch >= RTE_TIM40_CH_SUM))
{ {
case RTE_TIM40_CH0: ;
u16TDR = TM40->TDR[0U];
u16TSR = TM40->TSR[0U];
break;
case RTE_TIM40_CH1:
u16TDR = TM40->TDR[1U];
u16TSR = TM40->TSR[1U];
u8RollingCh = 0U;
break;
case RTE_TIM40_CH2:
u16TDR = TM40->TDR[2U];
u16TSR = TM40->TSR[2U];
break;
case RTE_TIM40_CH3:
u16TDR = TM40->TDR[3U];
u16TSR = TM40->TSR[3U];
break;
default:
u16TDR = TM40->TDR[0U];
u16TSR = TM40->TSR[0U];
break;
}
if (1U == (u16TSR & _0001_TM4_OVERFLOW_OCCURS))
{
g_stTIM40CapObj[u8ch].u32Period[g_stTIM40CapObj[u8ch].u8PeriodBufCnt] = (uint32_t)(u16TDR + 1UL) + 0x10000UL;
} }
else else
{ {
g_stTIM40CapObj[u8ch].u32Period[g_stTIM40CapObj[u8ch].u8PeriodBufCnt] = (uint32_t)(u16TDR + 1UL); if((g_stTIM40CapObj[u8ch].u8PeriodBufCnt < 0) || (g_stTIM40CapObj[u8ch].u8PeriodBufCnt >= RTE_TIM40_PERIOD_FILTER_SUM ))
// Fre_In_Channel_Capture_ISR_Reset_Count(FRE_ENGINE,g_stTIM40CapObj[u8ch].u32Period[g_stTIM40CapObj[u8ch].u8PeriodBufCnt]); {
} ;
g_stTIM40CapObj[u8ch].u8PeriodBufCnt++; }
if (g_stTIM40CapObj[u8ch].u8PeriodBufCnt >= RTE_TIM40_PERIOD_FILTER_SUM) else
{ {
g_stTIM40CapObj[u8ch].u8PeriodBufCnt = 0U; switch (u8ch)
{
case RTE_TIM40_CH0:
u16TDR = TM40->TDR[0U];
u16TSR = TM40->TSR[0U];
break;
case RTE_TIM40_CH1:
u16TDR = TM40->TDR[1U];
u16TSR = TM40->TSR[1U];
u8RollingCh = 0U;
break;
case RTE_TIM40_CH2:
u16TDR = TM40->TDR[2U];
u16TSR = TM40->TSR[2U];
break;
case RTE_TIM40_CH3:
u16TDR = TM40->TDR[3U];
u16TSR = TM40->TSR[3U];
break;
default:
u16TDR = TM40->TDR[0U];
u16TSR = TM40->TSR[0U];
break;
}
if (1U == (u16TSR & _0001_TM4_OVERFLOW_OCCURS))
{
g_stTIM40CapObj[u8ch].u32Period[g_stTIM40CapObj[u8ch].u8PeriodBufCnt] = (uint32_t)(u16TDR + 1UL) + 0x10000UL;
}
else
{
g_stTIM40CapObj[u8ch].u32Period[g_stTIM40CapObj[u8ch].u8PeriodBufCnt] = (uint32_t)(u16TDR + 1UL);
// Fre_In_Channel_Capture_ISR_Reset_Count(FRE_ENGINE,g_stTIM40CapObj[u8ch].u32Period[g_stTIM40CapObj[u8ch].u8PeriodBufCnt]);
}
g_stTIM40CapObj[u8ch].u8PeriodBufCnt++;
if (g_stTIM40CapObj[u8ch].u8PeriodBufCnt >= RTE_TIM40_PERIOD_FILTER_SUM)
{
g_stTIM40CapObj[u8ch].u8PeriodBufCnt = 0U;
}
if (g_stTIM40CapObj[u8ch].u8PeriodCnt < RTE_TIM40_PERIOD_FILTER_SUM)
{
g_stTIM40CapObj[u8ch].u8PeriodCnt++;
}
for( i = 0U;i < g_stTIM40CapObj[u8ch].u8PeriodCnt;i++)
{
u32Temp += g_stTIM40CapObj[u8ch].u32Period[i];
}
u32Temp = u32Temp / g_stTIM40CapObj[u8ch].u8PeriodCnt;
g_stTIM40CapObj[u8ch].u32Freq = (g_stTIM40CapObj[u8ch].u32CHClock * 10U) / u32Temp;
}
} }
if (g_stTIM40CapObj[u8ch].u8PeriodCnt < RTE_TIM40_PERIOD_FILTER_SUM)
{
g_stTIM40CapObj[u8ch].u8PeriodCnt++;
}
for( i = 0U;i < g_stTIM40CapObj[u8ch].u8PeriodCnt;i++)
{
u32Temp += g_stTIM40CapObj[u8ch].u32Period[i];
}
u32Temp = u32Temp / g_stTIM40CapObj[u8ch].u8PeriodCnt;
g_stTIM40CapObj[u8ch].u32Freq = (g_stTIM40CapObj[u8ch].u32CHClock * 10U) / u32Temp;
} }
/*********************************************************************************************************************** /***********************************************************************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment