硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2684|回复: 2
收起左侧

[有问必答] bsp_StartTimer和bsp_StartAutoTimer零延时的BUG

[复制链接]

36

主题

142

回帖

255

积分

高级会员

积分
255
发表于 2018-7-30 14:14:29 | 显示全部楼层 |阅读模式
安富莱BSP的bsp_timer.c
void bsp_StartAutoTimer(uint8_t _id, uint32_t _period)
bsp_StartAutoTimer(uint8_t _id, uint32_t _period)
这两个函数,_period参数为0时将会无限延时。
static void bsp_SoftTimerDec(SOFT_TMR *_tmr)
{
        if (_tmr->Count > 0)
        {
                if (--_tmr->Count == 0)
                {
                        _tmr->Flag = 1;
                        if(_tmr->Mode == TMR_AUTO_MODE)
                        {
                                _tmr->Count = _tmr->PreLoad;
                        }
                }
        }
}


我在使用过程_period作为用户输入,当为0时无限延时。
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
发表于 2018-7-30 14:18:52 | 显示全部楼层
不可以设置为0,为0的时候没做处理。

如果要处理的话,要做个非0判断,为0的话,直接返回。
回复

使用道具 举报

36

主题

142

回帖

255

积分

高级会员

积分
255
 楼主| 发表于 2018-7-30 14:34:47 | 显示全部楼层
void bsp_StartAutoTimer(uint8_t _id, uint32_t _period)
bsp_StartAutoTimer(uint8_t _id, uint32_t _period)
我修了一下上面在两次函娄数,为0时
        s_tTmr[_id].Count = 0;                               
        s_tTmr[_id].PreLoad = 0;                       
        s_tTmr[_id].Flag = 1;                       
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-28 01:22 , Processed in 0.154759 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表