xTimerResetFromISR Exception

papillon
Posts: 7
Joined: Tue Feb 21, 2017 12:31 am

xTimerResetFromISR Exception

Postby papillon » Fri Mar 03, 2017 11:00 pm

I am trying to reset a timer from within an ISR. The HW_IsrHandler is called when a button is pressed on pin 14, but resetting the timer generates a StoreProhibited exception at xTimerResetFromISR.

Code: Select all

#include <stdio.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/timer.h"
#include "freertos/timers.h"

TimerHandle_t timer=NULL;

void HW_IsrHandler(void* arg)
{
	gpio_num_t pin = (gpio_num_t) arg;
	if(gpio_get_level(pin)==0) {
		xTimerResetFromISR(timer, 1000 / portTICK_RATE_MS);
	}
}

void timerCallback(TimerHandle_t id) {
}

void app_main()
{
	uint8_t pin=14;
	timer=xTimerCreate("timer Callback", 1000 / portTICK_RATE_MS, pdFALSE, (void *)0, timerCallback);

	gpio_install_isr_service(0 );

	gpio_config_t io_conf;

	io_conf.pull_down_en = 0;
	io_conf.pull_up_en = 1;
	io_conf.intr_type = GPIO_INTR_ANYEDGE;
	io_conf.pin_bit_mask = (1<<pin);
	io_conf.mode = GPIO_MODE_INPUT;
	gpio_config(&io_conf);

	gpio_isr_handler_add(pin, HW_IsrHandler, (void*) &pin);
}
Any idea what could be causing this?
Thanks for your input!

papillon
Posts: 7
Joined: Tue Feb 21, 2017 12:31 am

Re: xTimerResetFromISR Exception

Postby papillon » Sun Mar 05, 2017 10:02 pm

The issue is that the ESP32 API differs from the FreeRTOS API. The FreeRTOS API has the following function:

Code: Select all

BaseType_t xTimerResetFromISR( TimerHandle_t xTimer, TickType_t xTicksToWait );
While the IDF has this one:

Code: Select all

BaseType_t xTimerResetFromISR( TimerHandle_t xTimer, BaseType_t *pxHigherPriorityTaskWoken );
The 2nd parameter is used for a different purpose. The compiler does not complain since the footprint is similar, but, obviously, execution causes an exception, because the parameter is used to return a status code.

Note that the xTimerReset function does not have the same issue, since both the IDF and the FreeRTOS version share the same declaration:

Code: Select all

BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: xTimerResetFromISR Exception

Postby kolban » Sun Mar 05, 2017 10:57 pm

I'm not sure I'm following .... if we look here ...

http://www.freertos.org/FreeRTOS-timers ... omISR.html

It appears that the FreeRTOS API for xTimerResetFromISR is:

Code: Select all

 BaseType_t xTimerResetFromISR(TimerHandle_t xTimer, BaseType_t *pxHigherPriorityTaskWoken);
which is distinct from:

Code: Select all

BaseType_t xTimerResetFromISR( TimerHandle_t xTimer, TickType_t xTicksToWait );
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

papillon
Posts: 7
Joined: Tue Feb 21, 2017 12:31 am

Re: xTimerResetFromISR Exception

Postby papillon » Mon Mar 06, 2017 12:53 am

Indeed rather confusing.
It turns out that the latest version of the FreeRTOS manual I was using (available at http://www.freertos.org/Documentation/1 ... _Guide.pdf) only covers up to version 8 of the RTOS, whereas the IDF is based on version 9. And the software timer reset function was indeed changed in version 9, hence the confusion.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: xTimerResetFromISR Exception

Postby WiFive » Mon Mar 06, 2017 1:37 am

IDF uses freertos 8.2.0. You're never going to use xTicksToWait in a FromISR function. It was probably just a brain fart, we all do it.

Who is online

Users browsing this forum: atx823, Gaston1980, Majestic-12 [Bot] and 248 guests