You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.2 KiB
75 lines
1.2 KiB
/*
|
|
* vtimer.c
|
|
*
|
|
* Created on: 2019-7-10
|
|
* Author: Administrator
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <xdc/std.h>
|
|
#include <xdc/runtime/System.h>
|
|
|
|
#include <ti/sysbios/BIOS.h>
|
|
#include <ti/sysbios/knl/Clock.h>
|
|
|
|
#include "vtimer.h"
|
|
struct timer {
|
|
Clock_Handle clk;
|
|
void *param;
|
|
void (*on_time)(void *param);
|
|
};
|
|
|
|
static Void _clkFxn(UArg arg0)
|
|
{
|
|
timer_t tm = (timer_t)arg0;
|
|
if (tm && tm->on_time)
|
|
tm->on_time(tm->param);
|
|
}
|
|
|
|
timer_t timer_new(int tick_ms, void *param, void (*on_time)(void *param))
|
|
{
|
|
timer_t tm;
|
|
Clock_Params clkParams;
|
|
|
|
tm = calloc(1, sizeof *tm);
|
|
if (tm) {
|
|
Clock_Params_init(&clkParams);
|
|
clkParams.period = tick_ms;
|
|
clkParams.startFlag = 0; //FLASE
|
|
clkParams.arg = (UArg)tm;
|
|
tm->clk = Clock_create(_clkFxn, tick_ms, &clkParams, NULL);
|
|
tm->param = param;
|
|
tm->on_time = on_time;
|
|
}
|
|
|
|
return tm;
|
|
}
|
|
|
|
void timer_free(timer_t tm)
|
|
{
|
|
if (tm) {
|
|
Clock_delete(&tm->clk);
|
|
free(tm);
|
|
}
|
|
}
|
|
|
|
int timer_active(timer_t tm)
|
|
{
|
|
if (tm)
|
|
Clock_start(tm->clk);
|
|
return 0;
|
|
}
|
|
|
|
int timer_deactive(timer_t tm)
|
|
{
|
|
if (tm)
|
|
Clock_stop(tm->clk);
|
|
return 0;
|
|
}
|
|
|
|
unsigned int time_millis(void )
|
|
{
|
|
return (unsigned int)Clock_getTicks();
|
|
}
|
|
|