Wrapper.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:22k
- /*****************************************************************************
- * 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:
- * ---------
- * Wrapper.c
- *
- * Project:
- * --------
- * MAUI
- *
- * Description:
- * ------------
- *
- *
- * 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!
- *
- *------------------------------------------------------------------------------
- * 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 : Wrapper.c
- PURPOSE : OS wrapper functions to make the task structure functionality
- independant of underlying operating system.
- REMARKS : nil
- AUTHOR : Neeraj Sharma
- DATE : Dec' 28, 2002
- **************************************************************/
- /* Include files ----------------------------------- */
- /* [001] */
- #include "WrapperGprot.h"
- #include "pixteldatatypes.h"
- #ifdef MMI_ON_WIN32
- #include "TaskInit.h"
- #include "QueueGprot.h"
- #include "NVRAMProt.h"
- #include "stdafx.h"
- extern CRITICAL_SECTION TimerCS;
- oslSoftTimerid TimerId[MAX_TIMERS];
- oslTimerid TimerCallBackHdlr;
- #include <assert.h>
- #endif /* MMI_ON_WIN32 */
- #ifndef MMI_ON_WIN32
- #include "l4dr.h"
- #endif
- #include "oslmemory.h"
- /* Macros and Data Structor Declerations -------------- */
- /* static oslTimerid TimerPtrs[MAX_TIMERS]; */
- static U8 TimerExist[MAX_TIMERS];
- /* kill all the semaphore and thread objects */
- /* ------Functions Decleration ------------------------------------- */
- /*-------------------------------------------------------------------
- Function Name : oslTaskid OslIntCreateTask
- Description : This module creates the task
- Input : PS8 task_name,
- U8 priority,
- U32 stack_size,
- oslTaskFuncPtr entry_func,
- void * entry_param,
- U8 misc_options
- Output : taskID
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntCreateTask
- * DESCRIPTION
- *
- * PARAMETERS
- * task_name [IN]
- * priority [IN]
- * stack_size [IN]
- * entry_func [IN]
- * entry_param [?]
- * misc_options [IN]
- * RETURNS
- *
- *****************************************************************************/
- oslTaskid OslIntCreateTask(
- PS8 task_name,
- U8 priority,
- U32 stack_size,
- oslTaskFuncPtr entry_func,
- void *entry_param,
- U8 misc_options)
- {
- #ifdef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U32 tThreadId;
- U32 win32_priority;
- oslTaskid taskid;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- taskid = CreateThread(
- NULL,
- stack_size,
- (LPTHREAD_START_ROUTINE) entry_func,
- entry_param,
- CREATE_SUSPENDED,
- &tThreadId);
- if (priority >= 0 && priority < 52)
- {
- win32_priority = THREAD_PRIORITY_HIGHEST;
- }
- else if (priority >= 52 && priority < 104)
- {
- win32_priority = THREAD_PRIORITY_ABOVE_NORMAL;
- }
- else if (priority >= 104 && priority < 156)
- {
- win32_priority = THREAD_PRIORITY_NORMAL;
- }
- else if (priority >= 156 && priority < 208)
- {
- win32_priority = THREAD_PRIORITY_BELOW_NORMAL;
- }
- else if (priority >= 208 && priority <= 255)
- {
- win32_priority = THREAD_PRIORITY_LOWEST;
- }
- SetThreadPriority(taskid, win32_priority);
- ResumeThread(taskid);
- return taskid;
- #else /* MMI_ON_WIN32 */
- return NULL;
- #endif /* MMI_ON_WIN32 */
- }
- /*-------------------------------------------------------------------
- Function Name : OslIntDleteTask
- Description : This module creates the task
- Input : TaskID
- Output : TRYE or FALSE
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntDleteTask
- * DESCRIPTION
- *
- * PARAMETERS
- * taskid [IN]
- * RETURNS
- *
- *****************************************************************************/
- OSLSTATUS OslIntDleteTask(oslTaskid taskid)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #ifdef MMI_ON_WIN32
- CloseHandle(taskid);
- #endif
- return OSL_SUCCESS;
- }
- /*-------------------------------------------------------------------
- Function Name : StartMyTimer
- Description : This module starts the timer
- Input : unsigned short nTimerId,
- unsigned short nTimeDuration,
- oslTimerFuncPtr TimerExpiry)
- Output : BOOL
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * StartMyTimerInt
- * DESCRIPTION
- *
- * PARAMETERS
- * nTimerId [IN]
- * nTimeDuration [IN]
- * TimerExpiry [IN]
- * alignment [IN]
- * RETURNS
- *
- *****************************************************************************/
- U16 StartMyTimerInt(U16 nTimerId, U32 nTimeDuration, oslTimerFuncPtr TimerExpiry, U8 alignment)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (TimerExist[nTimerId])
- {
- OslStopSoftTimer(nTimerId);
- }
- OslStartSoftTimer(nTimerId, TimerExpiry, nTimerId, nTimeDuration, alignment);
- TimerExist[nTimerId] = 1;
- return TRUE;
- }
- /*-------------------------------------------------------------------
- Function Name : StopMyTimer
- Description : This module stops the timer
- Input : timerID
- Output : bool
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * StopMyTimer
- * DESCRIPTION
- *
- * PARAMETERS
- * nTimerId [IN]
- * RETURNS
- *
- *****************************************************************************/
- U16 StopMyTimer(U16 nTimerId)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (TimerExist[nTimerId])
- {
- OslStopSoftTimer(nTimerId);
- TimerExist[nTimerId] = 0;
- }
- return TRUE;
- }
- /*-------------------------------------------------------------------
- Function Name : IsMyTimerExist
- Description : This module stops the timer
- Input : timerID
- Output : bool
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * IsMyTimerExist
- * DESCRIPTION
- *
- * PARAMETERS
- * nTimerId [IN]
- * RETURNS
- *
- *****************************************************************************/
- BOOL IsMyTimerExist(U16 nTimerId)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (TimerExist[nTimerId] == 1)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- /*-------------------------------------------------------------------
- Function Name : KillObjects
- Description : This module kills the object but
- currently of no use
- Input : null
- Output : bool
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * KillObjects
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- *
- *****************************************************************************/
- U16 KillObjects(void)
- {
- #ifdef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U16 i;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (i = 9; i < TOTAL_TASKS; i++)
- {
- OslIntDleteTask(task_info_g1[i].task_id);
- OslDeleteMsgQ(task_info_g1[i].task_ext_qid);
- }
- OslIntCancelTimer(TimerCallBackHdlr);
- OslIntDeleteTimer(TimerCallBackHdlr);
- for (i = 0; i < MAX_TIMERS; i++)
- if (TimerExist[i])
- {
- OslStopSoftTimer(i);
- }
- #endif /* MMI_ON_WIN32 */
- return TRUE;
- }
- /*-------------------------------------------------------------------
- Function Name : OslIntCreateTimer
- Description : This module creates the timer
- Input : timer name
- Output : timer ID
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntCreateTimer
- * DESCRIPTION
- *
- * PARAMETERS
- * timer_name [IN]
- * RETURNS
- *
- *****************************************************************************/
- oslTimerid OslIntCreateTimer(PS8 timer_name)
- {
- #ifdef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- win32_timerid *tmrid;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- tmrid = (win32_timerid*) OslMalloc(sizeof(win32_timerid));
- strcpy(tmrid->tmr_name, timer_name);
- tmrid->tmr_handler = 0;
- tmrid->tmr_timeout = 0;
- tmrid->tmr_callback = NULL;
- tmrid->tmr_callback_arg = NULL;
- return tmrid;
- #else /* MMI_ON_WIN32 */
- return NULL;
- #endif /* MMI_ON_WIN32 */
- }
- /*-------------------------------------------------------------------
- Function Name : OslIntSetTimer
- Description : This module sets the timer
- Input : oslTimerid timerid,
- oslTimerFuncPtr func_ptr,
- void * funcArg,
- U32 timeDurationMsec
- Output : bool
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntSetTimer
- * DESCRIPTION
- *
- * PARAMETERS
- * timerid [IN]
- * func_ptr [IN]
- * funcArg [?]
- * timeDurationMsec [IN]
- * RETURNS
- *
- *****************************************************************************/
- OSLSTATUS OslIntSetTimer(oslTimerid timerid, oslTimerFuncPtr func_ptr, void *funcArg, U32 timeDurationMsec)
- {
- #ifdef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- extern HWND hWnd;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- timerid->tmr_callback = func_ptr;
- timerid->tmr_callback_arg = funcArg;
- timerid->tmr_timeout = timeDurationMsec;
- timerid->tmr_handler = SetTimer(hWnd, (U32) timerid, timeDurationMsec, NULL);
- #endif /* MMI_ON_WIN32 */
- return OSL_SUCCESS;
- }
- /*-------------------------------------------------------------------
- Function Name : OslIntCancelTimer
- Description : This module cancels the timer
- Input : timerID
- Output : bool
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntCancelTimer
- * DESCRIPTION
- *
- * PARAMETERS
- * timerid [IN]
- * RETURNS
- *
- *****************************************************************************/
- OSLSTATUS OslIntCancelTimer(oslTimerid timerid)
- {
- #ifdef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- extern HWND hWnd;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- KillTimer(hWnd, (U32) timerid);
- #endif /* MMI_ON_WIN32 */
- return OSL_SUCCESS;
- }
- /*-------------------------------------------------------------------
- Function Name : OslIntDeleteTimer
- Description : This module delets the timer
- Input : timerID
- Output : bool
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntDeleteTimer
- * DESCRIPTION
- *
- * PARAMETERS
- * timerid [IN]
- * RETURNS
- *
- *****************************************************************************/
- OSLSTATUS OslIntDeleteTimer(oslTimerid timerid)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #ifdef MMI_ON_WIN32
- OslMfree(timerid);
- #endif
- return OSL_SUCCESS;
- }
- /*-------------------------------------------------------------------
- Function Name : OslIntStartSoftTimer
- Description : This module starts the soft timer
- Input : timerID
- Output : bool
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntStartSoftTimer
- * DESCRIPTION
- *
- * PARAMETERS
- * nTimerId [IN]
- * func_ptr [IN]
- * funcArg [?]
- * timeDurationMsec [IN]
- * RETURNS
- *
- *****************************************************************************/
- OSLSTATUS OslIntStartSoftTimer(unsigned short nTimerId, oslTimerFuncPtr func_ptr, void *funcArg, U32 timeDurationMsec)
- {
- #ifdef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- oslSoftTimerid TempTimerId;
- U32 nRoundOffMSec;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (timeDurationMsec % TIMER_CALLBACK_RESOLUTION)
- {
- nRoundOffMSec = ((timeDurationMsec / TIMER_CALLBACK_RESOLUTION) + 1) * TIMER_CALLBACK_RESOLUTION;
- }
- else
- {
- nRoundOffMSec = timeDurationMsec;
- }
- TempTimerId = OslMalloc(sizeof(win32_soft_timerid));
- TempTimerId->tmr_callback = func_ptr;
- TempTimerId->tmr_callback_arg = funcArg;
- TempTimerId->tmr_timeout = nRoundOffMSec;
- TempTimerId->tmr_count = TempTimerId->tmr_timeout;
- TempTimerId->tmr_state = OSL_RUN;
- EnterCriticalSection(&TimerCS);
- TimerId[nTimerId] = TempTimerId;
- LeaveCriticalSection(&TimerCS);
- #endif /* MMI_ON_WIN32 */
- return OSL_SUCCESS;
- }
- /*-------------------------------------------------------------------
- Function Name : OslIntStopSoftTimer
- Description : This module stops the soft timer
- Input : timerID
- Output : bool
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntStopSoftTimer
- * DESCRIPTION
- *
- * PARAMETERS
- * nTimerId [IN]
- * RETURNS
- *
- *****************************************************************************/
- OSLSTATUS OslIntStopSoftTimer(unsigned short nTimerId)
- {
- #ifdef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- EnterCriticalSection(&TimerCS);
- if (TimerId[nTimerId] != NULL)
- {
- OslMfree(TimerId[nTimerId]);
- TimerId[nTimerId] = NULL;
- }
- LeaveCriticalSection(&TimerCS);
- #endif /* MMI_ON_WIN32 */
- return OSL_SUCCESS;
- }