dcl_pwm.h
18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
/*****************************************************************************
* 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) 2001
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* dcl_PWM.h
*
* Project:
* --------
* Maui
*
* Description:
* ------------
* Header file of DCL (Driver Common Layer) for PWM.
*
* 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!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* 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!!
*============================================================================
****************************************************************************/
#ifdef DCL_DEFINITION_STRUCT
#ifndef __DCL_PWM_H_STRUCT__
#define __DCL_PWM_H_STRUCT__
#include "kal_non_specific_general_types.h"
#define PWM_OUTPUT_LOW 0
#define PWM_OUTPUT_HIGH 1
//******************************************
#define PWM_MAX_FREQ 50000
#define PWM_MAX_DUTY 100
#define PWM_MIN_FREQ 50
#define PWM_MIN_DUTY 1
//*****************************************
/*The devices which use PWM1/PWM2/PWM3 etc ,added for new structure later*/
typedef struct
{
DCL_UINT8 pwm_level; //the pwm level
DCL_UINT32 pwm_freq; //the pwm frequency
DCL_UINT8 pwm_duty; //pwm duty
}PWM_DATA_T;
typedef struct
{
DCL_UINT8 pwm_level; //the pwm level
}PWM_LEVEL_T;
typedef struct
{
DCL_UINT8 pwm_channel; //the pwm level
}PWM_CHANNEL_T;
typedef struct
{
kal_uint32 freq; // the PWM channel output frequency.
kal_uint8 duty; // the duty cycle of the high level under the periodical output.
}PWM_CMD_CONFIG_OLD_T;
typedef struct
{
kal_uint8 channel;
kal_uint32 (*pwm_array)[2];
}PWM_ARRAY_T;
//**********************************************/
typedef struct
{
DCL_UINT8 pitch; /*note vlaue*/
DCL_UINT8 volume; /*note volume*/
DCL_UINT16 on_duration; /* in ms */
DCL_UINT16 off_duration; /* in ms */
}BuzNoteStruct;
typedef struct
{
DCL_UINT8 volume;
DCL_UINT8 stop;
DCL_UINT32 handle; /*GPT handle*/
BuzNoteStruct NotesData;
kal_bool (*GetNotesCallbac)(BuzNoteStruct *Buz);
void (*EndofAlterPlay)(void);
}ALterNoteStruct;
/* PWM wrok mode enumerate*/
typedef enum
{
PWM_FIFO_MODE=0,
PWM_MEMO_MODE,
PWM_OLD_MODE,
PWM_RANDOM_MODE,
PWM_MODE_COUNT
}pwm_mode_e;
/*PWM FIFO mode data structure.[more detail in spec]*/
typedef struct
{
kal_uint32 data0;
kal_uint32 data1;
kal_uint16 repeat_count; /* 0 means endless repeat */
kal_uint8 stop_bitpos; /* 0~63*/
kal_uint16 high_dur; /* must>0. When set to N, the duration is N+1 clocks. */
kal_uint16 low_dur; /* must>0. When set to N, the duration is N+1 clocks. */
kal_uint16 guard_dur; /* must>0. When set to N, the duration is N+1 clocks. */
kal_uint8 idle_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
kal_uint8 guard_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
void (*pwm_callback)(kal_uint32 pwm_num);
}pwm_fifo_para_s;
/*PWM memory mode data structure.[more detail in spec] */
typedef struct
{
kal_uint32 *buf_addr;
kal_uint16 buf_size;
kal_uint16 repeat_count; /* 0 means endless repeat */
kal_uint8 stop_bitpos; /* 0~31 in the last 32bits*/
kal_uint16 high_dur; /* must>0. When set to N, the duration is N+1 clocks. */
kal_uint16 low_dur; /* must>0. When set to N, the duration is N+1 clocks. */
kal_uint16 guard_dur; /* must>0. When set to N, the duration is N+1 clocks. */
kal_uint8 idle_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
kal_uint8 guard_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
void (*pwm_callback)(kal_uint32 pwm_num);
}pwm_memo_para_s;
/*PWM old mode data structure.[more detail in spec]*/
typedef struct
{
kal_uint16 data_width;
kal_uint16 threshold;
kal_uint16 repeat_count; /* 0 means endless repeat */
kal_uint16 guard_dur; /* must>0. When set to N, the duration is N+1 clocks. */
kal_uint8 idle_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
kal_uint8 guard_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
void (*pwm_callback)(kal_uint32 pwm_num);
}pwm_old_para_s;
/*PWM random mode data structure.[more detail in spec]*/
typedef struct
{
kal_uint32 *buf0_addr;
kal_uint32 *buf1_addr;
kal_uint16 buf0_size; /* must>0 */
kal_uint16 buf1_size; /* must>0 */
kal_uint16 high_dur; /* must>0. When set to N, the duration is N+1 clocks. */
kal_uint16 low_dur; /* must>0. When set to N, the duration is N+1 clocks. */
kal_uint8 idle_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
void (*pwm_invalid_cb)(kal_uint32 pwm_num, kal_uint8 buf_num);
void (*pwm_underflow_cb)(kal_uint32 pwm_num);
}pwm_random_para_s;
typedef struct
{
DCL_UINT32 clksrc; //the Clock source of the PWM module.
DCL_UINT32 clkdiv; //The Clock Divisor value.
}PWM_CONFIG_T;
#define PWM_CONFIGS \
PWM_CONFIG_T rPWMConfig;
#ifdef __BUILD_DOM__
/*
* The ALERTER Command values in DCL_CTRL_CMD_T Enum of dcl.h
* DCL_CTRL_DATA_T Define the Control data structure for each module's command
*/
typedef enum
{
PWM_CMD_SEQ_OPEN, //This command is to open the PWM channel under the Sequential mode.
PWM_CMD_SEQ_START, //This command is to enable PWM output under the Sequential mode.
PWM_CMD_SEQ_STOP, //This command is to stop PWM output under the Sequential mode.
PWM_CMD_SEQ_CLOSE, //This command is to Close the PWM channel under the Sequential mode.
PWM_CONFIG_FREQ_STEPS, //The command is to set the output frequency and the steps.it is used by the Camera AF lens driver.
PWM_CMD_SET_DUTY, //The function is to set the output duty value, it should not larger than the Steps in the above function.it is used by the Camera AF lens driver.
PWM_CMD_OPEN, //This command is to Open PWM channel.This command should be called before any other configuration function.
PWM_CMD_CLOSE, //The function is to close the PWM channel.it should be called after stop the PWM channel.
PWM_CMD_START, //This command is to Start the PWM channel output.It is called after all the configuration finished
PWM_CMD_STOP, //This command is to stop the PWM channel output.
PWM_CMD_GET_DUTY_BY_LEVEL,
PWM_CMD_GET_FREQ_BY_LEVEL,
PWM_CMD_GET_CURRENT_LEVEL,
PWM_CMD_GET_MAX_LEVEL,
PWM_CMD_SET_LEVEL,
PWM_CMD_SET_DUTY_BY_LEVEL,
PWM_CMD_SET_FREQ_BY_LEVEL,
PWM_CMD_GET_PWM_CHANNEL,
PWM_CMD_SET_PWM_ARRAY,
PWM_CMD_GET_CURRENT_DUTY, //This command is to get current PWM1 output duty cycle.
PWM_CMD_GET_CURRENT_FREQ, //This command is to get current PWM1 output duty cycle.
PWM_CMD_CONFIG, //This command is to configure the PWM channel working mode and setting the accoring mode parameter.
PWM_CMD_CONFIG_OLD, //This command is to configure the PWM1 output frequency and duty cycle.the function is to generate the simpliest periodical output signal.
PWM_CMD_SET_BUF_VALID, //Set buffer status to be valid and update the buffer data.the function is called when receiving the finish interrupt under the random mode.it is responsible to call the function to update the buffer of the user.
PWM_CMD_SET_DELAY, //This command is to set the delay time during the adjacent channels under the Sequential mode.
//PWM_CMD_TEST_SEL, should remove.
ALERTER_CMD_CONFIGURE, //configure ALerter freq and duty.
ALERTER_CMD_START, //Start ALERTER module.
ALERTER_CMD_STOP, //Stop ALERTER module.
ALERTER_CMD_PWROPEN,
ALERTER_CMD_OUTPUT,
ALERTER_CMD_PLAYNOTES,
ALERTER_CMD_STOPNOTES,
ALERTER_CMD_SETBUZVOLUME,
ALERTER_CMD_GETLEVEL,
}DCL_CTRL_CMD_T;
#else
#define PWM_CMDS \
PWM_CMD_SEQ_OPEN, \
PWM_CMD_SEQ_START, \
PWM_CMD_SEQ_STOP, \
PWM_CMD_SEQ_CLOSE, \
PWM_CONFIG_FREQ_STEPS, \
PWM_CMD_START, \
PWM_CMD_STOP, \
PWM_CMD_GET_DUTY_BY_LEVEL, \
PWM_CMD_GET_FREQ_BY_LEVEL, \
PWM_CMD_GET_CURRENT_LEVEL, \
PWM_CMD_GET_MAX_LEVEL, \
PWM_CMD_SET_LEVEL, \
PWM_CMD_SET_DUTY_BY_LEVEL, \
PWM_CMD_SET_FREQ_BY_LEVEL, \
PWM_CMD_GET_PWM_CHANNEL, \
PWM_CMD_SET_PWM_ARRAY, \
PWM_CMD_GET_CURRENT_DUTY, \
PWM_CMD_GET_CURRENT_FREQ, \
PWM_CMD_CONFIG, \
PWM_CMD_CONFIG_OLD, \
PWM_CMD_SET_BUF_VALID, \
PWM_CMD_SET_DELAY, \
PWM_CMD_SET_DUTY, \
PWM_CMD_TEST_SEL, \
PWM_CMD_OPEN, \
PWM_CMD_CLOSE,
#define ALERTER_CMDS \
ALERTER_CMD_CONFIGURE, \
ALERTER_CMD_START, \
ALERTER_CMD_STOP, \
ALERTER_CMD_PWROPEN, \
ALERTER_CMD_OUTPUT, \
ALERTER_CMD_PLAYNOTES, \
ALERTER_CMD_STOPNOTES, \
ALERTER_CMD_SETBUZVOLUME, \
ALERTER_CMD_GETLEVEL,
#endif
/* For PWM_CMD_SEQ_START command parameter. */
typedef struct
{
DCL_UINT8 uEnCount; //the PWM Channel Group of the Sequential mode
}PWM_CTRL_SS_T;
/* For PWM_CMD_CLK_INIT command parameter. */
typedef struct
{
DCL_UINT32 u4ClkSel; //the Clock source of the PWM module.
DCL_UINT32 u4ClkDiv; // The Clock Divisor value.
}PWM_CTRL_CI_T;
/* For PWM_CMD_SET_BUF_VALID command parameter. */
typedef struct
{
DCL_UINT32 *pu4BufAddr; //the buffer address of the update data.
DCL_UINT16 u2BufSize; //the buffer size.
DCL_BOOL fgIsBuf0; //the flag indicates whether buffer 0 is to be update
}PWM_CTRL_SBV_T;
/* For PWM_CMD_SET_DELAY command parameter. */
typedef struct
{
DCL_UINT32 u4ClkSel; // the clock unit of the delay_cnt
DCL_UINT16 u2DelayCnt; //the delay clock count of the two channels.
}PWM_CTRL_SD_T;
/* For PWM_CMD_TEST_SEL command parameter. */
typedef struct
{
DCL_BOOLEAN bTestSel;
}PWM_CTRL_TS_T;
/* For PWM_CMD_CONFIG command parameter. */
typedef struct
{
DCL_UINT32 mode; //Set the work mode of the PWM channel.
void *para; // The mode parameter.
}PWM_CTRL_CONFIG_T;
/* For PWM_CMD_CONFIG_OLD command parameter. */
/*For PWM_CMD_SET_DUTY command parameter.*/
typedef struct
{
DCL_UINT16 duty; //the output duty value (0~steps).
}PWM_DUTY_T;
/*For PWM_CONFIG_FREQ_STEPS command parameter.*/
typedef struct
{
kal_uint32 freq; //the output frequency.
kal_uint16 steps; //the lens driver steps.
}PWM_CONFIG_FREQ_STEPS_T;
//#if !defined(DRV_ALERTER_NOT_EXIST)
typedef struct
{
DCL_UINT32 freq;
DCL_UINT8 duty;
}ALERTER_CONFIGURE_T;
typedef struct
{
DCL_BOOL poweron;
}ALERTER_PWROPEN_T;
typedef struct
{
kal_bool (*GetNotecallbac)(BuzNoteStruct *Buz);
void (*endofAlter)(void);
}ALERTER_PLAYNOTE_T;
typedef struct
{
DCL_UINT8 volumn;
}ALERTER_SETVOLUMN_T;
typedef struct
{
DCL_UINT8 mode;
DCL_UINT8 clock;
}ALERTER_CONFIG_T;
typedef struct
{
kal_uint8 output;
}ALERTER_OUTPUT_T;
typedef struct
{
kal_uint8 level;
}ALERTER_LEVEL_T;
#define ALERTER_CTRLS \
ALERTER_CONFIGURE_T ralertConfigure; \
ALERTER_PWROPEN_T ralertPwrOpen; \
ALERTER_PLAYNOTE_T ralertPlayNote; \
ALERTER_SETVOLUMN_T ralertSetVolumn; \
ALERTER_CONFIG_T ralertConfig; \
ALERTER_OUTPUT_T ralertOutput; \
ALERTER_LEVEL_T ralertlevel;
#define PWM_CTRLS \
PWM_CTRL_SS_T rPWMCtrlSS; \
PWM_CTRL_CI_T rPWMCtrlCI; \
PWM_CTRL_SBV_T rPWMCtrlSBV; \
PWM_CTRL_SD_T rPWMCtrlSD; \
PWM_CTRL_TS_T rPWMCtrlTS; \
PWM_DUTY_T rPWMCtrlDuty; \
PWM_DATA_T rPWMSaveData; \
PWM_CTRL_CONFIG_T rPWMConfig; \
PWM_CONFIG_FREQ_STEPS_T rPWMFreqConfig; \
PWM_CMD_CONFIG_OLD_T rPWMConfigOld; \
PWM_LEVEL_T rPWMLevel; \
PWM_CHANNEL_T rPWMChannel; \
PWM_ARRAY_T rPWMArray;
#endif // #ifndef __DCL_PWM_H_STRUCT__
#endif // #ifdef DCL_DEFINITION_STRUCT
#ifdef DCL_DEFINITION_PROTOTYPE
#ifndef __DCL_PWM_H_PROTOTYPE__
#define __DCL_PWM_H_PROTOTYPE__
/*************************************************************************
* FUNCTION
* DclPWM_Close
*
* DESCRIPTION
* This function is to close the software layer of PWM module.
*
* CALLS
* It is called to close PWM(1~6) module
*
* PARAMETERS
* None
*
* RETURNS
* DCL_STATUS_OK
* STATUS_INVALID_ARGUMENT: invalid arguments
*
* GLOBALS AFFECTED
* external_global
*************************************************************************/
extern DCL_STATUS DclPWM_Close(DCL_HANDLE handle);
/*************************************************************************
* FUNCTION
* DclPWM_Configure
*
* DESCRIPTION
* This function is to configure the PWM module. Include clock sources and div vaules.
*
* CALLS
* It is called to configure of the PWM module.
*
* PARAMETERS
* handle: - a valid handle return by DclPWM_Configure()
*
* RETURNS
* STATUS_OK: command is executed successfully.
* STATUS_FAIL: command is failed.
*
* GLOBALS AFFECTED
* external_global
*************************************************************************/
extern DCL_STATUS DclPWM_Configure(DCL_HANDLE handle, DCL_CONFIGURE_T *configure);
/*************************************************************************
* FUNCTION
* DclPWM_Control
*
* DESCRIPTION
* This function is to send command to control the PWM module.
* All command
*
* CALLS
* It is called to send command to control the PWM module.
*
* PARAMETERS
* handle: - a valid handle return by DclPWM_Open()
* cmd: - a control command for PWM module
* 1. PWM_CMD_START: to start a PWM timer
* 2. PWM_CMD_STOP: to stop a PWM timer
* 3. PWM_CMD_CONFIG: to config a pwm timer.
* 4. PWM_CMD_CONFIG_OLD
* 5. PWM_CMD_GET_CURRENT_LEVEL:
* 6. PWM_CMD_GET_CURRENT_DUTY:
* 7. PWM_CMD_GET_CURRENT_FREQ:
* 8. PWM_CMD_OPEN
* 9. PWM_CMD_CLOSE
* 10. PWM_CMD_SEQ_OPEN:
* 11. PWM_CMD_SEQ_START:
* 12. PWM_CMD_SEQ_STOP:
* 13. PWM_CMD_SEQ_CLOSE
* 14. PWM_CMD_SET_BUF_VALID
* 15. PWM_CMD_SET_DELAY
* 16. PWM_CMD_TEST_SEL
* data - for 1. PWM_CMD_START: poiter to a PWM_CTRL_START_T structure
* 2. PWM_CMD_STOP: a NULL pointer
* #if !defined(DRV_ALERTER_NOT_EXIST)
#define ALERTER_CMDS
ALERTER_CMD_CONFIGURE, \
ALERTER_CMD_START, \
ALERTER_CMD_STOP, \
ALERTER_CMD_PWROPEN, \
ALERTER_CMD_OUTPUT, \
ALERTER_CMD_PLAYNOTES, \
ALERTER_CMD_STOPNOTES, \
ALERTER_CMD_SETBUZVOLUME,
#endif
* RETURNS
* STATUS_OK: command is executed successfully.
* STATUS_FAIL: command is failed.
* STATUS_INVALID_CMD: It's a invalid command.
*
* GLOBALS AFFECTED
* external_global
*************************************************************************/
extern DCL_STATUS DclPWM_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data);
/*************************************************************************
* FUNCTION
* DclPWM_Initialize
*
* DESCRIPTION
* This function is to initialize PWM module, It's should be called during drv_init stage.
*
* For PWM, this function do nothing.
*
* For RWG, this function create some global variable and LISR, HISR.
*
* CALLS
* It is called to initialize PWM module
*
* PARAMETERS
* None
*
* RETURNS
* DCL_STATUS_OK
*
* GLOBALS AFFECTED
* external_global
*************************************************************************/
extern DCL_STATUS DclPWM_Initialize(void);
/*************************************************************************
* FUNCTION
* DclPWM_Open
*
* DESCRIPTION
* This function is to open the software layer PWM module and return a software handle.
* This function don't open the PWM hardware power or generate out wave.
* This is only for software layer to avoid multi open by different module.
*
* If you want to power on or start PWM hardware , you should send a command by use of DclPWM_Control.
* CALLS
* It is called to open PWM module
*
* PARAMETERS
* dev - valid for DCL_PWM1 ~ DCL_PWM6
* flags - module name that call this fuction.
*
* RETURNS
* DCL_HANDLE_OCCUPIED: - Open failed.
* STATUS_INVALID_ARGUMENT: - invalid arguments
* other value: - a valid handle
*
* GLOBALS AFFECTED
* external_global
*************************************************************************/
extern DCL_HANDLE DclPWM_Open(DCL_DEV dev, DCL_FLAGS flags);
/*************************************************************************
* FUNCTION
* DclPWM_RegisterCallback
*
* DESCRIPTION
* This function is not supported for the PWM module now.
*
* PARAMETERS
* N/A
*
* RETURNS
* STATUS_UNSUPPORTED
*
*************************************************************************/
extern DCL_STATUS DclPWM_RegisterCallback(DCL_HANDLE handle, DCL_EVENT event, PFN_DCL_CALLBACK callback);
#endif // #ifndef __DCL_PWM_H_PROTOTYPE__
#endif // #ifdef DCL_DEFINITION_PROTOTYPE