MMITimer.c, change:2008-03-17,size:48230b

本文详细解析了测试用例中的计时器功能,包括如何创建、初始化、调度以及不同计时器参数的影响。同时,文章还介绍了计时器在不同场景下的应用,如非对齐定时器和对齐定时器,并提供了相应的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. /*****************************************************************************   
  2. *  Copyright Statement:   
  3. *  --------------------   
  4. *  This software is protected by Copyright and the information contained   
  5. *  herein is confidential. The software may not be copied and the information   
  6. *  contained herein may not be used or disclosed except with the written   
  7. *  permission of MediaTek Inc. (C) 2005   
  8.  
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES   
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")   
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON   
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,   
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF   
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.   
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE   
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR   
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH   
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO   
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S   
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.   
  21.  
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE   
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,   
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,   
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO   
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.    
  27.  
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE   
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF   
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND   
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER   
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).   
  33.  
  34. *****************************************************************************/    
  35.    
  36. /*****************************************************************************   
  37.  *   
  38.  * Filename:   
  39.  * ---------   
  40.  *  MMITimer.c   
  41.  *   
  42.  * Project:   
  43.  * --------    
  44.  *  MAUI   
  45.  *   
  46.  * Description:   
  47.  * ------------   
  48.  *  MMI Timer.   
  49.  *   
  50.  * Author:   
  51.  * -------   
  52.  * -------   
  53.  *   
  54.  *============================================================================   
  55.  *             HISTORY   
  56.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!   
  57.  *------------------------------------------------------------------------------   
  58.  * removed!   
  59.  *   
  60.  * removed!   
  61.  * removed!   
  62.  * removed!   
  63.  *   
  64.  * removed!   
  65.  * removed!   
  66.  * removed!   
  67.  *   
  68.  * removed!   
  69.  * removed!   
  70.  * removed!   
  71.  *   
  72.  * removed!   
  73.  * removed!   
  74.  * removed!   
  75.  *   
  76.  * removed!   
  77.  * removed!   
  78.  * removed!   
  79.  *   
  80.  * removed!   
  81.  * removed!   
  82.  * removed!   
  83.  *   
  84.  * removed!   
  85.  * removed!   
  86.  * removed!   
  87.  *   
  88.  * removed!   
  89.  * removed!   
  90.  * removed!   
  91.  *   
  92.  * removed!   
  93.  * removed!   
  94.  * removed!   
  95.  *   
  96.  * removed!   
  97.  *   
  98.  *------------------------------------------------------------------------------   
  99.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!   
  100.  *============================================================================   
  101.  ****************************************************************************/    
  102.    
  103. /*****************************************************************************   
  104. * Include                                                                        
  105. *****************************************************************************/    
  106.    
  107. /*  Include: MMI header file */    
  108. #include "MMI_features.h"    
  109. #include "stdC.h"    
  110. #include "L4dr.h"    
  111. #include "MMIDataType.h"    
  112. #include "FrameworkGprot.h"            
  113. #include "FrameworkProt.h"      
  114. #include "DebugInitDef.h"    
  115. #include "MMI_trc.h"     
  116.    
  117.    
  118. /*****************************************************************************   
  119. * Define                                                                         
  120. *****************************************************************************/     
  121.    
  122. /* the recommended value: 12 or 24 */    
  123. #define SIMULTANEOUS_TIMER_NUM         (12)    
  124.    
  125. /* MSB(Most Significant Bit) of g_timer_table.timer_id[i] is align_timer_mask */    
  126. #define NO_ALIGNMENT_TIMER_MASK        (0x8000)    
  127. #define ALIGNMENT_TIMER_MASK           (0)    
  128.    
  129. /* ticks of 20 millisecond. because KAL did not define the valye. define in floating falue to avoid early rouning */    
  130. #define MMI_TICKS_20_MSEC  (KAL_TICKS_1_SEC/50.0)    
  131.    
  132. /* ticks of 5 millisecond. because KAL did not define the valye. define in floating falue to avoid early rouning */    
  133. #define MMI_TICKS_5_MSEC  (KAL_TICKS_1_SEC/200.0)    
  134.     
  135.    
  136. /*****************************************************************************   
  137. * Typedef                                                                        
  138. *****************************************************************************/    
  139.    
  140. /*    
  141.  * MTK added for two kinds of timer, one is for exactly time, another allow to delay.   
  142.  * TO Pixtel, This two defines should move to a proper place where    
  143.  * can be used by other files.   
  144.  */    
  145.    
  146. typedef   struct  {   
  147.     U16 timer_info;     /* timer info. */    
  148.     eventid event_id;   /* event_id returned from evshed_set_event() */    
  149.     oslTimerFuncPtr callback_func;  /* timer_expiry_func */    
  150.     void * arg;   
  151. } mmi_frm_timer_type;   
  152.    
  153.    
  154. typedef   struct  timertable   
  155. {   
  156.     mmi_frm_timer_type tm [SIMULTANEOUS_TIMER_NUM];   /* timer items */    
  157.     struct  timertable *next;     /* point to the next TIMERTABLE data */    
  158. } TIMERTABLE;   
  159.    
  160.    
  161. /*****************************************************************************   
  162. * Local Variable                                                                 
  163. *****************************************************************************/    
  164.    
  165. /*   
  166.  * In most case, the timers won't run simultaneously.   
  167.  * We run-time allocate the memory to store the timer information.    
  168.  */    
  169. static  TIMERTABLE g_timer_table = {0};   
  170. static  U16 g_timer_table_size = 0;   
  171. static  U16 g_timer_table_used = 0;   
  172.    
  173. static  oslTaskFuncPtr get_clocktime_callback_func;   
  174. static  oslTaskFuncPtr set_clocktime_callback_func;   
  175.    
  176. /*    
  177.  * MTK added for two kinds of timer, one is for exactly time, another allow to delay.   
  178.  */    
  179. static  stack_timer_struct base_timer1;  /* no alignment timer */    
  180. static  stack_timer_struct base_timer2;  /* allow alignment timer */    
  181. static  event_scheduler *event_scheduler1_ptr, *event_scheduler2_ptr;   
  182. static   void  L4StartTimer(   
  183.         unsigned short  nTimerId,   
  184.         oslTimerFuncPtr TimerExpiry,   
  185.         void  *funcArg,   
  186.         unsigned long  nTimeDuration,   
  187.         unsigned char  alignment);   
  188.    
  189. /*****************************************************************************   
  190. * Extern Global Variable                                                         
  191. *****************************************************************************/    
  192.    
  193. /*****************************************************************************   
  194. * Local Function                                                                 
  195. *****************************************************************************/    
  196.    
  197. //#define __MMI_FRM_TIMER_UNIT_TEST__    
  198.    
  199. #ifdef __MMI_FRM_TIMER_UNIT_TEST__    
  200. static   void  mmi_frm_ut_timer( void );   
  201. static   void  mmi_frm_ut_align_timer( void  *p);   
  202. static   void  mmi_frm_ut_nonalign_timer( void  *p);   
  203. #endif /* __MMI_FRM_TIMER_UNIT_TEST__ */    
  204.    
  205. static   void  L4StartBaseTimer( void  *base_timer_ptr, unsigned  int  time_out);   
  206. static   void  L4StopBaseTimer( void  *base_timer_ptr);   
  207. static  MMI_BOOL L4TimerUsePreciseTick(unsigned  short  nTimerId);   
  208. static   void  L4CallBackTimer( void  *p);   
  209. static   void  L4StopTimer(unsigned  short  nTimerId);   
  210.    
  211.    
  212. /*****************************************************************************   
  213. * Extern Global Function                                                         
  214. *****************************************************************************/    
  215.    
  216. /*****************************************************************************   
  217.  * FUNCTION   
  218.  *  StartTimer   
  219.  * DESCRIPTION   
  220.  *  This is used to set a timer   
  221.  * PARAMETERS   
  222.  *  timerid     [IN]           
  223.  *  delay       [IN]           
  224.  *  funcPtr     [IN]           
  225.  * RETURNS   
  226.  *  void   
  227.  *****************************************************************************/    
  228. void  StartTimer(U16 timerid, U32 delay, FuncPtr funcPtr)   
  229. {   
  230.     /*----------------------------------------------------------------*/    
  231.     /* Local Variables                                                */    
  232.     /*----------------------------------------------------------------*/    
  233.    
  234.     /*----------------------------------------------------------------*/    
  235.     /* Code Body                                                      */    
  236.     /*----------------------------------------------------------------*/    
  237.     L4StopTimer(timerid);   
  238.     L4StartTimer(timerid, (oslTimerFuncPtr)funcPtr,    
  239.                     (void  *)timerid, delay, TIMER_IS_ALIGNMENT);   
  240. }   
  241.    
  242.    
  243. /*****************************************************************************   
  244.  * FUNCTION   
  245.  *  StartTimerEx   
  246.  * DESCRIPTION   
  247.  *  This is used to set a timer with the argument   
  248.  * PARAMETERS   
  249.  *  timerid     [IN]           
  250.  *  delay       [IN]           
  251.  *  funcPtr     [IN]           
  252.  *  arg         [IN]   
  253.  * RETURNS   
  254.  *  void   
  255.  *****************************************************************************/    
  256. void  StartTimerEx(U16 timerid, U32 delay, oslTimerFuncPtr funcPtr,  void * arg)   
  257. {   
  258.     /*----------------------------------------------------------------*/    
  259.     /* Local Variables                                                */    
  260.     /*----------------------------------------------------------------*/    
  261.    
  262.     /*----------------------------------------------------------------*/    
  263.     /* Code Body                                                      */    
  264.     /*----------------------------------------------------------------*/    
  265.     L4StopTimer(timerid);   
  266.     L4StartTimer(timerid, (oslTimerFuncPtr)funcPtr,    
  267.                     (void  *)arg, delay, TIMER_IS_ALIGNMENT);   
  268. }   
  269.    
  270.    
  271. /*****************************************************************************   
  272.  * FUNCTION   
  273.  *  StartNonAlignTimer   
  274.  * DESCRIPTION   
  275.  *  start a non-alignment timer   
  276.  * PARAMETERS   
  277.  *  timerid     [IN]           
  278.  *  delay       [IN]           
  279.  *  funcPtr     [IN]           
  280.  * RETURNS   
  281.  *  void   
  282.  *****************************************************************************/    
  283. void  StartNonAlignTimer(U16 timerid, U32 delay, FuncPtr funcPtr)   
  284. {   
  285.     /*----------------------------------------------------------------*/    
  286.     /* Local Variables                                                */    
  287.     /*----------------------------------------------------------------*/    
  288.    
  289.     /*----------------------------------------------------------------*/    
  290.     /* Code Body                                                      */    
  291.     /*----------------------------------------------------------------*/    
  292.     L4StopTimer(timerid);   
  293.     L4StartTimer(timerid, (oslTimerFuncPtr)funcPtr,    
  294.                     (void  *)timerid, delay, TIMER_IS_NO_ALIGNMENT);   
  295. }   
  296.    
  297.    
  298. /*****************************************************************************   
  299.  * FUNCTION   
  300.  *  StartNonAlignTimerEx   
  301.  * DESCRIPTION   
  302.  *  start a non-alignment timer with the argument   
  303.  * PARAMETERS   
  304.  *  timerid     [IN]           
  305.  *  delay       [IN]           
  306.  *  funcPtr     [IN]           
  307.  *  argument    [IN]   
  308.  * RETURNS   
  309.  *  void   
  310.  *****************************************************************************/    
  311. void  StartNonAlignTimerEx(U16 timerid, U32 delay, oslTimerFuncPtr funcPtr,  void * arg)   
  312. {   
  313.     /*----------------------------------------------------------------*/    
  314.     /* Local Variables                                                */    
  315.     /*----------------------------------------------------------------*/    
  316.    
  317.     /*----------------------------------------------------------------*/    
  318.     /* Code Body                                                      */    
  319.     /*----------------------------------------------------------------*/    
  320.     L4StopTimer(timerid);   
  321.     L4StartTimer(timerid, (oslTimerFuncPtr)funcPtr,    
  322.                     (void  *)arg, delay, TIMER_IS_NO_ALIGNMENT);   
  323. }   
  324.    
  325. /*****************************************************************************   
  326.  * FUNCTION   
  327.  *  StopTimer   
  328.  * DESCRIPTION   
  329.  *  This is used to reset a timer   
  330.  * PARAMETERS   
  331.  *  timerid     [IN]           
  332.  * RETURNS   
  333.  *  void   
  334.  *****************************************************************************/    
  335. void  StopTimer(U16 timerid)   
  336. {   
  337.     /*----------------------------------------------------------------*/    
  338.     /* Local Variables                                                */    
  339.     /*----------------------------------------------------------------*/    
  340.    
  341.     /*----------------------------------------------------------------*/    
  342.     /* Code Body                                                      */    
  343.     /*----------------------------------------------------------------*/    
  344.     L4StopTimer(timerid);   
  345. }   
  346.    
  347.    
  348. /*****************************************************************************   
  349.  * FUNCTION   
  350.  *  EvshedMMITimerHandler   
  351.  * DESCRIPTION   
  352.  *  MMI Timer Event Scheduler   
  353.  * PARAMETERS   
  354.  *  dataPtr     [IN]        Data from L4   
  355.  * RETURNS   
  356.  *  void   
  357.  *****************************************************************************/    
  358. void  EvshedMMITimerHandler( void  *dataPtr)   
  359. {   
  360.     /*----------------------------------------------------------------*/    
  361.     /* Local Variables                                                */    
  362.     /*----------------------------------------------------------------*/    
  363.     stack_timer_struct *stack_timer_ptr;   
  364.    
  365.     stack_timer_ptr = (stack_timer_struct*) dataPtr;   
  366.    
  367.     /*----------------------------------------------------------------*/    
  368.     /* Code Body                                                      */    
  369.     /*----------------------------------------------------------------*/    
  370.     if  (stack_timer_ptr == &base_timer1)   
  371.     {   
  372.         if  (stack_is_time_out_valid(&base_timer1))   
  373.         {   
  374.             evshed_timer_handler(event_scheduler1_ptr);   
  375.         }   
  376.         stack_process_time_out(&base_timer1);   
  377.     }   
  378.     else   if  (stack_timer_ptr == &base_timer2)   
  379.     {   
  380.         if  (stack_is_time_out_valid(&base_timer2))   
  381.         {   
  382.             evshed_timer_handler(event_scheduler2_ptr);   
  383.         }   
  384.         stack_process_time_out(&base_timer2);   
  385.     }   
  386. }   
  387.    
  388.    
  389. /*****************************************************************************   
  390.  * FUNCTION   
  391.  *  L4SetClock   
  392.  * DESCRIPTION   
  393.  *  This function is to set the clock request.   
  394.  * PARAMETERS   
  395.  *  datetime        [IN]           
  396.  *  FuncRspPtr      [IN]           
  397.  *  a(?)            [IN]        Void   
  398.  * RETURNS   
  399.  *  void   
  400.  *****************************************************************************/    
  401. void  L4SetClock(rtc_format_struct datetime, oslTaskFuncPtr FuncRspPtr)   
  402. {   
  403.     /*----------------------------------------------------------------*/    
  404.     /* Local Variables                                                */    
  405.     /*----------------------------------------------------------------*/    
  406.     ilm_struct *ilm_ptr = NULL;   
  407.     mmi_eq_set_rtc_time_req_struct *local_data;   
  408.    
  409.     /*----------------------------------------------------------------*/    
  410.     /* Code Body                                                      */    
  411.     /*----------------------------------------------------------------*/    
  412.     /* store the set time clock callback function */    
  413.     set_clocktime_callback_func = FuncRspPtr;   
  414.    
  415.     ilm_ptr = allocate_ilm(MOD_MMI);   
  416.     ilm_ptr->msg_id = (U16) MSG_ID_MMI_EQ_SET_RTC_TIME_REQ;   
  417.     local_data = (mmi_eq_set_rtc_time_req_struct*)   
  418.         construct_local_para(sizeof (mmi_eq_set_rtc_time_req_struct), TD_CTRL);   
  419.    
  420.     local_data->set_type = RTC_SETTING_TYPE_DATETIME;   
  421.     local_data->rtc_type = RTC_TIME_CLOCK_IND;   
  422.     local_data->info.alarm_format = 0;   
  423.     local_data->info.alarm_index = 0;   
  424.     local_data->info.type = 0;   
  425.     local_data->info.text[0] = '/0' ;   
  426.     local_data->info.recurr = 0;   
  427.     local_data->info.data_time.rtc_year = datetime.rtc_year;   
  428.     local_data->info.data_time.rtc_wday = datetime.rtc_wday;   
  429.     local_data->info.data_time.rtc_mon = datetime.rtc_mon;   
  430.     local_data->info.data_time.rtc_day = datetime.rtc_day;   
  431.     local_data->info.data_time.rtc_hour = datetime.rtc_hour;   
  432.     local_data->info.data_time.rtc_min = datetime.rtc_min;   
  433.     local_data->info.data_time.rtc_sec = datetime.rtc_sec;   
  434.    
  435.     ilm_ptr->local_para_ptr = (local_para_struct*) local_data;   
  436.     ilm_ptr->peer_buff_ptr = NULL;   
  437.     SEND_ILM(MOD_MMI, MOD_L4C, MMI_L4C_SAP, ilm_ptr);   
  438. }   
  439.    
  440.    
  441. /*****************************************************************************   
  442.  * FUNCTION   
  443.  *  L4SetClockRSP   
  444.  * DESCRIPTION   
  445.  *  This function is to get to the result of clock set response.   
  446.  * PARAMETERS   
  447.  *  buf         [?]            
  448.  *  a(?)        [IN]        Buf   
  449.  * RETURNS   
  450.  *  void   
  451.  *****************************************************************************/    
  452. void  L4SetClockRSP( void  *buf)   
  453. {   
  454.     /*----------------------------------------------------------------*/    
  455.     /* Local Variables                                                */    
  456.     /*----------------------------------------------------------------*/    
  457.    
  458.     /*----------------------------------------------------------------*/    
  459.     /* Code Body                                                      */    
  460.     /*----------------------------------------------------------------*/    
  461.     if  (set_clocktime_callback_func != NULL)   
  462.     {   
  463.         set_clocktime_callback_func(buf);   
  464.     }   
  465. }   
  466.    
  467.    
  468. /*****************************************************************************   
  469.  * FUNCTION   
  470.  *  L4GetClockTime   
  471.  * DESCRIPTION   
  472.  *  This function is to request to get the clock.   
  473.  * PARAMETERS   
  474.  *  FuncRspPtr      [IN]           
  475.  *  a(?)            [IN]        Void   
  476.  * RETURNS   
  477.  *  void   
  478.  *****************************************************************************/    
  479. void  L4GetClockTime(oslTaskFuncPtr FuncRspPtr)   
  480. {   
  481.     /*----------------------------------------------------------------*/    
  482.     /* Local Variables                                                */    
  483.     /*----------------------------------------------------------------*/    
  484.     ilm_struct *ilm_ptr = NULL;   
  485.     mmi_eq_get_rtc_time_req_struct *local_data;   
  486.    
  487.     /*----------------------------------------------------------------*/    
  488.     /* Code Body                                                      */    
  489.     /*----------------------------------------------------------------*/    
  490.     /* store the get time clock callback function */    
  491.     get_clocktime_callback_func = FuncRspPtr;   
  492.    
  493.     ilm_ptr = allocate_ilm(MOD_MMI);   
  494.     local_data = (mmi_eq_get_rtc_time_req_struct*)   
  495.         construct_local_para(sizeof (mmi_eq_get_rtc_time_req_struct), TD_CTRL);   
  496.    
  497.     local_data->rtc_type = RTC_TIME_CLOCK_IND;   
  498.    
  499.     ilm_ptr->msg_id = (U16) MSG_ID_MMI_EQ_GET_RTC_TIME_REQ;   
  500.     ilm_ptr->local_para_ptr = (local_para_struct*) local_data;   
  501.     ilm_ptr->peer_buff_ptr = NULL;   
  502.    
  503.     SEND_ILM(MOD_MMI, MOD_L4C, MMI_L4C_SAP, ilm_ptr);   
  504. }   
  505.    
  506.    
  507. /*****************************************************************************   
  508.  * FUNCTION   
  509.  *  L4GetClockTimeRSP   
  510.  * DESCRIPTION   
  511.  *  This function is to receive the clock response.   
  512.  * PARAMETERS   
  513.  *  buf         [?]            
  514.  *  a(?)        [IN]        Buf   
  515.  * RETURNS   
  516.  *  void   
  517.  *****************************************************************************/    
  518. void  L4GetClockTimeRSP( void  *buf)   
  519. {   
  520.     /*----------------------------------------------------------------*/    
  521.     /* Local Variables                                                */    
  522.     /*----------------------------------------------------------------*/    
  523.    
  524.     /*----------------------------------------------------------------*/    
  525.     /* Code Body                                                      */    
  526.     /*----------------------------------------------------------------*/    
  527.     if  (get_clocktime_callback_func != NULL)   
  528.     {   
  529.         get_clocktime_callback_func(buf);   
  530.     }   
  531. }   
  532.    
  533.    
  534. /*****************************************************************************   
  535.  * FUNCTION   
  536.  *  L4InitTimer   
  537.  * DESCRIPTION   
  538.  *  This function is to init the timer while task create.   
  539.  * PARAMETERS   
  540.  *  void   
  541.  *  a(?)        [IN]        Void   
  542.  * RETURNS   
  543.  *  void   
  544.  *****************************************************************************/    
  545. void  L4InitTimer( void )   
  546. {   
  547.     /*----------------------------------------------------------------*/    
  548.     /* Local Variables                                                */    
  549.     /*----------------------------------------------------------------*/    
  550.     TIMERTABLE *p;   
  551.     TIMERTABLE *pp;   
  552.    
  553.     /*----------------------------------------------------------------*/    
  554.     /* Code Body                                                      */    
  555.     /*----------------------------------------------------------------*/    
  556.     /* Try to free TIMERTABLE list exclude g_timer_table */    
  557.     p = g_timer_table.next;   
  558.     pp = NULL;   
  559.     do    
  560.     {   
  561.         if  (p != NULL)   
  562.         {   
  563.             pp = p->next;   
  564.             OslMfree(p);   
  565.         }   
  566.         p = pp;   
  567.     } while  (p != NULL);   
  568.     /* reset g_timer_talbe */    
  569.     memset(&g_timer_table, 0, sizeof (TIMERTABLE));   
  570.     g_timer_table_size = SIMULTANEOUS_TIMER_NUM;   
  571.     g_timer_table_used = 0;   
  572.    
  573.     /* Initiate the clock time callback function. */    
  574.     get_clocktime_callback_func = NULL;   
  575.     set_clocktime_callback_func = NULL;   
  576.    
  577.     /* Initate the no alignment stack timer */    
  578.     stack_init_timer(&base_timer1, "MMI_Base_Timer1" , MOD_MMI);   
  579.    
  580.     /* Create a no alignment timer schedule */    
  581.     event_scheduler1_ptr = new_evshed(   
  582.                             &base_timer1,   
  583.                             L4StartBaseTimer,   
  584.                             L4StopBaseTimer,   
  585.                             0,   
  586.                             kal_evshed_get_mem,   
  587.                             kal_evshed_free_mem,   
  588.                             0);   
  589.    
  590.     /* Initate the alignment stack timer */    
  591.     stack_init_timer(&base_timer2, "MMI_Base_Timer2" , MOD_MMI);   
  592.    
  593.     /* Create an alignment timer schedule */    
  594.     event_scheduler2_ptr = new_evshed(   
  595.                             &base_timer2,   
  596.                             L4StartBaseTimer,   
  597.                             L4StopBaseTimer,   
  598.                             0,   
  599.                             kal_evshed_get_mem,   
  600.                             kal_evshed_free_mem,   
  601.                             254);   
  602.    
  603.     #ifdef __MMI_FRM_TIMER_UNIT_TEST__       
  604.     mmi_frm_ut_timer();   
  605.     #endif /* __MMI_FRM_TIMER_UNIT_TEST__ */    
  606.    
  607. }   
  608.    
  609.    
  610. /*****************************************************************************   
  611.  * FUNCTION   
  612.  *  L4StartTimer   
  613.  * DESCRIPTION   
  614.  *  This function is to start timer. To added for two kinds of timer,    
  615.  *  one is for exactly time, another allow to delay.   
  616.  * PARAMETERS   
  617.  *  nTimerId            [IN]        timer id    
  618.  *  TimerExpiry         [IN]        timer expiry callback function   
  619.  *  funcArg             [IN]        argument for expiry callback function    
  620.  *  nTimeDuration       [IN]        timeout value   
  621.  *  alignment           [IN]        alignment/non-alignment attribute   
  622.  * RETURNS   
  623.  *  void   
  624.  *****************************************************************************/    
  625. static   void  L4StartTimer(   
  626.         unsigned short  nTimerId,   
  627.         oslTimerFuncPtr TimerExpiry,   
  628.         void  *funcArg,   
  629.         unsigned long  nTimeDuration,   
  630.         unsigned char  alignment)   
  631. {   
  632.     /*----------------------------------------------------------------*/    
  633.     /* Local Variables                                                */    
  634.     /*----------------------------------------------------------------*/    
  635.     TIMERTABLE *pTable = NULL;   
  636.     U16 i = 0;   
  637.     U32 temp;   
  638.    
  639.     /*----------------------------------------------------------------*/    
  640.     /* Code Body                                                      */    
  641.     /*----------------------------------------------------------------*/    
  642.     if  (TimerExpiry == NULL)   
  643.     {   /* If TimerExpiry is NULL, we don't start the timer */    
  644.         MMI_ASSERT(0);   
  645.         return ;   
  646.     }   
  647.    
  648.     MMI_ASSERT(nTimerId < MAX_TIMERS);   
  649.    
  650.     if  (L4TimerUsePreciseTick(nTimerId))   
  651.     {   
  652.         alignment = TIMER_IS_NO_ALIGNMENT;   
  653.     }   
  654.    
  655.     if  (nTimeDuration == 1000)   
  656.     {   
  657.         temp = KAL_TICKS_1_SEC - 4;   
  658.     }   
  659.     else    
  660.     {   
  661.         temp = (U32)((nTimeDuration / 5) * MMI_TICKS_5_MSEC);   
  662.     }   
  663.    
  664.     if  (temp == 0)   
  665.     {   
  666.         /* Cause by by rounding. If expire immediately, MoDIS boot-up failure because MMI keeps running and block NVRAM task */    
  667.         temp = (U32)MMI_TICKS_5_MSEC;   
  668.     }   
  669.    
  670.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_L4DRV_STARTTIMER_HDLR, nTimerId, TimerExpiry, temp, alignment));   
  671.    
  672.     pTable = &g_timer_table;   
  673.     if  (g_timer_table_used >= g_timer_table_size)   
  674.     {   
  675.         /*   
  676.          * TIMERTABLE list doesn't have enough space, allocate the memory    
  677.          *   
  678.          * If we need to allocate the memeory, it means that MMI may have    
  679.          * such many timers run simultaneously. We won't free the memory    
  680.          * after we allocate more memory in TIMERTABLE list.   
  681.          */    
  682.         do    
  683.         {   
  684.             if  (pTable->next == NULL)   
  685.             {   
  686.                 pTable->next = OslMalloc(sizeof (TIMERTABLE));   
  687.                 memset(pTable->next, 0, sizeof (TIMERTABLE));   
  688.                 g_timer_table_size += SIMULTANEOUS_TIMER_NUM;   
  689.                 pTable = pTable->next;   
  690.                 i = 0;   
  691.                 break ;   
  692.             }   
  693.             pTable = pTable->next;   
  694.         } while  (pTable != NULL);   
  695.     }   
  696.     else    
  697.     {   
  698.         /* find the empty record in g_timer_table list */    
  699.         i = 0;   
  700.         do    
  701.         {   
  702.             if  (pTable-> tm [i].event_id == NULL)   
  703.             {   /* find the empty space */    
  704.                 break ;   
  705.             }   
  706.             i++;   
  707.             if  (i >= SIMULTANEOUS_TIMER_NUM)   
  708.             {   
  709.                 pTable = pTable->next;   
  710.                 i = 0;   
  711.             }   
  712.         } while  (pTable != NULL);   
  713.    
  714.         if  (pTable == NULL)   
  715.         {   
  716.             /* Can't find the empty space in TIMERTABLE list, assert!!! */    
  717.             MMI_ASSERT(0);   
  718.         }   
  719.     }   /* if (g_timer_table_used >= g_timer_table_size) */    
  720.    
  721.     /*    
  722.      * already find the empty record, and then start timer    
  723.      *   
  724.      * event_sheduler1 = NO alignment scherulder   
  725.      * event_sheduler2 = alignment scherulder (low power)   
  726.      */    
  727.     if  (alignment == TIMER_IS_NO_ALIGNMENT)   
  728.     {   
  729.         /* MSB(Most Significant Bit) is align_timer_mask */    
  730.         pTable->tm [i].timer_info = nTimerId | NO_ALIGNMENT_TIMER_MASK;   
  731.         pTable->tm [i].event_id = evshed_set_event(   
  732.                                     event_scheduler1_ptr,   
  733.                                     (kal_timer_func_ptr) L4CallBackTimer,   
  734.                                     (void *)&(pTable-> tm [i]),   
  735.                                     temp);   
  736.         pTable->tm [i].arg = funcArg;   
  737.         pTable->tm [i].callback_func = TimerExpiry;   
  738.         g_timer_table_used++;   
  739.     }   
  740.     else   if  (alignment == TIMER_IS_ALIGNMENT)   
  741.     {   
  742.         /* MSB(Most Significant Bit) is align_timer_mask */    
  743.         pTable->tm [i].timer_info = nTimerId | ALIGNMENT_TIMER_MASK;   
  744.         pTable->tm [i].event_id = evshed_set_event(   
  745.                                     event_scheduler2_ptr,   
  746.                                     (kal_timer_func_ptr) L4CallBackTimer,   
  747.                                     (void *)&(pTable-> tm [i]),   
  748.                                     temp);   
  749.         pTable->tm [i].arg = funcArg;   
  750.         pTable->tm [i].callback_func = TimerExpiry;   
  751.         g_timer_table_used++;   
  752.     }   
  753. }   
  754.    
  755.    
  756. /*****************************************************************************   
  757.  * FUNCTION   
  758.  *  mmi_frm_is_align_base_timer   
  759.  * DESCRIPTION   
  760.  *  is the given base timer an alignment one   
  761.  * PARAMETERS   
  762.  *  base_timer_ptr        [IN]        base timer pointer   
  763.  * RETURNS   
  764.  *  IMER_IS_ALIGNMENT (MMI_TRUE) or TIMER_IS_NO_ALIGNMENT (MMI_FALSE)   
  765.  *****************************************************************************/    
  766. MMI_BOOL mmi_frm_is_align_base_timer(void  *base_timer_ptr)   
  767. {   
  768.     if  ( base_timer_ptr == ( void  *)&base_timer2 )   
  769.         return  MMI_TRUE;   
  770.     else    
  771.         return  MMI_FALSE;   
  772. }   
  773.    
  774.    
  775. /*****************************************************************************   
  776.  * FUNCTION   
  777.  *  mmi_frm_suspend_timers   
  778.  * DESCRIPTION   
  779.  *  suspend all timers of given type   
  780.  * PARAMETERS   
  781.  *  type        [IN]        timer type (alignment or non-alignment)   
  782.  * RETURNS   
  783.  *  none   
  784.  *****************************************************************************/    
  785. void  mmi_frm_suspend_timers(U32 type)   
  786. {   
  787.     /*----------------------------------------------------------------*/    
  788.     /* Local Variables                                                */    
  789.     /*----------------------------------------------------------------*/    
  790.     event_scheduler *ev = NULL;   
  791.    
  792.     /*----------------------------------------------------------------*/    
  793.     /* Code Body                                                      */    
  794.     /*----------------------------------------------------------------*/        
  795.     switch (type)   
  796.     {   
  797.     case  TIMER_IS_NO_ALIGNMENT:   
  798.    
  799.         ev = event_scheduler1_ptr;   
  800.         break ;   
  801.            
  802.     case  TIMER_IS_ALIGNMENT:   
  803.         ev = event_scheduler2_ptr;   
  804.         break ;   
  805.    
  806.     default :   
  807.         /* undefined type */    
  808.         MMI_ASSERT(0);   
  809.         break ;   
  810.     }   
  811.     evshed_suspend_all_events(ev);   
  812. }   
  813.    
  814.    
  815. /*****************************************************************************   
  816.  * FUNCTION   
  817.  *  mmi_frm_resume_timers   
  818.  * DESCRIPTION   
  819.  *  resume all timers of given type   
  820.  * PARAMETERS   
  821.  *  type        [IN]        timer type (alignment or non-alignment)   
  822.  * RETURNS   
  823.  *  none   
  824.  *****************************************************************************/    
  825. void  mmi_frm_resume_timers(U32 type)   
  826. {   
  827.     /*----------------------------------------------------------------*/    
  828.     /* Local Variables                                                */    
  829.     /*----------------------------------------------------------------*/    
  830.     event_scheduler *ev = NULL;   
  831.    
  832.     /*----------------------------------------------------------------*/    
  833.     /* Code Body                                                      */    
  834.     /*----------------------------------------------------------------*/        
  835.     switch (type)   
  836.     {   
  837.     case  TIMER_IS_NO_ALIGNMENT:   
  838.    
  839.         ev = event_scheduler1_ptr;   
  840.         break ;   
  841.            
  842.     case  TIMER_IS_ALIGNMENT:   
  843.         ev = event_scheduler2_ptr;   
  844.         break ;   
  845.    
  846.     default :   
  847.         /* undefined type */    
  848.         MMI_ASSERT(0);   
  849.         break ;   
  850.     }   
  851.     evshed_resume_all_events(ev);   
  852. }   
  853.    
  854.    
  855. /*****************************************************************************   
  856.  * FUNCTION   
  857.  *  IsMyTimerExist   
  858.  * DESCRIPTION   
  859.  *  does the timer exist   
  860.  * PARAMETERS   
  861.  *  nTimerId        [IN]           
  862.  * RETURNS   
  863.  *  timer exists or not   
  864.  *****************************************************************************/    
  865. BOOL  IsMyTimerExist(U16 nTimerId)   
  866. {   
  867.     /*----------------------------------------------------------------*/    
  868.     /* Local Variables                                                */    
  869.     /*----------------------------------------------------------------*/    
  870.     TIMERTABLE *pTable = &g_timer_table;   
  871.     U16 i = 0;   
  872.    
  873.     /*----------------------------------------------------------------*/    
  874.     /* Code Body                                                      */    
  875.     /*----------------------------------------------------------------*/    
  876.     MMI_ASSERT(nTimerId < MAX_TIMERS);   
  877.    
  878.     /* find the nTimerId in TIMERTABLE list */    
  879.      do    
  880.      {   
  881.          /* MSB(Most Significant Bit) of timer_id is align_timer_mask */    
  882.          if  ((pTable-> tm [i].timer_info & (~NO_ALIGNMENT_TIMER_MASK)) == nTimerId)   
  883.          {   
  884.             /* timer found */    
  885.             return  MMI_TRUE;   
  886.          }   
  887.          i++;   
  888.          if  (i >= SIMULTANEOUS_TIMER_NUM)   
  889.          {   
  890.              pTable = pTable->next;   
  891.              i = 0;   
  892.          }   
  893.      } while  (pTable != NULL);   
  894.        
  895.     return  MMI_FALSE;   
  896. }   
  897.    
  898.    
  899. /*****************************************************************************    
  900. * Local Function   
  901. *****************************************************************************/    
  902.    
  903. #ifdef __MMI_FRM_TIMER_UNIT_TEST__    
  904.    
  905. #define ALIGN_TEST_TIMEOUT      1000   /* ms */    
  906. #define NON_ALIGN_TEST_TIMEOUT  1100   /* ms */    
  907.    
  908. #define ALIGN_TEST_TM_ID        MMI_TIMER_BASE    
  909. #define NON_ALIGN_TEST_TM_ID    KEY_TIMER_ID_NONE    
  910.    
  911. /*****************************************************************************   
  912.  * FUNCTION   
  913.  *  mmi_frm_ut_timer   
  914.  * DESCRIPTION   
  915.  *  timer unit-test   
  916.  * PARAMETERS   
  917.  *  none   
  918.  * RETURNS   
  919.  *  none   
  920.  *****************************************************************************/    
  921. static   void  mmi_frm_ut_timer( void )   
  922. {   
  923.     /* unit test for non-alignment timer in NVRAM access */    
  924.     L4StartTimer(NON_ALIGN_TEST_TM_ID, (oslTimerFuncPtr)mmi_frm_ut_nonalign_timer,    
  925.         (void  *)NON_ALIGN_TEST_TM_ID, NON_ALIGN_TEST_TIMEOUT, TIMER_IS_NO_ALIGNMENT);   
  926.        
  927.     /* unit test for alignment timer in NVRAM access */    
  928.     L4StartTimer(ALIGN_TEST_TM_ID, (oslTimerFuncPtr)mmi_frm_ut_align_timer,    
  929.         (void  *)ALIGN_TEST_TM_ID, ALIGN_TEST_TIMEOUT, TIMER_IS_ALIGNMENT);   
  930. }   
  931.    
  932.    
  933. /*****************************************************************************   
  934.  * FUNCTION   
  935.  *  mmi_frm_ut_nonalign_timer   
  936.  * DESCRIPTION   
  937.  *  timer callback for non-align timer unit test   
  938.  * PARAMETERS   
  939.  *  timer id   
  940.  * RETURNS   
  941.  *  none   
  942.  *****************************************************************************/    
  943. static   void  mmi_frm_ut_nonalign_timer( void  *p)   
  944. {   
  945.     if  (IsInNVRAMProcedure())   
  946.     {   
  947.         Trace2(TRACE_GROUP_1, "[UT] non-align timer works in nvram access" );   
  948.         //kal_print("/n[UT] non-align timer works in nvram access/n");    
  949.     }   
  950.     else    
  951.     {   
  952.         L4StartTimer(NON_ALIGN_TEST_TM_ID, (oslTimerFuncPtr)mmi_frm_ut_nonalign_timer,    
  953.             (void  *)NON_ALIGN_TEST_TM_ID, NON_ALIGN_TEST_TIMEOUT, TIMER_IS_NO_ALIGNMENT);   
  954.     }       
  955. }   
  956.    
  957.    
  958. /*****************************************************************************   
  959.  * FUNCTION   
  960.  *  mmi_frm_ut_align_timer   
  961.  * DESCRIPTION   
  962.  *  timer callback for align timer unit test   
  963.  * PARAMETERS   
  964.  *  timer id   
  965.  * RETURNS   
  966.  *  none   
  967.  *****************************************************************************/    
  968. static   void  mmi_frm_ut_align_timer( void  *p)   
  969. {   
  970.     if  (IsInNVRAMProcedure())   
  971.     {   
  972.         Trace2(TRACE_GROUP_1, "[UT] align timer will die in nvram access" );   
  973.         MMI_ASSERT(0);   
  974.     }   
  975.     else    
  976.     {   
  977.         L4StartTimer(ALIGN_TEST_TM_ID, (oslTimerFuncPtr)mmi_frm_ut_align_timer,    
  978.             (void  *)ALIGN_TEST_TM_ID, ALIGN_TEST_TIMEOUT, TIMER_IS_ALIGNMENT);   
  979.     }       
  980. }   
  981.    
  982.    
  983. /*****************************************************************************   
  984.  * FUNCTION   
  985.  *  mmi_frm_ut_timer_with_arg   
  986.  * DESCRIPTION   
  987.  *  time unit-test:   
  988.  *  StartTimerEx(), StartNonAlignTimerEx(), StopTimer()   
  989.  * PARAMETERS   
  990.  *  tc          [IN]        test case id     
  991.  * RETURNS   
  992.  *  none   
  993.  *****************************************************************************/    
  994. static   void  mmi_frm_ut_align_timer_with_arg( void  *p);   
  995. static   void  mmi_frm_ut_nonalign_timer_with_arg( void  *p);   
  996. void  mmi_frm_ut_timer_with_arg( int  tc)   
  997. {   
  998.     /*----------------------------------------------------------------*/    
  999.     /* Local Variables                                                */    
  1000.     /*----------------------------------------------------------------*/    
  1001.        
  1002.     /*----------------------------------------------------------------*/    
  1003.     /* Code Body                                                      */    
  1004.     /*----------------------------------------------------------------*/    
  1005.     /* We could parser the string to execute the different actions. */    
  1006.     switch (tc)   
  1007.     {   
  1008.         case  1:   
  1009.             Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_timer_with_arg : 1" );   
  1010.             StartTimerEx(ALIGN_TEST_TM_ID, ALIGN_TEST_TIMEOUT, mmi_frm_ut_align_timer_with_arg, (void *)1);   
  1011.             StartNonAlignTimerEx(NON_ALIGN_TEST_TM_ID, NON_ALIGN_TEST_TIMEOUT, mmi_frm_ut_nonalign_timer_with_arg, (void *)110);   
  1012.             /* add the code here */    
  1013.             break ;   
  1014.         case  2:   
  1015.             Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_timer_with_arg : 2" );   
  1016.             StartTimerEx(ALIGN_TEST_TM_ID, ALIGN_TEST_TIMEOUT, mmi_frm_ut_align_timer_with_arg, (void *)20);   
  1017.             StartNonAlignTimerEx(NON_ALIGN_TEST_TM_ID, NON_ALIGN_TEST_TIMEOUT, mmi_frm_ut_nonalign_timer_with_arg, (void *)220);   
  1018.    
  1019.             /* add the code here */    
  1020.             break ;   
  1021.         case  3:   
  1022.             Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_timer_with_arg : 3" );   
  1023.             StopTimer(ALIGN_TEST_TM_ID);   
  1024.             StopTimer(NON_ALIGN_TEST_TM_ID);   
  1025.             /* add the code here */    
  1026.             break ;   
  1027.         default :   
  1028.             /* add the code here */    
  1029.             break ;   
  1030.     }   
  1031. }   
  1032.    
  1033.    
  1034. /*****************************************************************************   
  1035.  * FUNCTION   
  1036.  *  mmi_frm_ut_align_timer_with_arg   
  1037.  * DESCRIPTION   
  1038.  *  timer callback for align timer unit test   
  1039.  * PARAMETERS   
  1040.  *  timer id   
  1041.  * RETURNS   
  1042.  *  none   
  1043.  *****************************************************************************/    
  1044. static   void  mmi_frm_ut_align_timer_with_arg( void  *p)   
  1045. {   
  1046.     /*----------------------------------------------------------------*/    
  1047.     /* Local Variables                                                */    
  1048.     /*----------------------------------------------------------------*/    
  1049.        
  1050.     /*----------------------------------------------------------------*/    
  1051.     /* Code Body                                                      */    
  1052.     /*----------------------------------------------------------------*/    
  1053.     if  (( int )p == 1)   
  1054.     {   
  1055.         Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_align_timer_with_arg timeout (1)" );   
  1056.         StartTimerEx(ALIGN_TEST_TM_ID, ALIGN_TEST_TIMEOUT/3, mmi_frm_ut_align_timer_with_arg, (void *)2);   
  1057.     }   
  1058.     else   if  (( int )p == 2)   
  1059.     {   
  1060.         Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_align_timer_with_arg timeout (2)" );   
  1061.         StartTimerEx(ALIGN_TEST_TM_ID, ALIGN_TEST_TIMEOUT*2/3, mmi_frm_ut_align_timer_with_arg, (void *)3);   
  1062.     }   
  1063.     else   if  (( int )p == 3)   
  1064.     {   
  1065.         Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_align_timer_with_arg timeout (3) - finish" );   
  1066.     }   
  1067.     else   if  (( int )p == 20)   
  1068.     {   
  1069.         Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_align_timer_with_arg timeout (20)" );   
  1070.         StartTimerEx(ALIGN_TEST_TM_ID, ALIGN_TEST_TIMEOUT, mmi_frm_ut_align_timer_with_arg, (void *)21);   
  1071.     }   
  1072.     else   if  (( int )p == 21)   
  1073.     {   
  1074.         Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_align_timer_with_arg timeout (21)" );   
  1075.         StartTimerEx(ALIGN_TEST_TM_ID, ALIGN_TEST_TIMEOUT/2, mmi_frm_ut_align_timer_with_arg, (void *)20);   
  1076.     }   
  1077. }   
  1078.    
  1079.    
  1080. /*****************************************************************************   
  1081.  * FUNCTION   
  1082.  *  mmi_frm_ut_nonalign_timer_with_arg   
  1083.  * DESCRIPTION   
  1084.  *  timer callback for nonalign timer unit test   
  1085.  * PARAMETERS   
  1086.  *  timer id   
  1087.  * RETURNS   
  1088.  *  none   
  1089.  *****************************************************************************/    
  1090. static   void  mmi_frm_ut_nonalign_timer_with_arg( void  *p)   
  1091. {   
  1092.     /*----------------------------------------------------------------*/    
  1093.     /* Local Variables                                                */    
  1094.     /*----------------------------------------------------------------*/    
  1095.        
  1096.     /*----------------------------------------------------------------*/    
  1097.     /* Code Body                                                      */    
  1098.     /*----------------------------------------------------------------*/    
  1099.     if  (( int )p == 110)   
  1100.     {   
  1101.         Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_nonalign_timer_with_arg timeout (110)" );   
  1102.         StartNonAlignTimerEx(NON_ALIGN_TEST_TM_ID, NON_ALIGN_TEST_TIMEOUT*2, mmi_frm_ut_nonalign_timer_with_arg, (void *)120);   
  1103.     }   
  1104.     else   if  (( int )p == 120)   
  1105.     {   
  1106.         Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_nonalign_timer_with_arg timeout (120) - finish" );   
  1107.     }   
  1108.     else   if  (( int )p == 220)   
  1109.     {   
  1110.         Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_nonalign_timer_with_arg timeout (220)" );   
  1111.         StartNonAlignTimerEx(NON_ALIGN_TEST_TM_ID, NON_ALIGN_TEST_TIMEOUT/2, mmi_frm_ut_nonalign_timer_with_arg, (void *)221);   
  1112.     }   
  1113.     else   if  (( int )p == 221)   
  1114.     {   
  1115.         Trace2(TRACE_GROUP_1, "[Timer-UT] mmi_frm_ut_nonalign_timer_with_arg timeout (221)" );   
  1116.         StartNonAlignTimerEx(NON_ALIGN_TEST_TM_ID, NON_ALIGN_TEST_TIMEOUT, mmi_frm_ut_nonalign_timer_with_arg, (void *)220);   
  1117.     }   
  1118. }   
  1119.    
  1120. #endif /* __MMI_FRM_TIMER_UNIT_TEST__ */    
  1121.    
  1122.    
  1123. /*****************************************************************************   
  1124.  * FUNCTION   
  1125.  *  L4StopTimer   
  1126.  * DESCRIPTION   
  1127.  *  This function is to stop timer.    
  1128.  *  To added for two kinds of timer, one is for exactly time, another allow to delay.   
  1129.  * PARAMETERS   
  1130.  *  nTimerId        [IN]           
  1131.  *  a(?)            [IN]        NTimerId   
  1132.  * RETURNS   
  1133.  *  void   
  1134.  *****************************************************************************/    
  1135. static   void  L4StopTimer(unsigned  short  nTimerId)   
  1136. {   
  1137.     /*----------------------------------------------------------------*/    
  1138.     /* Local Variables                                                */    
  1139.     /*----------------------------------------------------------------*/    
  1140.     TIMERTABLE *pTable = &g_timer_table;   
  1141.     U16 i = 0;   
  1142.    
  1143.     /*----------------------------------------------------------------*/    
  1144.     /* Code Body                                                      */    
  1145.     /*----------------------------------------------------------------*/    
  1146.     MMI_ASSERT(nTimerId < MAX_TIMERS);   
  1147.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_L4DRV_STOPTIMER_HDLR, nTimerId));   
  1148.    
  1149.     /* find the nTimerId in TIMERTABLE list */    
  1150.     do    
  1151.     {   
  1152.         /* MSB(Most Significant Bit) of timer_id is align_timer_mask */    
  1153.         if  ((pTable-> tm [i].timer_info & (~NO_ALIGNMENT_TIMER_MASK)) == nTimerId)   
  1154.         {   
  1155.             /* find the nTimerId */    
  1156.             if  (pTable-> tm [i].event_id != NULL)   
  1157.             {   
  1158.                 if  ((pTable-> tm [i].timer_info & NO_ALIGNMENT_TIMER_MASK) == NO_ALIGNMENT_TIMER_MASK)   
  1159.                 {   /* NO_ALIGNMENT_TIMER */    
  1160.                     evshed_cancel_event(event_scheduler1_ptr, &(pTable->tm [i].event_id));   
  1161.                 }   
  1162.                 else    
  1163.                 {   /* ALIGNMENT_TIMER */    
  1164.                     evshed_cancel_event(event_scheduler2_ptr, &(pTable->tm [i].event_id));   
  1165.                 }   
  1166.    
  1167.                 g_timer_table_used--;   
  1168.                 memset( &(pTable->tm [i]), 0,  sizeof (mmi_frm_timer_type));   
  1169.             }   
  1170.             break ;   
  1171.         }   
  1172.         i++;   
  1173.         if  (i >= SIMULTANEOUS_TIMER_NUM)   
  1174.         {   
  1175.             pTable = pTable->next;   
  1176.             i = 0;   
  1177.         }   
  1178.     } while  (pTable != NULL);   
  1179.    
  1180.     /* if can't find nTimerId, do nothing */    
  1181.    
  1182. }   
  1183.    
  1184.    
  1185. /*****************************************************************************   
  1186.  * FUNCTION   
  1187.  *  L4StopBaseTimer   
  1188.  * DESCRIPTION   
  1189.  *  This function is to assign the stop timer base.   
  1190.  * PARAMETERS   
  1191.  *  base_timer_ptr      [?]            
  1192.  *  a(?)                [IN]        Base_timer_ptr   
  1193.  * RETURNS   
  1194.  *  void   
  1195.  *****************************************************************************/    
  1196. static   void  L4StopBaseTimer( void  *base_timer_ptr)   
  1197. {   
  1198.     /*----------------------------------------------------------------*/    
  1199.     /* Local Variables                                                */    
  1200.     /*----------------------------------------------------------------*/    
  1201.    
  1202.     /*----------------------------------------------------------------*/    
  1203.     /* Code Body                                                      */    
  1204.     /*----------------------------------------------------------------*/    
  1205.     stack_stop_timer((stack_timer_struct*) base_timer_ptr);   
  1206. }   
  1207.    
  1208.    
  1209. /*****************************************************************************   
  1210.  * FUNCTION   
  1211.  *  L4StartBaseTimer   
  1212.  * DESCRIPTION   
  1213.  *  This function is to assign the start timer base.   
  1214.  * PARAMETERS   
  1215.  *  base_timer_ptr      [?]            
  1216.  *  time_out            [IN]           
  1217.  *  a(?)                [IN]        Base_timer_ptr   
  1218.  *  b(?)                [IN]        Time_out   
  1219.  * RETURNS   
  1220.  *  void   
  1221.  *****************************************************************************/    
  1222. static   void  L4StartBaseTimer( void  *base_timer_ptr, unsigned  int  time_out)   
  1223. {   
  1224.     /*----------------------------------------------------------------*/    
  1225.     /* Local Variables                                                */    
  1226.     /*----------------------------------------------------------------*/    
  1227.    
  1228.     /*----------------------------------------------------------------*/    
  1229.     /* Code Body                                                      */    
  1230.     /*----------------------------------------------------------------*/    
  1231.     stack_start_timer((stack_timer_struct*) base_timer_ptr, 0, time_out);   
  1232. }   
  1233.    
  1234.    
  1235. /*****************************************************************************   
  1236.  * FUNCTION   
  1237.  *  L4TimerUsePreciseTick   
  1238.  * DESCRIPTION   
  1239.  *  Typically we round timer period to multiple of 100ms.    
  1240.  *  However, some timers need to be more accurate.   
  1241.  * PARAMETERS   
  1242.  *  nTimerId        [IN]        Timer ID   
  1243.  * RETURNS   
  1244.  *  void   
  1245.  *****************************************************************************/    
  1246. static  MMI_BOOL L4TimerUsePreciseTick(unsigned  short  nTimerId)   
  1247. {   
  1248.     /*----------------------------------------------------------------*/    
  1249.     /* Local Variables                                                */    
  1250.     /*----------------------------------------------------------------*/    
  1251.    
  1252.     /*----------------------------------------------------------------*/    
  1253.     /* Code Body                                                      */    
  1254.     /*----------------------------------------------------------------*/    
  1255.     switch  (nTimerId)   
  1256.     {   
  1257. #if defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__)    
  1258.         case  PEN_POLLING_TIMER:   
  1259.             return  MMI_TRUE;   
  1260. #endif /* defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__) */     
  1261.    
  1262. #ifdef __MMI_DSM__    
  1263.           case  DSM_TIMER:   
  1264.                 return  MMI_TRUE;   
  1265. #endif    
  1266.    
  1267.         default :   
  1268.             return  MMI_FALSE;   
  1269.     }   
  1270. }   
  1271.    
  1272.    
  1273. /*****************************************************************************   
  1274.  * FUNCTION   
  1275.  *  L4CallBackTimer   
  1276.  * DESCRIPTION   
  1277.  *  This function is to execute the timer expire.   
  1278.  * PARAMETERS   
  1279.  *  p           [IN]         pointer to timer item   
  1280.  * RETURNS   
  1281.  *  void   
  1282.  *****************************************************************************/    
  1283. static   void  L4CallBackTimer( void  *p)   
  1284. {   
  1285.     /*----------------------------------------------------------------*/    
  1286.     /* Local Variables                                                */    
  1287.     /*----------------------------------------------------------------*/    
  1288.     mmi_frm_timer_type *pTimer = (mmi_frm_timer_type *)p;   
  1289.     U32 nTimerId = pTimer->timer_info & (~NO_ALIGNMENT_TIMER_MASK);   
  1290.     oslTimerFuncPtr pTimerExpiry = pTimer->callback_func;   
  1291.     void  * arg = pTimer->arg;   
  1292.    
  1293.     /*----------------------------------------------------------------*/    
  1294.     /* Code Body                                                      */    
  1295.     /*----------------------------------------------------------------*/    
  1296.     MMI_ASSERT(nTimerId < MAX_TIMERS);   
  1297.    
  1298.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_L4DRV_CBTIMER_HDLR, nTimerId, pTimerExpiry));   
  1299.     g_timer_table_used--;   
  1300.     memset( pTimer, 0, sizeof (mmi_frm_timer_type));  /* clear timer */    
  1301.        
  1302.     /*   
  1303.      * we process g_timer_table_used, event_id and timer_id ... first    
  1304.      * because the user may call stoptimer() in the timer_expiry_func   
  1305.      */    
  1306.    
  1307.     if  (pTimerExpiry)   
  1308.     {   
  1309.         pTimerExpiry((void  *)arg);   
  1310.     }   
  1311.    
  1312.     mmi_frm_fetch_msg_from_extQ_to_circularQ();   
  1313.    
  1314.     /*    
  1315.      * Because we modify MMI process protocol events and key events mechanism,   
  1316.      * we don't need to process key events here.   
  1317.      */    
  1318. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值