Skip to content

Commit 9bc9f2f

Browse files
Edmund Hsuadbridge
authored andcommitted
Fix EV_COG_AD4050LZ us_ticker_fire_interrupt() minimal time interval
- ensure us_ticker_irq_handler() is called only when GP2 timer expires - set us_ticker_set_interrupt() time interval to be 9.846 us - set us_ticker_fire_interrupt() time interval to be 0.03846 us - convert tab to space
1 parent 07ea79c commit 9bc9f2f

File tree

1 file changed

+22
-12
lines changed
  • targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/api

1 file changed

+22
-12
lines changed

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)