在没有打开TimerCache时,主程序首先设置了TimeraCompare4的值,再设置TimeraCompare3的值,调用TIMERA_CompareInit函数后,红色字的语句会把TimeraCompare3会赋值到TimeraCompare4,导致波形出错,红色的语句加上判断Cache是否打开语句后可恢复正常
en_result_t TIMERA_CompareInit(M4_TMRA_TypeDef *TIMERAx, en_timera_channel_t enChannel,
const stc_timera_compare_init_t *pstcCompareInit)
{
en_result_t enRet = ErrorInvalidParameter;
__IO stc_tmra_pconr_field_t *pstcTimeraPort;
__IO stc_tmra_bconr_field_t *pstcTimeraCache;
__IO stc_tmra_cmpar_field_t *pstcTimeraCompare;
__IO stc_tmra_cconr_field_t *pstcTimeraCapture;
/* Check parameters */
if(IS_VALID_NORMAL_TIMERA_UNIT(TIMERAx) && (NULL != pstcCompareInit))
{
DDL_ASSERT(IS_VALID_NORMAL_TIMERA_CHANNEL(enChannel));
DDL_ASSERT(IS_VALID_COUNT_START_OUTPUT(pstcCompareInit->enStartCountOutput));
DDL_ASSERT(IS_VALID_COUNT_STOP_OUTPUT(pstcCompareInit->enStopCountOutput));
DDL_ASSERT(IS_VALID_COMPARE_MATCH_OUTPUT(pstcCompareInit->enCompareMatchOutput));
DDL_ASSERT(IS_VALID_PERIOD_MATCH_OUTPUT(pstcCompareInit->enPeriodMatchOutput));
DDL_ASSERT(IS_VALID_SPECIFY_OUTPUT_STATUS(pstcCompareInit->enSpecifyOutput));
DDL_ASSERT(IS_FUNCTIONAL_STATE(pstcCompareInit->enCacheEn));
DDL_ASSERT(IS_FUNCTIONAL_STATE(pstcCompareInit->enTriangularCrestTransEn));
DDL_ASSERT(IS_FUNCTIONAL_STATE(pstcCompareInit->enTriangularTroughTransEn));
/* Configure port control register */
pstcTimeraPort = (stc_tmra_pconr_field_t *)TIMERA_CALC_REG_ADDR(TIMERAx->PCONR1, enChannel);
pstcTimeraPort->STAC = pstcCompareInit->enStartCountOutput;
pstcTimeraPort->STPC = pstcCompareInit->enStopCountOutput;
pstcTimeraPort->CMPC = pstcCompareInit->enCompareMatchOutput;
pstcTimeraPort->PERC = pstcCompareInit->enPeriodMatchOutput;
pstcTimeraPort->FORC = pstcCompareInit->enSpecifyOutput;
/* Configure cache control register */
if ((TimeraCh1 == enChannel) || (TimeraCh3 == enChannel) ||
(TimeraCh5 == enChannel) || (TimeraCh7 == enChannel))
{
pstcTimeraCache = (stc_tmra_bconr_field_t *)TIMERA_CALC_REG_ADDR(TIMERAx->BCONR1, enChannel);
pstcTimeraCache->BSE0 = pstcCompareInit->enTriangularCrestTransEn;
pstcTimeraCache->BSE1 = pstcCompareInit->enTriangularTroughTransEn;
pstcTimeraCache->BEN = pstcCompareInit->enCacheEn;
/* Configure compare cache value register */
pstcTimeraCompare = (stc_tmra_cmpar_field_t *)TIMERA_CALC_REG_ADDR(TIMERAx->CMPAR1, enChannel + 1);
pstcTimeraCompare->CMP = pstcCompareInit->u16CompareCacheVal;
}
/* Configure compare value register */
pstcTimeraCompare = (stc_tmra_cmpar_field_t *)TIMERA_CALC_REG_ADDR(TIMERAx->CMPAR1, enChannel);
pstcTimeraCompare->CMP = pstcCompareInit->u16CompareVal;
/* Set compare output function */
pstcTimeraCapture = (stc_tmra_cconr_field_t *)TIMERA_CALC_REG_ADDR(TIMERAx->CCONR1, enChannel);
pstcTimeraCapture->CAPMD = 0u;
enRet = Ok;
}
return enRet;
}
|