Porting to freescale MAC7111

acehigh1971 wrote on Monday, June 26, 2006:

Following the discussion from another thread (was OT there).

I’m porting the freertos on a freescale MAC7111.
I started from the Philips LPC2106 GCC port and the main problem I encountered was the different interrupt controller. It’s vectored but I have to read the source by software. I can’t jump directly to the proper ISR, but to a single ISR in which i read a register in which there is the interrupt source (63 sources), and then jump to the corresponding function.
So, for example, the 2106 port handles differently the preemptivetick (savecontext/restorecontext naked function) and serialISR (savecontext/restore + switchingisr) functions. The microcontroller jumps directly to the correct ISR depending on the interrupt.

In my case i jump into a function (IRQ_ISR), in which I must save the context, and then jump to the proper ISR. This single ISR is defined naked and all the context is saved/restored. the jump is made as a normal function call (using the IRQ stack) and, if for example, I’m in the serialISR, I do a portENTER_SWITCHING_ISR() in which I don’t save the context but only do the sub r11,#4 , as the savecontext was already done in the IRQ_ISR.

So, every IRQ that I raise in my application causes a save/restore context.
Is it right?
Can someone suggest a better approach?

nobody wrote on Monday, June 26, 2006:

This is the approach taken in the ARM9 port (latest download).  There is a single handler that saves the context (must be done before any registers change), then in this case reads the VIC, calls the interrupt function as a standard function call (no irq or naked modifier), then returns to restore the context.

In this case the start/end switching ISR are very different to the LPC demo.  The start is not needed and the switch simply calls the context switch function in the task.c file.  It does not need to do anything else.

The overhead is that each interrupt has to save the context even if it is not going to perform a switch, but the code I have seen as standard from people like atmel and st does this anyway.  It is not a long operation.  I think this approach is more user friendly.

The sub r11, #4 thing is very GCC specific.  There was a thread a few hours ago on that.  Only required because the function is declared naked.

acehigh1971 wrote on Tuesday, June 27, 2006:

You’re telling me that, because the switching isr is no more naked, there is no need of that extra sub r11, lr, #4 ?
There is only the need of the exitswitchingISR macro?

I’m going to test it.

acehigh1971 wrote on Thursday, August 03, 2006:

Tested for some time. It worked ok. I removed the sub r11,#4 instruction, but I had to introduce the -fomit-frame-pointer option to the compiler, so the calling preamble is always the same with any optimization level.

The isr is only one (two, one for FIQ and one for IRQ), and the specific ISR functions are simple ones, they are not declared naked and don’t have the extra sub r11,#4.

There is only the portEXIT_SWITCHING_ISR if the specific function (ie. the serialISR function) has to do a context switch.