Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to move interrupt vector from 0x0 to some offset
PostPosted: Fri Jan 08, 2010 1:47 pm 
Offline

Joined: Fri Jan 08, 2010 12:00 am
Posts: 10
Hello all,

I am newbie to Arm and IAR. I have develope an application using IAR5.30 and
AT91SAM7S128 which has interuupt vector starting from 0x0 and rom starting from
0x5000 and when i load this application using jflash utitlity it is working
fine.

On the same configuration(address) i have devloped a bootloader application.
Now i want to download first application using this bootloader application. As
the both bootloader application and the first application has the same interrupt
vector address 0x0 so when i download it donot work.

Do i need to move the interrupt vector to some where else, ?

When i moved the interrupt vector of my application to 0x5000 , i.e. just in
the start of the application, the interrupt are not working.

Kindly send your valuable advise and observation to help solving my problem.

Your kind guidence will be highly appricated.

Regards
Dani


Top
 Profile  
 
 Post subject: Re: How to move interrupt vector from 0x0 to some offset
PostPosted: Sat Jan 09, 2010 3:32 am 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
Hi Dani

You shouldn't have to (be able to) move the location of the interrupt vectors to work with a boot loader. As long as the boot loader includes the typical interrupt handler (IAR delivers something like

Code:
irqHandler:
        /* Save interrupt context on the stack to allow nesting */
        SUB     lr, lr, #4
        STMFD   sp!, {lr}
        MRS     lr, SPSR
        STMFD   sp!, {r0, lr}

        /* Write in the IVR to support Protect Mode */
        LDR     lr, =AT91C_BASE_AIC
        LDR     r0, [r14, #AIC_IVR]
        STR     lr, [r14, #AIC_IVR]

        /* Branch to interrupt handler in Supervisor mode */
        MSR     CPSR_c, #ARM_MODE_SVC | I_BIT
        STMFD   sp!, {r1-r3, r12, lr}
        MOV     lr, pc
        BX      r0
        LDMIA   sp!, {r1-r3, r12, lr}
        MSR     CPSR_c, #ARM_MODE_IRQ | I_BIT

        /* Acknowledge interrupt */
        LDR     lr, =AT91C_BASE_AIC
        STR     lr, [r14, #AIC_EOICR]

        /* Restore interrupt context and branch back to calling code */
        LDMIA   sp!, {r0, lr}
        MSR     SPSR_cxsf, lr
        LDMIA   sp!, {pc}^
        END

)

The locations of the individual interrupt handlers are entered into the Advanced Interrupt Controller by the application and so are automatically dispatched by the boot code.

Regards

Mark

www.uTasker.com


Top
 Profile  
 
 Post subject: Re: How to move interrupt vector from 0x0 to some offset
PostPosted: Mon Jan 11, 2010 2:46 pm 
Offline

Joined: Fri Jan 08, 2010 12:00 am
Posts: 10
Thanks for reply,

You mean i dont need to change the interrupt vector address. right ?

My bootloader application is starting from 0x0 and interrupt vector at the start.

I want my application to start from 0x5000. Which independently works fine when its interrupt vectors are started from 0x0 but donot work at 0x5000.

So i have two application with two interrupt vector tables.

What are your thoughts on it. what i am doing wrong ???


Top
 Profile  
 
 Post subject: Re: How to move interrupt vector from 0x0 to some offset
PostPosted: Mon Jan 11, 2010 3:10 pm 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
Hi

1) Make sure that your boot code has the interrupt vector and also the interrupt dispatcher (eg. as shown in previous post).

2) Make sure that the second application then enters its own interrupts into the interrupt controller.

Typically this is done like this:
Code:
    unsigned long *ptrInt = ADD_AIC_SVR0;                                               // set up the default interrupts handler vectors
    *ptrInt++ = (unsigned long)AT91F_Default_FIQ_handler;                // enter fast interrupt
    for (i = 0; i < 31; i++) {
        *ptrInt++ = (unsigned long)AT91F_Default_IRQ_handler;            // set default handler to all locations
    }
    AIC_SPU = (unsigned long)AT91F_Spurious_handler;                     // enter spurious interrupt handler


This is setting the default handler for all interrupts. When the application opens a particular peripheral driver it will then enter the specific interrupt to be used.

Regards

Mark

www.uTasker.com


Top
 Profile  
 
 Post subject: Re: How to move interrupt vector from 0x0 to some offset
PostPosted: Mon Jan 11, 2010 4:36 pm 
Offline

Joined: Fri Jan 08, 2010 12:00 am
Posts: 10
Here is the startup file for bootloader and the application. It is same for both. Is it ok to have identical startup files for both bootloader and applicatiion. ??

MODULE ?cstartup

SECTION IRQ_STACK:DATA:NOROOT(3)
SECTION FIQ_STACK:DATA:NOROOT(3)
SECTION UND_STACK:DATA:NOROOT(3)
SECTION ABT_STACK:DATA:NOROOT(3)
SECTION SVC_STACK:DATA:NOROOT(3)
SECTION CSTACK:DATA:NOROOT(3)

SECTION .intvec:CODE:NOROOT(2)

PUBLIC __vector
PUBLIC __vector_0x14
PUBLIC __iar_program_start
EXTERN Undef_Wrapper
EXTERN SWI_Wrapper
EXTERN Prefetch_Wrapper
EXTERN Abort_Wrapper
EXTERN IRQ_Wrapper
EXTERN FIQ_Wrapper

ARM

;;==============================================================================
;; EXECPTION HANDLERS
; All default exception handlers (except reset) are
; defined as weak symbol definitions.
; If a handler is defined by the application it will take precedence.
;;==============================================================================

__vector:

LDR PC,Reset_Addr ; Reset
LDR PC,Undefined_Addr ; Undefined instructions
LDR PC,SWI_Addr ; Software interrupt (SWI/SVC)
LDR PC,Prefetch_Addr ; Prefetch abort
LDR PC,Abort_Addr ; Data abort
__vector_0x14:
DCD 0 ; RESERVED
LDR PC,IRQ_Addr ; IRQ
LDR PC,FIQ_Addr ; FIQ

Reset_Addr: DCD __iar_program_start
Undefined_Addr: DCD Undef_Wrapper
SWI_Addr: DCD SWI_Wrapper
Prefetch_Addr: DCD Prefetch_Wrapper
Abort_Addr: DCD Abort_Wrapper
IRQ_Addr: DCD IRQ_Wrapper
FIQ_Addr: DCD FIQ_Wrapper

;;==============================================================================
;; LOW LEVEL SYSTEM INITIALIZATION
; After a reset execution starts here, the mode is ARM, supervisor
; with interrupts disabled.
;;==============================================================================


SECTION .text:CODE:NOROOT(2)
EXTERN ?main
REQUIRE __vector
EXTERN AT91LowLevelInit
EXTERN at91_spurious_handler

ARM

__iar_program_start:
?cstartup:

; Minumum C initialization

ldr r13,=SFE(SVC_STACK)
; Call Low level init function
ldr r0,=AT91LowLevelInit
mov lr, pc
bx r0

;
; Add initialization needed before setup of stackpointers here.
;

;
; Initialize the stack pointers.
; The pattern below can be used for any of the exception stacks:
; FIQ, IRQ, SVC, ABT, UND, SYS.
; The USR mode uses the same stack as SYS.
; The stack segments must be defined in the linker command file,
; and be declared above.
;


; --------------------
; Mode, corresponds to bits 0-5 in CPSR

MODE_MSK DEFINE 0x1F ; Bit mask for mode bits in CPSR

USR_MODE DEFINE 0x10 ; User mode
FIQ_MODE DEFINE 0x11 ; Fast Interrupt Request mode
IRQ_MODE DEFINE 0x12 ; Interrupt Request mode
SVC_MODE DEFINE 0x13 ; Supervisor mode
ABT_MODE DEFINE 0x17 ; Abort mode
UND_MODE DEFINE 0x1B ; Undefined Instruction mode
SYS_MODE DEFINE 0x1F ; System mode


MRS r0, cpsr ; Original PSR value
;;==============================================================================
;; STACK POINTERS SETUP
;;==============================================================================

;; Setup the interrupt stack pointer.

BIC r0, r0, #MODE_MSK ; Clear the mode bits
ORR r0, r0, #IRQ_MODE ; Set IRQ mode bits
MSR cpsr_c, r0 ; Change the mode
LDR sp, =SFE(IRQ_STACK) ; End of IRQ_STACK

;; Set up the fast interrupt stack pointer.

BIC r0, r0, #MODE_MSK ; Clear the mode bits
ORR r0, r0, #FIQ_MODE ; Set FIR mode bits
MSR cpsr_c, r0 ; Change the mode
LDR sp, =SFE(FIQ_STACK) ; End of FIQ_STACK

bic r0,r0,#MODE_MSK ; Clear the mode bits
orr r0,r0,#UND_MODE ; Set UND mode bits
msr cpsr_c,r0 ; Change the mode
ldr sp,=SFE(UND_STACK) ; End of UND_STACK

bic r0,r0,#MODE_MSK ; Clear the mode bits
orr r0,r0,#ABT_MODE ; Set ABT mode bits
msr cpsr_c,r0 ; Change the mode
ldr sp,=SFE(ABT_STACK) ; End of ABT_STACK

bic r0,r0,#MODE_MSK ; Clear the mode bits
orr r0,r0,#SYS_MODE ; Set SYS mode bits
msr cpsr_c,r0 ; Change the mode
ldr sp,=SFE(CSTACK) ; End of CSTACK

;; Set up the normal stack pointer.

BIC r0 ,r0, #MODE_MSK ; Clear the mode bits
ORR r0 ,r0, #SVC_MODE ; Set SVC mode bits
MSR cpsr_c, r0 ; Change the mode
LDR sp, =SFE(SVC_STACK) ; End of SVC_STACK
; setup spurious interrupt handler
ldr r0,=at91_spurious_handler
ldr r1,=AT91C_BASE_AIC
str r0,[r1, #AIC_SPU]

#ifdef __ARMVFP__
;; Enable the VFP coprocessor.

MOV r0, #0x40000000 ; Set EN bit in VFP
FMXR fpexc, r0 ; FPEXC, clear others.

;
; Disable underflow exceptions by setting flush to zero mode.
; For full IEEE 754 underflow compliance this code should be removed
; and the appropriate exception handler installed.
;

MOV r0, #0x01000000 ; Set FZ bit in VFP
FMXR fpscr, r0 ; FPSCR, clear others.
#endif

;
; Add more initialization here
;

; Continue to ?main for C-level initialization.

B ?main

END


Top
 Profile  
 
 Post subject: Re: How to move interrupt vector from 0x0 to some offset
PostPosted: Mon Jan 11, 2010 5:09 pm 
Offline

Joined: Thu Mar 02, 2006 1:32 pm
Posts: 127
Location: Switzerland
Hi

It is OK to use the same start-up code.
The boot loader should jump to the reset vector address and then the application will start as normal.

The application interrupt vectors will never be used (the boot ones will) so they could be removed from the application start-up code, but this is a detail and not necessary.

Regards

Mark


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: