|
@@ -9,16 +9,21 @@ class CadenceTest : public testing::Test
|
|
|
protected:
|
|
|
static void SetUpTestSuite()
|
|
|
{
|
|
|
- cadence_voCadenceInit();
|
|
|
- iRt_Init();
|
|
|
+
|
|
|
}
|
|
|
virtual void SetUp() override
|
|
|
{
|
|
|
+ iRt_Init();
|
|
|
+ iCap_BindDeviceInterrupt(0,IC_CountMaxISR);
|
|
|
+ iCap_EnableDeviceInterrupt(0);
|
|
|
+ iCap_BindChannelInterrupt(0,CAP_CH(2),IC_CadenceISR);
|
|
|
+ iCap_EnableChannelInterrupt(0,CAP_CH(2));
|
|
|
|
|
|
+ cadence_voCadenceInit();
|
|
|
}
|
|
|
virtual void TearDown() override
|
|
|
{
|
|
|
- cadence_voCadenceInit();
|
|
|
+
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -36,6 +41,7 @@ TEST_P(CadenceTest1, FreCal)
|
|
|
int cadenceSignal = 0, cadCnt = 0, cadenceSignalLast = 0;
|
|
|
int cadencePrd = get<0>(GetParam());
|
|
|
int capValue = 0;
|
|
|
+ int capOverflowCnt = 0, capOverflowCnt2 = 0;
|
|
|
|
|
|
testGpioBValue[GPIOB] = get<1>(GetParam());
|
|
|
|
|
@@ -76,11 +82,14 @@ TEST_P(CadenceTest1, FreCal)
|
|
|
/* Interrupt: update and capture */
|
|
|
if(testTimerIntFlg[TIMER1][TIMER_INT_FLAG_UP])
|
|
|
{
|
|
|
+ capOverflowCnt ++;
|
|
|
cadence_voCadenceCal(1);
|
|
|
testTimerIntFlg[TIMER1][TIMER_INT_FLAG_UP] = 0;
|
|
|
}
|
|
|
else if(testTimerIntFlg[TIMER1][TIMER_INT_FLAG_CH2])
|
|
|
{
|
|
|
+ capOverflowCnt2 = capOverflowCnt;
|
|
|
+ capOverflowCnt = 0;
|
|
|
cadence_voCadenceCal(2);
|
|
|
testTimerIntFlg[TIMER1][TIMER_INT_FLAG_CH2] = 0;
|
|
|
}
|
|
@@ -89,7 +98,7 @@ TEST_P(CadenceTest1, FreCal)
|
|
|
|
|
|
double cadFreqPu = (double)TIM1CLK_KHZ * 1000 * 2 * 1048576 / cadencePrd / FBASE / cadence_stFreGetCof.uwNumbersPulses; // Q20
|
|
|
|
|
|
- if(cadFreqPu > cadence_stFreGetCof.uwMaxCadenceFre || cadence_stFreGetOut.uwCaputureOverflowCnt > cadence_stFreGetCof.uwHfMaxTimeCnt || cadence_stFreGetOut.cadence_dir == 1)
|
|
|
+ if(cadFreqPu > cadence_stFreGetCof.uwMaxCadenceFre || capOverflowCnt2 > cadence_stFreGetCof.uwHfMaxTimeCnt || cadence_stFreGetOut.cadence_dir == 1)
|
|
|
{
|
|
|
EXPECT_NEAR(cadence_stFreGetOut.uwFrequencyPu, 0, 0.1);
|
|
|
}
|
|
@@ -102,40 +111,39 @@ TEST_P(CadenceTest1, FreCal)
|
|
|
INSTANTIATE_TEST_SUITE_P(DiffCadencePeriod, CadenceTest1,
|
|
|
::testing::Combine(::testing::Values(0, 500, 3000, 18002, 100000,1000000), ::testing::Values(0,0x0004)));
|
|
|
|
|
|
-TEST_F(CadenceTest, FreCal2)
|
|
|
+TEST_F(CadenceTest, IntSimultFreCal)
|
|
|
{
|
|
|
/* Coef Cal */
|
|
|
cadence_voCadenceCof();
|
|
|
cadence_stFreGetCof.uwNumbersPulses = CADENCE_NUMBERS_PULSES;
|
|
|
+ switch_flg.SysCoef_Flag = TRUE;
|
|
|
+ bikespeed_voBikeSpeedCof(); ///< timer更新中断函数中有bikespeed函数,防止运行时除0
|
|
|
|
|
|
/* Test conditions */
|
|
|
cadence_stFreGetOut.cadence_fsm = CADENCE_HFreWork;
|
|
|
cadence_stFreGetOut.uwCaputureNumCnt = 1;
|
|
|
- cadence_stFreGetOut.uwCaputure1Cnt = 0;
|
|
|
- cadence_stFreGetOut.uwCaputureOverflowCnt = 0;
|
|
|
+ cadence_stFreGetOut.uwCaputure1Cnt = 100;
|
|
|
+ cadence_stFreGetOut.uwCaputureOverflowCnt = 1; ///< OverflowCnt cant be 0
|
|
|
testGpioBValue[GPIOB] = 0;
|
|
|
|
|
|
double overflowCnt = cadence_stFreGetOut.uwCaputureOverflowCnt;
|
|
|
double cap1Cnt = cadence_stFreGetOut.uwCaputure1Cnt;
|
|
|
|
|
|
- testTimerIntFlg[TIMER1][TIMER_INT_FLAG_UP] = 1;
|
|
|
testCh2CapValue[TIMER1] = 17900;
|
|
|
- testTimerIntFlg[TIMER1][TIMER_INT_FLAG_CH2] = 1;
|
|
|
|
|
|
- /* Interrupt: update and capture */
|
|
|
- if(testTimerIntFlg[TIMER1][TIMER_INT_FLAG_UP])
|
|
|
+ /* Interrupt flag */
|
|
|
+ testTimerIntFlag2[TIMER1] = 0x0009;
|
|
|
+
|
|
|
+ /* Interrupt: update and capture */
|
|
|
+ if(testTimerIntFlag2[TIMER1] != 0)
|
|
|
{
|
|
|
- cadence_voCadenceCal(1);
|
|
|
- testTimerIntFlg[TIMER1][TIMER_INT_FLAG_UP] = 0;
|
|
|
+ iRtCap_Isr(0);
|
|
|
}
|
|
|
- else if(testTimerIntFlg[TIMER1][TIMER_INT_FLAG_CH2])
|
|
|
- {
|
|
|
- cadence_voCadenceCal(2);
|
|
|
- testTimerIntFlg[TIMER1][TIMER_INT_FLAG_CH2] = 0;
|
|
|
- }
|
|
|
-
|
|
|
- double cadFreqPu = overflowCnt * 18000 + cadence_stFreGetOut.uwCaputure2Cnt - cap1Cnt;
|
|
|
- cadFreqPu = (double)TIM1CLK_KHZ * 1000 * 2 * 1048576 / cadFreqPu / FBASE / cadence_stFreGetCof.uwNumbersPulses; // Q20
|
|
|
+
|
|
|
+ double capValErrLast = 0, capValErr = 0, cadFreqPu = 0;
|
|
|
+ capValErrLast = capValErr;
|
|
|
+ capValErr = overflowCnt * 18000 + cadence_stFreGetOut.uwCaputure2Cnt - cap1Cnt;
|
|
|
+ cadFreqPu = (double)TIM1CLK_KHZ * 1000 * 1048576 / ((capValErr + capValErrLast) / 2)/ FBASE / cadence_stFreGetCof.uwNumbersPulses; // Q20
|
|
|
|
|
|
if(cadFreqPu > cadence_stFreGetCof.uwMaxCadenceFre || cadence_stFreGetOut.uwCaputureOverflowCnt > cadence_stFreGetCof.uwHfMaxTimeCnt || cadence_stFreGetOut.cadence_dir == 1)
|
|
|
{
|