打印
[技术问答]

驱动库Timera.c的TIMERA_CompareInit函数是否存在bug?

[复制链接]
2463|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
poooolo|  楼主 | 2021-11-3 17:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在没有打开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;
}


使用特权

评论回复
沙发
chenqianqian| | 2021-11-7 17:12 | 只看该作者
坐等原厂来解答

使用特权

评论回复
板凳
huquanz711| | 2021-11-7 18:52 | 只看该作者
貌似是有问题

使用特权

评论回复
地板
wubangmi| | 2021-11-8 14:58 | 只看该作者
你最好自己单步仿真跑一下,我用了CH5和CH6这两个通道单步跑,没有发现你说的这种情况,当然我都是没有开启CACHE功能的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝