Interrupção (IRQ) no LPC2103.

Software e Hardware para linha ARM

Moderadores: 51, guest2003, Renie, gpenga

Interrupção (IRQ) no LPC2103.

Mensagempor gkassick » 07 Mar 2007 17:10

Senhores, alguem me ajude, estou mais perdido que custo em tiroteio...
Consegui colocar o timer do 2103 para funcionar beleza, porem quando fui usar a interrupção começou a dar pau...
Procurando material encontrei um exemplo neste forum e com isto montei o seguinte condigo adiante:

#include "includes.h"

__irq __arm void IRQ_Handler (void);
void NonVectISR(void);
void InitVectors(void);
void TIMER_IRQ(void);

unsigned char ciclo=0;

int main()
{
//Configura PLL
PLLCFG= 0x00000023; //Como Clock= M * cristal, neste caso cristal= 14.7456MHZ
//O maximo M possivel é 4, que dará um clock de 58.9824MHZ
//Pois o maximo clock do 2103 é 70MHZ, desta forma
//M=4 e P= 2, no PLLCFG vai o MSEL e PSEL, sendo MSEL=M-1
//e PSEL= P-1, MSEL[4:0] e PSEL[5:6]
PLLCON= 0x00000001; //Habilita a PLL

PLLFEED= 0x000000AA; //Atualiza os registradores
PLLFEED= 0x00000055;

while(!(PLLSTAT&0x00000400)); //Testa o BitLock da PLL

PLLCON= 0x00000003; //Conecta a PLL

PLLFEED= 0x000000AA; //Atualiza os registradores
PLLFEED= 0x00000055;

APBDIV= 0x00000002; //Configura o divisor APB para 14.7456MHZ
//Clock/4

//Configura os pinos de porta
PINSEL0= 0x00000000;
PINSEL1= 0x00003000;

IODIR = 0x0000FFFF;
IOSET = 0x0000FFFF;

//Rotina do Timer...
//Reseta e mantem desabilitado do Timer
T0TCR= 0x00000002; //Bit 0= Habilitação, Bit 1= Reset
//Configura o timer para pulsos internos
T0CTCR= 0x00000000; //Bits 0 e 1 00= pulsos internos
//Configura o valor do preescaler do contador
T0PR= 0x00001000;
//Configura o valor de comparação do canal 0
T0MR0= 0x00000FFF;
//Programa o modo de comparação do contador
T0MCR= 0x00000003; //Bit 0= Habilita a interrupção do canal 0, Bit 1= Habilita o reset quando ocorre uma iguldade
//Mantem desabilitado os modos captura
T0CCR= 0x00000000;
//Configura o pino de saida do canal 0
T0EMR= 0x00000031;
//Habilita o timer para contagem..
T0TCR= 0x00000001;

//Inicia os vetores de interreupção
InitVectors();

VICIntSelect= 0;
VICVectAddr0 = (unsigned)&TIMER_IRQ;
VICVectCntl0 = 0x24;
VICIntEnable= 0x10;

while(1);
}

void InitVectors()
{
VICIntSelect = 0;
VICIntEnClear = 0xFFFFFFFF;
VICSoftIntClear = 0xFFFFFFFF;
VICProtection = 0;
VICDefVectAddr = 0;
VICVectAddr = 0;

VICVectAddr0 = 0;
VICVectAddr1 = 0;
VICVectAddr2 = 0;
VICVectAddr3 = 0;
VICVectAddr4 = 0;
VICVectAddr5 = 0;
VICVectAddr6 = 0;
VICVectAddr7 = 0;
VICVectAddr8 = 0;
VICVectAddr9 = 0;
VICVectAddr10 = 0;
VICVectAddr11 = 0;
VICVectAddr12 = 0;
VICVectAddr13 = 0;
VICVectAddr14 = 0;
VICVectAddr15 = 0;

VICVectCntl0 = 0;
VICVectCntl1 = 0;
VICVectCntl2 = 0;
VICVectCntl3 = 0;
VICVectCntl4 = 0;
VICVectCntl5 = 0;
VICVectCntl6 = 0;
VICVectCntl7 = 0;
VICVectCntl8 = 0;
VICVectCntl9 = 0;
VICVectCntl10 = 0;
VICVectCntl11 = 0;
VICVectCntl12 = 0;
VICVectCntl13 = 0;
VICVectCntl14 = 0;
VICVectCntl15 = 0;
}

void NonVectISR(void)
{
while(TRUE); // Se chegar aqui seu programa está com super paus!
}

__irq __arm void IRQ_Handler (void)
{
void (*interrupt_function)();
unsigned int vector;
vector = VICVectAddr; // Get interrupt vector.

interrupt_function = (void(*)())vector; // Call MM_TIMER0_ISR thru pointer
(*interrupt_function)(); // Call vectored interrupt function
VICVectAddr = 0; // Clear interrupt in VIC
}

void TIMER_IRQ(void)
{
T0IR|= 0x00000001;

if(ciclo)
{
IOCLR= 0x000000FF;
ciclo--;
}
else
{
IOSET= 0x000000FF;
ciclo++;
}
VICVectAddr = 0;
}

O problema é que quando mando compilar ele acusa o seguinte erro:
Error[Pa046]: function type has no prototype
Este erro esta na linha: (*interrupt_function)();

O CSTARTUP.S79 creio que esteja ok...

Alguem imagina o porque disso?

Gabriel
gkassick
Bit
 
Mensagens: 5
Registrado em: 06 Mar 2007 17:09

Mensagempor Viktor » 08 Mar 2007 14:25

1.-Dar "pau" é tão vago quanto os discursos do Presidente
2.-"CSTARTUP.S79 creio que esteja ok" Mostre este arquivo para poder poder ter certeza.
Viktor
Byte
 
Mensagens: 281
Registrado em: 12 Out 2006 11:33

Mensagempor gkassick » 08 Mar 2007 14:39

Viktor,
Obrigado pela atenção...
Quanto a dar pau, eu quiz dizer que nõ conseguia colocar para funcionar a interrupção, pois na compilação aparece o erro que coloquei descrito anteriormente, segue novmente:
Error[Pa046]: function type has no prototype
Este erro esta na linha: (*interrupt_function)();

Quanto ao CSTARTUP.s79 segue conteudo abaixo:

;-----------------------------------------------------------------------------
; This file contains the startup code used by the ICCARM C compiler.
;
; The modules in this file are included in the libraries, and may be replaced
; by any user-defined modules that define the PUBLIC symbol _program_start or
; a user defined start symbol.
; To override the cstartup defined in the library, simply add your modified
; version to the workbench project.
;
; All code in the modules (except ?RESET) will be placed in the ICODE segment.
;
; $Revision: 1.2 $
;
;-----------------------------------------------------------------------------

;
; Naming covention of labels in this file:
;
; ?xxx - External labels only accessed from assembler.
; __xxx - External labels accessed from or defined in C.
; xxx - Labels local to one module (note: this file contains
; several modules).
; main - The starting point of the user program.
;

;---------------------------------------------------------------
; Macros and definitions for the whole file
;---------------------------------------------------------------

; Mode, correspords to bits 0-5 in CPSR
MODE_BITS 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


;---------------------------------------------------------------
; ?RESET
; Reset Vector.
; Normally, segment INTVEC is linked at address 0.
; For debugging purposes, INTVEC may be placed at other
; addresses.
; A debugger that honors the entry point will start the
; program in a normal way even if INTVEC is not at address 0.
;---------------------------------------------------------------

MODULE ?RESET
COMMON INTVEC:CODE:NOROOT(2)
PUBLIC __program_start
EXTERN ?cstartup
; EXTERN undef_handler, swi_handler, prefetch_handler
; EXTERN data_handler, fiq_handler
EXTERN IRQ_Handler
EXTERN FIQ_Handler
CODE32 ; Always ARM mode after reset
org 0x00
__program_start
ldr pc,=?cstartup ; Absolute jump can reach 4 GByte
; ldr b,?cstartup ; Relative branch allows remap, limited to 32 MByte
org 0x04
undef_handler ldr pc,=undef_handler
org 0x08
swi_handler ldr pc,=swi_handler
org 0x0c
prefetch_handler ldr pc,=prefetch_handler
org 0x10
data_handler ldr pc,=data_handler
org 0x18
ldr pc,=IRQ_Handler
org 0x1c
fiq_handler ldr pc,=FIQ_Handler

; Constant table entries (for ldr pc) will be placed at 0x20
org 0x20
LTORG
; ENDMOD __program_start
ENDMOD


;---------------------------------------------------------------
; ?CSTARTUP
;---------------------------------------------------------------
MODULE ?CSTARTUP

RSEG IRQ_STACK:DATA(2)
RSEG SVC_STACK:DATA:NOROOT(2)
RSEG CSTACK:DATA(2)
RSEG ICODE:CODE:NOROOT(2)
PUBLIC ?cstartup
EXTERN ?main

; Execution starts here.
; After a reset, the mode is ARM, Supervisor, interrupts disabled.


CODE32
?cstartup

; Add initialization nedded 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.
mrs r0,cpsr ; Original PSR value
bic r0,r0,#MODE_BITS ; 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) & 0xFFFFFFF8 ; End of IRQ_STACK

bic r0,r0,#MODE_BITS ; Clear the mode bits
orr r0,r0,#SYS_MODE ; Set System mode bits
msr cpsr_c,r0 ; Change the mode
ldr sp,=SFE(CSTACK) & 0xFFFFFFF8 ; End of CSTACK

#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 more IAR specific system startup

ldr r0,=?main
bx r0

LTORG

ENDMOD


END




Agradeço muito a ajuda...
gkassick
Bit
 
Mensagens: 5
Registrado em: 06 Mar 2007 17:09

Mensagempor Viktor » 09 Mar 2007 09:22

Aparentemente está correto
Viktor
Byte
 
Mensagens: 281
Registrado em: 12 Out 2006 11:33


Voltar para ARM

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

x