34 #pragma diag_suppress=Pm011,Pm073,Pm123,Pm140,Pm141,Pm143 47 #include <adi_processor.h> 48 #include <adi_tmr_config.h> 49 #include <rtos_map/adi_rtos_map.h> 50 #include <drivers/tmr/adi_tmr.h> 53 #include "adi_tmr_data.c" 55 #if defined(__ADUCM4x50__) 57 #if BITP_TMR_RGB_PWM0CTL_IDLESTATE != BITP_TMR_RGB_PWM1CTL_IDLESTATE 58 #error "Bit positions for PWM0 and PWM1 do not match. Fix adi_tmr_ConfigPwm." 60 #if BITP_TMR_RGB_PWM0CTL_IDLESTATE != BITP_TMR_RGB_PWM2CTL_IDLESTATE 61 #error "Bit positions for PWM0 and PWM2 do not match. Fix adi_tmr_ConfigPwm." 63 #if BITP_TMR_RGB_PWM0CTL_MATCH != BITP_TMR_RGB_PWM1CTL_MATCH 64 #error "Bit positions for PWM0 and PWM1 do not match. Fix adi_tmr_ConfigPwm." 66 #if BITP_TMR_RGB_PWM0CTL_MATCH != BITP_TMR_RGB_PWM2CTL_MATCH 67 #error "Bit positions for PWM0 and PWM2 do not match. Fix adi_tmr_ConfigPwm." 72 #if defined(__ADUCM302x__) 73 #define ADI_TMR_NUM_EVENTS (16u) 74 #elif defined(__ADUCM4x50__) 75 #define ADI_TMR_NUM_EVENTS (40u) 77 #error TMR is not ported for this processor 83 #if defined(__ADUCM302x__) 84 static ADI_TMR_TypeDef * adi_tmr_registers[
ADI_TMR_DEVICE_NUM] = {pADI_TMR0, pADI_TMR1, pADI_TMR2};
85 #elif defined(__ADUCM4x50__) 86 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};
88 #error TMR is not ported for this processor 92 #if defined(__ADUCM302x__) 93 static const IRQn_Type adi_tmr_interrupt[
ADI_TMR_DEVICE_NUM] = {TMR0_EVT_IRQn, TMR1_EVT_IRQn, TMR2_EVT_IRQn};
94 #elif defined(__ADUCM4x50__) 95 static const IRQn_Type adi_tmr_interrupt[
ADI_TMR_DEVICE_NUM] = {TMR0_EVT_IRQn, TMR1_EVT_IRQn, TMR2_EVT_IRQn, TMR_RGB_EVT_IRQn};
97 #error TMR is not ported for this processor 106 void GP_Tmr0_Int_Handler(
void);
107 void GP_Tmr1_Int_Handler(
void);
108 void GP_Tmr2_Int_Handler(
void);
109 #if defined(__ADUCM4x50__) 110 void RGB_Tmr_Int_Handler(
void);
150 if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_EN) == BITM_TMR_RGB_CTL_EN) {
155 adi_tmr_callbacks [eDevice] = pfCallback;
156 adi_tmr_parameters[eDevice] = pCBParam;
159 if (bEnableInt ==
true) {
160 NVIC_EnableIRQ(adi_tmr_interrupt[eDevice]);
163 NVIC_DisableIRQ(adi_tmr_interrupt[eDevice]);
167 adi_tmr_registers[eDevice]->CTL = aTimerCtlConfig [eDevice];
168 adi_tmr_registers[eDevice]->LOAD = aTimerLoadConfig [eDevice];
169 adi_tmr_registers[eDevice]->ALOAD = aTimerALoadConfig [eDevice];
170 adi_tmr_registers[eDevice]->PWM0CTL = aTimerPwmCtlConfig [eDevice];
171 adi_tmr_registers[eDevice]->PWM0MATCH = aTimerPwmMatchConfig[eDevice];
172 #if defined(__ADUCM4x50__) 173 adi_tmr_registers[eDevice]->EVENTSELECT = aTimerEventConfig [eDevice];
178 adi_tmr_registers[eDevice]->PWM1CTL = aTimerPwmCtlConfig [eDevice+1u];
179 adi_tmr_registers[eDevice]->PWM1MATCH = aTimerPwmMatchConfig[eDevice+1u];
181 adi_tmr_registers[eDevice]->PWM2CTL = aTimerPwmCtlConfig [eDevice+2u];
182 adi_tmr_registers[eDevice]->PWM2MATCH = aTimerPwmMatchConfig[eDevice+2u];
221 if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_EN) == BITM_TMR_RGB_CTL_EN) {
226 adi_tmr_registers[eDevice]->LOAD = timerConfig->
nLoad;
227 adi_tmr_registers[eDevice]->ALOAD = timerConfig->
nAsyncLoad;
230 if (
ADI_TMR_SUCCESS != WaitForStatusBit(eDevice, (uint16_t) BITM_TMR_RGB_STAT_BUSY)) {
235 nTemp = adi_tmr_registers[eDevice]->CTL;
236 nTemp &= (uint16_t) (BITM_TMR_RGB_CTL_EVTEN | BITM_TMR_RGB_CTL_RSTEN );
239 nTemp |= (uint16_t)(((uint16_t) timerConfig->
ePrescaler ) << BITP_TMR_RGB_CTL_PRE);
240 nTemp |= (uint16_t)(((uint16_t) timerConfig->
eClockSource) << BITP_TMR_RGB_CTL_CLK);
244 nTemp |= (1u << BITP_TMR_RGB_CTL_MODE);
249 nTemp |= (1u << BITP_TMR_RGB_CTL_UP);
254 nTemp |= (1u << BITP_TMR_RGB_CTL_RLD);
259 nTemp |= (1u << BITP_TMR_RGB_CTL_SYNCBYP);
263 adi_tmr_registers[eDevice]->CTL = nTemp;
302 if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_EN) == BITM_TMR_RGB_CTL_EN) {
307 #if defined(__ADUCM4x50__) 309 adi_tmr_registers[eDevice]->EVENTSELECT = (uint16_t) eventConfig->
nEventID;
313 if (
ADI_TMR_SUCCESS != WaitForStatusBit(eDevice, (uint16_t) BITM_TMR_RGB_STAT_BUSY)) {
318 adi_tmr_registers[eDevice]->CTL &= (uint16_t) ~(BITM_TMR_RGB_CTL_EVTEN | BITM_TMR_RGB_CTL_RSTEN );
321 if (eventConfig->
bEnable ==
true) {
322 adi_tmr_registers[eDevice]->CTL |= (uint16_t) BITM_TMR_RGB_CTL_EVTEN;
327 adi_tmr_registers[eDevice]->CTL |= (uint16_t) BITM_TMR_RGB_CTL_RSTEN;
330 #if defined(__ADUCM302x__) 332 adi_tmr_registers[eDevice]->CTL |= (uint16_t) (((uint16_t) eventConfig->
nEventID) << BITP_TMR_CTL_EVTRANGE);
363 uint16_t nControl = 0u;
370 if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_EN) == BITM_TMR_RGB_CTL_EN) {
373 #if defined(__ADUCM4x50__) 382 nControl = (1u << ((uint16_t) BITP_TMR_RGB_PWM0CTL_IDLESTATE));
386 if (pwmConfig->
bMatch ==
true) {
387 nControl |= (1u << ((uint16_t) BITP_TMR_RGB_PWM0CTL_MATCH));
392 adi_tmr_registers[eDevice]->PWM0CTL = nControl;
393 adi_tmr_registers[eDevice]->PWM0MATCH = pwmConfig->
nMatchValue;
395 #if defined(__ADUCM4x50__) 398 adi_tmr_registers[eDevice]->PWM1CTL = nControl;
399 adi_tmr_registers[eDevice]->PWM1MATCH = pwmConfig->
nMatchValue;
402 adi_tmr_registers[eDevice]->PWM2CTL = nControl;
403 adi_tmr_registers[eDevice]->PWM2MATCH = pwmConfig->
nMatchValue;
433 if (
ADI_TMR_SUCCESS != WaitForStatusBit(eDevice, (uint16_t) BITM_TMR_RGB_STAT_BUSY)) {
438 adi_tmr_registers[eDevice]->CTL &= (uint16_t) ~BITM_TMR_RGB_CTL_EN;
441 if (bEnable ==
true) {
442 adi_tmr_registers[eDevice]->CTL |= (uint16_t) BITM_TMR_RGB_CTL_EN;
471 if (pCount == NULL) {
475 *pCount = adi_tmr_registers[eDevice]->CURCNT;
503 if (pCount == NULL) {
507 *pCount = adi_tmr_registers[eDevice]->CAPTURE;
535 if ((adi_tmr_registers[eDevice]->CTL & BITM_TMR_RGB_CTL_RLD) != BITM_TMR_RGB_CTL_RLD) {
540 adi_tmr_registers[eDevice]->CLRINT = BITM_TMR_RGB_CLRINT_TIMEOUT;
542 if (
ADI_TMR_SUCCESS != WaitForStatusBit(eDevice, (uint16_t) BITM_TMR_RGB_STAT_PDOK)) {
557 for (uint16_t i = 0u; i < 1000u; i++) {
559 if ((adi_tmr_registers[(eDevice)]->STAT & nBusyBit) == ((uint16_t) 0u)) {
568 uint16_t IntStatus = adi_tmr_registers[eDevice]->STAT;
570 if(adi_tmr_callbacks[eDevice] != NULL) {
572 if((IntStatus & ((uint16_t) BITM_TMR_RGB_STAT_TIMEOUT)) != ((uint16_t) 0u)) {
576 if((IntStatus & ((uint16_t) BITM_TMR_RGB_STAT_CAPTURE)) != ((uint16_t) 0u)) {
581 adi_tmr_registers[eDevice]->CLRINT = (BITM_TMR_RGB_CLRINT_EVTCAPT | BITM_TMR_RGB_CLRINT_TIMEOUT);
584 void GP_Tmr0_Int_Handler(
void) {
590 void GP_Tmr1_Int_Handler(
void) {
596 void GP_Tmr2_Int_Handler(
void) {
602 #if defined(__ADUCM4x50__) 603 void RGB_Tmr_Int_Handler(
void) {
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.