46 lines
745 B
C
46 lines
745 B
C
![]() |
#include "rtthread.h"
|
||
|
#include "stdlib.h"
|
||
|
#include "stdint.h"
|
||
|
#include "stdio.h"
|
||
|
|
||
|
|
||
|
typedef struct{
|
||
|
void (*later_fun)(void *t);
|
||
|
void *t;
|
||
|
rt_timer_t timer;
|
||
|
}later_def;
|
||
|
|
||
|
|
||
|
static void later_fun_exe(void *t)
|
||
|
{
|
||
|
later_def *l=t;
|
||
|
rt_timer_delete(l->timer);
|
||
|
if(l->later_fun){
|
||
|
l->later_fun(l->t);
|
||
|
}
|
||
|
free(l);
|
||
|
}
|
||
|
|
||
|
// 延迟一段时间调用函数
|
||
|
void later_execute(void (*fun)(void *t),void *t,int ms)
|
||
|
{
|
||
|
static uint16_t count;
|
||
|
char s1[16]={0};
|
||
|
sprintf(s1,"later_t#%d",count);
|
||
|
later_def *l=calloc(1,sizeof(later_def));
|
||
|
l->later_fun=fun;
|
||
|
l->t=t;
|
||
|
l->timer=rt_timer_create(s1,later_fun_exe,l,
|
||
|
rt_tick_from_millisecond(ms),
|
||
|
RT_TIMER_FLAG_ONE_SHOT|RT_TIMER_FLAG_SOFT_TIMER);
|
||
|
rt_timer_start(l->timer);
|
||
|
count++;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|