blob: ca51d86acf0cf73f0d426d5edc01a768a65500a4 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
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) 2016
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* This Software is the property of VIA Telecom, Inc. and may only be used pursuant to a license from VIA Telecom, Inc.
38*
39* Any unauthorized use inconsistent with the terms of such license is strictly prohibited.
40*
41* Copyright (c) 2007-2010 VIA Telecom, Inc. All rights reserved.
42*
43*************************************************************/
44#ifndef _TASKTIMER_H_
45#define _TASKTIMER_H_
46/*****************************************************************************
47*
48* FILE NAME : tasktimer.h
49*
50* DESCRIPTION : Timer Management interface
51*
52*
53*****************************************************************************/
54#include "monapi.h"
55
56/* RTOS timer expire message */
57typedef struct
58{
59 kal_uint32 TimerId; /* Expired timer Id */
60
61} TaskTimerExpiredMsgT;
62
63/*----------------------------------------------------------------------------
64 Timer Manager Global Defines
65----------------------------------------------------------------------------*/
66/* protocol timer expiration handler function */
67typedef void (*ProtocolTimerHandlerT)(void);
68typedef void (*TaskTimerCallBackT)(kal_uint32 TimerId);
69
70typedef struct {
71 event_scheduler *es;
72 eventid *pEventID;
73 kal_uint8 numRtosTimers; /* number of RTOS timer. max 255 RTOS timers */
74 kal_uint8 *rtosTimerUserIdTable; /* RTOS timer user Id array */
75 kal_uint16 *rtosTimerUserProtType;/* protocol currently using the RTOS timer */
76 kal_bool *rtosTimerPeriodicAttr;/* RTOS timer periodic attribute array */
77 kal_uint32 *rtosTimerPeriodicDura;/* RTOS timer periodic attribute timer duration array */
78
79 kal_uint8 numProtocolTimers; /* number of protocol defined timer */
80 kal_uint8 *protocolTimerStatusTable; /* protocol timer status array */
81 const ProtocolTimerHandlerT *protocolTimerHandlerTable; /* protocol timer handler pointer array */
82 TaskTimerCallBackT TaskTimerCallBack; /* RTOS timer callback function */
83 kal_uint32 ErrIdInvalidCallbackTimer; /*XXX_ERR_INVALID_CALLBACK_TIMER_ID*/
84 kal_uint32 ErrIdInsufficientTimer; /*XXX_ERR_INSUFFICIENT_TIMER_ID*/
85} TaskTimerObjT;
86
87/*----------------------------------------------------------------------------
88 Timer Manager Global Function Prototypes
89----------------------------------------------------------------------------*/
90
91void InitTaskTimerObj(TaskTimerObjT *taskTimerObj,
92 event_scheduler *es,
93 eventid *pEventId,
94 kal_uint8 numRtosTimers,
95 kal_uint8 *rtosTimerUserIdTable,
96 kal_uint16 *rtosTimerUserProtType,
97 kal_bool *rtosTimerPeriodicAttr,
98 kal_uint32 *rtosTimerPeriodicDura,
99 kal_uint8 numProtocolTimers,
100 kal_uint8 *protocolTimerStatusTable,
101 const ProtocolTimerHandlerT *protocolTimerHandlerTable,
102 kal_uint32 ErrIdInvalidCallbackTimer,
103 kal_uint32 ErrIdInsufficientTimer,
104 TaskTimerCallBackT TaskTimerCallBack);
105
106void ProcessTaskTimerExpiredMsg(TaskTimerObjT *taskTimerObj, kal_uint32 Input_timerId);
107void StartProtocolTimer(TaskTimerObjT *taskTimerObj, kal_uint8 protocolTimerId,
108 kal_uint32 duration, kal_bool periodic, kal_uint16 prot);
109void StopProtocolTimer(TaskTimerObjT *taskTimerObj, kal_uint8 protocolTimerId);
110void StopAllProtocolTimers(TaskTimerObjT *taskTimerObj);
111void StopProtProtocolTimers(TaskTimerObjT *taskTimerObj, kal_uint16 prot);
112kal_bool IsProtocolTimerActive(TaskTimerObjT *taskTimerObj, kal_uint8 protocolTimerId);
113void TaskTimerCallBack(kal_uint32 TimerId, module_type _dest_mod_id,
114 kal_uint32 TimerExpireMsgId);
115/*----------------------------------------------------------------------------
116 Timer Manager Global Macros
117
118 Note: 1. when calling the following Macros, no ; is needed at the line end.
119 2. timer ID enum type shall use name of "xxxTimerIdT", where xxx is the
120 task name which muse be same as the "taskName" parameter of following
121 Macros.
122 3. xxxTimerInit() function shall be called at task initialzation point.
123 4. xxxProcessTimerExpiredMsg(void* MsgP) function shall be called as
124 the XXX_TIMER_EXPIRED_MSG handler in task message loop.
125 5. before calling , it shall first define and initiate the protocol timer
126 handler table as:
127
128 static const ProtocolTimerHandlerT protocolTimerHandlerTable[NUM_SLCTMRs] = {
129 xxxtimerHandler,
130 ...
131 }
132 the order of the functions in the table shall correspond to the time ID enum.
133 ----------------------------------------------------------------------------*/
134#define TaskTimerObjDef(taskName, numRtosTimers, numProtocolTimers, \
135 ModuleId, MailboxId, TimerExpireMsgId, es, \
136 ErrIdInvalidCallbackTimer, ErrIdInsufficientTimer) \
137 static TaskTimerObjT taskTimerObj; \
138 static eventid pEventId[numRtosTimers]; \
139 static kal_uint8 rtosTimerUserIdTable[numRtosTimers]; \
140 static kal_uint16 rtosTimerUserProtType[numRtosTimers]; \
141 static kal_bool rtosTimerPeriodicAttr[numRtosTimers]; \
142 static kal_uint32 rtosTimerPeriodicDura[numRtosTimers]; \
143 static kal_uint8 protocolTimerStatusTable[numProtocolTimers]; \
144 \
145 void taskName##TaskTimerCallBack(kal_uint32 TimerId) \
146 { \
147 ProcessTaskTimerExpiredMsg(&taskTimerObj, TimerId); \
148 } \
149 \
150 void taskName##TimerInit(void) \
151 { \
152 InitTaskTimerObj( &taskTimerObj, \
153 es, \
154 pEventId, \
155 numRtosTimers, \
156 rtosTimerUserIdTable, \
157 rtosTimerUserProtType, \
158 rtosTimerPeriodicAttr, \
159 rtosTimerPeriodicDura, \
160 numProtocolTimers, \
161 protocolTimerStatusTable, \
162 protocolTimerHandlerTable, \
163 ErrIdInvalidCallbackTimer, \
164 ErrIdInsufficientTimer, \
165 taskName##TaskTimerCallBack); \
166 } \
167 \
168 void taskName##StartTimer(taskName##TimerIdT TimerId, kal_uint32 duration, kal_bool periodic, kal_uint16 prot) \
169 { \
170 StartProtocolTimer(&taskTimerObj, TimerId, duration, periodic, prot); \
171 } \
172 \
173 void taskName##StopTimer(taskName##TimerIdT TimerId) \
174 { \
175 StopProtocolTimer(&taskTimerObj, TimerId); \
176 } \
177 \
178 void taskName##StopAllProtocolTimers(void) \
179 { \
180 StopAllProtocolTimers(&taskTimerObj); \
181 } \
182 \
183 void taskName##StopProtProtocolTimers(kal_uint16 prot) \
184 { \
185 StopProtProtocolTimers(&taskTimerObj, prot); \
186 } \
187 \
188 kal_bool taskName##IsTimerActive(taskName##TimerIdT TimerId) \
189 { \
190 return IsProtocolTimerActive(&taskTimerObj, TimerId); \
191 } \
192 \
193 void taskName##ProcessTimerExpiredMsg(kal_uint32 TimerId) \
194 { \
195 ProcessTaskTimerExpiredMsg(&taskTimerObj, TimerId); \
196 }
197
198/*----------------------------------------------------------------------------*/
199#define TaskTimerAPIDef(taskName) \
200 \
201 void taskName##TaskTimerCallBack(kal_uint32 TimerId); \
202 void taskName##TimerInit(void); \
203 void taskName##StartTimer(taskName##TimerIdT TimerId, kal_uint32 duration, kal_bool periodic, kal_uint16 prot); \
204 void taskName##StopTimer(taskName##TimerIdT TimerId); \
205 void taskName##StopAllProtocolTimers(void); \
206 void taskName##StopProtProtocolTimers(kal_uint16 prot); \
207 kal_bool taskName##IsTimerActive(taskName##TimerIdT TimerId); \
208 void taskName##ProcessTimerExpiredMsg(kal_uint32 TimerId);
209
210/*----------------------------------------------------------------------------*/
211
212#endif /*_TASKTIMER_H_*/
213
214
215