summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2013-10-30 10:44:14 +0100
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>2013-10-30 10:44:14 +0100
commit29a827a09c536892b5934eec1ee53a439d84f37a (patch)
treebe50fb1b99a469f2522975dfbb7ce6f3a596c915
parent0432807fb541a9ea70deac8a50e53268fb3d84e7 (diff)
downloadOSELAS.BSP-EnergyMicro-Gecko-29a827a09c536892b5934eec1ee53a439d84f37a.tar.gz
OSELAS.BSP-EnergyMicro-Gecko-29a827a09c536892b5934eec1ee53a439d84f37a.tar.xz
OSELAS.BSP-EnergyMicro-Gecko: geckoboot: refactor UART output
The code generated is slightly less effective because of the added push and pop pairs and fifo handling which doesn't outweigh the advantages though: - improved readabiltiy - easier use because no registers are clobbered - putc waits for the UART to be idle
-rw-r--r--local_src/geckoboot-2013.01.0/geckoboot.S104
1 files changed, 73 insertions, 31 deletions
diff --git a/local_src/geckoboot-2013.01.0/geckoboot.S b/local_src/geckoboot-2013.01.0/geckoboot.S
index 17e93db..36f53e5 100644
--- a/local_src/geckoboot-2013.01.0/geckoboot.S
+++ b/local_src/geckoboot-2013.01.0/geckoboot.S
@@ -11,6 +11,70 @@
.int 0x10001000 @ Initial SP value
.int reset + 1
+#define UARTn_STATUS 0x0010
+#define UARTn_STATUS_TXC 0x0020
+#define UARTn_STATUS_TXBL 0x0040
+
+#define UARTn_TXDATA 0x0034
+
+ @ load UART base address into \rx
+ .macro addruart, rx, tmp
+ ldr \rx, =(0x4000e400)
+ .endm
+
+ @ send char \rd with \rx holding the UART base address
+ .macro senduart, rd, rx
+ strb \rd, [\rx, #UARTn_TXDATA]
+ .endm
+
+ @ wait for the UART to become ready to take another char
+ .macro waituart, rd, rx
+1001: ldr \rd, [\rx, #UARTn_STATUS]
+ tst \rd, #UARTn_STATUS_TXBL
+ beq 1001b
+ .endm
+
+ @ wait for the fifo and shifter to become idle
+ .macro busyuart, rd, rx
+1001: ldr \rd, [\rx, #UARTn_STATUS]
+ tst \rd, #UARTn_STATUS_TXC
+ bne 1001b
+ .endm
+
+/* printascii and printch are mostly copied from Linux v3.12, arch/arm/kernel/debug.S */
+
+@ prints a zero-terminated string pointed to by r0
+printascii:
+ addruart r3, r1
+ b 2f
+1: /* send char in r1 */
+ waituart r2, r3
+ senduart r1, r3
+ teq r1, #'\n'
+ moveq r1, #'\r'
+ beq 1b
+2: /* load next char from r0 */
+ teq r0, #0
+ ldrbne r1, [r0], #1
+ teqne r1, #0
+ bne 1b
+ busyuart r2, r3
+ bx lr
+
+@ prints a single char contained in r0
+printch:
+ addruart r3, r1
+ mov r1, r0
+ mov r0, #0
+ b 1b
+
+ .macro putc, val, cond=al
+ push\cond {r0-r3}
+ mov\cond r0, \val
+ bl\cond printch
+ pop\cond {r0-r3}
+ .endm
+
reset:
/* init external RAM, serial port, EBI and stuff */
adr r0, reginit
@@ -39,22 +103,15 @@ reset:
bne 1b
/* First sign of life */
- ldr r0, =(UARTBASE + 0x34)
- mov r1, #'G'
- str r1, [r0]
+ putc #'G'
/* if PB1 is pressed setup for SWO */
ldr r0, =(BC_REGISTER)
ldr r1, [r0, #8] @ BC_REGISTER->UIF_PB
tst r1, #1
- ldrne r0, =(UARTBASE + 0x34)
- movne r1, #'e'
- strne r1, [r0]
+ putc #'e', ne
bne wait_boot_linux
-
- ldr r0, =(UARTBASE + 0x34)
- mov r1, #'E'
- str r1, [r0]
+ putc #'E'
/* poll for CMU_STATUS_AUXHFRCORDY */
ldr r0, =(0x400c8000)
@@ -76,28 +133,18 @@ reset:
wait_boot_linux:
#ifdef CONFIG_WAIT_FOR_PB2
- ldr r0, =(UARTBASE + 0x34)
- mov r1, #'C'
- str r1, [r0]
+ putc #'C'
/* only boot into Linux when PB2 is pressed */
ldr r0, =(BC_REGISTER)
1: ldr r1, [r0, #8] @ BC_REGISTER->UIF_PB
tst r1, #2
bne 1b
#else
- ldr r0, =(UARTBASE)
- mov r1, #'c'
- str r1, [r0, 0x34]
- @ wait for STATUS.TXBL being set, otherwise the 'k' might not appear
-1: ldr r1, [r0, 0x10]
- tst r1, #0x40
- beq 1b
+ putc #'c'
#endif
boot_linux:
- ldr r0, =(UARTBASE + 0x34)
- mov r1, #'k'
- str r1, [r0]
+ putc #'k'
/* Copy oftree to RAM */
ldr r0, =(DTB_DST)
@@ -107,13 +154,9 @@ boot_linux:
bl memcpy
- ldr r0, =(UARTBASE + 0x34)
- mov r1, #'o'
- str r1, [r0]
- mov r1, #'\r'
- str r1, [r0]
- mov r1, #'\n'
- str r1, [r0]
+ putc #'o'
+ putc #'\r'
+ putc #'\n'
/* boot Linux */
mov r0, #0
@@ -296,6 +339,5 @@ swoinit:
.int 0xe00400f0, 0xffffffff, 0x00000002 @ Set protocol to NRZ
.int 0xe0000fb0, 0xffffffff, 0xc5acce55 @ Unlock ITM
.int 0xe0000e80, 0xffffffff, 0x00010009 @ output data
- .int (UARTBASE + 0x34), 0xffffffff, 0x00000043 @ some output to uart
swoinit_end:
.size swoinit, . - swoinit