summaryrefslogtreecommitdiffstats
path: root/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Termin2Aufgabe4a1.c
blob: fb99f59ed8b35c0d05252087431b2092d7b1d2eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// L�sung zu Termin2
// Aufgabe 4
// Namen: __________; ___________
// Matr.: __________; ___________
// vom :  __________
//
#include "../mi2/h/pio.h"
#include "../mi2/h/pmc.h"
#include "../mi2/h/aic.h"

StructPMC* myPMC = PMC_BASE;
StructAIC* myAIC = AIC_BASE;
StructPIO* myPIOB = PIOB_BASE;

void taste_irq_handler (void) __attribute__ ((interrupt));

void taste_irq_handler (void)
{
	
	volatile int keyPressed = myPIOB->PIO_ISR;
	
	if (!(keyPressed & KEY1))
		myPIOB->PIO_SODR = LED1;
	//if (!(myPIOB->PIO_PDSR & KEY2))
	if (!(keyPressed &  KEY2))
		myPIOB->PIO_CODR = LED1;
		
	myAIC->AIC_EOICR = 0x01;  // write something to register
																				// to signal end of Interrupt Service Routine
}

int main(void)
{	
	myAIC->AIC_EOICR = myPIOB->PIO_ISR;
	// disable all interrupt sources of pio
	myPIOB->PIO_IDR = 0xFFFFFFFF;
		
	
	// Initialize PIOB
	myPIOB->PIO_PER = KEY1|KEY2|LED1;  // Enable PIO for SW1,SW2,LED1,LED2
	//myPIOB->PIO_OER = LED1|LED2;					// Set LED1 and LED2 as output
	myPIOB->PIO_OER = LED1;					// Set LED1 and LED2 as output
	myPIOB->PIO_CODR = LED1;					// Clear Output Data Register
	
	
	// Enable Interrupts in CPU
	// done by OS
	
	// disable PIOB Interrupt in AIC
	myAIC->AIC_IDCR = (1<<PIOB_ID);
	// Enable Interrupt for PIOB in AIC
	myAIC->AIC_SMR[PIOB_ID] = AIC_SRCTYPE_EXT_LOW_LEVEL; // which register? what to put in it? 0x1 for low
	myAIC->AIC_SVR[PIOB_ID] = (volatile unsigned int)&taste_irq_handler;  // Address of Interrupt handling routine...
	
	// enable PIOB Interrupt in AIC
	myAIC->AIC_IECR	= (1<<PIOB_ID);				// Enable Interrupt for PIOB
	
	// enable PIOB Interrupt
	myPIOB->PIO_IER  = KEY1|KEY2; 					// what to put here? 
	
	myPMC->PMC_PCER = (1<<PIOB_ID);	// Clock PIO B
	// loop to infinity
	while(1)
	{
	}
	
	return 0;
}