Quitting the scheduler loop [xtensa] [_frxt_dispatch]

guido-roncarolo wrote on Tuesday, February 26, 2019:

I have a question related to quitting the scheduler loop in the Xtensa FreeRTOS port:

Freertos doc says that in order to quit the RTOS scheduling loop vTaskEndScheduler must be called
Please see https://www.freertos.org/a00133.html

vTaskEndScheduler is implemented in term of vPortEndScheduler

Xtensa port has this implementation for vPortEndScheduler
void vPortEndScheduler( void )
{
/* It is unlikely that the Xtensa port will get stopped. If required simply
disable the tick interrupt here. */
}

Having ask my HW buddy, the tick interrupt for us is interrupt 2 and 3,

 Interrupt | Type   |Level | BInterrupt | Pin Source 
----------+--------+------+------------+-----------
0         | Level  | 1    | 0          | Tied low 
1         | Edge   | 3    | 1          | Tied low
2         | Timer.0| 2    |            | Internal
3         | Timer.1| 3    |            | Internal

so I did something like this

void vPortEndScheduler( void )
{
    /* It is unlikely that the Xtensa port will get stopped.  If required simply
    disable the tick interrupt here. */
    uint32_t ints = xthal_get_intenable();
    __dsp_printf("1) xthal_get_intenable 0x%x\n", ints);
 
    xt_ints_off(1 << 2);
    xt_ints_off(1 << 3);
    ints = xthal_get_intenable();
    __dsp_printf("2) xthal_get_intenable 0x%x\n", ints);
}

that gives me

1) xthal_get_intenable 0x4
2) xthal_get_intenable 0x0

So it would seem that the interrupt is OFF.

Unfortunately _frxt_dispatch keeps running.

Am I making a mistake?
Would it be possible to have you guys double check this, please?

Thanks in advance

guido

xz8987f wrote on Tuesday, February 26, 2019:

Hi guido,
I have implemented ending the scheduler for several microcontrollers. Basically I’m using a combination of setjmp and longjmp. I have documented it in https://mcuoneclipse.com/2019/01/20/freertos-how-to-end-and-restart-the-scheduler/ which has links to the implementation on GitHub. I think you can do the same for your port.

I hope this helps,
Erich

guido-roncarolo wrote on Wednesday, February 27, 2019:

Hello Erich!

Thanks so much for the very detail and well documented work you did: I tested on my xtensa hifi4 and does work OK!

Thank you so much

guido