Skip to content

Commit da6c6bd

Browse files
author
Edmund Hsu
committed
Resolve adi_tmr_ConfigTimer discrepancy between __ADuCM4050__ and __ADuCM3029__
1 parent 6a7bfeb commit da6c6bd

File tree

1 file changed

+64
-34
lines changed
  • targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/bsp/tmr

1 file changed

+64
-34
lines changed

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/bsp/tmr/adi_tmr.c

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file adi_tmr.c
33
* @brief GP and RGB timer device driver implementation
44
-----------------------------------------------------------------------------
5-
Copyright (c) 2016 Analog Devices, Inc.
5+
Copyright (c) 2016-2018 Analog Devices, Inc.
66
77
All rights reserved.
88
@@ -86,7 +86,7 @@ POSSIBILITY OF SUCH DAMAGE.
8686
#include "adi_tmr_data.c"
8787
#endif
8888

89-
89+
#if defined(__ADUCM4050__)
9090
/* 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. */
9191
#if BITP_TMR_RGB_PWM0CTL_IDLESTATE != BITP_TMR_RGB_PWM1CTL_IDLESTATE
9292
#error "Bit positions for PWM0 and PWM1 do not match. Fix adi_tmr_ConfigPwm."
@@ -100,17 +100,36 @@ POSSIBILITY OF SUCH DAMAGE.
100100
#if BITP_TMR_RGB_PWM0CTL_MATCH != BITP_TMR_RGB_PWM2CTL_MATCH
101101
#error "Bit positions for PWM0 and PWM2 do not match. Fix adi_tmr_ConfigPwm."
102102
#endif
103+
#endif /*__ADUCM4050__*/
103104

104105
/*! Number of events that can be captured */
106+
#if defined(__ADUCM3029__)
107+
#define ADI_TMR_NUM_EVENTS (16u)
108+
#elif defined(__ADUCM4050__)
105109
#define ADI_TMR_NUM_EVENTS (40u)
110+
#else
111+
#error TMR is not ported for this processor
112+
#endif
106113

107114
/*! \cond PRIVATE */
108115

109116
/* 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__)
110120
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
111124

112125
/* 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__)
113129
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
114133

115134
/* Private data that the driver needs to retain between function calls */
116135
static ADI_CALLBACK adi_tmr_callbacks[ADI_TMR_DEVICE_NUM];
@@ -121,8 +140,9 @@ static void CommonIntHandler (ADI_TMR_DEVICE const eDevice);
121140
void GP_Tmr0_Int_Handler(void);
122141
void GP_Tmr1_Int_Handler(void);
123142
void GP_Tmr2_Int_Handler(void);
143+
#if defined(__ADUCM4050__)
124144
void RGB_Tmr_Int_Handler(void);
125-
145+
#endif
126146
/*! \endcond */
127147

128148

@@ -181,10 +201,10 @@ ADI_TMR_RESULT adi_tmr_Init(ADI_TMR_DEVICE const eDevice, ADI_CALLBACK const pfC
181201
adi_tmr_registers[eDevice]->CTL = aTimerCtlConfig [eDevice];
182202
adi_tmr_registers[eDevice]->LOAD = aTimerLoadConfig [eDevice];
183203
adi_tmr_registers[eDevice]->ALOAD = aTimerALoadConfig [eDevice];
184-
adi_tmr_registers[eDevice]->EVENTSELECT = aTimerEventConfig [eDevice];
185204
adi_tmr_registers[eDevice]->PWM0CTL = aTimerPwmCtlConfig [eDevice];
186205
adi_tmr_registers[eDevice]->PWM0MATCH = aTimerPwmMatchConfig[eDevice];
187-
206+
#if defined(__ADUCM4050__)
207+
adi_tmr_registers[eDevice]->EVENTSELECT = aTimerEventConfig [eDevice];
188208
/* IF(Initializing the RGB timer, there are 2 other PWM outputs to configure) */
189209
if (eDevice == ADI_TMR_DEVICE_RGB) {
190210
/* 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
194214
adi_tmr_registers[eDevice]->PWM2CTL = aTimerPwmCtlConfig [eDevice+2u];
195215
adi_tmr_registers[eDevice]->PWM2MATCH = aTimerPwmMatchConfig[eDevice+2u];
196216
} /* ENDIF */
217+
#endif
197218
#endif
198219

199220
return ADI_TMR_SUCCESS;
@@ -219,15 +240,15 @@ ADI_TMR_RESULT adi_tmr_Init(ADI_TMR_DEVICE const eDevice, ADI_CALLBACK const pfC
219240
* - #ADI_TMR_SUCCESS Function call completed successfully
220241
*
221242
*/
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) {
223244
uint16_t nTemp;
224245
#ifdef ADI_DEBUG
225246
/* IF(Bad device input parameter) */
226247
if (eDevice >= ADI_TMR_DEVICE_NUM) {
227248
return ADI_TMR_BAD_DEVICE_NUM;
228249
} /* ENDIF */
229250
/* 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)) {
231252
return ADI_TMR_BAD_RELOAD_CONFIGURATION;
232253
} /* ENDIF */
233254
/* IF(The timer is already running) */
@@ -236,8 +257,8 @@ ADI_TMR_RESULT adi_tmr_ConfigTimer(ADI_TMR_DEVICE const eDevice, ADI_TMR_CONFIG
236257
} /* ENDIF */
237258
#endif
238259
/* 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;
241262

242263
/* IF(Busy bit does not clear after waiting) */
243264
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
249270
nTemp &= (uint16_t) (BITM_TMR_RGB_CTL_EVTEN | BITM_TMR_RGB_CTL_RSTEN);
250271

251272
/* 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);
254275

255276
/* IF(Periodic mode) */
256-
if (timerConfig.bPeriodic == true) {
277+
if (timerConfig->bPeriodic == true) {
257278
nTemp |= (1u << BITP_TMR_RGB_CTL_MODE);
258279
} /* ENDIF */
259280

260281
/* IF(Counting up) */
261-
if (timerConfig.bCountingUp == true) {
282+
if (timerConfig->bCountingUp == true) {
262283
nTemp |= (1u << BITP_TMR_RGB_CTL_UP);
263284
} /* ENDIF */
264285

265286
/* IF(Reloading is enabled) */
266-
if (timerConfig.bReloading == true) {
287+
if (timerConfig->bReloading == true) {
267288
nTemp |= (1u << BITP_TMR_RGB_CTL_RLD);
268289
} /* ENDIF */
269290

270291
/* IF(Sync bypass is enabled) */
271-
if (timerConfig.bSyncBypass == true) {
292+
if (timerConfig->bSyncBypass == true) {
272293
nTemp |= (1u << BITP_TMR_RGB_CTL_SYNCBYP);
273294
} /* ENDIF */
274295

@@ -301,24 +322,25 @@ ADI_TMR_RESULT adi_tmr_ConfigTimer(ADI_TMR_DEVICE const eDevice, ADI_TMR_CONFIG
301322
* - #ADI_TMR_SUCCESS Function call completed successfully
302323
*
303324
*/
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) {
305326
#ifdef ADI_DEBUG
306327
/* IF(Bad device input parameter) */
307328
if (eDevice >= ADI_TMR_DEVICE_NUM) {
308329
return ADI_TMR_BAD_DEVICE_NUM;
309330
} /* ENDIF */
310331
/* IF(Bad event input parameter) */
311-
if (eventConfig.nEventID >= ADI_TMR_NUM_EVENTS) {
332+
if (eventConfig->nEventID >= ADI_TMR_NUM_EVENTS) {
312333
return ADI_TMR_BAD_EVENT_ID;
313334
} /* ENDIF */
314335
/* IF(The timer is already running) */
315336
if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_EN) == BITM_TMR_RGB_CTL_EN) {
316337
return ADI_TMR_OPERATION_NOT_ALLOWED;
317338
} /* ENDIF */
318339
#endif
340+
#if defined(__ADUCM4050__)
319341
/* 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
322344
/* IF(Busy bit does not clear after waiting) */
323345
if (ADI_TMR_SUCCESS != WaitForStatusBit(eDevice, (uint16_t) BITM_TMR_RGB_STAT_BUSY)) {
324346
return ADI_TMR_DEVICE_BUSY;
@@ -328,15 +350,20 @@ ADI_TMR_RESULT adi_tmr_ConfigEvent(ADI_TMR_DEVICE const eDevice, ADI_TMR_EVENT_C
328350
adi_tmr_registers[eDevice]->CTL &= (uint16_t) ~(BITM_TMR_RGB_CTL_EVTEN | BITM_TMR_RGB_CTL_RSTEN);
329351

330352
/* IF(Turning event capture on) */
331-
if (eventConfig.bEnable == true) {
353+
if (eventConfig->bEnable == true) {
332354
adi_tmr_registers[eDevice]->CTL |= (uint16_t) BITM_TMR_RGB_CTL_EVTEN;
333355
} /* ENDIF */
334356

335357
/* IF(Enabling reset on event capture) */
336-
if (eventConfig.bPrescaleReset == true) {
358+
if (eventConfig->bPrescaleReset == true) {
337359
adi_tmr_registers[eDevice]->CTL |= (uint16_t) BITM_TMR_RGB_CTL_RSTEN;
338360
} /* ENDIF */
339361

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+
340367
return ADI_TMR_SUCCESS;
341368
}
342369

@@ -364,7 +391,7 @@ ADI_TMR_RESULT adi_tmr_ConfigEvent(ADI_TMR_DEVICE const eDevice, ADI_TMR_EVENT_C
364391
* - #ADI_TMR_SUCCESS Function call completed successfully
365392
*
366393
*/
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) {
368395
uint16_t nControl = 0u;
369396
#ifdef ADI_DEBUG
370397
/* IF(Bad device input parameter) */
@@ -375,35 +402,38 @@ ADI_TMR_RESULT adi_tmr_ConfigPwm(ADI_TMR_DEVICE const eDevice, ADI_TMR_PWM_CONFI
375402
if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_EN) == BITM_TMR_RGB_CTL_EN) {
376403
return ADI_TMR_OPERATION_NOT_ALLOWED;
377404
} /* ENDIF */
405+
#if defined(__ADUCM4050__)
378406
/* 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)) {
380408
return ADI_TMR_BAD_PWM_NUM;
381409
} /* ENDIF */
410+
#endif
382411
#endif
383412
/* IF(Idle high is set) */
384-
if (pwmConfig.bIdleHigh == true) {
413+
if (pwmConfig->bIdleHigh == true) {
385414
nControl = (1u << ((uint16_t) BITP_TMR_RGB_PWM0CTL_IDLESTATE));
386415
} /* ENDIF */
387416

388417
/* IF(Match mode is enabled) */
389-
if (pwmConfig.bMatch == true) {
418+
if (pwmConfig->bMatch == true) {
390419
nControl |= (1u << ((uint16_t) BITP_TMR_RGB_PWM0CTL_MATCH));
391420
} /* ENDIF */
392-
421+
393422
/* IF(PWM output 0) */
394-
if (pwmConfig.eOutput == ADI_TMR_PWM_OUTPUT_0) {
423+
if (pwmConfig->eOutput == ADI_TMR_PWM_OUTPUT_0) {
395424
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__)
397427
/* IF(PWM output 1) */
398-
} else if (pwmConfig.eOutput == ADI_TMR_PWM_OUTPUT_1) {
428+
} else if (pwmConfig->eOutput == ADI_TMR_PWM_OUTPUT_1) {
399429
adi_tmr_registers[eDevice]->PWM1CTL = nControl;
400-
adi_tmr_registers[eDevice]->PWM1MATCH = pwmConfig.nMatchValue;
430+
adi_tmr_registers[eDevice]->PWM1MATCH = pwmConfig->nMatchValue;
401431
/* ELSE(PWM output 2) */
402432
} else {
403433
adi_tmr_registers[eDevice]->PWM2CTL = nControl;
404-
adi_tmr_registers[eDevice]->PWM2MATCH = pwmConfig.nMatchValue;
434+
adi_tmr_registers[eDevice]->PWM2MATCH = pwmConfig->nMatchValue;
435+
#endif
405436
} /* ENDIF */
406-
407437
return ADI_TMR_SUCCESS;
408438
}
409439

@@ -599,13 +629,13 @@ void GP_Tmr2_Int_Handler(void) {
599629
CommonIntHandler(ADI_TMR_DEVICE_GP2);
600630
ISR_EPILOG()
601631
}
602-
632+
#if defined(__ADUCM4050__)
603633
void RGB_Tmr_Int_Handler(void) {
604634
ISR_PROLOG()
605635
CommonIntHandler(ADI_TMR_DEVICE_RGB);
606636
ISR_EPILOG()
607637
}
608-
638+
#endif
609639
/*! \endcond */
610640

611641
/*! @} */

0 commit comments

Comments
 (0)