blob: 2747c4b73bbaa0c1783405f6d007b017af714c2c [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/*****************************************************************************
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) 2001
8*
9*****************************************************************************/
10
11/*****************************************************************************
12 *
13 * Filename:
14 * ---------
15 * dcl_gpt.h
16 *
17 * Project:
18 * --------
19 * TATAKA
20 *
21 * Description:
22 * ------------
23 * Header file of DCL (Driver Common Layer) for GPT.
24 *
25 * Author:
26 * -------
27 * -------
28 *
29 *============================================================================
30 * HISTORY
31 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
32 *------------------------------------------------------------------------------
33 * removed!
34 * removed!
35 * removed!
36 *
37 * removed!
38 * removed!
39 * removed!
40 *
41 * removed!
42 * removed!
43 * removed!
44 *
45 * removed!
46 * removed!
47 * removed!
48 *
49 * removed!
50 * removed!
51 * removed!
52 *
53 * removed!
54 * removed!
55 * removed!
56 * removed!
57 * removed!
58 * removed!
59 * removed!
60 *
61 * removed!
62 * removed!
63 * removed!
64 *
65 * removed!
66 * removed!
67 * removed!
68 *
69 * removed!
70 * removed!
71 * removed!
72 *
73 * removed!
74 * removed!
75 * removed!
76 *
77 * removed!
78 * removed!
79 * removed!
80 *
81 * removed!
82 * removed!
83 * removed!
84 *
85 * removed!
86 * removed!
87 * removed!
88 *
89 * removed!
90 * removed!
91 * removed!
92 *
93 * removed!
94 * removed!
95 * removed!
96 *
97 * removed!
98 * removed!
99 * removed!
100 *
101 *------------------------------------------------------------------------------
102 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
103 *============================================================================
104 ****************************************************************************/
105
106#ifdef DCL_DEFINITION_STRUCT
107#ifndef __DCL_GPT_H_STRUCT__
108#define __DCL_GPT_H_STRUCT__
109#include "kal_general_types.h"
110#include "kal_public_defs.h"
111
112// GPT Interrupt Interval. [write to hardware register.]
113// put this macro in here, becasue it will be used in alerter.c
114#define gptimer_interval 10
115/*******************************************************************************
116 * DCL_OPTIONS for GPT
117 *******************************************************************************/
118#define GPT_OPTIONS
119
120/*******************************************************************************
121 * DCL_CONFIGURE_T for GPT
122 *******************************************************************************/
123
124
125/*******************************************************************************
126 * DCL_EVENT
127 *******************************************************************************/
128#define GPT_EVENTS \
129 EVENT_HGPT_TIMEOUT = 0x1,
130
131/*******************************************************************************
132 * DCL_CTRL_CMD
133 *******************************************************************************/
134 #ifdef __BUILD_DOM__
135/*
136* The GPIO Command values in DCL_CTRL_CMD_T Enum of dcl.h
137* DCL_CTRL_DATA_T Define the Control data structure for each module's command
138*/
139typedef enum
140{
141 SGPT_CMD_START, //GPT Start command. <DCL_GPT_CB>
142 SGPT_CMD_STOP, //GPT Stop command. <DCL_GPT_CB>
143 SGPT_CMD_GET_REMAINING_TICK, //LITE GPT Used Command
144 SGPT_CMD_BUSYWAIT, //GPT Busywait command, that's only support to DCL_GPT_BusyWait.
145 SGPT_CMD_RUNNING_TICK, // C2K to Get running tick number
146 SGPT_CMD_MODIFY_CNT, //C2K to modify auto repeat GPT duration
147
148 SGPT2_CMD_START, //for gpt2 start command.
149 SGPT2_CMD_STOP,
150 SGPT2_CMD_SET_COUNTVALUE,
151 SGPT2_CMD_REGISTERCALLBACK,
152 SGPT2_CMD_SET_CLK,
153
154 FGPT_CMD_START, //Free run GPT start command <DCL_GPT_FreeRUN3 & DCL_GPT_FreeRUN4>
155 FGPT_CMD_STOP, //Free run GPT Stop command <DCL_GPT_FreeRUN3 & DCL_GPT_FreeRUN4>
156 FGPT_CMD_RETURN_COUNT, //Free run GPT return current count value. <DCL_GPT_FreeRUN3 & DCL_GPT_FreeRUN4>
157}DCL_CTRL_CMD_T;
158#else
159#define GPT_CMDS \
160 SGPT_CMD_START, \
161 SGPT_CMD_STOP, \
162 SGPT_CMD_GET_REMAINING_TICK, \
163 SGPT_CMD_BUSYWAIT, \
164 SGPT_CMD_RUNNING_TICK, \
165 SGPT_CMD_MODIFY_CNT, \
166 SGPT2_CMD_START, \
167 SGPT2_CMD_STOP, \
168 SGPT2_CMD_SET_COUNTVALUE, \
169 SGPT2_CMD_REGISTERCALLBACK, \
170 SGPT2_CMD_SET_CLK, \
171 FGPT_CMD_START, \
172 FGPT_CMD_STOP, \
173 FGPT_CMD_RETURN_COUNT,
174#endif
175
176/* For SGPT_CMD_START command. */
177typedef struct
178{
179 DCL_UINT16 u2Tick;//The time Ticks(a tick is 10ms) that register callback function delay to wake up.
180 DCL_UINT32 u4Tick;
181 void (*pfCallback)(void *); //register callback function
182 void *vPara; //parameter of register callback function
183} SGPT_CTRL_START_T;
184
185/* For FGPT_CMD_RETURN_COUNT command. */
186typedef DCL_UINT16 FGPT_CTRL_RETURN_COUNT_T;
187/*For SGPT_CMD_BUSYWAIT command*/
188typedef DCL_UINT16 GPT_BUSYWAIT_COUNT;
189
190
191//added by dongming for gpt2
192typedef struct
193{
194 DCL_UINT16 u2CountValue;
195 DCL_BOOL fgAutoReload;
196} SGPT2_CTRL_RESET_DATA_T;
197
198typedef struct
199{
200 DCL_UINT32 u4Clock; // for gpt2 SGPT2_CTRL_CLK_T enum
201} SGPT2_CTRL_CLK_T;
202
203
204typedef DCL_UINT32 DCL_EVENT_NEW;
205
206typedef void (*SGPT2_CALLBACK_FUNC)(DCL_EVENT_NEW event);
207
208typedef struct{
209 SGPT2_CALLBACK_FUNC gpt2CallBack;
210}SGPT2_CALLBACK_FUNC_T;
211
212
213#ifdef __BUILD_DOM__
214/*The GPIO command prarmeter data structure for each command. that's enum in in DCL_CTRL_DATA_T*/
215typedef enum
216 {
217 SGPT_CTRL_START_T rSGPTStart, /* For SGPT_CMD_START command. */
218 FGPT_CTRL_RETURN_COUNT_T u2RetCount, /* For FGPT_CMD_RETURN_COUNT command. */
219 GPT_BUSYWAIT_COUNT uBusyWaitcount, /*For SGPT_CMD_BUSYWAIT command*/
220 SGPT2_CTRL_RESET_DATA_T rHGPTReset, /*add for gpt2 reset command */
221 SGPT2_CALLBACK_FUNC_T gpt2_callback,/*add for gpt2 registercallback command */
222 SGPT2_CTRL_CLK_T gpt2_clk,
223 }DCL_CTRL_DATA_T;
224#else
225#define GPT_CTRLS \
226 SGPT_CTRL_START_T rSGPTStart; \
227 FGPT_CTRL_RETURN_COUNT_T u2RetCount; \
228 GPT_BUSYWAIT_COUNT uBusyWaitcount;\
229 SGPT2_CTRL_RESET_DATA_T rHGPTReset;\
230 SGPT2_CALLBACK_FUNC_T gpt2_callback;\
231 SGPT2_CTRL_CLK_T gpt2_clk;
232#endif // __BUILD_DOM__
233
234#endif // #ifndef __DCL_GPT_H_STRUCT__
235#endif // #ifdef DCL_DEFINITION_STRUCT
236#ifndef DCL_GPT_H_
237#define DCL_GPT_H_
238#define MAX_GPT_ITEMS 32
239#define DSP_USER_NUM 4
240#define EMPTY_GPT_CB_HANDLER 0x7F
241
242#if defined(__FPGA__)
243/* ALTERA JADE Version */
244//#define LITEGPT_CLOCK 31250//31250
245//#define LITEGPT_US_TO_TICK(us) ((us)/32)
246/* HAPS JADE Version */
247#define LITEGPT_CLOCK 31920//31920
248#define LITEGPT_US_TO_TICK(us) ((us)/125)
249
250#else
251
252#define LITEGPT_CLOCK 32768
253#define LITEGPT_US_TO_TICK(us) (((us)*2)/61)
254#endif
255
256//static kal_bool fgGPT1Init = KAL_FALSE;
257
258typedef struct
259{
260 void (*gpt1_func)(void);
261 void (*gpt2_func)(void);
262}gpt_func;
263
264typedef struct
265{
266 kal_uint32 tick;
267 void (*gptimer_func)(void *parameter);
268 void *parameter;
269}gptimer_item;
270
271typedef struct
272{
273 kal_bool execute;
274 kal_uint32 tick;
275 void (*gptimer_func)(void *parameter);
276 void *parameter;
277}gptimer_multiple;
278
279typedef struct
280{
281 kal_uint32 status; /*1,activated ,0:de-activated*/
282 kal_bool GPTSTOP;
283 kal_uint32 Hgpt_handle;
284 kal_uint16 GPT_TICK;
285 kal_uint8 MAX_GPTIMER_ITEMS; // Indicate the current registered GPT users
286 kal_uint8 GPTUsed[32]; /* 0: Not registered by user, 1: Registerd by used*/
287 /* Reset to 0 when user release GPT handle*/
288 gptimer_item GPTItems[32]; /*support at most 32 gptimer*/
289 gpt_func GPT_FUNC;
290 kal_hisrid hisr;
291} GPTStruct;
292#endif
293#if defined(DCL_DEFINITION_PROTOTYPE)
294#ifndef __DCL_GPT_H_PROTOTYPE__
295#define __DCL_GPT_H_PROTOTYPE__
296
297
298/*************************************************************************
299* FUNCTION
300* DclSGPT_Initialize
301*
302* DESCRIPTION
303* This function is to initialize SW GPT module.
304*
305* PARAMETERS
306* DCL_STATUS_OK
307*
308* RETURNS
309* none
310*
311*************************************************************************/
312extern DCL_STATUS DclSGPT_Initialize(void);
313
314/*************************************************************************
315* FUNCTION
316* DclSGPT_Open
317*
318* DESCRIPTION
319* This function is to open the SW GPT module and get a handle.
320* Note that for DCL_GPT_CB, multiple opens are allowed.For DCL_GPT_BusyWait, Multiple opens are not support.
321*
322* PARAMETERS
323* eDev: only valid for DCL_GPT_CB DCL_GPT_BusyWait
324* flags: no sepcial flags is needed. Please use FLAGS_NONE
325*
326* RETURN VALUES
327* DCL_HANDLE_INVALID: Open failed.
328* other value: Open success, return a a valid handle
329*
330*************************************************************************/
331extern DCL_HANDLE DclSGPT_Open(DCL_DEV dev, DCL_FLAGS flags);
332
333/*************************************************************************
334* FUNCTION
335* DclSGPT_ReadData
336*
337* DESCRIPTION
338* This function is not supported for the SW GPT module now.
339*
340* PARAMETERS
341* N/A
342*
343* RETURN VALUES
344* STATUS_UNSUPPORTED:
345*
346*************************************************************************/
347extern DCL_STATUS DclSGPT_ReadData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN *buf_len, DCL_OPTIONS options);
348
349/*************************************************************************
350* FUNCTION
351* DclSGPT_WriteData
352*
353* DESCRIPTION
354* This function is not supported for the SW GPT module now.
355*
356* PARAMETERS
357* N/A
358*
359* RETURN VALUES
360* STATUS_UNSUPPORTED:
361*
362*************************************************************************/
363extern DCL_STATUS DclSGPT_WriteData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN *buf_len, DCL_OPTIONS options);
364
365/*************************************************************************
366* FUNCTION
367* DclSGPT_Configure
368*
369* DESCRIPTION
370* This function is not supported for the SW GPT module now.
371*
372* PARAMETERS
373* N/A
374*
375* RETURN VALUES
376* STATUS_UNSUPPORTED:
377*
378*************************************************************************/
379extern DCL_STATUS DclSGPT_Configure(DCL_HANDLE handle, DCL_CONFIGURE_T *configure);
380
381/*************************************************************************
382* FUNCTION
383* DclSGPT_RegisterCallback
384*
385* DESCRIPTION
386* This function is not supported for the SW GPT module now.
387*
388* PARAMETERS
389* N/A
390*
391* RETURN VALUES
392* STATUS_UNSUPPORTED:
393*
394*************************************************************************/
395extern DCL_STATUS DclSGPT_RegisterCallback(DCL_HANDLE handle, DCL_EVENT event, PFN_DCL_CALLBACK callback);
396
397/*************************************************************************
398* FUNCTION
399* DclSGPT_Control
400*
401* DESCRIPTION
402* This function is to send command to control the SW GPT module.
403*
404* Now, we support two kind of GPT function.
405* For DCL_GPT_CB timer, you can register a callback function with some tick waiting to run.(a tick is 10ms)
406* when timeout ,the callback function will be run in DRV_HISR.
407*
408* For DCL_GPT_BusyWait, You can call DclSGPT_Control with SGPT_CMD_BUSYWAIT command, the programm will be loop in this
409* function until timeout. (a busywait tick is 1ms).
410*
411* PARAMETERS
412* handle: a valid handle return by DclSGPT_Open()
413* cmd: a control command for GPT module
414* 1. SGPT_CMD_START - to start a GPT timer
415* 2. SGPT_CMD_STOP- to stop a GPT timer
416* 3. SGPT_CMD_BUSYWAIT - to start GPT Busywait function.
417* data: data structure for control command.
418* 1. SGPT_CMD_START- pointer to a SGPT_CTRL_START_T structure
419* 2. SGPT_CMD_STOP- a NULL pointer
420* 3. SGPT_CMD_BUSYWAIT - a pointer to GPT_BUSYWAIT_COUNT;
421*
422* RETURN VALUES
423* STATUS_OK: command is executed successfully.
424* STATUS_FAIL: command is failed.
425* DCL_HANDLE_INVALID: It's a invaild handle.
426* STATUS_INVALID_CMD: It's a invalid command.
427*
428*************************************************************************/
429extern DCL_STATUS DclSGPT_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data);
430
431/*************************************************************************
432* FUNCTION
433* DclSGPT_Close
434*
435* DESCRIPTION
436* This function is to close the SW GPT module.
437*
438* PARAMETERS
439* handle: hanlde previous got from DclSGPT_Open()
440*
441* RETURN VALUES
442* DCL_STATUS_OK: successfully close the SW GPT module.
443* DCL_STATUS_fail: fails to close the SW GPT module.
444* STATUS_INVALID_HANDLE: invalid handle.
445*************************************************************************/
446extern DCL_STATUS DclSGPT_Close(DCL_HANDLE *handle);
447
448/*************************************************************************
449* FUNCTION
450* DclFGPT_Initialize
451*
452* DESCRIPTION
453* This function is to initialize the free run GPT module.
454*
455* PARAMETERS
456* None
457*
458* RETURN VALUES
459* DCL_STATUS_OK
460*
461*************************************************************************/
462extern DCL_STATUS DclFGPT_Initialize(void);
463
464/*************************************************************************
465* FUNCTION
466* DclFGPT_Open
467*
468* DESCRIPTION
469* This function is to open a free run GPT module if it exists. Note
470* that it supports multiple opens and no need to close it.
471*
472* PARAMETERS
473* eDev: only valid for <DCL_GPT_FreeRUN3 & DCL_GPT_FreeRUN4>
474* flags: no sepcial flags is needed. Please use FLAGS_NONE
475*
476* RETURN VALUES
477* DCL_HANDLE_INVALID: Open failed. It means no free run GPT exists or
478* open a wrong device.
479* other value: a valid handle
480*
481*************************************************************************/
482extern DCL_HANDLE DclFGPT_Open(DCL_DEV dev, DCL_FLAGS flags);
483
484/*************************************************************************
485* FUNCTION
486* DclFGPT_ReadData
487*
488* DESCRIPTION
489* This function is not supported for the free run GPT module now.
490*
491* PARAMETERS
492* N/A
493*
494* RETURNS
495* STATUS_UNSUPPORTED
496*
497*************************************************************************/
498extern DCL_STATUS DclFGPT_ReadData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN *buf_len, DCL_OPTIONS options);
499
500/*************************************************************************
501* FUNCTION
502* DclFGPT_WriteData
503*
504* DESCRIPTION
505* This function is not supported for the free run GPT module now.
506*
507* PARAMETERS
508* N/A
509*
510* RETURNS
511* STATUS_UNSUPPORTED
512*
513*************************************************************************/
514extern DCL_STATUS DclFGPT_WriteData(DCL_HANDLE handle, DCL_BUFF *buff, DCL_BUFF_LEN *buf_len, DCL_OPTIONS options);
515
516/*************************************************************************
517* FUNCTION
518* DclFGPT_Configure
519*
520* DESCRIPTION
521* This function is not supported for the free run GPT module now.
522*
523* PARAMETERS
524* N/A
525*
526* RETURNS
527* STATUS_UNSUPPORTED
528*
529*************************************************************************/
530extern DCL_STATUS DclFGPT_Configure(DCL_HANDLE handle, DCL_CONFIGURE_T *configure);
531
532/*************************************************************************
533* FUNCTION
534* DclFGPT_RegisterCallback
535*
536* DESCRIPTION
537* This function is not supported for the free run GPT module now.
538*
539* PARAMETERS
540* N/A
541*
542* RETURNS
543* STATUS_UNSUPPORTED
544*
545*************************************************************************/
546extern DCL_STATUS DclFGPT_RegisterCallback(DCL_HANDLE handle, DCL_EVENT event, PFN_DCL_CALLBACK callback);
547
548/*************************************************************************
549* FUNCTION
550* DclFGPT_Control
551*
552* DESCRIPTION
553* This function is to send command to control the free run GPT module.
554*
555* PARAMETERS
556* handle: a valid handle return by DclFGPT_Open()
557* cmd: a control command for free ryb GPT module
558* 1. FGPT_CMD_START - to start free run gpt timer
559* 2. FGPT_CMD_STOP - to stop free run gpt timer
560* 3. FGPT_CMD_RETURN_COUNT - to get the timer count
561* data:
562* 1. FGPT_CMD_RETURN_COUNT- pointer to a FGPT_CTRL_RETURN_COUNT_T type
563* 2. FGPT_CMD_START - pointer to null
564* 3. FGPT_CMD_STOP -pointer to null
565*
566* RETURN VALUES
567* STATUS_OK: command is executed successfully.
568* STATUS_FAIL: command is failed. No free run GPT is supported.
569* STATUS_INVALID_CMD: The command is invalid.
570* STATUS_INVALID_HANDLE: The handle is invalid.
571*
572*************************************************************************/
573extern DCL_STATUS DclFGPT_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data);
574
575/*************************************************************************
576* FUNCTION
577* DclFGPT_Close
578*
579* DESCRIPTION
580* This function is to close the SW GPT module.
581*
582* PARAMETERS
583* handle: hanlde previous got from DclSGPT_Open()
584*
585* RETURN VALUES
586* DCL_STATUS_OK: successfully close the SW GPT module.
587* DCL_STATUS_fail: fails to close the SW GPT module.
588* STATUS_INVALID_HANDLE: invalid handle.
589*
590*************************************************************************/
591extern DCL_STATUS DclFGPT_Close(DCL_HANDLE handle);
592
593#endif // #ifndef __DCL_GPT_H_PROTOTYPE__
594#endif // #ifdef DCL_DEFINITION_PROTOTYPE
595
596