reset:
    br always >main
    nop

hardfault:
    reti
    nop

memfault:
    reti
    nop

timer_interrupt:
    reti
    nop

can_interrupt:
    br >can_interrupt
    nop

.align
led_addr: .word 0x000F0000

timer_counter_addr: .word 0x000F0008
timer_status_addr: .word 0x000F000C

dmem_start_addr: .word 0x00000400
dmem_end_addr: .word 0x000004FC

priority_mask: .word 0xFFFFFF03

timer_target_value: .word 127 // for simulation
// timer_target_value: .word 0xF10000 // for real board

can_base_addr: .word 0x000F0100

can_control_ptr: .word =can_base_addr
can_command_ptr: .word =can_base_addr + 1
can_acceptance_code_ptr: .word =can_base_addr + 4
can_acceptance_mask_ptr: .word =can_base_addr + 5
can_acceptance_bus_timing0_ptr: .word =can_base_addr + 6
can_acceptance_bus_timing1_ptr: .word =can_base_addr + 7
can_output_control_ptr: .word =can_base_addr + 8
can_identifier0_ptr: .word =can_base_addr + 10
can_identifier1_ptr: .word =can_base_addr + 11
can_data0_ptr: .word =can_base_addr + 12
can_data1_ptr: .word =can_base_addr + 13

main:
    // Initialize stack pointer to the end of the data memory
    ldr r12, >dmem_end_addr

    // Set runtime priority
    ldr r0, >priority_mask
    and r14, r0, r14

    // Set LED to pattern
    clr r2
    addi r2, 0x7A
    st08 r0, r2

    // Initialize CAN
    ldr r0, >can_acceptance_code_ptr

loop:
    br >loop
    nop

can_interrupt:
    reti
    nop
