MTK平臺定時器消息處理機制
MTK平臺定時器消息處理機制是本文要介紹的內容,主要是來了解并學習MTK中定時器的處理機制,不多說,具體內容的實現來看本文詳解。
發送定時器消息
(1).步驟
StartTimer->L4StartTimer
(2).兩種類型的定時器
MTK中有兩種類型的定時器
a、NO_ALIGNMENT
非隊列式的,即要求立即執行的定時器,時間到了就自動被reset.
b、ALIGNMENT
隊列式的,即可以通過隊列操作,有一定的延時容忍的定時器.y
其基本執行流程:執行定時器-->超時?-->保存timerid,eventid--timerstop||noevent?---->END;
- |YN|
- ||
- ----------------------------------------------------------
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)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">
小結:
MTK平臺定時器消息處理機制的內容介紹完了,希望通過本文的學習能對你有所幫助!