2
2
* @file adi_tmr.c
3
3
* @brief GP and RGB timer device driver implementation
4
4
-----------------------------------------------------------------------------
5
- Copyright (c) 2016 Analog Devices, Inc.
5
+ Copyright (c) 2016-2018 Analog Devices, Inc.
6
6
7
7
All rights reserved.
8
8
@@ -86,7 +86,7 @@ POSSIBILITY OF SUCH DAMAGE.
86
86
#include "adi_tmr_data.c"
87
87
#endif
88
88
89
-
89
+ #if defined( __ADUCM4050__ )
90
90
/* In adi_tmr_ConfigPwm, the bit positions for just PWM0 are used for PWM1 and PWM2 to simplify the code. Check here to make sure this is safe. */
91
91
#if BITP_TMR_RGB_PWM0CTL_IDLESTATE != BITP_TMR_RGB_PWM1CTL_IDLESTATE
92
92
#error "Bit positions for PWM0 and PWM1 do not match. Fix adi_tmr_ConfigPwm."
@@ -100,17 +100,36 @@ POSSIBILITY OF SUCH DAMAGE.
100
100
#if BITP_TMR_RGB_PWM0CTL_MATCH != BITP_TMR_RGB_PWM2CTL_MATCH
101
101
#error "Bit positions for PWM0 and PWM2 do not match. Fix adi_tmr_ConfigPwm."
102
102
#endif
103
+ #endif /*__ADUCM4050__*/
103
104
104
105
/*! Number of events that can be captured */
106
+ #if defined(__ADUCM3029__ )
107
+ #define ADI_TMR_NUM_EVENTS (16u)
108
+ #elif defined(__ADUCM4050__ )
105
109
#define ADI_TMR_NUM_EVENTS (40u)
110
+ #else
111
+ #error TMR is not ported for this processor
112
+ #endif
106
113
107
114
/*! \cond PRIVATE */
108
115
109
116
/* Since the RGB typedef is a superset of the GP typedef, treat the GP timers as RGB timers and restrict top register access */
117
+ #if defined(__ADUCM3029__ )
118
+ static ADI_TMR_TypeDef * adi_tmr_registers [ADI_TMR_DEVICE_NUM ] = {pADI_TMR0 , pADI_TMR1 , pADI_TMR2 };
119
+ #elif defined(__ADUCM4050__ )
110
120
static ADI_TMR_RGB_TypeDef * adi_tmr_registers [ADI_TMR_DEVICE_NUM ] = {(ADI_TMR_RGB_TypeDef * ) pADI_TMR0 , (ADI_TMR_RGB_TypeDef * ) pADI_TMR1 , (ADI_TMR_RGB_TypeDef * ) pADI_TMR2 , pADI_TMR_RGB };
121
+ #else
122
+ #error TMR is not ported for this processor
123
+ #endif
111
124
112
125
/* Interrupt enums */
126
+ #if defined(__ADUCM3029__ )
127
+ static const IRQn_Type adi_tmr_interrupt [ADI_TMR_DEVICE_NUM ] = {TMR0_EVT_IRQn , TMR1_EVT_IRQn , TMR2_EVT_IRQn };
128
+ #elif defined(__ADUCM4050__ )
113
129
static const IRQn_Type adi_tmr_interrupt [ADI_TMR_DEVICE_NUM ] = {TMR0_EVT_IRQn , TMR1_EVT_IRQn , TMR2_EVT_IRQn , TMR_RGB_EVT_IRQn };
130
+ #else
131
+ #error TMR is not ported for this processor
132
+ #endif
114
133
115
134
/* Private data that the driver needs to retain between function calls */
116
135
static ADI_CALLBACK adi_tmr_callbacks [ADI_TMR_DEVICE_NUM ];
@@ -121,8 +140,9 @@ static void CommonIntHandler (ADI_TMR_DEVICE const eDevice);
121
140
void GP_Tmr0_Int_Handler (void );
122
141
void GP_Tmr1_Int_Handler (void );
123
142
void GP_Tmr2_Int_Handler (void );
143
+ #if defined(__ADUCM4050__ )
124
144
void RGB_Tmr_Int_Handler (void );
125
-
145
+ #endif
126
146
/*! \endcond */
127
147
128
148
@@ -181,10 +201,10 @@ ADI_TMR_RESULT adi_tmr_Init(ADI_TMR_DEVICE const eDevice, ADI_CALLBACK const pfC
181
201
adi_tmr_registers [eDevice ]-> CTL = aTimerCtlConfig [eDevice ];
182
202
adi_tmr_registers [eDevice ]-> LOAD = aTimerLoadConfig [eDevice ];
183
203
adi_tmr_registers [eDevice ]-> ALOAD = aTimerALoadConfig [eDevice ];
184
- adi_tmr_registers [eDevice ]-> EVENTSELECT = aTimerEventConfig [eDevice ];
185
204
adi_tmr_registers [eDevice ]-> PWM0CTL = aTimerPwmCtlConfig [eDevice ];
186
205
adi_tmr_registers [eDevice ]-> PWM0MATCH = aTimerPwmMatchConfig [eDevice ];
187
-
206
+ #if defined(__ADUCM4050__ )
207
+ adi_tmr_registers [eDevice ]-> EVENTSELECT = aTimerEventConfig [eDevice ];
188
208
/* IF(Initializing the RGB timer, there are 2 other PWM outputs to configure) */
189
209
if (eDevice == ADI_TMR_DEVICE_RGB ) {
190
210
/* The array is bumped by 1 to get to the 5th entry in the static config array, which contains RGB PWM1 */
@@ -194,6 +214,7 @@ ADI_TMR_RESULT adi_tmr_Init(ADI_TMR_DEVICE const eDevice, ADI_CALLBACK const pfC
194
214
adi_tmr_registers [eDevice ]-> PWM2CTL = aTimerPwmCtlConfig [eDevice + 2u ];
195
215
adi_tmr_registers [eDevice ]-> PWM2MATCH = aTimerPwmMatchConfig [eDevice + 2u ];
196
216
} /* ENDIF */
217
+ #endif
197
218
#endif
198
219
199
220
return ADI_TMR_SUCCESS ;
@@ -219,15 +240,15 @@ ADI_TMR_RESULT adi_tmr_Init(ADI_TMR_DEVICE const eDevice, ADI_CALLBACK const pfC
219
240
* - #ADI_TMR_SUCCESS Function call completed successfully
220
241
*
221
242
*/
222
- ADI_TMR_RESULT adi_tmr_ConfigTimer (ADI_TMR_DEVICE const eDevice , ADI_TMR_CONFIG timerConfig ) {
243
+ ADI_TMR_RESULT adi_tmr_ConfigTimer (ADI_TMR_DEVICE const eDevice , ADI_TMR_CONFIG * timerConfig ) {
223
244
uint16_t nTemp ;
224
245
#ifdef ADI_DEBUG
225
246
/* IF(Bad device input parameter) */
226
247
if (eDevice >= ADI_TMR_DEVICE_NUM ) {
227
248
return ADI_TMR_BAD_DEVICE_NUM ;
228
249
} /* ENDIF */
229
250
/* IF(Bad configuration, cannot enable reloading while in free running mode) */
230
- if ((timerConfig . bPeriodic == false) && (timerConfig . bReloading == true)) {
251
+ if ((timerConfig -> bPeriodic == false) && (timerConfig -> bReloading == true)) {
231
252
return ADI_TMR_BAD_RELOAD_CONFIGURATION ;
232
253
} /* ENDIF */
233
254
/* IF(The timer is already running) */
@@ -236,8 +257,8 @@ ADI_TMR_RESULT adi_tmr_ConfigTimer(ADI_TMR_DEVICE const eDevice, ADI_TMR_CONFIG
236
257
} /* ENDIF */
237
258
#endif
238
259
/* Set the load registers */
239
- adi_tmr_registers [eDevice ]-> LOAD = timerConfig . nLoad ;
240
- adi_tmr_registers [eDevice ]-> ALOAD = timerConfig . nAsyncLoad ;
260
+ adi_tmr_registers [eDevice ]-> LOAD = timerConfig -> nLoad ;
261
+ adi_tmr_registers [eDevice ]-> ALOAD = timerConfig -> nAsyncLoad ;
241
262
242
263
/* IF(Busy bit does not clear after waiting) */
243
264
if (ADI_TMR_SUCCESS != WaitForStatusBit (eDevice , (uint16_t ) BITM_TMR_RGB_STAT_BUSY )) {
@@ -249,26 +270,26 @@ ADI_TMR_RESULT adi_tmr_ConfigTimer(ADI_TMR_DEVICE const eDevice, ADI_TMR_CONFIG
249
270
nTemp &= (uint16_t ) (BITM_TMR_RGB_CTL_EVTEN | BITM_TMR_RGB_CTL_RSTEN );
250
271
251
272
/* Setup the prescaler and the clock source */
252
- nTemp |= (uint16_t )(((uint16_t ) timerConfig . ePrescaler ) << BITP_TMR_RGB_CTL_PRE );
253
- nTemp |= (uint16_t )(((uint16_t ) timerConfig . eClockSource ) << BITP_TMR_RGB_CTL_CLK );
273
+ nTemp |= (uint16_t )(((uint16_t ) timerConfig -> ePrescaler ) << BITP_TMR_RGB_CTL_PRE );
274
+ nTemp |= (uint16_t )(((uint16_t ) timerConfig -> eClockSource ) << BITP_TMR_RGB_CTL_CLK );
254
275
255
276
/* IF(Periodic mode) */
256
- if (timerConfig . bPeriodic == true) {
277
+ if (timerConfig -> bPeriodic == true) {
257
278
nTemp |= (1u << BITP_TMR_RGB_CTL_MODE );
258
279
} /* ENDIF */
259
280
260
281
/* IF(Counting up) */
261
- if (timerConfig . bCountingUp == true) {
282
+ if (timerConfig -> bCountingUp == true) {
262
283
nTemp |= (1u << BITP_TMR_RGB_CTL_UP );
263
284
} /* ENDIF */
264
285
265
286
/* IF(Reloading is enabled) */
266
- if (timerConfig . bReloading == true) {
287
+ if (timerConfig -> bReloading == true) {
267
288
nTemp |= (1u << BITP_TMR_RGB_CTL_RLD );
268
289
} /* ENDIF */
269
290
270
291
/* IF(Sync bypass is enabled) */
271
- if (timerConfig . bSyncBypass == true) {
292
+ if (timerConfig -> bSyncBypass == true) {
272
293
nTemp |= (1u << BITP_TMR_RGB_CTL_SYNCBYP );
273
294
} /* ENDIF */
274
295
@@ -301,24 +322,25 @@ ADI_TMR_RESULT adi_tmr_ConfigTimer(ADI_TMR_DEVICE const eDevice, ADI_TMR_CONFIG
301
322
* - #ADI_TMR_SUCCESS Function call completed successfully
302
323
*
303
324
*/
304
- ADI_TMR_RESULT adi_tmr_ConfigEvent (ADI_TMR_DEVICE const eDevice , ADI_TMR_EVENT_CONFIG eventConfig ) {
325
+ ADI_TMR_RESULT adi_tmr_ConfigEvent (ADI_TMR_DEVICE const eDevice , ADI_TMR_EVENT_CONFIG * eventConfig ) {
305
326
#ifdef ADI_DEBUG
306
327
/* IF(Bad device input parameter) */
307
328
if (eDevice >= ADI_TMR_DEVICE_NUM ) {
308
329
return ADI_TMR_BAD_DEVICE_NUM ;
309
330
} /* ENDIF */
310
331
/* IF(Bad event input parameter) */
311
- if (eventConfig . nEventID >= ADI_TMR_NUM_EVENTS ) {
332
+ if (eventConfig -> nEventID >= ADI_TMR_NUM_EVENTS ) {
312
333
return ADI_TMR_BAD_EVENT_ID ;
313
334
} /* ENDIF */
314
335
/* IF(The timer is already running) */
315
336
if ((adi_tmr_registers [eDevice ]-> CTL & BITM_TMR_RGB_CTL_EN ) == BITM_TMR_RGB_CTL_EN ) {
316
337
return ADI_TMR_OPERATION_NOT_ALLOWED ;
317
338
} /* ENDIF */
318
339
#endif
340
+ #if defined(__ADUCM4050__ )
319
341
/* Set the event number */
320
- adi_tmr_registers [eDevice ]-> EVENTSELECT = (uint16_t ) eventConfig . nEventID ;
321
-
342
+ adi_tmr_registers [eDevice ]-> EVENTSELECT = (uint16_t ) eventConfig -> nEventID ;
343
+ #endif
322
344
/* IF(Busy bit does not clear after waiting) */
323
345
if (ADI_TMR_SUCCESS != WaitForStatusBit (eDevice , (uint16_t ) BITM_TMR_RGB_STAT_BUSY )) {
324
346
return ADI_TMR_DEVICE_BUSY ;
@@ -328,15 +350,20 @@ ADI_TMR_RESULT adi_tmr_ConfigEvent(ADI_TMR_DEVICE const eDevice, ADI_TMR_EVENT_C
328
350
adi_tmr_registers [eDevice ]-> CTL &= (uint16_t ) ~(BITM_TMR_RGB_CTL_EVTEN | BITM_TMR_RGB_CTL_RSTEN );
329
351
330
352
/* IF(Turning event capture on) */
331
- if (eventConfig . bEnable == true) {
353
+ if (eventConfig -> bEnable == true) {
332
354
adi_tmr_registers [eDevice ]-> CTL |= (uint16_t ) BITM_TMR_RGB_CTL_EVTEN ;
333
355
} /* ENDIF */
334
356
335
357
/* IF(Enabling reset on event capture) */
336
- if (eventConfig . bPrescaleReset == true) {
358
+ if (eventConfig -> bPrescaleReset == true) {
337
359
adi_tmr_registers [eDevice ]-> CTL |= (uint16_t ) BITM_TMR_RGB_CTL_RSTEN ;
338
360
} /* ENDIF */
339
361
362
+ #if defined(__ADUCM3029__ )
363
+ /* Write the event index */
364
+ adi_tmr_registers [eDevice ]-> CTL |= (uint16_t ) (((uint16_t ) eventConfig -> nEventID ) << BITP_TMR_CTL_EVTRANGE );
365
+ #endif
366
+
340
367
return ADI_TMR_SUCCESS ;
341
368
}
342
369
@@ -364,7 +391,7 @@ ADI_TMR_RESULT adi_tmr_ConfigEvent(ADI_TMR_DEVICE const eDevice, ADI_TMR_EVENT_C
364
391
* - #ADI_TMR_SUCCESS Function call completed successfully
365
392
*
366
393
*/
367
- ADI_TMR_RESULT adi_tmr_ConfigPwm (ADI_TMR_DEVICE const eDevice , ADI_TMR_PWM_CONFIG pwmConfig ) {
394
+ ADI_TMR_RESULT adi_tmr_ConfigPwm (ADI_TMR_DEVICE const eDevice , ADI_TMR_PWM_CONFIG * pwmConfig ) {
368
395
uint16_t nControl = 0u ;
369
396
#ifdef ADI_DEBUG
370
397
/* IF(Bad device input parameter) */
@@ -375,35 +402,38 @@ ADI_TMR_RESULT adi_tmr_ConfigPwm(ADI_TMR_DEVICE const eDevice, ADI_TMR_PWM_CONFI
375
402
if ((adi_tmr_registers [eDevice ]-> CTL & BITM_TMR_RGB_CTL_EN ) == BITM_TMR_RGB_CTL_EN ) {
376
403
return ADI_TMR_OPERATION_NOT_ALLOWED ;
377
404
} /* ENDIF */
405
+ #if defined(__ADUCM4050__ )
378
406
/* IF(Bad PWM output and device combo OR bad PWM output) */
379
- if (((eDevice != ADI_TMR_DEVICE_RGB ) && (pwmConfig . eOutput != ADI_TMR_PWM_OUTPUT_0 )) || (pwmConfig . eOutput >= ADI_TMR_PWM_OUTPUT_NUM )) {
407
+ if (((eDevice != ADI_TMR_DEVICE_RGB ) && (pwmConfig -> eOutput != ADI_TMR_PWM_OUTPUT_0 )) || (pwmConfig -> eOutput >= ADI_TMR_PWM_OUTPUT_NUM )) {
380
408
return ADI_TMR_BAD_PWM_NUM ;
381
409
} /* ENDIF */
410
+ #endif
382
411
#endif
383
412
/* IF(Idle high is set) */
384
- if (pwmConfig . bIdleHigh == true) {
413
+ if (pwmConfig -> bIdleHigh == true) {
385
414
nControl = (1u << ((uint16_t ) BITP_TMR_RGB_PWM0CTL_IDLESTATE ));
386
415
} /* ENDIF */
387
416
388
417
/* IF(Match mode is enabled) */
389
- if (pwmConfig . bMatch == true) {
418
+ if (pwmConfig -> bMatch == true) {
390
419
nControl |= (1u << ((uint16_t ) BITP_TMR_RGB_PWM0CTL_MATCH ));
391
420
} /* ENDIF */
392
-
421
+
393
422
/* IF(PWM output 0) */
394
- if (pwmConfig . eOutput == ADI_TMR_PWM_OUTPUT_0 ) {
423
+ if (pwmConfig -> eOutput == ADI_TMR_PWM_OUTPUT_0 ) {
395
424
adi_tmr_registers [eDevice ]-> PWM0CTL = nControl ;
396
- adi_tmr_registers [eDevice ]-> PWM0MATCH = pwmConfig .nMatchValue ;
425
+ adi_tmr_registers [eDevice ]-> PWM0MATCH = pwmConfig -> nMatchValue ;
426
+ #if defined(__ADUCM4050__ )
397
427
/* IF(PWM output 1) */
398
- } else if (pwmConfig . eOutput == ADI_TMR_PWM_OUTPUT_1 ) {
428
+ } else if (pwmConfig -> eOutput == ADI_TMR_PWM_OUTPUT_1 ) {
399
429
adi_tmr_registers [eDevice ]-> PWM1CTL = nControl ;
400
- adi_tmr_registers [eDevice ]-> PWM1MATCH = pwmConfig . nMatchValue ;
430
+ adi_tmr_registers [eDevice ]-> PWM1MATCH = pwmConfig -> nMatchValue ;
401
431
/* ELSE(PWM output 2) */
402
432
} else {
403
433
adi_tmr_registers [eDevice ]-> PWM2CTL = nControl ;
404
- adi_tmr_registers [eDevice ]-> PWM2MATCH = pwmConfig .nMatchValue ;
434
+ adi_tmr_registers [eDevice ]-> PWM2MATCH = pwmConfig -> nMatchValue ;
435
+ #endif
405
436
} /* ENDIF */
406
-
407
437
return ADI_TMR_SUCCESS ;
408
438
}
409
439
@@ -599,13 +629,13 @@ void GP_Tmr2_Int_Handler(void) {
599
629
CommonIntHandler (ADI_TMR_DEVICE_GP2 );
600
630
ISR_EPILOG ()
601
631
}
602
-
632
+ #if defined( __ADUCM4050__ )
603
633
void RGB_Tmr_Int_Handler (void ) {
604
634
ISR_PROLOG ()
605
635
CommonIntHandler (ADI_TMR_DEVICE_RGB );
606
636
ISR_EPILOG ()
607
637
}
608
-
638
+ #endif
609
639
/*! \endcond */
610
640
611
641
/*! @} */
0 commit comments