Forums

Re: nesting of interrupts

Started by bugs_u April 17, 2007
hello TomW

the actual code which i wrote is as follows:always whenever i go for its simulation i found that it get stuck up in PWM isr.

The application note i followed is AN10381 on nesting of interrupts.

main code:

#include "lpc213x.h"#include "inttypes.h"#include "Nisr_preprocessor.c"#include "Nisr_function.c"#include "Nisr_init.c"#include "Nisr_variables.c"#include "Nisr_isr.c"

int main(void){ config_pwm; config_ad04; config_ad16;/*********************************************************************************Configure Vectored Interrupt Controller for PWM**********************************************************************************/ sel_pwm_vec; addr_vec; control_vec; ena_pwm_vec;/*********************************************************************************Configure Vectored Interrupt Controller for A/D**********************************************************************************/ sel_ad0_vec; addr_ad0_vec; control_ad0_vec; def_addr_vecs; ena_ad0_vec;/*********************************************************************************Configure PWM module**********************************************************************************/ ps_03; config_pcr; config_mcr; pwm_period = 500;//10000; pwm_ONwidth = 250;//1000; config_ler; pwm_reset; pwm_enable;/*********************************************************************************Configure ADC module**********************************************************************************/ adc0_init(4); while(1) { }

}

interrupt service routine :

void pwm0_isr(void) __irq { reset_mr0int;

IENABLE;

start_adc0; switch_to_idle; while((ad0_done&&ad1_done)) { } stop_adc0; ad0_done = 0; ad1_done = 1; IDISABLE;

dummy_write; }void ad0_isr(void) __irq { i = adc0_val; IENABLE;

ad0_done = 1;

IDISABLE;

dummy_write; }void default_isr(void) __irq{ dummy_write;}

perprocessors code:

/*********************************************************************************ADC0 initializations**********************************************************************************/#define init_adc00 AD0CR = 0x00200701 #define init_adc01 AD0CR = 0x00200702#define init_adc02 AD0CR = 0x00200704#define init_adc03 AD0CR = 0x00200708#define init_adc04 AD0CR = 0x00200710#define init_adc05 AD0CR = 0x00200720#define init_adc06 AD0CR = 0x00200740#define init_adc07 AD0CR = 0x00200780

#define start_adc0 AD0CR = (AD0CR | 0x01000000) #define stop_adc0 AD0CR = (AD0CR & 0xfeffffff)

#define adc0_notdone ((AD0DR & 0x80000000) < 0x80000000)

#define adc0_val ((AD0DR & 0X0000FFC0)>>6)#define adc0_delay 40#define adc0_PDN (AD0CR = AD0CR & 0xFFDFFFFF)

/*********************************************************************************PWM Module initializations**********************************************************************************/#define pwm_reset (PWMTCR = (PWMTCR | 0x02)& 0x02)

#define pwm_enable (PWMTCR = (PWMTCR | 0x09)& 0xfd)

#define ps_03 (PWMPR = 0x00000002)

#define pwm_period PWMMR0

#define pwm_ONwidth PWMMR2

#define config_mcr (PWMMCR = (PWMMCR & 0xFFFFFE3F)|0x00000003) //2--3

#define config_pcr (PWMPCR = ((PWMPCR & 0xFFFFFFFB)|0x00000400))

#define config_ler (PWMLER = (PWMLER | 0x00000005))

#define reset_mr0int (PWMIR = PWMIR | 0x00000001)functions called :

void adc0_init(uint8_t adc_ch){ switch(adc_ch) { case 0: init_adc00;break; case 1: init_adc01;break; case 2: init_adc02;break; case 3: init_adc03;break; case 4: init_adc04;break; case 5: init_adc05;break; case 6: init_adc06;break; case 7: init_adc07;break; default:init_adc00;break; }}void adc0_start(void){ uint8_t adc_cnt = 0; start_adc0;

while((adc0_notdone) && (adc_cnt < adc0_delay)) {++adc_cnt;}}

global variables

uint8_t ad0_done = 0,ad1_done =1;uint16_t i=0,j=0;

initializations :

/*********************************************************************************POWER DOWN MODE Enabler**********************************************************************************/#define switch_to_idle (PCON = PCON | 0x01)#define switch_to_PD (PCON = PCON | 0x03)

// Macros for Interrupt Nesting#define IENABLE /* Nested Interrupts Entry */ \ __asm { MRS LR, SPSR } /* Copy SPSR_irq to LR */ \ __asm { STMFD SP!, {LR} } /* Save SPSR_irq */ \ __asm { MSR CPSR_c, #0x1F } /* Enable IRQ (Sys Mode) */ \ __asm { STMFD SP!, {LR} } /* Save LR */ \

#define IDISABLE /* Nested Interrupts Exit */ \ __asm { LDMFD SP!, {LR} } /* Restore LR */ \ __asm { MSR CPSR_c, #0x92 } /* Disable IRQ (IRQ Mode) */ \ __asm { LDMFD SP!, {LR} } /* Restore SPSR_irq to LR */ \ __asm { MSR SPSR_cxsf, LR } /* Copy LR to SPSR_irq */ \

/*********************************************************************************Vector interrupt initializations **********************************************************************************/#define sel_pwm_vec VICIntSelect = VICIntSelect & 0xfffffeff#define addr_vec VICVectAddr0 = (unsigned)pwm0_isr; #define control_vec VICVectCntl0 = 0x00000028;#define def_addr_vecs VICDefVectAddr =(unsigned)default_isr; #define ena_pwm_vec VICIntEnable = VICIntEnable | 0x00000100#define dis_pwm_vec VICIntEnClr = VICIntEnClr | 0x00000100/*********************************************************************************Vector interrupt initializations for ad0**********************************************************************************/#define sel_ad0_vec VICIntSelect = VICIntSelect & 0xfffbffff#define addr_ad0_vec VICVectAddr1 = (unsigned)ad0_isr; #define control_ad0_vec VICVectCntl1 = 0x00000032;#define ena_ad0_vec VICIntEnable = VICIntEnable | 0x00040000#define dis_ad0_vec VICIntEnClr = VICIntEnClr | 0x00040000/*********************************************************************************Vector interrupt initializations for ad1**********************************************************************************/#define sel_ad1_vec VICIntSelect = VICIntSelect & 0xffdfffff#define addr_ad1_vec VICVectAddr2 = (unsigned)ad1_isr; #define control_ad1_vec VICVectCntl2 = 0x00000035;#define ena_ad1_vec VICIntEnable = VICIntEnable | 0x00200000#define dis_ad1_vec VICIntEnClr = VICIntEnClr | 0x00200000/*********************************************************************************Default vector initializations**********************************************************************************/#define def_addr_vecs VICDefVectAddr =(unsigned)default_isr; #define dummy_write VICVectAddr = 0x00000000;/*********************************************************************************AD0 & AD1 configuration**********************************************************************************/#define config_ad04 PINSEL1 = ((PINSEL1 | 0X00040000)& 0XFFF7FFFF)#define config_ad16 PINSEL1 = ((PINSEL1 | 0X00000800)& 0XFFFFFBFF)/*********************************************************************************Purpose:configuration of PWM Created By: Vishal Shah Date:dd/mm/yyyy**********************************************************************************/#define config_pwm PINSEL0 = ((PINSEL0 & 0xffffbfff)|0x00008000)

l... wrote:

bugs_u wrote:>> TomW>> its not exactly,i alwasys clear the interrupt when i enter into the > PWM isr & then only enable the interrupt.>> kindly look at the attachment where i had given the source code.>AFAIK, Yahoo does not allow the use of attachments. At least, I do not see one.TomW-- Tom Walsh - WN3L - Embedded Systems Consultanthttp://openhardware.net http://cyberiansoftware.com http://openzipit.org"Windows? No thanks, I have work to do..."----------------

An Engineer's Guide to the LPC2100 Series