IAR debug behavior LPC 2148

Started by Sumit Bhatnagar November 17, 2008
I am unable to understand the behavior of IAR in debug. I am using the
IAR Embedded Workbench Kickstart for ARM 5.20 with HJTAG.

This code is adapted from the ADC example from the IAR examples for
LPC2148. If you would like to see the actual code let me know.

In the code below the program does not reach the installTimer function
and keeps going back to the ISR tmrIntPtr. I am baffeled.

if(softTimer[1].us_Event == TIMER_EXPIRED){
installTimer(ptr2Timer,1,TICKS_PER_50_mSEC,FIFTY__mSEC_TIMER_INSTALLED);

Code is appended below

//-----------------------------//
//-----------------------------//
//-----------------------------//
//-----------------------------//
#include "main.h"
#include

int main()
{
//char str[100];
//double ADCresmV;
int ADCresult;
SoftwareTimer_t *ptr2Timer = &softTimer[0];
initializeInterruptDataStructs();
installTimer(ptr2Timer,1,TICKS_PER_50_mSEC,FIFTY__mSEC_TIMER_INSTALLED);
initializeMCU();

AD0CR_bit.START = 0x0001; //start 1st cnvrsn
immediately
ADCresult;

while(1==1){
if(softTimer[1].us_Event == TIMER_EXPIRED){

installTimer(ptr2Timer,1,TICKS_PER_50_mSEC,FIFTY__mSEC_TIMER_INSTALLED);
/* Fetch the last A/D conversion and start up the A/D for the
next one */
while(AD0DR_bit.DONE == 0); //wait until
conversion done
AD0DR_bit.CHN = 0; // Data in channel 0
ADCresult = AD0DR_bit.VVDDA ; // save the converted
data
// ADCresmV = (ADCresult)*3000/1024; // 10 bit resolution,
3V max

sendByte(0x65);
printf("ssa %d",40);
AD0CR_bit.START = 0x0001; // start the next
conversion
}

} // end foreground loop
}
/*************************************************************************
* Function Name: irq_handler
* Parameters: void
* Return: void
*
* Description: IRQ subroutine
* Note: This is ARM mode code - full 32 bit code
*************************************************************************/
__irq __arm void irq_handler (void)
{
void (*interrupt_function)();
unsigned int vector;

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

void initializeMCU(void){
/* Init MCU Clock */
/* Fosc = 12MHz, Fpckl = 12MHz */
PLLCON_bit.PLLC = PLLCON_bit.PLLE = 0; // Disable and disconnect PLL
PLLCFG=0x00000024;
PLLCON=0x00000001;
feed(); // PLL feed sequence
while(!(PLLSTAT & 0x00000400));
PLLCON=0x00000003;
feed();
/* Init Peripherial divider Pckl = Clk/2 */
VPBDIV = 0x00000002;

T0IR=0xFF; // reset match and capture event interrupts
T0TC=0; // Clear timer counter
T0PR= 0; // No Prescalar
T0MR0=PCLKFREQ/100; // Count up to 30000 for 100Hz interrupt,
period = 10ms
T0MCR = 3; // Reset Timer Counter & Interrupt on match
T0TCR = 1; // Counting enable

// initialize the ADC unit with P30 as ADC input channel
initADC();

//initialize the UART1 with 9600 8 0 1
initUART();

// SCS = 0x03; // select the "fast" version of the I/O ports
// FIO1DIR |= 0x01000000; // pin P1.24 is an output, everything else
is input after reset
VICIntSelect = 0; // Set all VIC interrupts to IRQ for now
VICIntEnClear = 0xFFFFFFFF; // Diasable all interrupts
VICSoftIntClear = 0xFFFFFFFF; // Clear all software interrutps
VICProtection = 0; // VIC registers can be accessed in
User or

VICVectAddr = 0; // Clear interrupt
VICDefVectAddr = (unsigned int)&NonVectISR; // Install default ISR addr

/* Setup the Timer0 interrupt on match interrupt */
VICIntSelect &= ~(1< VICVectAddr0 = (unsigned int)&tmrIntPtr; // Install ISR in VIC
addr slot
VICVectCntl0 = 0x20 | VIC_TIMER0; // IRQ type, TIMER 0
int enabled
VICIntEnable |= (1<
__enable_interrupt(); // Global interrupt enable

}
void installTimer
(
SoftwareTimer_t *ptr2Timer,
unsigned int us_offset,
unsigned int us_ticks,
unsigned int us_event
)
{
(ptr2Timer+us_offset)->us_Ticks = us_ticks;
(ptr2Timer+us_offset)->us_Event = us_event;
// (ptr2Timer+us_offset)->us_Event = us_event;
}

void initializeInterruptDataStructs(void)
{
unsigned int i=0;
for(i=0;i {
softTimer[i].us_Ticks = 0;
softTimer[i].us_Event = EVENT_UNDEFINED;
}
}

void tmrIntPtr()
{
unsigned int IntType;
unsigned int p=1;
// for(p=0; p if(softTimer[p].us_Ticks > 1){ // if timer installed
decrement
softTimer[p].us_Ticks--;
}else{
softTimer[p].us_Event = TIMER_EXPIRED; // us_Ticks == 1; timer
expired
}
// }
IntType = (T0IR & 0xFF); // confirm interrupt type
T0IR = (IntType & 0xFF); // Clear timer interrupt
}

/* More init code removed */

An Engineer's Guide to the LPC2100 Series