MTK HTTP 协议之时间操作

整的有点复杂,不习惯的可以简化

 

nw_time.c

 

#include "nw_define.h"
#include "Vmsys.h"

NW_TIMER_DATA nw_timer;

#define NW_HTTP_TIMER_ID    125
#define NW_TIMER_SUPPORT_MAX   (16)
#define NW_TIMER_MAIN_LOOP	(100)

void nw_http_timer_loop(void);

void nw_http_main_timer_start()
{
	StartTimer(NW_HTTP_TIMER_ID, 100, nw_http_timer_loop);
}

void nw_http_main_timer_stop()
{
	StopTimer(NW_HTTP_TIMER_ID);
}

nw_uint32 nw_timer_get_interval()
{
	return NW_TIMER_MAIN_LOOP;  //100毫秒
}

void nw_http_timer_loop(void)
{
	if (nw_timer.callback_func != NULL)
	{
		if (nw_timer.remain_time <= nw_timer_get_interval())
		{
			NW_TIMER_CALLBACK timer_func = nw_timer.callback_func;
			nw_timer.callback_func = NULL;
			timer_func(nw_timer.nw_timer_param_i,nw_timer.nw_timer_param_w);
		}
		else
		{
			nw_timer.remain_time -= nw_timer_get_interval();
		}
	}
}

nw_uint16 nw_http_timer_start(nw_int8 app_index, nw_uint32 delay, NW_TIMER_CALLBACK callback_func, NW_TIMER_TYPE type)
{
	if(nw_timer.used == 0)
	{
		nw_timer.timer_id =  1; 
		nw_timer.remain_time= delay;
		nw_timer.callback_func	= callback_func;
		nw_timer.soc_id= app_index;
		nw_timer.nw_timer_param_i	= (void*)nw_timer.soc_id;
		nw_timer.used = 1;
		nw_timer.type = type;
		nw_timer.nw_timer_param_w	= (void*)nw_timer.type;
		return (nw_timer.timer_id);
	}
	return 0;
}

nw_uint16 nw_http_get_timer_id_by_app_index(nw_int8 app_index , NW_TIMER_TYPE type)
{
	if((nw_timer.soc_id == app_index) && (nw_timer.type == type))
	{
		return (nw_timer.timer_id);
	}
	return 0;
}

nw_uint16 nw_http_timer_stop(nw_uint16 timer_id)
{
	if(timer_id == nw_timer.timer_id)
	{
		nw_timer.timer_id = 0; 
		nw_timer.remain_time= 0;
		nw_timer.callback_func	= 0;
		nw_timer.soc_id= 0;
	}
	return 0;
}



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值