-
Notifications
You must be signed in to change notification settings - Fork 3
/
stack.s
184 lines (151 loc) · 3.52 KB
/
stack.s
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* ULP Example: Read temperautre in deep sleep
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
This file contains assembly code which runs on the ULP.
*/
/* ULP assembly files are passed through C preprocessor first, so include directives
and C macros may be used in these files
*/
#include "version.h"
// RTC_GPIO_6 == GPIO_25
// RTC_GPIO_7 == GPIO_26
// RTC_GPIO_9 == GPIO_32
// RTC_GPIO_8 == GPIO_33
.set SCL_PIN, ULP_SCL_PIN
.set SDA_PIN, ULP_SDA_PIN
.set SENSOR_WSTATUS_AWAKE, 0x01
.set SENSOR_WSTATUS_SLEEP, 0x02
.macro push rx
st \rx,r3,0
sub r3,r3,1
.endm
.macro pop rx
add r3,r3,1
ld \rx,r3,0
.endm
// Prepare subroutine jump
.macro psr
.set addr,(.+16)
move r1,addr
push r1
.endm
// Return from subroutine
.macro ret
pop r1
jump r1
.endm
.macro store _addr val
move r1,\_addr // store result
move r0,\val //
st r0,r1,0
.endm
.macro store_mem addr_src addr_dst
move r2, \addr_src
move r1, \addr_dst
ld r0, r2, 0
st r0, r1, 0 // Save data in memory
.endm
.macro set_flag addr val
move r2, \addr
ld r0, r2, 0
or r0, r0, \val
st r0, r2, 0
.endm
.macro del_flag addr val
move r2, \addr
ld r0, r2, 0
and r0, r0, \val
st r0, r2, 0
.endm
.macro inc addr
move r2, \addr
ld r0, r2, 0
add r0, r0, 1 // Increment
st r0, r2, 0 // Save data in memory 1
.endm
.macro dec addr
move r2, \addr
ld r0, r2, 0
sub r0, r0, 1 // Increment
st r0, r2, 0 // Save data in memory 1
.endm
.macro if_flag test_var SENSOR_IDX handler
move r0, \test_var
ld r0, r0, 0
and r0, r0, \SENSOR_IDX // mask
jumpr \handler,\SENSOR_IDX,eq
.endm
.macro if_noflag test_var SENSOR_IDX handler
move r0, \test_var
ld r0, r0, 0
and r0, r0, \SENSOR_IDX // mask
jumpr \handler,0,eq
.endm
.macro if_val_eq var test_var handler
move r0, \var
ld r0, r0, 0
jumpr \handler,\test_var,eq
.endm
.macro if_val_noteq var test_var handler
move r0, \var
ld r0, r0, 0
jumpr \handler,\test_var,lt
jumpr \handler,\test_var,gt
.endm
// don't use r1 in DATA argumemt!!! =)
.macro read_i2c ADDR REG fail
move r1, \ADDR
push r1
move r1,\REG
push r1
psr
jump read8
add r3,r3,2 // remove call parameters from stack
move r1,r0 // save result
move r0,r2 // test for error
jumpr \fail,1,ge
.endm
// don't use r1 in DATA argumemt!!! =)
.macro write_i2c ADDR REG DATA fail
move r1,\ADDR
push r1
move r1,\REG
push r1
move r1,\DATA
push r1
psr
jump write8
add r3,r3,3 // remove call parameters from stack
move r0, r2 // test for error in r2
jumpr \fail,1,ge
.endm
.macro update_i2c_register ADDR REG fail mask value
read_i2c \ADDR \REG \fail
and r0, r1, \mask // take result from r1
or r0, r0, \value
write_i2c \ADDR \REG r0 \fail
.endm
/*
.macro update_i2c_register ADDR REG fail mask value
move r1,\ADDR
push r1
move r1,\REG
push r1
psr
jump read8
move r1,r0 // save result
move r0,r2 // test for error
jumpr no\fail, 0, eq
jump \fail
no\fail:
and r0, r1, \mask // take result from r1
or r0, r0, \value
push r0
psr
jump write8
add r3, r3, 3 // remove call parameters from stack
move r0, r2 // test for error in r2
jumpr \fail,1,ge
.endm*/