微處理器 - Nuvoton NUC977 - Assembly - Enhance Timer1 Controller(ETMR1)



參考資訊:
https://github.com/OpenNuvoton/NUC970_NonOS_BSP

Timer Interrupt


ETMR_EN、MODE_SEL


Compare


Interrupt Enable


Interrupt Flag


main.s

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    .equ GPIOD_DIR,     (0xb8003000 + 0xc0)
    .equ GPIOD_DATAOUT, (0xb8003000 + 0xc4)
    .equ CLK_PCLKEN0,   (0xb0000200 + 0x18)
    .equ AIC_MECRH,     (0xb8002000 + 0x134)
    .equ AIC_EOSCR,     (0xb8002000 + 0x150)
    .equ ETMR1_CTL,     (0xb8001500 + 0x00)
    .equ ETMR1_CMPR,    (0xb8001500 + 0x08)
    .equ ETMR1_IER,     (0xb8001500 + 0x0c)
    .equ ETMR1_ISR,     (0xb8001500 + 0x10)
 
    .data
blink: .dcb 1
   
    .text
    .align 2
    .global _start
_start:    b reset
_undef:    b .
_swi:      b .
_pabort:   b .
_dabort:   b .
_reserved: b .
_irq:      b irq_handler
_fiq:      b .
  
reset:
    mrs r0, cpsr
    bic r0, #0x80
    msr cpsr_c, r0
 
    ldr r0, =AIC_MECRH
    ldr r1, =(1 << 16)
    str r1, [r0]
 
    ldr r0, =CLK_PCLKEN0
    ldr r1, [r0]
    ldr r2, =((1 << 3) | (1 << 5))
    orr r1, r2
    str r1, [r0]
 
    ldr r0, =ETMR1_CMPR
    ldr r1, =6000000
    str r1, [r0]
 
    ldr r0, =ETMR1_CTL
    ldr r1, =1
    str r1, [r0]
 
    ldr r0, =ETMR1_IER
    ldr r1, =1
    str r1, [r0]
 
    ldr r0, =GPIOD_DIR
    ldr r1, =(1 << 6)
    str r1, [r0]
 
    ldr r0, =GPIOD_DATAOUT
    ldr r1, =(1 << 6)
    str r1, [r0]
 
    ldr r0, =blink
    ldr r1, =0x00
    str r1, [r0]
    b .
 
irq_handler:
    ldr r0, =blink
    ldr r1, [r0]
    cmp r1, #0x00
    beq 1f
    ldr r0, =GPIOD_DATAOUT
    ldr r1, =(1 << 6)
    str r1, [r0]
    b 2f
1:
    ldr r0, =GPIOD_DATAOUT
    ldr r1, =~(1 << 6)
    str r1, [r0]
2:
    ldr r0, =blink
    ldr r1, [r0]
    eor r1, #0xff
    str r1, [r0]
  
    ldr r0, =AIC_EOSCR
    ldr r1, =1
    str r1, [r0]
  
    ldr r0, =ETMR1_ISR
    ldr r1, [r0]
    orr r1, #1
    str r1, [r0]
    
    ldr r0, =ETMR1_CTL
    ldr r1, =1
    str r1, [r0]
   
    subs pc, lr, #4
    .end

完成