How to improve interrupt latency with Arduino/C
Posted: Tue Feb 26, 2019 9:57 am
After having issues with interrupt latency I've checked an older thread where it's described that interrupt latency with C is around 2us.
Is there a way (if possible code please) to improve it with some kind of in-line assembly (without RTOS change)? My ISR routines are very simple e.g. capturing PCNT value to some global variable, setting a flag etc. Thus the latency and the overhead is very high compared to the code.
Code examples what I'd like to improve:
Thanks in advance.
Is there a way (if possible code please) to improve it with some kind of in-line assembly (without RTOS change)? My ISR routines are very simple e.g. capturing PCNT value to some global variable, setting a flag etc. Thus the latency and the overhead is very high compared to the code.
Code examples what I'd like to improve:
Code: Select all
volatile uint32_t refcovf = 0;
volatile uint32_t sigcovf = 0;
void IRAM_ATTR pcnt_isr_fmeas(void * ovfp) {
uint32_t intr_status = PCNT.int_st.val;
if (intr_status & PCNT0_INT) {
PCNT.int_clr.val = PCNT0_INT;
intr_status ^= PCNT0_INT;
if (PCNT.status_unit[0].h_lim_lat) {
refcovf++;
}
}
if (intr_status & PCNT1_INT) {
PCNT.int_clr.val = PCNT1_INT;
intr_status ^= PCNT1_INT;
if (PCNT.status_unit[1].h_lim_lat) {
sigcovf++;
}
}
// check channels not handled so far
if (! intr_status ) return;
for (int i = 2; i < PCNT_UNIT_MAX; i++) {
if (intr_status & (BIT(i))) {
PCNT.int_clr.val = BIT(i);
}
}
}// pcnt_isr_fmeas
volatile int16_t signumcnt, gpsrefcnt;
volatile uint32_t signumovf, gpsrefovf, gpsnum=0;
void IRAM_ATTR isrsigrdy() {
signumcnt = (REG_READ(PCNT_U1_CNT_REG)&0x7FFF);
signumovf = sigcovf;
} // isrsigrdy
void IRAM_ATTR isrgpsrdy() {
gpsrefcnt = (REG_READ(PCNT_U0_CNT_REG)&0x7FFF);
gpsrefovf = refcovf;
gpsnum=1;
} // isrgpsrdy