Strange behaviour FRC1 timer / interrupt handler

eriksl
Posts: 157
Joined: Fri May 22, 2015 6:22 pm

Strange behaviour FRC1 timer / interrupt handler

Postby eriksl » Fri Aug 19, 2016 6:10 pm

When I make a handler function for the FRC1 timer interrupt, it acts strangely, I can't explain. Please help.

The only thing the handler does (for the moment) is count how many times it has been called (counter++). It does not clear an interrupt mask and also it does not reload the timer, so it might or might not called more than once. I am aware of that.

This is what happens:

- when using "normal" FRC1 interrupt, NOTHING happens, the interrupt handler is never called (counter remains at zero)
- when using the "NMI" FRC1 interrupt, the handler is called, but the timer is reloaded automatically and the handler is called again and again, without the timer being reloaded by me and without setting "autoreload".

I am NOT using any os_timer* functions. I am NOT using pwm (not even -lpwm linked).

This is my testing code:

Code: Select all

enum
{
   FRC1_DIVIDE_BY_1 = 0,
   FRC1_DIVIDE_BY_16 = 4,
   FRC1_DIVIDE_BY_256 = 8
};

enum
{
   FRC1_EDGE_INT = 0,
   FCR1_LEVEL_INT = 1
};

enum
{
   FRC1_AUTO_LOAD = 0x0040,
   FRC1_ENABLE_TIMER = 0x0080,
};

enum
{
   FRC1_NMI_SOURCE = 0x8000
};

unsigned int ints;

static void intr_handler(void)
{
   ints++;
}

ICACHE_FLASH_ATTR static void intr_test(void)
{
   RTC_REG_WRITE(FRC1_CTRL_ADDRESS, FRC1_ENABLE_TIMER | FRC1_DIVIDE_BY_16 | FRC1_EDGE_INT);

   ETS_FRC_TIMER1_INTR_ATTACH(intr_handler, NULL); // non-NMI interrupt
   //ETS_FRC_TIMER1_NMI_INTR_ATTACH(intr_handler); // NMI interrupt, choose one

   TM1_EDGE_INT_ENABLE();

   ETS_FRC1_INTR_ENABLE();

   RTC_REG_WRITE(FRC1_LOAD_ADDRESS, 256);

   RTC_CLR_REG_MASK(FRC1_INT_ADDRESS, FRC1_INT_CLR_MASK);
}

eriksl
Posts: 157
Joined: Fri May 22, 2015 6:22 pm

Re: Strange behaviour FRC1 timer / interrupt handler

Postby eriksl » Tue Aug 23, 2016 6:42 pm

Nobody at Espressif got a clue?

I copied this code in various variants from examples (because of documentation lacking...), and apparently it does work for those people...

I deactivated all code that does something with interrupts, i.e. the UART handler and the code that is run by os_timer_arm etc.

What to try next? I have no idea. Could it be the RTC clock calibration (see SDK function)?

eriksl
Posts: 157
Joined: Fri May 22, 2015 6:22 pm

Re: Strange behaviour FRC1 timer / interrupt handler

Postby eriksl » Fri Aug 26, 2016 11:26 pm

Using this function I found:

Code: Select all

static inline uint32_t ETS_INTR_ENABLED(void) // FIXME
{
    uint32_t enabled;
    __asm__ __volatile__("esync; rsr %0,intenable":"=a" (enabled));
    return enabled;
}


I can see that the FRC1 interrupts are enabled.

Without enabling FRC1 interrupts, it reads 521, bit 9 is clear
With enabeling FRC1 interrupts, it reads 721, bit 9 is set

eriksl
Posts: 157
Joined: Fri May 22, 2015 6:22 pm

Re: Strange behaviour FRC1 timer / interrupt handler

Postby eriksl » Sat Aug 27, 2016 1:08 am

When I "or" 0x01 into the value that is written into FRC1_CTRL_ADDRESS (+ PERIPHS_TIMER_BASEADDR of course), it works.

According to the "documentation" (ehhhrmm, just examples found here and there), LEVEL_INT would be 0x1 and EDGE_INT would be 0x0. It seems it's the other way around actually?

It IS an EDGE interrupt now, because I don't need to clear the interrupt mask to have the ISR called again.

How comes it seems to for others nonetheless?

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 7 guests