MTK平臺定時(shí)器消息處理機(jī)制
MTK平臺定時(shí)器消息處理機(jī)制是本文要介紹的內(nèi)容,主要是來了解并學(xué)習(xí)MTK中定時(shí)器的處理機(jī)制,不多說,具體內(nèi)容的實(shí)現(xiàn)來看本文詳解。
發(fā)送定時(shí)器消息
(1).步驟
StartTimer->L4StartTimer
(2).兩種類型的定時(shí)器
MTK中有兩種類型的定時(shí)器
a、NO_ALIGNMENT
非隊(duì)列式的,即要求立即執(zhí)行的定時(shí)器,時(shí)間到了就自動被reset.
b、ALIGNMENT
隊(duì)列式的,即可以通過隊(duì)列操作,有一定的延時(shí)容忍的定時(shí)器.y
其基本執(zhí)行流程:執(zhí)行定時(shí)器-->超時(shí)?-->保存timerid,eventid--timerstop||noevent?---->END;
- |YN|
- ||
- ----------------------------------------------------------
c.除了觸摸屏和手寫,其他情況下的定時(shí)器一般都是隊(duì)列式的.
(3).L4StartTimer的作用
判斷將要發(fā)送的定時(shí)器ID,根據(jù)是否是隊(duì)列類型傳遞給不同的隊(duì)列結(jié)構(gòu)(event_sheduler1/event_sheduler2);
(4).TimerExpiry
這是作為參數(shù)傳遞給L4StartTimer的回調(diào)函數(shù),由于MTK做了一定的封裝,因此其內(nèi)部具體回調(diào)觸發(fā)過程
無法得知,但根據(jù)猜測,應(yīng)該是在定時(shí)時(shí)間一到,以中斷的方式發(fā)出消息(MSG_ID_TIMER_EXPIRY),并將其寫到MMI的循環(huán)隊(duì)列.
該函數(shù)可能是在L4CallBackTimer中調(diào)用的,L4CallBackTimer的作用如下:
a.重置當(dāng)前定時(shí)器信息結(jié)構(gòu)(mmi_frm_timer_type);
b.執(zhí)行定時(shí)器到點(diǎn)后的執(zhí)行函數(shù)(TimerExpiry);
c.講Timer消息寫到MMI循環(huán)隊(duì)列中.
與StartTimer對應(yīng)的StopTimer
(1).具體實(shí)現(xiàn)通過調(diào)用L4StopTimer操作.
(2).作用:找出指定要停止的定時(shí)器ID在隊(duì)列中的位置,然后使用evshed_cancel_event將指定定時(shí)器節(jié)點(diǎn)從隊(duì)列中刪除.
定時(shí)器消息的處理
(1).步驟
...->創(chuàng)建MMITask->設(shè)置MMITask入口函數(shù)->調(diào)用EvshedMMITimerHandler
(2).evshed_timer_handler()->處理具體的定時(shí)器事件
簡單分析MTK定時(shí)器消息事件,由于只是簡單的分析,謬誤定然甚多,忘包涵包涵并不吝指正.
MTK定時(shí)器消息處理機(jī)制
一、基本概念及Neclus內(nèi)核定時(shí)器初始化
expires:指定定時(shí)器到期的時(shí)間,這個(gè)時(shí)間被表示成自系統(tǒng)啟動以來的時(shí)鐘滴答計(jì)數(shù)(也即時(shí)鐘節(jié)拍數(shù))。當(dāng)一個(gè)定時(shí)器的expires值小于或等于jiffies變量時(shí),我們就說這個(gè)定時(shí)器已經(jīng)超時(shí)或到期了。在初始化一個(gè)定時(shí)器后,通常把它的expires域設(shè)置成當(dāng)前expires變量的當(dāng)前值加上某個(gè)時(shí)間間隔值(以時(shí)鐘滴答次數(shù)計(jì)。
- 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)timer_id:定時(shí)器id最多同時(shí)12個(gè)。
(2)雙向鏈表元素event_id:用來將多個(gè)定時(shí)器調(diào)度動作連接成一條雙向循環(huán)隊(duì)列。
(3)函數(shù)指針callback_func:指向一個(gè)可執(zhí)行函數(shù)。當(dāng)定時(shí)器到期時(shí),內(nèi)核就執(zhí)行function所指定的函數(shù),產(chǎn)生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">
小結(jié):
MTK平臺定時(shí)器消息處理機(jī)制的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你有所幫助!