TDT4160/o2/o2.s

110 lines
1.9 KiB
ArmAsm

.thumb
.syntax unified
.include "gpio_constants.s" // Register-adresser og konstanter for GPIO
.include "sys-tick_constants.s" // Register-adresser og konstanter for SysTick
.text
.global Start
TENTH_SECOND_FREQUENCY = FREQUENCY / 10
SYSTICK_LOAD_BASE = SYSTICK_BASE + SYSTICK_LOAD
SYSTICK_VAL_BASE = SYSTICK_BASE + SYSTICK_VAL
SYSTICK_CTRL_BASE = SYSTICK_BASE + SYSTICK_CTRL
GPIO_EXTIPSELH_BASE = GPIO_BASE + GPIO_EXTIPSELH
GPIO_EXTIFALL_BASE = GPIO_BASE + GPIO_EXTIFALL
GPIO_IEN_BASE = GPIO_BASE + GPIO_IEN
GPIO_IFC_BASE = GPIO_BASE + GPIO_IFC
GPIO_LED_BASE = GPIO_BASE + (LED_PORT * PORT_SIZE) + GPIO_PORT_DOUTTGL
Start:
LDR R0, =TENTH_SECOND_FREQUENCY
LDR R1, =SYSTICK_CTRL_BASE
LDR R2, =SYSTICK_LOAD_BASE
LDR R3, =SYSTICK_VAL_BASE
MOV R4, #0b110
STR R4, [R1]
LDR R4, =TENTH_SECOND_FREQUENCY
STR R4, [R2]
MOV R4, #1
STR R4, [R3]
LDR R0, =GPIO_EXTIPSELH_BASE
LDR R1, [R0] // 0b xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
BFI R1, R4, #4, #4 // 0b xxxx xxxx xxxx xxxx xxxx xxxx 0001 xxxx
STR R1, [R0]
LDR R0, =GPIO_EXTIFALL_BASE
LDR R1, [R0]
ORR R1, 1 << BUTTON_PIN
STR R1, [R0]
LDR R0, =GPIO_IEN_BASE
LDR R1, [R0]
ORR R1, 1 << BUTTON_PIN
STR R1, [R0]
Loop:
WFI
B Loop
.global SysTick_Handler
.thumb_func
SysTick_Handler:
LDR R0, =tenths
LDR R1, =seconds
LDR R2, =minutes
LDR R10, [R0]
LDR R11, [R1]
LDR R12, [R2]
// Tenth
ADD R10, #1
CMP R10, #10
BNE SysTick_Update
MOV R10, 0
// LED
LDR R3, =GPIO_LED_BASE
LDR R4, =1<<LED_PIN
STR R4, [R3]
// Second
ADD R11, #1
CMP R11, #60
BNE SysTick_Update
MOV R11, 0
// Minute
ADD R12, #1
SysTick_Update:
STR R10, [R0]
STR R11, [R1]
STR R12, [R2]
BX LR
.global GPIO_ODD_IRQHandler
.thumb_func
GPIO_ODD_IRQHandler:
LDR R0, =SYSTICK_CTRL_BASE
LDR R1, [R0]
EOR R1, #1
STR R1, [R0]
LDR R2, =GPIO_IFC_BASE
MOV R3, 1 << BUTTON_PIN
STR R3, [R2]
BX LR
NOP