66 #pragma diag_suppress=Pm011,Pm073,Pm123,Pm140,Pm141,Pm143 79 #include <adi_processor.h> 80 #include <adi_tmr_config.h> 81 #include <rtos_map/adi_rtos_map.h> 82 #include <drivers/tmr/adi_tmr.h> 85 #include "adi_tmr_data.c" 87 #if defined(__ADUCM4x50__) 89 #if BITP_TMR_RGB_PWM0CTL_IDLESTATE != BITP_TMR_RGB_PWM1CTL_IDLESTATE 90 #error "Bit positions for PWM0 and PWM1 do not match. Fix adi_tmr_ConfigPwm." 92 #if BITP_TMR_RGB_PWM0CTL_IDLESTATE != BITP_TMR_RGB_PWM2CTL_IDLESTATE 93 #error "Bit positions for PWM0 and PWM2 do not match. Fix adi_tmr_ConfigPwm." 95 #if BITP_TMR_RGB_PWM0CTL_MATCH != BITP_TMR_RGB_PWM1CTL_MATCH 96 #error "Bit positions for PWM0 and PWM1 do not match. Fix adi_tmr_ConfigPwm." 98 #if BITP_TMR_RGB_PWM0CTL_MATCH != BITP_TMR_RGB_PWM2CTL_MATCH 99 #error "Bit positions for PWM0 and PWM2 do not match. Fix adi_tmr_ConfigPwm." 104 #if defined(__ADUCM302x__) 105 #define ADI_TMR_NUM_EVENTS (16u) 106 #elif defined(__ADUCM4x50__) 107 #define ADI_TMR_NUM_EVENTS (40u) 109 #error TMR is not ported for this processor 115 #if defined(__ADUCM302x__) 116 static ADI_TMR_TypeDef * adi_tmr_registers[
ADI_TMR_DEVICE_NUM] = {pADI_TMR0, pADI_TMR1, pADI_TMR2};
117 #elif defined(__ADUCM4x50__) 118 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};
120 #error TMR is not ported for this processor 124 #if defined(__ADUCM302x__) 125 static const IRQn_Type adi_tmr_interrupt[
ADI_TMR_DEVICE_NUM] = {TMR0_EVT_IRQn, TMR1_EVT_IRQn, TMR2_EVT_IRQn};
126 #elif defined(__ADUCM4x50__) 127 static const IRQn_Type adi_tmr_interrupt[
ADI_TMR_DEVICE_NUM] = {TMR0_EVT_IRQn, TMR1_EVT_IRQn, TMR2_EVT_IRQn, TMR_RGB_EVT_IRQn};
129 #error TMR is not ported for this processor 138 void GP_Tmr0_Int_Handler(
void);
139 void GP_Tmr1_Int_Handler(
void);
140 void GP_Tmr2_Int_Handler(
void);
141 #if defined(__ADUCM4x50__) 142 void RGB_Tmr_Int_Handler(
void);
182 if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_EN) == BITM_TMR_RGB_CTL_EN) {
187 adi_tmr_callbacks [eDevice] = pfCallback;
188 adi_tmr_parameters[eDevice] = pCBParam;
191 if (bEnableInt ==
true) {
192 NVIC_EnableIRQ(adi_tmr_interrupt[eDevice]);
195 NVIC_DisableIRQ(adi_tmr_interrupt[eDevice]);
199 adi_tmr_registers[eDevice]->CTL = aTimerCtlConfig [eDevice];
200 adi_tmr_registers[eDevice]->LOAD = aTimerLoadConfig [eDevice];
201 adi_tmr_registers[eDevice]->ALOAD = aTimerALoadConfig [eDevice];
202 adi_tmr_registers[eDevice]->PWM0CTL = aTimerPwmCtlConfig [eDevice];
203 adi_tmr_registers[eDevice]->PWM0MATCH = aTimerPwmMatchConfig[eDevice];
204 #if defined(__ADUCM4x50__) 205 adi_tmr_registers[eDevice]->EVENTSELECT = aTimerEventConfig [eDevice];
208 if (eDevice == ADI_TMR_DEVICE_RGB) {
210 adi_tmr_registers[eDevice]->PWM1CTL = aTimerPwmCtlConfig [eDevice+1u];
211 adi_tmr_registers[eDevice]->PWM1MATCH = aTimerPwmMatchConfig[eDevice+1u];
213 adi_tmr_registers[eDevice]->PWM2CTL = aTimerPwmCtlConfig [eDevice+2u];
214 adi_tmr_registers[eDevice]->PWM2MATCH = aTimerPwmMatchConfig[eDevice+2u];
253 if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_EN) == BITM_TMR_RGB_CTL_EN) {
258 adi_tmr_registers[eDevice]->LOAD = timerConfig->
nLoad;
259 adi_tmr_registers[eDevice]->ALOAD = timerConfig->
nAsyncLoad;
262 if (
ADI_TMR_SUCCESS != WaitForStatusBit(eDevice, (uint16_t) BITM_TMR_RGB_STAT_BUSY)) {
267 nTemp = adi_tmr_registers[eDevice]->CTL;
268 nTemp &= (uint16_t) (BITM_TMR_RGB_CTL_EVTEN | BITM_TMR_RGB_CTL_RSTEN );
271 nTemp |= (uint16_t)(((uint16_t) timerConfig->
ePrescaler ) << BITP_TMR_RGB_CTL_PRE);
272 nTemp |= (uint16_t)(((uint16_t) timerConfig->
eClockSource) << BITP_TMR_RGB_CTL_CLK);
276 nTemp |= (1u << BITP_TMR_RGB_CTL_MODE);
281 nTemp |= (1u << BITP_TMR_RGB_CTL_UP);
286 nTemp |= (1u << BITP_TMR_RGB_CTL_RLD);
291 nTemp |= (1u << BITP_TMR_RGB_CTL_SYNCBYP);
295 adi_tmr_registers[eDevice]->CTL = nTemp;
334 if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_EN) == BITM_TMR_RGB_CTL_EN) {
339 #if defined(__ADUCM4x50__) 341 adi_tmr_registers[eDevice]->EVENTSELECT = (uint16_t) eventConfig->
nEventID;
345 if (
ADI_TMR_SUCCESS != WaitForStatusBit(eDevice, (uint16_t) BITM_TMR_RGB_STAT_BUSY)) {
350 adi_tmr_registers[eDevice]->CTL &= (uint16_t) ~(BITM_TMR_RGB_CTL_EVTEN | BITM_TMR_RGB_CTL_RSTEN );
353 if (eventConfig->
bEnable ==
true) {
354 adi_tmr_registers[eDevice]->CTL |= (uint16_t) BITM_TMR_RGB_CTL_EVTEN;
359 adi_tmr_registers[eDevice]->CTL |= (uint16_t) BITM_TMR_RGB_CTL_RSTEN;
362 #if defined(__ADUCM302x__) 364 adi_tmr_registers[eDevice]->CTL |= (uint16_t) (((uint16_t) eventConfig->
nEventID) << BITP_TMR_CTL_EVTRANGE);
395 uint16_t nControl = 0u;
402 if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_EN) == BITM_TMR_RGB_CTL_EN) {
405 #if defined(__ADUCM4x50__) 414 nControl = (1u << ((uint16_t) BITP_TMR_RGB_PWM0CTL_IDLESTATE));
418 if (pwmConfig->
bMatch ==
true) {
419 nControl |= (1u << ((uint16_t) BITP_TMR_RGB_PWM0CTL_MATCH));
424 adi_tmr_registers[eDevice]->PWM0CTL = nControl;
425 adi_tmr_registers[eDevice]->PWM0MATCH = pwmConfig->
nMatchValue;
427 #if defined(__ADUCM4x50__) 430 adi_tmr_registers[eDevice]->PWM1CTL = nControl;
431 adi_tmr_registers[eDevice]->PWM1MATCH = pwmConfig->
nMatchValue;
434 adi_tmr_registers[eDevice]->PWM2CTL = nControl;
435 adi_tmr_registers[eDevice]->PWM2MATCH = pwmConfig->
nMatchValue;
465 if (
ADI_TMR_SUCCESS != WaitForStatusBit(eDevice, (uint16_t) BITM_TMR_RGB_STAT_BUSY)) {
470 adi_tmr_registers[eDevice]->CTL &= (uint16_t) ~BITM_TMR_RGB_CTL_EN;
473 if (bEnable ==
true) {
474 adi_tmr_registers[eDevice]->CTL |= (uint16_t) BITM_TMR_RGB_CTL_EN;
503 if (pCount == NULL) {
507 *pCount = adi_tmr_registers[eDevice]->CURCNT;
535 if (pCount == NULL) {
539 *pCount = adi_tmr_registers[eDevice]->CAPTURE;
567 if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_RLD) != BITM_TMR_RGB_CTL_RLD) {
572 adi_tmr_registers[eDevice]->CLRINT = BITM_TMR_RGB_CLRINT_TIMEOUT;
574 if (
ADI_TMR_SUCCESS != WaitForStatusBit(eDevice, (uint16_t) BITM_TMR_RGB_STAT_PDOK)) {
589 for (uint16_t i = 0u; i < 1000u; i++) {
591 if ((adi_tmr_registers[(eDevice)]->STAT & nBusyBit) == ((uint16_t) 0u)) {
600 uint16_t IntStatus = adi_tmr_registers[eDevice]->STAT;
602 if(adi_tmr_callbacks[eDevice] != NULL) {
604 if((IntStatus & ((uint16_t) BITM_TMR_RGB_STAT_TIMEOUT)) != ((uint16_t) 0u)) {
608 if((IntStatus & ((uint16_t) BITM_TMR_RGB_STAT_CAPTURE)) != ((uint16_t) 0u)) {
613 adi_tmr_registers[eDevice]->CLRINT = (BITM_TMR_RGB_CLRINT_EVTCAPT | BITM_TMR_RGB_CLRINT_TIMEOUT);
616 void GP_Tmr0_Int_Handler(
void) {
622 void GP_Tmr1_Int_Handler(
void) {
628 void GP_Tmr2_Int_Handler(
void) {
634 #if defined(__ADUCM4x50__) 635 void RGB_Tmr_Int_Handler(
void) {
637 CommonIntHandler(ADI_TMR_DEVICE_RGB);
ADI_TMR_PRESCALER ePrescaler
ADI_TMR_PWM_OUTPUT eOutput
ADI_TMR_RESULT adi_tmr_Enable(ADI_TMR_DEVICE const eDevice, bool bEnable)
Enable or Disable the GP or RGB Timer.
ADI_TMR_RESULT adi_tmr_GetCaptureCount(ADI_TMR_DEVICE const eDevice, uint16_t *pCount)
Get GP or RGB Timer Captured Count.
ADI_TMR_RESULT adi_tmr_Init(ADI_TMR_DEVICE const eDevice, ADI_CALLBACK const pfCallback, void *const pCBParam, bool bEnableInt)
Initialize GP or RGB Timer.
ADI_TMR_CLOCK_SOURCE eClockSource
ADI_TMR_RESULT adi_tmr_ConfigPwm(ADI_TMR_DEVICE const eDevice, ADI_TMR_PWM_CONFIG *pwmConfig)
Setup GP or RGB Timer Pulse Width Modulation.
ADI_TMR_RESULT adi_tmr_ConfigTimer(ADI_TMR_DEVICE const eDevice, ADI_TMR_CONFIG *timerConfig)
Configure GP or RGB Timer.
#define ADI_TMR_NUM_EVENTS
ADI_TMR_RESULT adi_tmr_Reload(ADI_TMR_DEVICE const eDevice)
Reload GP or RGB Timer.
ADI_TMR_RESULT adi_tmr_ConfigEvent(ADI_TMR_DEVICE const eDevice, ADI_TMR_EVENT_CONFIG *eventConfig)
Setup GP or RGB Timer Event Capture.
ADI_TMR_RESULT adi_tmr_GetCurrentCount(ADI_TMR_DEVICE const eDevice, uint16_t *pCount)
Get GP or RGB Timer Current Count.