L4Drv.C
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:33k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * L4Drv.C
- *
- * Project:
- * --------
- * MAUI
- *
- * Description:
- * ------------
- * This file is intends for Timer/Clock control.
- *
- * Author:
- * -------
- * -------
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- /*******************************************************************************
- * Copyright Notice
- * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
- * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
- * (It is illegal to remove this copyright notice from this software or any
- * portion of it)
- *******************************************************************************/
- /*******************************************************************************
- *
- * Filename:
- * ---------
- * L4Drv.c
- *
- * Project:
- * --------
- * MediaTeck GSM
- *
- * Description:
- * ------------
- * This Module defines the l4 driver routines.
- *
- * Author:
- * -------
- * -------
- *
- *
- * HISTORY
- * -------
- * Created On 13 Dec
- *******************************************************************************/
- /* ------- Include Files ----------------------------- */
- #ifndef MMI_ON_WIN32
- /* Include: MMI header file */
- #include "MMI_features.h"
- #include "stdC.h"
- #include "L4Dr1.h"
- #include "PixtelDataTypes.h"
- /* ... Add More MMI header */
- #include "globalconstants.h"
- #include "QueueGprot.h"
- #include "OslMemory.h"
- /* amit Audio L4 integration header file */
- #include "AudioInc.h"
- #include "TimerEvents.h"
- #include "TaskInit.h"
- #include "KeyBrd.h"
- #include "DebugInitDef.h"
- #include "l4dr.h"
- #include "MMI_trc.h"
- #include "gpioInc.h"
- #if defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__)
- #include "TouchScreenGprot.h"
- #endif
- #include "MMITaskProt.h"
- /*****************************************************************************
- * Define
- *****************************************************************************/
- /* the recommended value: 12 or 24 */
- #define SIMULTANEOUS_TIMER_NUM (12)
- /* MSB(Most Significant Bit) of g_timer_table.timer_id[i] is align_timer_mask */
- #define NO_ALIGNMENT_TIMER_MASK (0x8000)
- #define ALIGNMENT_TIMER_MASK (0)
- /* ticks of 20 millisecond. because KAL did not define the valye. define in floating falue to avoid early rouning */
- #define MMI_TICKS_20_MSEC (KAL_TICKS_1_SEC/50.0)
- /* ticks of 5 millisecond. because KAL did not define the valye. define in floating falue to avoid early rouning */
- #define MMI_TICKS_5_MSEC (KAL_TICKS_1_SEC/200.0)
- /*****************************************************************************
- * Typedef
- *****************************************************************************/
- typedef void (*L4FuncPtr) (oslParaType *);
- typedef struct
- {
- U16 eventID;
- L4FuncPtr entryFuncPtr;
- } L4eventInfo;
- /*
- * MTK added for two kinds of timer, one is for exactly time, another allow to delay.
- * TO Pixtel, This two defines should move to a proper place where
- * can be used by other files.
- */
- typedef struct timertable
- {
- /* store the timer_id. MSB(Most Significant Bit) is align_timer_mask */
- U16 timer_id[SIMULTANEOUS_TIMER_NUM];
- /* store the event_id that returns from evshed_set_event() */
- eventid event_id[SIMULTANEOUS_TIMER_NUM];
- /* store the timer_expiry_func */
- oslTimerFuncPtr callback_func[SIMULTANEOUS_TIMER_NUM];
- /* point to the next TIMERTABLE data */
- struct timertable *next;
- } TIMERTABLE;
- /*****************************************************************************
- * Local Variable
- *****************************************************************************/
- /*
- * In most case, the timers won't run simultaneously.
- * We run-time allocate the memory to store the timer information.
- */
- static TIMERTABLE g_timer_table = {0};
- static U16 g_timer_table_size = 0;
- static U16 g_timer_table_used = 0;
- static oslTaskFuncPtr get_clocktime_callback_func;
- static oslTaskFuncPtr set_clocktime_callback_func;
- /*****************************************************************************
- * Local Function
- *****************************************************************************/
- //#define __MMI_FRM_TIMER_UNIT_TEST__
- #ifdef __MMI_FRM_TIMER_UNIT_TEST__
- static void mmi_frm_ut_timer();
- static void mmi_frm_ut_align_timer(void *p);
- static void mmi_frm_ut_nonalign_timer(void *p);
- #endif /* __MMI_FRM_TIMER_UNIT_TEST__ */
- /*****************************************************************************
- * Global Variable
- *****************************************************************************/
- extern stack_timer_struct base_timer1;
- extern stack_timer_struct base_timer2;
- extern event_scheduler *event_scheduler1_ptr, *event_scheduler2_ptr;
- /*****************************************************************************
- * Global Function
- *****************************************************************************/
- /*****************************************************************************
- * FUNCTION
- * L4SetClock
- * DESCRIPTION
- * This function is to set the clock request.
- * PARAMETERS
- * datetime [IN]
- * FuncRspPtr [IN]
- * a(?) [IN] Void
- * RETURNS
- * void
- *****************************************************************************/
- void L4SetClock(rtc_format_struct datetime, oslTaskFuncPtr FuncRspPtr)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- ilm_struct *ilm_ptr = NULL;
- mmi_eq_set_rtc_time_req_struct *local_data;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* store the set time clock callback function */
- set_clocktime_callback_func = FuncRspPtr;
- ilm_ptr = allocate_ilm(MOD_MMI);
- ilm_ptr->msg_id = (U16) MSG_ID_MMI_EQ_SET_RTC_TIME_REQ;
- local_data = (mmi_eq_set_rtc_time_req_struct*)
- construct_local_para(sizeof(mmi_eq_set_rtc_time_req_struct), TD_CTRL);
- local_data->set_type = RTC_SETTING_TYPE_DATETIME;
- local_data->rtc_type = RTC_TIME_CLOCK_IND;
- local_data->info.alarm_format = 0;
- local_data->info.alarm_index = 0;
- local_data->info.type = 0;
- local_data->info.text[0] = ' ';
- local_data->info.recurr = 0;
- local_data->info.data_time.rtc_year = datetime.rtc_year;
- local_data->info.data_time.rtc_wday = datetime.rtc_wday;
- local_data->info.data_time.rtc_mon = datetime.rtc_mon;
- local_data->info.data_time.rtc_day = datetime.rtc_day;
- local_data->info.data_time.rtc_hour = datetime.rtc_hour;
- local_data->info.data_time.rtc_min = datetime.rtc_min;
- local_data->info.data_time.rtc_sec = datetime.rtc_sec;
- ilm_ptr->local_para_ptr = (local_para_struct*) local_data;
- ilm_ptr->peer_buff_ptr = NULL;
- SEND_ILM(MOD_MMI, MOD_L4C, MMI_L4C_SAP, ilm_ptr);
- }
- /*****************************************************************************
- * FUNCTION
- * L4SetClockRSP
- * DESCRIPTION
- * This function is to get to the result of clock set response.
- * PARAMETERS
- * buf [?]
- * a(?) [IN] Buf
- * RETURNS
- * void
- *****************************************************************************/
- void L4SetClockRSP(void *buf)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (set_clocktime_callback_func != NULL)
- {
- set_clocktime_callback_func(buf);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * L4GetClockTime
- * DESCRIPTION
- * This function is to request to get the clock.
- * PARAMETERS
- * FuncRspPtr [IN]
- * a(?) [IN] Void
- * RETURNS
- * void
- *****************************************************************************/
- void L4GetClockTime(oslTaskFuncPtr FuncRspPtr)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- ilm_struct *ilm_ptr = NULL;
- mmi_eq_get_rtc_time_req_struct *local_data;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* store the get time clock callback function */
- get_clocktime_callback_func = FuncRspPtr;
- ilm_ptr = allocate_ilm(MOD_MMI);
- local_data = (mmi_eq_get_rtc_time_req_struct*)
- construct_local_para(sizeof(mmi_eq_get_rtc_time_req_struct), TD_CTRL);
- local_data->rtc_type = RTC_TIME_CLOCK_IND;
- ilm_ptr->msg_id = (U16) MSG_ID_MMI_EQ_GET_RTC_TIME_REQ;
- ilm_ptr->local_para_ptr = (local_para_struct*) local_data;
- ilm_ptr->peer_buff_ptr = NULL;
- SEND_ILM(MOD_MMI, MOD_L4C, MMI_L4C_SAP, ilm_ptr);
- }
- /*****************************************************************************
- * FUNCTION
- * L4GetClockTimeRSP
- * DESCRIPTION
- * This function is to receive the clock response.
- * PARAMETERS
- * buf [?]
- * a(?) [IN] Buf
- * RETURNS
- * void
- *****************************************************************************/
- void L4GetClockTimeRSP(void *buf)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (get_clocktime_callback_func != NULL)
- {
- get_clocktime_callback_func(buf);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * L4InitTimer
- * DESCRIPTION
- * This function is to init the timer while task create.
- * PARAMETERS
- * void
- * a(?) [IN] Void
- * RETURNS
- * void
- *****************************************************************************/
- void L4InitTimer(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- TIMERTABLE *p;
- TIMERTABLE *pp;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Try to free TIMERTABLE list exclude g_timer_table */
- p = g_timer_table.next;
- pp = NULL;
- do
- {
- if (p != NULL)
- {
- pp = p->next;
- OslMfree(p);
- }
- p = pp;
- } while (p != NULL);
- /* reset g_timer_talbe */
- memset(&g_timer_table, 0, sizeof(TIMERTABLE));
- g_timer_table_size = SIMULTANEOUS_TIMER_NUM;
- g_timer_table_used = 0;
- /* Initiate the clock time callback function. */
- get_clocktime_callback_func = NULL;
- set_clocktime_callback_func = NULL;
- /* Initate the no alignment stack timer */
- stack_init_timer(&base_timer1, "MMI_Base_Timer1", MOD_MMI);
- /* Create a no alignment timer schedule */
- event_scheduler1_ptr = new_evshed(
- &base_timer1,
- L4StartBaseTimer,
- L4StopBaseTimer,
- 0,
- kal_evshed_get_mem,
- kal_evshed_free_mem,
- 0);
- /* Initate the alignment stack timer */
- stack_init_timer(&base_timer2, "MMI_Base_Timer2", MOD_MMI);
- /* Create an alignment timer schedule */
- event_scheduler2_ptr = new_evshed(
- &base_timer2,
- L4StartBaseTimer,
- L4StopBaseTimer,
- 0,
- kal_evshed_get_mem,
- kal_evshed_free_mem,
- 254);
- #ifdef __MMI_FRM_TIMER_UNIT_TEST__
- mmi_frm_ut_timer();
- #endif /* __MMI_FRM_TIMER_UNIT_TEST__ */
- }
- /*****************************************************************************
- * FUNCTION
- * L4StopBaseTimer
- * DESCRIPTION
- * This function is to assign the stop timer base.
- * PARAMETERS
- * base_timer_ptr [?]
- * a(?) [IN] Base_timer_ptr
- * RETURNS
- * void
- *****************************************************************************/
- void L4StopBaseTimer(void *base_timer_ptr)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- stack_stop_timer((stack_timer_struct*) base_timer_ptr);
- }
- /*****************************************************************************
- * FUNCTION
- * L4StartBaseTimer
- * DESCRIPTION
- * This function is to assign the start timer base.
- * PARAMETERS
- * base_timer_ptr [?]
- * time_out [IN]
- * a(?) [IN] Base_timer_ptr
- * b(?) [IN] Time_out
- * RETURNS
- * void
- *****************************************************************************/
- void L4StartBaseTimer(void *base_timer_ptr, unsigned int time_out)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- stack_start_timer((stack_timer_struct*) base_timer_ptr, 0, time_out);
- }
- /*****************************************************************************
- * FUNCTION
- * L4CallBackTimer
- * DESCRIPTION
- * This function is to execute the timer expire.
- * PARAMETERS
- * p [?]
- * a(?) [IN] P
- * RETURNS
- * void
- *****************************************************************************/
- void L4CallBackTimer(void *p)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U32 nTimerId = (U32) p;
- TIMERTABLE *pTable = &g_timer_table;
- U32 i = 0;
- oslTimerFuncPtr pTimerExpiry = NULL;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- MMI_ASSERT(nTimerId < MAX_TIMERS);
- /* find the nTimerId in TIMERTABLE list */
- do
- {
- /* MSB(Most Significant Bit) of timer_id[i] is align_timer_mask */
- if ((pTable->timer_id[i] & (~NO_ALIGNMENT_TIMER_MASK)) == (U16) nTimerId)
- {
- /* find out nTimerId */
- if (pTable->callback_func[i] != NULL)
- {
- pTimerExpiry = pTable->callback_func[i];
- MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_L4DRV_CBTIMER_HDLR, nTimerId, pTimerExpiry));
- g_timer_table_used--;
- pTable->event_id[i] = 0;
- pTable->timer_id[i] = 0;
- pTable->callback_func[i] = NULL;
- /*
- * we process g_timer_table_used, event_id and timer_id ... first
- * because the user may call stoptimer() in the timer_expiry_func
- */
- pTimerExpiry(p);
- }
- break;
- }
- i++;
- if (i >= SIMULTANEOUS_TIMER_NUM)
- {
- pTable = pTable->next;
- i = 0;
- }
- } while (pTable != NULL);
- /* can't find nTimerId, do nothing */
- mmi_frm_fetch_msg_from_extQ_to_circularQ();
- /*
- * Because we modify MMI process protocol events and key events mechanism,
- * we don't need to process key events here.
- */
- }
- /*****************************************************************************
- * FUNCTION
- * L4TimerUsePreciseTick
- * DESCRIPTION
- * Typically we round timer period to multiple of 100ms. However, some timers need to be
- * more accurate.
- * PARAMETERS
- * nTimerId [IN] Timer ID
- * RETURNS
- * void
- *****************************************************************************/
- MMI_BOOL L4TimerUsePreciseTick(unsigned short nTimerId)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- switch (nTimerId)
- {
- #if defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__)
- case PEN_POLLING_TIMER:
- return MMI_TRUE;
- #endif /* defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__) */
- default:
- return MMI_FALSE;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * L4StartTimer
- * DESCRIPTION
- * This function is to start timer. To added for two kinds of timer, one is for exactly time, another allow to delay.
- * PARAMETERS
- * nTimerId [IN]
- * TimerExpiry [IN]
- * funcArg [?]
- * nTimeDuration [IN]
- * alignment [IN]
- * e(?) [IN] Alignment
- * a(?) [IN] NTimerId
- * d(?) [IN] NTimeDuration
- * c(?) [IN] FuncArg
- * b(?) [IN] TimerExpiry
- * RETURNS
- * void
- *****************************************************************************/
- void L4StartTimer(
- unsigned short nTimerId,
- oslTimerFuncPtr TimerExpiry,
- void *funcArg,
- unsigned long nTimeDuration,
- unsigned char alignment)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- TIMERTABLE *pTable = NULL;
- U16 i = 0;
- U32 temp;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (TimerExpiry == NULL)
- { /* If TimerExpiry is NULL, we don't start the timer */
- MMI_ASSERT(0);
- return;
- }
- MMI_ASSERT(nTimerId < MAX_TIMERS);
- if (L4TimerUsePreciseTick(nTimerId))
- {
- temp = (nTimeDuration * KAL_TICKS_10_MSEC) / 10;
- if (temp == 0)
- {
- temp = KAL_TICKS_10_MSEC;
- }
- alignment = TIMER_IS_NO_ALIGNMENT;
- }
- else
- {
- if (nTimeDuration == 1000)
- {
- temp = KAL_TICKS_1_SEC - 4;
- }
- else
- {
- temp = (U32)((nTimeDuration / 5) * MMI_TICKS_5_MSEC);
- }
- if (temp == 0)
- {
- /* Cause by by rounding. If expire immediately, MoDIS boot-up failure because MMI keeps running and block NVRAM task */
- temp = (U32)MMI_TICKS_5_MSEC;
- }
- } /* if (L4TimerUsePreciseTick(nTimerId)) */
- MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_L4DRV_STARTTIMER_HDLR, nTimerId, TimerExpiry, temp, alignment));
- pTable = &g_timer_table;
- if (g_timer_table_used >= g_timer_table_size)
- {
- /*
- * TIMERTABLE list doesn't have enough space, allocate the memory
- *
- * If we need to allocate the memeory, it means that MMI may have
- * such many timers run simultaneously. We won't free the memory
- * after we allocate more memory in TIMERTABLE list.
- */
- do
- {
- if (pTable->next == NULL)
- {
- pTable->next = OslMalloc(sizeof(TIMERTABLE));
- memset(pTable->next, 0, sizeof(TIMERTABLE));
- g_timer_table_size += SIMULTANEOUS_TIMER_NUM;
- pTable = pTable->next;
- i = 0;
- break;
- }
- pTable = pTable->next;
- } while (pTable != NULL);
- }
- else
- {
- /* find the empty record in g_timer_table list */
- i = 0;
- do
- {
- if (pTable->event_id[i] == NULL)
- { /* find the empty space */
- break;
- }
- i++;
- if (i >= SIMULTANEOUS_TIMER_NUM)
- {
- pTable = pTable->next;
- i = 0;
- }
- } while (pTable != NULL);
- if (pTable == NULL)
- {
- /* Can't find the empty space in TIMERTABLE list, assert!!! */
- MMI_ASSERT(0);
- }
- } /* if (g_timer_table_used >= g_timer_table_size) */
- /*
- * already find the empty record, and then start timer
- *
- * event_sheduler1 = NO alignment scherulder
- * event_sheduler2 = alignment scherulder (low power)
- */
- if (alignment == TIMER_IS_NO_ALIGNMENT)
- {
- /* MSB(Most Significant Bit) is align_timer_mask */
- pTable->timer_id[i] = nTimerId | NO_ALIGNMENT_TIMER_MASK;
- pTable->event_id[i] = evshed_set_event(
- event_scheduler1_ptr,
- (kal_timer_func_ptr) L4CallBackTimer,
- (void*)nTimerId,
- temp);
- pTable->callback_func[i] = TimerExpiry;
- g_timer_table_used++;
- }
- else if (alignment == TIMER_IS_ALIGNMENT)
- {
- /* MSB(Most Significant Bit) is align_timer_mask */
- pTable->timer_id[i] = nTimerId | ALIGNMENT_TIMER_MASK;
- pTable->event_id[i] = evshed_set_event(
- event_scheduler2_ptr,
- (kal_timer_func_ptr) L4CallBackTimer,
- (void*)nTimerId,
- temp);
- pTable->callback_func[i] = TimerExpiry;
- g_timer_table_used++;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * L4StopTimer
- * DESCRIPTION
- * This function is to stop timer. To added for two kinds of timer, one is for exactly time, another allow to delay.
- * PARAMETERS
- * nTimerId [IN]
- * a(?) [IN] NTimerId
- * RETURNS
- * void
- *****************************************************************************/
- void L4StopTimer(unsigned short nTimerId)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- TIMERTABLE *pTable = &g_timer_table;
- U16 i = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- MMI_ASSERT(nTimerId < MAX_TIMERS);
- MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_L4DRV_STOPTIMER_HDLR, nTimerId));
- /* find the nTimerId in TIMERTABLE list */
- do
- {
- /* MSB(Most Significant Bit) of timer_id[i] is align_timer_mask */
- if ((pTable->timer_id[i] & (~NO_ALIGNMENT_TIMER_MASK)) == nTimerId)
- {
- /* find the nTimerId */
- if (pTable->event_id[i] != NULL)
- {
- if ((pTable->timer_id[i] & NO_ALIGNMENT_TIMER_MASK) == NO_ALIGNMENT_TIMER_MASK)
- { /* NO_ALIGNMENT_TIMER */
- evshed_cancel_event(event_scheduler1_ptr, &(pTable->event_id[i]));
- }
- else
- { /* ALIGNMENT_TIMER */
- evshed_cancel_event(event_scheduler2_ptr, &(pTable->event_id[i]));
- }
- g_timer_table_used--;
- pTable->event_id[i] = NULL;
- pTable->timer_id[i] = 0;
- pTable->callback_func[i] = NULL;
- }
- break;
- }
- i++;
- if (i >= SIMULTANEOUS_TIMER_NUM)
- {
- pTable = pTable->next;
- i = 0;
- }
- } while (pTable != NULL);
- /* if can't find nTimerId, do nothing */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_is_align_base_timer
- * DESCRIPTION
- * is the given base timer an alignment one
- * PARAMETERS
- * base_timer_ptr [IN] base timer pointer
- * RETURNS
- * IMER_IS_ALIGNMENT (MMI_TRUE) or TIMER_IS_NO_ALIGNMENT (MMI_FALSE)
- *****************************************************************************/
- MMI_BOOL mmi_frm_is_align_base_timer(void *base_timer_ptr)
- {
- if ( base_timer_ptr == (void *)&base_timer2 )
- return MMI_TRUE;
- else
- return MMI_FALSE;
- }
- /*****************************************************************************
- * Local Function
- *****************************************************************************/
- #ifdef __MMI_FRM_TIMER_UNIT_TEST__
- #define ALIGN_TEST_TIMEOUT 1000 /* ms */
- #define NON_ALIGN_TEST_TIMEOUT 1100 /* ms */
- #define ALIGN_TEST_TM_ID MMI_TIMER_BASE
- #define NON_ALIGN_TEST_TM_ID KEY_TIMER_ID_NONE
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_ut_timer
- * DESCRIPTION
- * timer unit-test
- * PARAMETERS
- * none
- * RETURNS
- * none
- *****************************************************************************/
- static void mmi_frm_ut_timer()
- {
- /* unit test for non-alignment timer in NVRAM access */
- L4StartTimer(NON_ALIGN_TEST_TM_ID, (oslTimerFuncPtr)mmi_frm_ut_nonalign_timer,
- (void *)NON_ALIGN_TEST_TM_ID, NON_ALIGN_TEST_TIMEOUT, TIMER_IS_NO_ALIGNMENT);
-
- /* unit test for alignment timer in NVRAM access */
- L4StartTimer(ALIGN_TEST_TM_ID, (oslTimerFuncPtr)mmi_frm_ut_align_timer,
- (void *)ALIGN_TEST_TM_ID, ALIGN_TEST_TIMEOUT, TIMER_IS_ALIGNMENT);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_ut_nonalign_timer
- * DESCRIPTION
- * timer callback for non-align timer unit test
- * PARAMETERS
- * timer id
- * RETURNS
- * none
- *****************************************************************************/
- static void mmi_frm_ut_nonalign_timer(void *p)
- {
- if (IsInNVRAMProcedure())
- {
- Trace2(TRACE_GROUP_1, "[UT] non-align timer works in nvram access");
- //kal_print("n[UT] non-align timer works in nvram accessn");
- }
- else
- {
- L4StartTimer(NON_ALIGN_TEST_TM_ID, (oslTimerFuncPtr)mmi_frm_ut_nonalign_timer,
- (void *)NON_ALIGN_TEST_TM_ID, NON_ALIGN_TEST_TIMEOUT, TIMER_IS_NO_ALIGNMENT);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_ut_align_timer
- * DESCRIPTION
- * timer callback for align timer unit test
- * PARAMETERS
- * timer id
- * RETURNS
- * none
- *****************************************************************************/
- static void mmi_frm_ut_align_timer(void *p)
- {
- if (IsInNVRAMProcedure())
- {
- Trace2(TRACE_GROUP_1, "[UT] align timer will die in nvram access");
- MMI_ASSERT(0);
- }
- else
- {
- L4StartTimer(ALIGN_TEST_TM_ID, (oslTimerFuncPtr)mmi_frm_ut_align_timer,
- (void *)ALIGN_TEST_TM_ID, ALIGN_TEST_TIMEOUT, TIMER_IS_ALIGNMENT);
- }
- }
- #endif /* __MMI_FRM_TIMER_UNIT_TEST__ */
- #endif /* MMI_ON_WIN32 */