Interrupt vectors - Porting to STR75x/Rowley
Posted by ogradyg
on March 14, 2008
I'm working on porting FreeRTOS over to an existing STR75x based hardware platform and I'm using the Rowley Crossworks tools.
I've got the basics converted over from the STR75x RIDE/GCC port but I'm not sure what the best way to get the interrupt vectoring working is. I've used the Rowley/SAM7 FreeRTOS port on another project and after reviewing it, it appears that the vectoring functions are included in the Atmel supplied libraries.
The work I've done in the past with Rowley and the STR75x used no RTOS and in that case, I used the Rowley ctl library functions for configuring vectors. The STR75x RIDE demo used a startup file from ST with modifications from Raisonance and FreeRTOS and I'm not sure what the beset way to proceed is.
RE: Interrupt vectors - Porting to STR75x/Rowley
Posted by Dave
on March 14, 2008
The important thing with FreeRTOS is that there are no instructions prior to portSAVE_CONTEXT being called. At least if there are instructions then all registers are put back to their interrupted state before portSAVE_CONTEXT is called.
There are two methods of doing this on the LPC2000 and SAM7 and I guess the same is true for STR75x.
The first method is to vector directly to the interrupt handler, and have the handler save and restore the context. This is the sort of thing described on the following page http://www.freertos.org/portlpc2106.html. Scroll down to the section headed "Interrupt service routines". When this technique is used the IRQ vector must go directly to the handler. So the IRQ vector loads the handler address directly from the interrupt controller. So using the LPC2000 as an example, the vector table looks like this:
b _start/* reset - _start*/
ldr pc, _undf/* undefined - _undf*/
ldr pc, _swi/* SWI - _swi*/
ldr pc, _pabt/* program abort - _pabt*/
ldr pc, _dabt/* data abort - _dabt*/
ldr pc, [pc,#-0xFF0]/* IRQ - read the VIC*/
ldr pc, _fiq/* FIQ - _fiq*/
_undf: .word __undf /* undefined*/
_swi: .word vPortYieldProcessor /* SWI*/
_pabt: .word __pabt /* program abort*/
_dabt: .word __dabt /* data abort*/
_fiq: .word __fiq /* FIQ*/
__undf: b . /* undefined*/
__pabt: b . /* program abort*/
__dabt: b . /* data abort*/
__fiq: b . /* FIQ*/
with the line ldr pc, [pc,#-0xFF0] being the IRQ vector loading the program counter with the address provided by the interrupt controller.
The second technique is to have a single IRQ handler entry point that calls portSAVE_CONTEXT first, then looks at the interrupt controller to find the address of the application handler, jumps to the handler, then returns to the single entry point to restore the context of the new task. This is also demonstrated in the FreeRTOS download. Look at the crt0_STR75x_FreeRTOS.s file in the Demo\ARM7_STR75x_GCC\SystemFiles directory and you will see how this is done. In this file the vector table looks like this
LDR PC, Reset_Addr
LDR PC, Undefined_Addr
LDR PC, SWI_Addr
LDR PC, Prefetch_Addr
LDR PC, Abort_Addr
NOP /*; Reserved vector*/
LDR PC, IRQ_Addr
LDR PC, FIQ_Addr
Reset_Addr : .long Reset_Handler
Undefined_Addr : .long UndefinedHandler
SWI_Addr : .long SWIHandler
Prefetch_Addr : .long PrefetchAbortHandler
Abort_Addr : .long DataAbortHandler
.long 0 /*; Reserved vector*/
IRQ_Addr : .long IRQHandler
FIQ_Addr : .long FIQHandler
and IRQHandler like this
portSAVE_CONTEXT/*; Save the context of the current task. */
LDR r0, =EIC_base_addr
LDR r1, =IVR_off_addr
LDR lr, =ReturnAddress/*; Load the return address. */
ADD pc,r0,r1/*; Branch to the IRQ handler. */
LDR r0, =EIC_base_addr
LDR r2, [r0, #CICR_off_addr]/*; Get the IRQ channel number. */
MOV r3,r3,LSL r2
STR r3,[r0, #IPR_off_addr]/*; Clear the corresponding IPR bit. */
portRESTORE_CONTEXT/*; Restore the context of the selected task. */
This is code that will work on you CPU directly as it is from an STR750 GCC example.
I would just copy the files from the STR750 example.
Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd..
See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.