Interrupt Eclipse
2005-08-09 by flying_wookie1
Hello all,
I am trying to build one of the examples from the hitex book (keil has
the code examples) on the eclipse development environment. When I
compile with the keil IDE, the nested interrupt example and download
it, the code runs correctly.... When I modify Lynchzillas tutorial
code to use the timer interrupt and flash an LED, just as in the keil
examples, nothing happens.. I have included the code for my example..
Could anyone spot what is incorrect with the eclipse code? Am I
setting up the linker correctly?
Any help appreciated.
PS sorry about the copy and paste, yahoo groups does not allow file
attachments. :(
=====================================================================
=====================================================================
=====================================================================
=====================================================================
/* *********************************************************
Function declarations
********************************************************* */
/**********************************************************
Header files
**********************************************************/
#include "LPC213x.h"
#include "serial.h"
/**********************************************************
Global Variables
**********************************************************/
volatile int timeval = 0;
volatile int SecondCnt = 0;
void Initialize(void);
void init_timer (void);
void feed(void);
void IRQ_Routine (void) __attribute__ ((interrupt("IRQ")));
void FIQ_Routine (void) __attribute__ ((interrupt("FIQ")));
void SWI_Routine (void) __attribute__ ((interrupt("SWI")));
void UNDEF_Routine (void) __attribute__ ((interrupt("UNDEF")));
void tc0 (void) __attribute__ ((interrupt("IRQ")));
/**********************************************************
MAIN
**********************************************************/
int main (void)
{
// Initialize the system
Initialize();
IODIR1 = 0x00FF0000;
//IOSET1 = 0x00010000;
//IOCLR1 = 0x00FF0000;
while (1)
{
if ((SecondCnt & 1) == 0)
{
IOCLR1 = 0x00FF0000;
}
else
{
IOSET1 = 0x00FF0000;
}
}
}
/**********************************************************
Initialize
**********************************************************/
// Setup the Timer Counter 0 Interrupt
void init_timer (void)
{
T0MR0 = 1499; // 0.1mSec = 1.500-1 counts
T0MCR = 3; // Interrupt and Reset
on MR0
T0TCR = 1; // Timer0 Enable
VICVectAddr0 = (unsigned long)tc0; // set interrupt vector in 0
VICVectCntl0 = 0x20 | 4; // use it for Timer 0
Interrupt
VICIntEnable = 0x00000010; // Enable Timer0 Interrupt
}
#define PLOCK 0x400
void Initialize(void)
{
// Setting the Phased Lock Loop (PLL)
// ----------------------------------
//
//
*******************************************************************************************
// Keil MCB2130 has a 12.0000 mhz crystal
//
// We'd like the MCB2130 to run at 60.0000 mhz (has to be an even
multiple of crystal)
//
// According to the Philips LPC2138 manual: M = cclk / Fosc where:
M = PLL multiplier (bits 0-4 of PLLCFG)
// cclk = 60000000 hz
// Fosc = 12000000 hz
//
// Solving: M = 60000000 / 12000000 = 5
// M = 5
//
// Note: M - 1 must be entered into bits 0-4 of PLLCFG (assign 4 to
these bits)
//
//
// The Current Controlled Oscilator (CCO) must operate in the range
156 mhz to 320 mhz
//
// According to the Philips LPC2138 manual: Fcco = cclk * 2 * P
where: Fcco = CCO frequency
// cclk = 53236800 hz
// P = PLL divisor (bits 5-6 of PLLCFG)
//
// Solving: Fcco = 60000000 * 2 * P
// P = 2 (trial value)
// Fcco = 60000000 * 2 * 2
// Fcc0 = 240000000 hz (good choice for P since it's within the
156 mhz to 320 mhz range
//
// From Table 20 (page 32) of Philips LPC2138 manual P = 2, PLLCFG
bits 5-6 = 1 (assign 1 to these bits)
//
// Finally: PLLCFG = 0 01 00100 = 0x24
//
// Final note: to load PLLCFG register, we must use the 0xAA followed
0x55 write sequence to the PLLFEED register
// this is done in the short function feed() below
// Setting Multiplier and Divider values
PLLCFG = 0x24;
feed();
// Enabling the PLL */
PLLCON = 0x1;
feed();
// Wait for the PLL to lock to set frequency
while(!(PLLSTAT & PLOCK)) ;
// Connect the PLL as the clock source
PLLCON=0x3;
feed();
// Enabling MAM and setting number of clocks used for Flash memory
fetch (4 cclks in this case)
MAMCR = 0x2;
MAMTIM = 0x4;
/* Initialize MEMAP - re-map vector table to RAM */
MEMMAP = 0x02;
// Setting peripheral Clock (pclk) to System Clock (cclk)
VPBDIV=0x1;
//VPBDIV=0x0; //MCB2100 serial port demo works with this setting
//init_serial();
init_timer();
}
void feed(void)
{
PLLFEED=0xAA;
PLLFEED=0x55;
}
/* Stubs for various interrupts (may be replaced later) */
/* ---------------------------------------------------- */
/* Timer Counter 0 Interrupt executes each 10ms @ 60 MHz CPU Clock */
void tc0 (void)
{
++timeval;
if ((timeval % 10000) == 0)
{
timeval = 0;
SecondCnt++;
}
T0IR = 1; // Clear interrupt flag
VICVectAddr = 0; // Acknowledge Interrupt
}
void IRQ_Routine (void)
{
while (1) ;
}
void FIQ_Routine (void)
{
while (1) ;
}
void SWI_Routine (void)
{
while (1) ;
}
void UNDEF_Routine (void)
{
while (1) ;
}
=====================================================================
=====================================================================
=====================================================================
=====================================================================
/*
***************************************************************************************************************
crt.s STARTUP ASSEMBLY CODE
-----------------------
Module includes the interrupt vectors and start-up code.
***************************************************************************************************************
*/
/* Stack Sizes */
.set UND_STACK_SIZE, 0x00000004 /* stack for "undefined instruction"
interrupts is 4 bytes */
.set ABT_STACK_SIZE, 0x00000004 /* stack for "abort" interrupts is 4
bytes */
.set FIQ_STACK_SIZE, 0x00000004 /* stack for "FIQ" interrupts is 4
bytes */
.set IRQ_STACK_SIZE, 0x00000080 /* stack for "IRQ" normal interrupts
is 4 bytes */
.set SVC_STACK_SIZE, 0x00000004 /* stack for "SVC" supervisor mode
is 4 bytes */
/* Standard definitions of Mode bits and Interrupt (I & F) flags in
PSRs (program status registers) */
.set MODE_USR, 0x10 /* Normal User Mode */
.set MODE_FIQ, 0x11 /* FIQ Processing Fast
Interrupts Mode */
.set MODE_IRQ, 0x12 /* IRQ Processing Standard
Interrupts Mode */
.set MODE_SVC, 0x13 /* Supervisor Processing Software
Interrupts Mode */
.set MODE_ABT, 0x17 /* Abort Processing memory
Faults Mode */
.set MODE_UND, 0x1B /* Undefined Processing Undefined
Instructions Mode */
.set MODE_SYS, 0x1F /* System Running Priviledged
Operating System Tasks Mode */
.set I_BIT, 0x80 /* when I bit is set, IRQ is
disabled (program status registers) */
.set F_BIT, 0x40 /* when F bit is set, FIQ is
disabled (program status registers) */
.text
.arm
.global Reset_Handler
.global _startup
.func _startup
_startup:
# Exception Vectors
_vectors: ldr PC, Reset_Addr
ldr PC, Undef_Addr
ldr PC, SWI_Addr
ldr PC, PAbt_Addr
ldr PC, DAbt_Addr
nop /* Reserved Vector (holds Philips ISP
checksum) */
ldr PC, [PC,#-0xFF0] /* see page 71 of "Insiders
Guide to the Philips ARM7-Based Microcontrollers" by Trevor Martin */
ldr PC, FIQ_Addr
Reset_Addr: .word Reset_Handler /* defined in this module below */
Undef_Addr: .word UNDEF_Routine /* defined in main.c */
SWI_Addr: .word SWI_Routine /* defined in main.c */
PAbt_Addr: .word UNDEF_Routine /* defined in main.c */
DAbt_Addr: .word UNDEF_Routine /* defined in main.c */
IRQ_Addr: .word IRQ_Routine /* defined in main.c */
FIQ_Addr: .word FIQ_Routine /* defined in main.c */
.word 0 /* rounds the vectors and ISR addresses
to 64 bytes total */
# Reset Handler
Reset_Handler:
/* Setup a stack for each mode - note that this only sets up a
usable stack
for User mode. Also each mode is setup with interrupts initially
disabled. */
ldr r0, =_stack_end
msr CPSR_c, #MODE_UND|I_BIT|F_BIT /* Undefined Instruction
Mode */
mov sp, r0
sub r0, r0, #UND_STACK_SIZE
msr CPSR_c, #MODE_ABT|I_BIT|F_BIT /* Abort Mode */
mov sp, r0
sub r0, r0, #ABT_STACK_SIZE
msr CPSR_c, #MODE_FIQ|I_BIT|F_BIT /* FIQ Mode */
mov sp, r0
sub r0, r0, #FIQ_STACK_SIZE
msr CPSR_c, #MODE_IRQ|I_BIT|F_BIT /* IRQ Mode */
mov sp, r0
sub r0, r0, #IRQ_STACK_SIZE
msr CPSR_c, #MODE_SVC|I_BIT|F_BIT /* Supervisor Mode */
mov sp, r0
sub r0, r0, #SVC_STACK_SIZE
msr CPSR_c, #MODE_SYS|I_BIT|F_BIT /* User Mode */
mov sp, r0
/* copy .data section (Copy from ROM to RAM) */
ldr R1, =_etext
ldr R2, =_data
ldr R3, =_edata
1: cmp R2, R3
ldrlo R0, [R1], #4
strlo R0, [R2], #4
blo 1b
/* Clear .bss section (Zero init) */
mov R0, #0
ldr R1, =_bss_start
ldr R2, =_bss_end
2: cmp R1, R2
strlo R0, [R1], #4
blo 2b
/* Enter the C code */
b main
.endfunc
.end