summaryrefslogtreecommitdiff
path: root/software/first/delay.S
blob: 656625f234ee77d4172e93c4d2c66ee8865d0e06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
.section .text
.align 2
.global delay
.include "memory_map.inc"


# a0 is delay in milliseconds argument

delay:
	addi sp, sp, -16 # Allocate stack frame
	sw ra, 12(sp)    # save return address to the stack

	li t0, MTIME     # load the timer register
	lw t1, 0(t0)     # load value of the timer

	li t2, MTIME_FREQUENCY # get clock freq (approx.)
	mul t2, t2, a0         # multiply milliseconds with freq
	add t2, t1, t2         # target mtime is now in t2
	li t3, MTIMECMP        # load address of MTIMECMP register
	sw t2, 0(t3)           # store target time to MTIMECMP register. This only stores 32 bits so I am not sure if that is correct...

	lw ra, 12(sp)   # load return address
	addi sp, sp, 16 # deallocate stack frame
	ret