mirror of
https://github.com/isfshax/isfshax.git
synced 2024-12-01 16:04:15 +01:00
lolserial_asm: fix accidental register corruption in debug builds, code improvements
oof
This commit is contained in:
parent
ef5565ada8
commit
b16cca5a8c
@ -27,72 +27,77 @@
|
|||||||
|
|
||||||
.equ LOLSERIAL_WAIT_TICKS, 200
|
.equ LOLSERIAL_WAIT_TICKS, 200
|
||||||
.equ GP_SENSORBAR, 0x00000100
|
.equ GP_SENSORBAR, 0x00000100
|
||||||
.equ GP_SENSORBAR_SHIFT, 8
|
|
||||||
|
|
||||||
|
@ arg:r0 string address
|
||||||
lolserial_print:
|
lolserial_print:
|
||||||
mov r1, #-1
|
mov r1, #-1
|
||||||
|
|
||||||
|
@ arg:r0 string address
|
||||||
|
@ arg:r1 max length
|
||||||
lolserial_lprint:
|
lolserial_lprint:
|
||||||
push {r5-r6}
|
push {r4-r5}
|
||||||
add r1, r1, r0
|
add r1, r0 @ end address in r1
|
||||||
|
ldr r5, =LT_REG_BASE @ latte registers base in r5
|
||||||
|
|
||||||
ldr r6, =0x0D800000
|
@ clear32(LT_GPIO_OWNER, GP_SENSORBAR)
|
||||||
|
ldr r2, [r5, #0x0FC]
|
||||||
|
bic r2, r2, #GP_SENSORBAR
|
||||||
|
str r2, [r5, #0x0FC]
|
||||||
|
|
||||||
/* clear32(LT_GPIO_OWNER, GP_SENSORBAR) */
|
@ set32(LT_GPIO_ENABLE, GP_SENSORBAR)
|
||||||
ldr r5, [r6, #0x0FC]
|
ldr r2, [r5, #0x0DC]
|
||||||
bic r5, r5, #GP_SENSORBAR
|
orr r2, r2, #GP_SENSORBAR
|
||||||
str r5, [r6, #0x0FC]
|
str r2, [r5, #0x0DC]
|
||||||
|
|
||||||
/* set32(LT_GPIO_ENABLE, GP_SENSORBAR) */
|
@ set32(LT_GPIO_DIR, GP_SENSORBAR)
|
||||||
ldr r5, [r6, #0x0DC]
|
ldr r2, [r5, #0x0E4]
|
||||||
orr r5, r5, #GP_SENSORBAR
|
orr r2, r2, #GP_SENSORBAR
|
||||||
str r5, [r6, #0x0DC]
|
str r2, [r5, #0x0E4]
|
||||||
|
|
||||||
/* set32(LT_GPIO_DIR, GP_SENSORBAR) */
|
@ set32(LT_GPIO_OUT, GP_SENSORBAR)
|
||||||
ldr r5, [r6, #0x0E4]
|
ldr r2, [r5, #0x0E0]
|
||||||
orr r5, r5, #GP_SENSORBAR
|
orr r2, r2, #GP_SENSORBAR
|
||||||
str r5, [r6, #0x0E4]
|
str r2, [r5, #0x0E0]
|
||||||
|
|
||||||
/* set32(LT_GPIO_OUT, GP_SENSORBAR) */
|
|
||||||
ldr r5, [r6, #0x0E0]
|
|
||||||
orr r5, r5, #GP_SENSORBAR
|
|
||||||
str r5, [r6, #0x0E0]
|
|
||||||
|
|
||||||
lolserial_send_string_loop:
|
lolserial_send_string_loop:
|
||||||
cmp r0, r1
|
cmp r0, r1 @ ensure end address was not reached
|
||||||
ldrneb r5, [r0], #1
|
ldrneb r3, [r0], #1 @ load cur char in r3, increment r0 string ptr
|
||||||
cmpne r5, #0
|
cmpne r3, #0 @ check for string null termination
|
||||||
beq lolserial_send_string_end
|
beq lolserial_send_string_end
|
||||||
|
|
||||||
mov r3, #0x200
|
@ r3: bits to send (serial end bit, data byte, serial start bit)
|
||||||
orr r3, r3, r5, lsl #1
|
@ r3 = (1 << 9) | (r3:chr << 1) | (0 << 0)
|
||||||
|
lsl r3, #1
|
||||||
|
orr r3, #0x200
|
||||||
|
|
||||||
|
@ loop over bits to send
|
||||||
lolserial_send_char_loop:
|
lolserial_send_char_loop:
|
||||||
and r4, r3, #1
|
@ mask32(LT_GPIO_OUT, GP_SENSORBAR, bit ? GP_SENSORBAR : 0)
|
||||||
|
tst r3, #1
|
||||||
|
ldr r2, [r5, #0x0E0]
|
||||||
|
biceq r2, #GP_SENSORBAR
|
||||||
|
orrne r2, #GP_SENSORBAR
|
||||||
|
str r2, [r5, #0x0E0]
|
||||||
|
|
||||||
ldr r5, [r6, #0x0E0]
|
@ wait for LOLSERIAL_WAIT_TICKS timer ticks
|
||||||
bic r5, r5, #GP_SENSORBAR
|
ldr r2, [r5, #0x010] @ r2: current ticks
|
||||||
orr r5, r5, r4, lsl #GP_SENSORBAR_SHIFT
|
adds r4, r2, #LOLSERIAL_WAIT_TICKS @ r4: wait time end
|
||||||
str r5, [r6, #0x0E0]
|
|
||||||
|
|
||||||
ldr r5, [r6, #0x010]
|
|
||||||
adds r4, r5, #LOLSERIAL_WAIT_TICKS
|
|
||||||
bcc timer_wait_loop
|
|
||||||
timer_wait_overflow_loop:
|
timer_wait_overflow_loop:
|
||||||
ldr r2, [r6, #0x010]
|
cmp r4, r2
|
||||||
cmp r2, r5
|
ldr r2, [r5, #0x010]
|
||||||
bhs timer_wait_overflow_loop
|
blo timer_wait_overflow_loop
|
||||||
timer_wait_loop:
|
timer_wait_loop:
|
||||||
ldr r5, [r6, #0x010]
|
cmp r4, r2
|
||||||
cmp r5, r4
|
ldr r2, [r5, #0x010]
|
||||||
blo timer_wait_loop
|
bhi timer_wait_loop
|
||||||
|
|
||||||
movs r3, r3, lsr #1
|
lsrs r3, #1 @ go to next bit
|
||||||
bne lolserial_send_char_loop
|
bne lolserial_send_char_loop @ unless r3 is 0 (end bit sent)
|
||||||
|
|
||||||
b lolserial_send_string_loop
|
b lolserial_send_string_loop
|
||||||
lolserial_send_string_end:
|
lolserial_send_string_end:
|
||||||
|
|
||||||
pop {r5-r6}
|
pop {r4-r5}
|
||||||
bx lr
|
bx lr
|
||||||
|
|
||||||
#endif /* LOLSERIAL_DEBUG */
|
#endif /* LOLSERIAL_DEBUG */
|
||||||
|
Loading…
Reference in New Issue
Block a user