Sie sind auf Seite 1von 8

INTERRUPT PERFORMANCE CHARACTERISTICS OF ARM AND FPGA

PROGRAM:

#include <LPC214x.H>
#define CR 0x0D
#define PLOCK 0x400
/* Function Prototypes */
unsigned int count=0,count1,Flag = 0;
unsigned char
CSLSB0,CSLSB1,CSLSB2,CSLSB3,CSLSB4,CSLSB5,CSLSB6,CSLSB7,CSLSB8;
//#include <stdio.h>
long int volatile EINT1 = 0;
long int volatile EINT2 = 0;
void ExtInt_Serve1(void)__irq;
void ExtInt_Serve2(void)__irq;
#define PRESCALE 60000
void PLLInit(void)
{
unsigned long loop_ctr;
PLL1CFG = 0x00000024;
PLL1CON = 0x01;
PLL1FEED = 0xAA;
PLL1FEED = 0x55;
loop_ctr = 10000;
while (((PLL1STAT<<10) == 0) && (loop_ctr > 0))
{
loop_ctr--;
}
PLL1CON = 0x02;
PLL1FEED = 0xA0;
PLL1FEED = 0x55;
VPBDIV = 0x01;
}

void DefISR (void) __irq


{
;
}
__irq void ExtInt_Serve1(void)
{
++EINT1;
EXTINT |= 2;
VICVectAddr = 1;
}
void ExtInt_Init1(void)
{
EXTMODE |= 2;
EXTPOLAR = 0;
PINSEL0 |= 0x200000C0;
VICVectCntl0 = 0x20 | 15;
VICVectAddr0 = (unsigned long) ExtInt_Serve1;
VICIntEnable |= 1<<15;
}
void DelayMs(unsigned int count)
{
unsigned int i,j;

for(i=0;i<count;i++)
{
for(j=0;j<1000;j++);
}
}
static void feed(void)
{
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
}
void PLL_Init()
{
PLL0CFG = 0x24;
feed();
PLL0CON = 0x01;
feed();
while(!(PLL0STAT & PLOCK));
PLL0CON = 0x3;
feed();
MAMTIM = 0x04;
MAMCR = 0x02;
VPBDIV = 0x01;
}
void UART0_Init()
{
PINSEL0 |= 0x05;
U0LCR = 0x83;
U0DLL = 0x86;
U0DLM = 0x01;
U0LCR = 0x03;
VPBDIV = 0x01;
}
/*Get_Char*/
unsigned char Get_Char(void)
{
while (!(U0LSR&0x01));
return U0RBR;
}
/*Send_Char*/
unsigned char Send_Char(unsigned char ch)
{
if (ch == '\n')
{
while(!(U0LSR & 0x20));
U0THR = CR;
}
while(!(U0LSR & 0x20));

return (U0THR = ch);


}
void Send_String(unsigned char *ch)
{
while(*ch != '\0')
{
Send_Char(*ch++);
}
}
/*Hex to ASCII Conversion*/
void CS5532_HexToASCII(unsigned long int Result)
{
CSLSB0 = Result%10;
CSLSB0 |= 0x30;
Result = Result/10;
CSLSB1 = Result%10;
CSLSB1 |= 0x30;
Result = Result/10;
CSLSB2 = Result%10;
CSLSB2 |= 0x30;
Result = Result/10;
CSLSB3 = Result%10;
CSLSB3 |= 0x30;
Result = Result/10;
CSLSB4 = Result%10;
CSLSB4 |= 0x30;
Result = Result/10;
CSLSB5 = Result%10;
CSLSB5 |= 0x30;
Result = Result/10;
CSLSB6 = Result%10;
CSLSB6 |= 0x30;
Result = Result/10;
CSLSB7 = Result%10;
CSLSB7 |= 0x30;
Result = Result/10;
CSLSB8 = Result%10;
CSLSB8 |= 0x30;
}
/*Timer0 Init*/
void initTimer0(void)
{
T0CTCR = 0x0;
T0PR = 59999;
T0TCR = 0x02;
}
/*Delay Routine*/
void delayMS(unsigned int milliseconds)
{
T0TCR = 0x02;
T0TCR = 0x01;
while(T0TC < milliseconds);
T0TCR = 0x00; /
}
/*Main function*/
int main(void)
{
PLLInit();
IO0DIR = 0x00FF0000;
UART0_Init();
initTimer0();
ExtInt_Init1(); //Initialize Interrupt 1
Send_Char(0x0C);
Send_String ("***************** External Interrupt Demo
***************************\n\n\r");
DelayMs(100);
Send_String (">>> Connect Signal On Interrupt Pin INT1 for Output... \n\n\n\r");
DelayMs(100);
while(1)
{
EINT1 = 0;
EINT2 = 0;
delayMS(1000);
Send_String("INT1 Generated = ");
CS5532_HexToASCII(EINT1);
Send_Char(CSLSB7);
Send_Char(CSLSB6);
Send_Char(CSLSB5);
Send_Char(CSLSB4);
Send_Char(CSLSB3);
Send_Char(CSLSB2);
Send_Char(CSLSB1);
Send_Char(CSLSB0);
Send_String("\n");
delayMS(2000);
}}
#include<LPC214x.h>
#include <stdio.h>
int volatile EINT1 = 0;
int volatile EINT2 = 0;
#define CR 0x0D
#define PLOCK 0x400
void ExtInt_Serve1(void)__irq;
void ExtInt_Serve2(void)__irq;
void PLLInit(void)
{
unsigned long loop_ctr;
PLL1CFG = 0x00000024;
PLL1CON = 0x01;
PLL1FEED = 0xAA;
PLL1FEED = 0x55;
loop_ctr = 10000;
while (((PLL1STAT<<10) == 0) && (loop_ctr > 0))
{
loop_ctr--;
}
PLL1CON = 0x02;

PLL1FEED = 0xA0;
PLL1FEED = 0x55;
VPBDIV = 0x01;
}
void ExtInt_Serve1(void)__irq
{
++EINT1;
EXTINT |= 2;
VICVectAddr = 1;
}
void ExtInt_Serve2(void)__irq
{
++EINT2;
EXTINT |= 4;
VICVectAddr = 0;
}
void ExtInt_Init2(void)
{
EXTMODE |= 4;
EXTPOLAR = 0;
PINSEL0 |= 0x80000000;
VICVectCntl1 = 0x20 | 16;
VICVectAddr1 = (unsigned long) ExtInt_Serve2;
VICIntEnable |= 1<<16;
}
void ExtInt_Init1(void)
{
EXTMODE |= 2;
EXTPOLAR = 0;
PINSEL0 |= 0x20000000;
VICVectCntl0 = 0x20 | 15; //
VICVectAddr0 = (unsigned long) ExtInt_Serve1;
VICIntEnable |= 1<<15;
}
void Serial_Init(void)
{
PINSEL0 |= 0X00000005;
U0LCR = 0x00000083;
U0DLL = 0x00000061;
U0LCR = 0x00000003;
}
void DelayMs(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
{
for(j=0;j<1000;j++);
}
}
int main(void)
{
PLLInit();
Serial_Init();
ExtInt_Init1();
ExtInt_Init2();
putchar(0x0C);
printf ("***************** External Interrupt Demo
***************************\n\n\r");
DelayMs(100);
printf (">>> Press Interrupt Keys SW2(INT1) and SW3(INT2) for Output... \n\n\n\r");
DelayMs(100);
while(1)
{
DelayMs(500);
printf("INT1 Generated : %d | INT2 Generated : %d \r", EINT1, EINT2);
DelayMs(500);
}
}

Das könnte Ihnen auch gefallen