📄 l4drv.c
字号:
/*----------------------------------------------------------------*/
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 access\n");
}
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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -