.syntax unified
.include "regs.asm"
.global initIRQ

.extern isr
.equ enableInt,0x4100

//Taste an PC13
initIRQ:
	//Test globale Variable x
	ldr	r1,=x
	ldr r2,[r1]

	//interrupt vector auf isr einstellen
	ldr r1,=0x20000000
	ldr r2,=isr1
	str r2,[r1,#0xe0]
	//GPIOC mit Takt versorgen
	ldr 	r1,=rcc
	ldr r2,[r1,#RCC_AHBENR]	//APB2 peripheral clock enable register
	add r2,#0x00000004	//GPIOC clock enable
	str r2,[r1,#RCC_AHBENR]

	ldr	r1,=exti	//EXTI Base Address
	//EXTI13 config
	mov.w	r2,#0x2000
	str	r2,[r1,#0x00]	//maskregister
	str r2,[r1,#0x0c]	//falling edge register
	str r2,[r1,#0x14]	//clear pending register (EXTI_PR)
	ldr r1,=rcc	//rcc base address
	ldr r2,[r1,#0x20]	//APB2 peripheral clock enable register
	add r2,#0x00000001	//SYSCFGEN: System configuration controller clock enable
	str r2,[r1,#0x20]

	ldr r1,=SysCFG	//SysCFG Base Address
	mov.w r2,#0x0020	//PCx - Pin als Interruptquelle
	strh r2,[r1,#0x14]	//SYSCFG external interrupt configuration register 4
	//NVIC config enable Interrupt
	ldr r1,=nvic
	ldr r2,=enableInt
	str r2,[r1,isr1]

	bx lr

.end


