MTK平台定时器消息处理机制是本文要介绍的内容,主要是来了解并学习MTK中定时器的处理机制,不多说,具体内容的实现来看本文详解。
发送定时器消息
(1).步骤
StartTimer->L4StartTimer
(2).两种类型的定时器
MTK中有两种类型的定时器
a、NO_ALIGNMENT
非队列式的,即要求立即执行的定时器,时间到了就自动被reset.
b、ALIGNMENT
队列式的,即可以通过队列操作,有一定的延时容忍的定时器.y
其基本执行流程:执行定时器-->超时?-->保存timerid,eventid--timerstop||noevent?---->END;
|YN|
||
----------------------------------------------------------
- 1.
- 2.
- 3.
- 4.
- 5.
c.除了触摸屏和手写,其他情况下的定时器一般都是队列式的.
(3).L4StartTimer的作用
判断将要发送的定时器ID,根据是否是队列类型传递给不同的队列结构(event_sheduler1/event_sheduler2);
(4).TimerExpiry
这是作为参数传递给L4StartTimer的回调函数,由于MTK做了一定的封装,因此其内部具体回调触发过程
无法得知,但根据猜测,应该是在定时时间一到,以中断的方式发出消息(MSG_ID_TIMER_EXPIRY),并将其写到MMI的循环队列.
该函数可能是在L4CallBackTimer中调用的,L4CallBackTimer的作用如下:
a.重置当前定时器信息结构(mmi_frm_timer_type);
b.执行定时器到点后的执行函数(TimerExpiry);
c.讲Timer消息写到MMI循环队列中.
与StartTimer对应的StopTimer
(1).具体实现通过调用L4StopTimer操作.
(2).作用:找出指定要停止的定时器ID在队列中的位置,然后使用evshed_cancel_event将指定定时器节点从队列中删除.
定时器消息的处理
(1).步骤
...->创建MMITask->设置MMITask入口函数->调用EvshedMMITimerHandler
(2).evshed_timer_handler()->处理具体的定时器事件
简单分析MTK定时器消息事件,由于只是简单的分析,谬误定然甚多,忘包涵包涵并不吝指正.
MTK定时器消息处理机制
一、基本概念及Neclus内核定时器初始化
expires:指定定时器到期的时间,这个时间被表示成自系统启动以来的时钟滴答计数(也即时钟节拍数)。当一个定时器的expires值小于或等于jiffies变量时,我们就说这个定时器已经超时或到期了。在初始化一个定时器后,通常把它的expires域设置成当前expires变量的当前值加上某个时间间隔值(以时钟滴答次数计。
typedefstructtimertable
{/*storethetimer_id.MSB(MostSignificantBit)isalign_timer_mask*/
U16timer_id[SIMULTANEOUS_TIMER_NUM];
/*storetheevent_idthatreturnsfromevshed_set_event()*/
eventidevent_id[SIMULTANEOUS_TIMER_NUM];
/*storethetimer_expiry_func*/
oslTimerFuncPtrcallback_func[SIMULTANEOUS_TIMER_NUM];
/*pointtothenextTIMERTABLEdata*/
structtimertable*next;
}TIMERTABLE;
typedeflcd_dll_node*eventid;
structlcd_dll_node{
void*data;
lcd_dll_node*prev;
lcd_dll_node*next;
};
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
(1)timer_id:定时器id最多同时12个。
(2)双向链表元素event_id:用来将多个定时器调度动作连接成一条双向循环队列。
(3)函数指针callback_func:指向一个可执行函数。当定时器到期时,内核就执行function所指定的函数,产生expires消息。
//L4initthetimer
/*****************************************************************************
*FUNCTION
*L4InitTimer
*DESCRIPTION
*Thisfunctionistoinitthetimerwhiletaskcreate.
*
*PARAMETERS
*aINvoid
*RETURNS
*VOID.
*GLOBALSAFFECTED
*external_global
*****************************************************************************/
voidL4InitTimer(void)
{
/*----------------------------------------------------------------*/
/*LocalVariables*/
/*----------------------------------------------------------------*/
TIMERTABLE*p;
TIMERTABLE*pp;
/*----------------------------------------------------------------*/
/*CodeBody*/
/*----------------------------------------------------------------*/
/*TrytofreeTIMERTABLElistexcludeg_timer_table*/
p=g_timer_table.next;
pp=NULL;
do
{
if(p!=NULL)
{
ppp=p->next;
OslMfree(p);
}
p=pp;
}while(p!=NULL);
/*resetg_timer_talbe*/
memset(&g_timer_table,0,sizeof(TIMERTABLE));
g_timer_table_size=SIMULTANEOUS_TIMER_NUM;
g_timer_table_used=0;
/*Initiatetheclocktimecallbackfunction.*/
get_clocktime_callback_func=NULL;
set_clocktime_callback_func=NULL;
/*Initatethenoalignmentstacktimer*/
stack_init_timer(&base_timer1,"MMI_Base_Timer1",MOD_MMI);
/*Createanoalignmenttimerschedule*/
event_scheduler1_ptr=new_evshed(&base_timer1,
L4StartBaseTimer,L4StopBaseTimer,
0,kal_evshed_get_mem,kal_evshed_free_mem,0);
/*Initatethealignmentstacktimer*/
stack_init_timer(&base_timer2,"MMI_Base_Timer2",MOD_MMI);
/*Createanalignmenttimerschedule*/
event_scheduler2_ptr=new_evshed(&base_timer2,
L4StartBaseTimer,L4StopBaseTimer,
0,kal_evshed_get_mem,kal_evshed_free_mem,255);
}
typedefstructstack_timer_struct_t{
module_typedest_mod_id;
kal_timeridkal_timer_id;
kal_uint16timer_indx;
stack_timer_status_typetimer_status;
kal_uint8invalid_time_out_count;
}stack_timer_struct;
/*************************************************************************
*ExportedFunctionPrototypes
*************************************************************************/
/*
*Important:
*Currentimplementationmax_delay_ticks_disibledevent="text-indent:24pt;line-height:150%"align="left">
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
小结:
MTK平台定时器消息处理机制的内容介绍完了,希望通过本文的学习能对你有所帮助!