commit 62c0baf87b41ca67319400b478ac5bb441f4232b
parent d87427e253fed2f078fe90e9105b4a4783c5981d
Author: Matsuda Kenji <info@mtkn.jp>
Date: Thu, 29 Feb 2024 08:57:13 +0900
move to c
Diffstat:
M | ex3/main.c | | | 12 | +++++++++--- |
M | ex3/start.s | | | 69 | +++++++++++++++++++++++++++++++++------------------------------------ |
2 files changed, 42 insertions(+), 39 deletions(-)
diff --git a/ex3/main.c b/ex3/main.c
@@ -1,12 +1,18 @@
-void puts(char *);
+int puts(char *);
+void set_alarm(unsigned int);
int
main(void) {
- puts("C file\n");
+ puts("C file");
return 0;
}
void
isr_svcall(void) {
- puts("svcall\n");
+ puts("svcall");
+}
+
+void
+isr_alarm(void) {
+ set_alarm(0x20000);
}
diff --git a/ex3/start.s b/ex3/start.s
@@ -114,13 +114,9 @@ wait_vco:
mov r0, #1
str r0, [r3, r1] // M0PLUS: NVIC_ISER
- // setup timer
- ldr r3, timer_base
- // enable alarm_0 interrupt
- mov r0, #1 // ALARM_0
- str r0, [r3, #0x38] // TIMER: INTE
// set timer
- ldr r0, =0x20000 //
+ bl init_timer
+ ldr r0, =0x20000
bl set_alarm
bl main
@@ -134,35 +130,10 @@ loop:
// functions
-isr_systick:
- push {lr}
- mov r0, #'\r'
- bl putbyte
- ldr r1, =0x20000000
- ldr r0, [r1, #0]
- add r0, #1
- str r0, [r1, #0]
- bl printh
- mov r0, #'\n'
- bl putbyte
- pop {pc}
-
-isr_alarm:
- push {lr}
- // clear interrupt
- ldr r3, timer_base
- ldr r2, atomic_clr
- mov r1, #0x34
- add r1, r1, r2
- mov r0, #1
- str r0, [r3, r1] // TIMER: INTR
- // reset timer
- ldr r0, =0x20000 // 1 sec
- bl set_alarm
- pop {pc}
-
- // unreset deasserts reset bit of subsystems specified by r0
+ // void unreset(unsigned int sub_systems);
+ // unreset deasserts reset bit of subsystems specified by sub_systems.
// and wait for them complete unreset.
+ .global unreset
unreset:
ldr r3, resets_base
ldr r1, atomic_clr
@@ -173,9 +144,30 @@ unreset_chk:
bne unreset_chk
bx lr
- // set_alarm sets alarm_0 to fire after r0 us.
+ // void init_timer(void);
+ // Init_timer enables alarm_0 and its interrupt.
+ // It assumes that the timer is out of reset.
+ .global init_timer
+init_timer:
+ ldr r3, timer_base
+ // enable alarm_0 interrupt
+ mov r0, #1 // ALARM_0
+ str r0, [r3, #0x38] // TIMER: INTE
+ bx lr
+
+ // void set_alarm(unsigned int us);
+ // Set_alarm clears timer interrupt and then sets alarm_0 to fire,
+ // after us micro seconds.
+ .global set_alarm
set_alarm:
ldr r3, timer_base
+ // clear interrupt
+ ldr r2, atomic_clr
+ mov r1, #0x34
+ add r1, r1, r2
+ mov r2, #1
+ str r2, [r3, r1] // TIMER: INTR
+ // set alarm0
ldr r1, [r3, #0x28] // TIMER: TIMERAWL
add r0, r1
str r0, [r3, #0x10] // TIMER: ALARM0
@@ -204,7 +196,9 @@ alpha:
bge printh_loop
pop {r4, r5, r6, r7, pc}
- // puts prints null terminated string starting at r0.
+ // Puts prints null terminated string starting at r0 and a trailing new line
+ // to uart0.
+ // It returns a nonnegative number on success.
.global puts
puts:
push {r4, lr}
@@ -217,6 +211,9 @@ puts_loop:
add r4, #1
b puts_loop
puts_end:
+ mov r0, #'\n'
+ bl putbyte
+ mov r0, #0 // return value
pop {r4, pc}
putbyte: