时驱函数的进阶:定时器链表

全局变量一共用4次声明+创建+开始+结束       名字很长 其实就是ID号  在链表中的号码牌

 

time_ops_type   timer =
{
    .creat = timer_register_isr,
    .stop = timer_stop_time , 
    .start = timer_start_time,
};

 

然后先看简单的

uint8_t timer_stop_time(uint8_t handle)
{
    time_type *priv = time;
    
    while( priv != NULL )
    {
        if( priv->handle == handle)
        {
            priv->start = false;
            priv->cnt = 0;
            return true;
        }
        priv = priv->next;     
    }  
    
    return false;
}

uint8_t timer_start_time(uint8_t handle)
{
    time_type *priv = time;
    
    while( priv != NULL )
    {
        if( priv->handle == handle)
        {
            priv->start = true;
            return true;
        }
        priv = priv->next;     
    }  
    
    return false;
}

基本是一样的 开始和结束 就是在链表里面去找这个handle 找到以后就设置它true/false

看创建

uint8_t timer_register_isr(  uint32_t time_out ,uint8_t start, time_call_back call_back)
{
    time_type *priv;
    time_type    *this;

    this = (time_type *)timer_malloc(sizeof(time_type));
    if( this != NULL)
    {

        this->cnt = 0;
        this->start = start;
        this->handle = timerTaskId++;
        this->time_out = time_out;
        this->fun = call_back;
        this->next = NULL;
        if( time == NULL)
        {
             time = this;
        }
        else
        {
            priv = time;
            while( priv->next != NULL )    priv = priv->next;
            priv->next = this;
        }    
    }
    else
    {
        return 0xFF;
    }


    return (this->handle);

}
这是一个链表 并且每次都是尾巴插入 做成一个链表呀

全局变量 //osal time queue
time_type            *time = NULL;

是头 后面都是尾巴插入

 

最后怎么用呢?

链表做好了 时驱函数一样的 需要一个后台的程序在定时器不停的扫描

start为1就是开启的 为0就是关闭的

handle就是编号

cnt tinmeout 是变量和常量的比较

next指针

还有一个回调函数

后续:http://www.stmcu.org/module/forum/thread-616779-1-1.html

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值