Assembly examples for Red-V Thing Plus (SiFive FE310-G002)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
1.1 KiB

#
# p_delay.s: functions for waiting
#
# 2021 flabbergast@drak.xyz
# Unlicense: https://unlicense.org/
#
.if compressed_isa
.balign 2, 0
.else
.balign 4, 0
.endif
.include "platform_regs.inc"
.equ MTIME_FREQUENCY, 33 # 32_768 Hz clock
# a0: delay value in milliseconds
# (should be less than 0xFFFF_FFFF/33/4)
delay:
li t0, CLINT_BASE+CLINT_MTIME # Load the timer registers base
lw t1, 0(t0) # Load the current value of the timer
li t2, MTIME_FREQUENCY # Get our clock frequency
mul t2, t2, a0 # Multiply milliseconds with frequency
add t2, t1, t2 # Target mtime is now in t2
bltu t2, t1, 2f # Overflown back to zero?
# if yes, (signed)t1<0
1:
lw t1, 0(t0) # Read mtime value again
bltu t1, t2, 1b # Keep looping until timout
ret
2: # Overflown branch
lw t1, 0(t0) # Read mtime; t1 can be "<0"
blt t1, t2, 2b # Do signed compare
ret
# a0: (delay in cycles)/2
busy_delay_cycles:
1:
addi a0, a0, -1
bnez a0, 1b
ret