Skip to content

Commit 54b6aa3

Browse files
authored
Merge pull request #6490 from li-ho/ev-cog-us-ticker-fire-interrupt
ADI: Fix EV_COG_AD3029LZ and EV_COG_AD4050LZ us_ticker_fire_interrupt() minimal time interval
2 parents 3328ecd + 04eaabf commit 54b6aa3

File tree

2 files changed

+36
-16
lines changed
  • targets/TARGET_Analog_Devices

2 files changed

+36
-16
lines changed

targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/api/us_ticker.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2010-2017 Analog Devices, Inc.
2+
* Copyright (c) 2010-2018 Analog Devices, Inc.
33
*
44
* All rights reserved.
55
*
@@ -206,7 +206,10 @@ static void event_timer()
206206
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, &tmr2Config);
207207
adi_tmr_Enable(ADI_TMR_DEVICE_GP2, true);
208208
} else {
209-
us_ticker_irq_handler();
209+
tmr2Config.nLoad = 65535u;
210+
tmr2Config.nAsyncLoad = 65535u;
211+
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, &tmr2Config);
212+
adi_tmr_Enable(ADI_TMR_DEVICE_GP2, true);
210213
}
211214
}
212215

@@ -231,7 +234,11 @@ static void GP2CallbackFunction(void *pCBParam, uint32_t Event, void * pArg)
231234

232235
if (largecnt < 65536u) {
233236
adi_tmr_Enable(ADI_TMR_DEVICE_GP2, false);
234-
event_timer();
237+
if (largecnt) {
238+
event_timer();
239+
} else {
240+
us_ticker_irq_handler();
241+
}
235242
}
236243
}
237244

@@ -328,6 +335,7 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
328335
*
329336
*/
330337
calc_event_counts(timestamp); // use timestamp to calculate largecnt to control number of timer interrupts
338+
tmr2Config.ePrescaler = ADI_TMR_PRESCALER_256; // TMR2 at 26MHz/256
331339
event_timer(); // uses largecnt to initiate timer interrupts
332340
}
333341

@@ -339,7 +347,9 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
339347
*/
340348
void us_ticker_fire_interrupt(void)
341349
{
342-
NVIC_SetPendingIRQ(TMR2_EVT_IRQn);
350+
largecnt = 1; // set a minimal interval so interrupt fire immediately
351+
tmr2Config.ePrescaler = ADI_TMR_PRESCALER_1; // TMR2 at 26MHz/1
352+
event_timer(); // enable the timer and interrupt
343353
}
344354

345355

targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api/us_ticker.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2010-2017 Analog Devices, Inc.
2+
* Copyright (c) 2010-2018 Analog Devices, Inc.
33
*
44
* All rights reserved.
55
*
@@ -116,7 +116,7 @@ static uint32_t get_current_time(void)
116116
* thereby clearing any TMR1 pend's. This have no effect if this routine is called with interrupts globally disabled.
117117
*/
118118

119-
NVIC_DisableIRQ(adi_tmr_interrupt[ADI_TMR_DEVICE_GP1]); // Prevent Upper_count increment
119+
NVIC_DisableIRQ(adi_tmr_interrupt[ADI_TMR_DEVICE_GP1]); // Prevent Upper_count increment
120120
tmrpend0 = NVIC_GetPendingIRQ(adi_tmr_interrupt[ADI_TMR_DEVICE_GP1]);
121121
// Check if there is a pending interrupt for timer 1
122122

@@ -128,27 +128,27 @@ static uint32_t get_current_time(void)
128128

129129
tmrcnt1 = adi_tmr_registers[ADI_TMR_DEVICE_GP1]->CURCNT; // read both timers manually
130130

131-
totaltmr0 = tmrcnt0; // expand to u32 bits
132-
totaltmr1 = tmrcnt1; // expand to u32 bits
131+
totaltmr0 = tmrcnt0; // expand to u32 bits
132+
totaltmr1 = tmrcnt1; // expand to u32 bits
133133

134134
tmrcnt0 &= 0xff00u;
135135
tmrcnt1 <<= 8;
136136

137137
__DMB();
138138

139-
uc1 = *ucptr; // Read Upper_count
139+
uc1 = *ucptr; // Read Upper_count
140140

141141
tmrpend1 = NVIC_GetPendingIRQ(adi_tmr_interrupt[ADI_TMR_DEVICE_GP1]);
142142
// Check for a pending interrupt again. Only leave loop if they match
143143

144-
NVIC_EnableIRQ(adi_tmr_interrupt[ADI_TMR_DEVICE_GP1]); // enable interrupt on every loop to allow TMR1 interrupt to run
144+
NVIC_EnableIRQ(adi_tmr_interrupt[ADI_TMR_DEVICE_GP1]); // enable interrupt on every loop to allow TMR1 interrupt to run
145145
} while ((tmrcnt0 != tmrcnt1) || (tmrpend0 != tmrpend1));
146146

147147
totaltmr1 <<= 8; // Timer1 runs 256x slower
148148
totaltmr1 += totaltmr0 & 0xffu; // Use last 8 bits of Timer0 as it runs faster
149149
// totaltmr1 now contain 24 bits of significance
150150

151-
if (tmrpend0) { // If an interrupt is pending, then increment local copy of upper count
151+
if (tmrpend0) { // If an interrupt is pending, then increment local copy of upper count
152152
uc1++;
153153
}
154154

@@ -158,7 +158,7 @@ static uint32_t get_current_time(void)
158158
// Divide Uc by 26 (26MHz converted to 1MHz) todo scale for other clock freqs
159159

160160
Uc *= 1290555u; // Divide total(1/26) << 25
161-
Uc >>= 25; // shift back. Fixed point avoid use of floating point divide.
161+
Uc >>= 25; // shift back. Fixed point avoid use of floating point divide.
162162
// Compiler does this inline using shifts and adds.
163163

164164
return Uc;
@@ -205,7 +205,10 @@ static void event_timer()
205205
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, tmr2Config);
206206
adi_tmr_Enable(ADI_TMR_DEVICE_GP2, true);
207207
} else {
208-
us_ticker_irq_handler();
208+
tmr2Config.nLoad = 65535u;
209+
tmr2Config.nAsyncLoad = 65535u;
210+
adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, tmr2Config);
211+
adi_tmr_Enable(ADI_TMR_DEVICE_GP2, true);
209212
}
210213
}
211214

@@ -229,7 +232,11 @@ static void GP2CallbackFunction(void *pCBParam, uint32_t Event, void * pArg)
229232

230233
if (largecnt < 65536u) {
231234
adi_tmr_Enable(ADI_TMR_DEVICE_GP2, false);
232-
event_timer();
235+
if (largecnt) {
236+
event_timer();
237+
} else {
238+
us_ticker_irq_handler();
239+
}
233240
}
234241
}
235242

@@ -326,7 +333,8 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
326333
*
327334
*/
328335
calc_event_counts(timestamp); // use timestamp to calculate largecnt to control number of timer interrupts
329-
event_timer(); // uses largecnt to initiate timer interrupts
336+
tmr2Config.ePrescaler = ADI_TMR_PRESCALER_256; // TMR2 at 26MHz/256
337+
event_timer(); // uses largecnt to initiate timer interrupts
330338
}
331339

332340
/** Set pending interrupt that should be fired right away.
@@ -337,7 +345,9 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
337345
*/
338346
void us_ticker_fire_interrupt(void)
339347
{
340-
NVIC_SetPendingIRQ(TMR2_EVT_IRQn);
348+
largecnt = 1; // set a minimal interval so interrupt fire immediately
349+
tmr2Config.ePrescaler = ADI_TMR_PRESCALER_1; // TMR2 at 26MHz/1
350+
event_timer(); // enable the timer and interrupt
341351
}
342352

343353

0 commit comments

Comments
 (0)