-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLOCK_MODULE.s
More file actions
56 lines (40 loc) · 1.47 KB
/
CLOCK_MODULE.s
File metadata and controls
56 lines (40 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
; Amaar Ebrahim
; Utilities module for the clock
; @MOVE THIS TO THE GPIO DRIVER
GET GPIO_ADR.s
AREA CLOCK_MODULE, CODE, READONLY
THUMB
ENTRY
;-----------------------------------------------------------------------
; turns on GPIO ports by enabling their clocks
; @param (R0): a 32-bit number. Each bit corresponds to which port to
; turn on. A 1 means turn it on.
; Example: 0x0000_0008 means turn on GPIO D
;-----------------------------------------------------------------------
EXPORT TURN_ON_CLOCK
TURN_ON_CLOCK PROC
PUSH {R1, R2} ; push R1 and R2 onto the stack
LDR R1,=RCC_AHB1ENR ; load the address of RCC_AHB1ENR, which controls the clocks
LDR R2,[R1] ; load the value of RCC_AHB1ENR
ORR R2, R0 ; turn on the appropriate GPIO ports
STR R2,[R1] ; store the new settings
POP {R1, R2}
BX LR ; exit
ENDP
;-----------------------------------------------------------------------
; Delays N half seconds using a for loop
; @param (R0): a 32-bit number with the number of half seconds to
; delay.
;-----------------------------------------------------------------------
EXPORT DELAY_N_HALF_SECONDS
DELAY_N_HALF_SECONDS PROC
PUSH {R1}
LDR R1, =3600000 ; there are 3600000 cycles/half second
MUL R0, R1 ; get total cycles to burn through
DELAY_N_HALF_SECONDS_LP
SUBS R0, #1
BNE DELAY_N_HALF_SECONDS_LP
POP {R1}
BX LR
ENDP
END