| /***************************************************************************** |
| * 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) 2016 |
| * |
| * 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). |
| * |
| *****************************************************************************/ |
| /************************************************************* |
| * |
| * This Software is the property of VIA Telecom, Inc. and may only be used pursuant to a license from VIA Telecom, Inc. |
| * |
| * Any unauthorized use inconsistent with the terms of such license is strictly prohibited. |
| * |
| * Copyright (c) 2007-2010 VIA Telecom, Inc. All rights reserved. |
| * |
| *************************************************************/ |
| #ifndef _TASKTIMER_H_ |
| #define _TASKTIMER_H_ |
| /***************************************************************************** |
| * |
| * FILE NAME : tasktimer.h |
| * |
| * DESCRIPTION : Timer Management interface |
| * |
| * |
| *****************************************************************************/ |
| #include "monapi.h" |
| |
| /* RTOS timer expire message */ |
| typedef struct |
| { |
| kal_uint32 TimerId; /* Expired timer Id */ |
| |
| } TaskTimerExpiredMsgT; |
| |
| /*---------------------------------------------------------------------------- |
| Timer Manager Global Defines |
| ----------------------------------------------------------------------------*/ |
| /* protocol timer expiration handler function */ |
| typedef void (*ProtocolTimerHandlerT)(void); |
| typedef void (*TaskTimerCallBackT)(kal_uint32 TimerId); |
| |
| typedef struct { |
| event_scheduler *es; |
| eventid *pEventID; |
| kal_uint8 numRtosTimers; /* number of RTOS timer. max 255 RTOS timers */ |
| kal_uint8 *rtosTimerUserIdTable; /* RTOS timer user Id array */ |
| kal_uint16 *rtosTimerUserProtType;/* protocol currently using the RTOS timer */ |
| kal_bool *rtosTimerPeriodicAttr;/* RTOS timer periodic attribute array */ |
| kal_uint32 *rtosTimerPeriodicDura;/* RTOS timer periodic attribute timer duration array */ |
| |
| kal_uint8 numProtocolTimers; /* number of protocol defined timer */ |
| kal_uint8 *protocolTimerStatusTable; /* protocol timer status array */ |
| const ProtocolTimerHandlerT *protocolTimerHandlerTable; /* protocol timer handler pointer array */ |
| TaskTimerCallBackT TaskTimerCallBack; /* RTOS timer callback function */ |
| kal_uint32 ErrIdInvalidCallbackTimer; /*XXX_ERR_INVALID_CALLBACK_TIMER_ID*/ |
| kal_uint32 ErrIdInsufficientTimer; /*XXX_ERR_INSUFFICIENT_TIMER_ID*/ |
| } TaskTimerObjT; |
| |
| /*---------------------------------------------------------------------------- |
| Timer Manager Global Function Prototypes |
| ----------------------------------------------------------------------------*/ |
| |
| void InitTaskTimerObj(TaskTimerObjT *taskTimerObj, |
| event_scheduler *es, |
| eventid *pEventId, |
| kal_uint8 numRtosTimers, |
| kal_uint8 *rtosTimerUserIdTable, |
| kal_uint16 *rtosTimerUserProtType, |
| kal_bool *rtosTimerPeriodicAttr, |
| kal_uint32 *rtosTimerPeriodicDura, |
| kal_uint8 numProtocolTimers, |
| kal_uint8 *protocolTimerStatusTable, |
| const ProtocolTimerHandlerT *protocolTimerHandlerTable, |
| kal_uint32 ErrIdInvalidCallbackTimer, |
| kal_uint32 ErrIdInsufficientTimer, |
| TaskTimerCallBackT TaskTimerCallBack); |
| |
| void ProcessTaskTimerExpiredMsg(TaskTimerObjT *taskTimerObj, kal_uint32 Input_timerId); |
| void StartProtocolTimer(TaskTimerObjT *taskTimerObj, kal_uint8 protocolTimerId, |
| kal_uint32 duration, kal_bool periodic, kal_uint16 prot); |
| void StopProtocolTimer(TaskTimerObjT *taskTimerObj, kal_uint8 protocolTimerId); |
| void StopAllProtocolTimers(TaskTimerObjT *taskTimerObj); |
| void StopProtProtocolTimers(TaskTimerObjT *taskTimerObj, kal_uint16 prot); |
| kal_bool IsProtocolTimerActive(TaskTimerObjT *taskTimerObj, kal_uint8 protocolTimerId); |
| void TaskTimerCallBack(kal_uint32 TimerId, module_type _dest_mod_id, |
| kal_uint32 TimerExpireMsgId); |
| /*---------------------------------------------------------------------------- |
| Timer Manager Global Macros |
| |
| Note: 1. when calling the following Macros, no ; is needed at the line end. |
| 2. timer ID enum type shall use name of "xxxTimerIdT", where xxx is the |
| task name which muse be same as the "taskName" parameter of following |
| Macros. |
| 3. xxxTimerInit() function shall be called at task initialzation point. |
| 4. xxxProcessTimerExpiredMsg(void* MsgP) function shall be called as |
| the XXX_TIMER_EXPIRED_MSG handler in task message loop. |
| 5. before calling , it shall first define and initiate the protocol timer |
| handler table as: |
| |
| static const ProtocolTimerHandlerT protocolTimerHandlerTable[NUM_SLCTMRs] = { |
| xxxtimerHandler, |
| ... |
| } |
| the order of the functions in the table shall correspond to the time ID enum. |
| ----------------------------------------------------------------------------*/ |
| #define TaskTimerObjDef(taskName, numRtosTimers, numProtocolTimers, \ |
| ModuleId, MailboxId, TimerExpireMsgId, es, \ |
| ErrIdInvalidCallbackTimer, ErrIdInsufficientTimer) \ |
| static TaskTimerObjT taskTimerObj; \ |
| static eventid pEventId[numRtosTimers]; \ |
| static kal_uint8 rtosTimerUserIdTable[numRtosTimers]; \ |
| static kal_uint16 rtosTimerUserProtType[numRtosTimers]; \ |
| static kal_bool rtosTimerPeriodicAttr[numRtosTimers]; \ |
| static kal_uint32 rtosTimerPeriodicDura[numRtosTimers]; \ |
| static kal_uint8 protocolTimerStatusTable[numProtocolTimers]; \ |
| \ |
| void taskName##TaskTimerCallBack(kal_uint32 TimerId) \ |
| { \ |
| ProcessTaskTimerExpiredMsg(&taskTimerObj, TimerId); \ |
| } \ |
| \ |
| void taskName##TimerInit(void) \ |
| { \ |
| InitTaskTimerObj( &taskTimerObj, \ |
| es, \ |
| pEventId, \ |
| numRtosTimers, \ |
| rtosTimerUserIdTable, \ |
| rtosTimerUserProtType, \ |
| rtosTimerPeriodicAttr, \ |
| rtosTimerPeriodicDura, \ |
| numProtocolTimers, \ |
| protocolTimerStatusTable, \ |
| protocolTimerHandlerTable, \ |
| ErrIdInvalidCallbackTimer, \ |
| ErrIdInsufficientTimer, \ |
| taskName##TaskTimerCallBack); \ |
| } \ |
| \ |
| void taskName##StartTimer(taskName##TimerIdT TimerId, kal_uint32 duration, kal_bool periodic, kal_uint16 prot) \ |
| { \ |
| StartProtocolTimer(&taskTimerObj, TimerId, duration, periodic, prot); \ |
| } \ |
| \ |
| void taskName##StopTimer(taskName##TimerIdT TimerId) \ |
| { \ |
| StopProtocolTimer(&taskTimerObj, TimerId); \ |
| } \ |
| \ |
| void taskName##StopAllProtocolTimers(void) \ |
| { \ |
| StopAllProtocolTimers(&taskTimerObj); \ |
| } \ |
| \ |
| void taskName##StopProtProtocolTimers(kal_uint16 prot) \ |
| { \ |
| StopProtProtocolTimers(&taskTimerObj, prot); \ |
| } \ |
| \ |
| kal_bool taskName##IsTimerActive(taskName##TimerIdT TimerId) \ |
| { \ |
| return IsProtocolTimerActive(&taskTimerObj, TimerId); \ |
| } \ |
| \ |
| void taskName##ProcessTimerExpiredMsg(kal_uint32 TimerId) \ |
| { \ |
| ProcessTaskTimerExpiredMsg(&taskTimerObj, TimerId); \ |
| } |
| |
| /*----------------------------------------------------------------------------*/ |
| #define TaskTimerAPIDef(taskName) \ |
| \ |
| void taskName##TaskTimerCallBack(kal_uint32 TimerId); \ |
| void taskName##TimerInit(void); \ |
| void taskName##StartTimer(taskName##TimerIdT TimerId, kal_uint32 duration, kal_bool periodic, kal_uint16 prot); \ |
| void taskName##StopTimer(taskName##TimerIdT TimerId); \ |
| void taskName##StopAllProtocolTimers(void); \ |
| void taskName##StopProtProtocolTimers(kal_uint16 prot); \ |
| kal_bool taskName##IsTimerActive(taskName##TimerIdT TimerId); \ |
| void taskName##ProcessTimerExpiredMsg(kal_uint32 TimerId); |
| |
| /*----------------------------------------------------------------------------*/ |
| |
| #endif /*_TASKTIMER_H_*/ |
| |
| |
| |