-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathi2c_ds3231.s
155 lines (124 loc) · 3.31 KB
/
i2c_ds3231.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
// SPDX-FileCopyrightText: 2020-2021 Ivan Ivanov
// SPDX-License-Identifier: GPL-3.0-or-later
#include "soc/rtc_cntl_reg.h"
#include "soc/rtc_io_reg.h"
#include "soc/soc_ulp.h"
#include "stack.s"
.set DS3231_ADDR, 0x68
.set DS3231_REG_TIME, 0x00
.bss
.global ds3231_error
ds3231_error:
.long 0
.global ds3231_second
ds3231_second:
.long 0
.global ds3231_minute
ds3231_minute:
.long 0
.global ds3231_hour
ds3231_hour:
.long 0
.global ds3231_dayOfWeek
ds3231_dayOfWeek:
.long 0
.global ds3231_day
ds3231_day:
.long 0
.global ds3231_month
ds3231_month:
.long 0
.global ds3231_year
ds3231_year:
.long 0
.global ds3231_set_second
ds3231_set_second:
.long 0
.global ds3231_set_minute
ds3231_set_minute:
.long 0
.global ds3231_set_hour
ds3231_set_hour:
.long 0
.global ds3231_set_dayOfWeek
ds3231_set_dayOfWeek:
.long 0
.global ds3231_set_day
ds3231_set_day:
.long 0
.global ds3231_set_month
ds3231_set_month:
.long 0
.global ds3231_set_year
ds3231_set_year:
.long 0
.text
/*
*
-----
21:58:01.084 -> 0x5 0x68 0x0 0x336 0x42 0x14 0x21 0x2
21:58:01.084 -> 0x2 0x1 0x0 0x3f6 0x4b0 0x0 0x0 0x0
21:58:01.084 -> 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
21:58:01.084 -> 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
21:58:01.084 ->
21:58:01.084 -> wakeupReason ESP_SLEEP_WAKEUP_UNDEFINED, statRecord_cnt 0
21:58:01.084 -> ds3231 data: year 2000, month 1, day 2, dayOfWeek 2, hour 21, minute 14, second 42
21:58:04.036 -> 0x5 0x68 0x0 0x336 0x3dc 0x37e 0x4a5 0x2
21:58:04.036 -> 0x2 0x1 0x0 0x3f6 0x4b0 0x0 0x0 0x0
21:58:04.036 -> 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
21:58:04.036 -> 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
21:58:20.111 -> 0x5 0x68 0x0 0x336 0x0 0x0 0x0 0x0
21:58:20.111 -> 0x0 0x0 0x0 0x3f6 0x4b0 0x0 0x0 0x0
21:58:20.111 -> 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
21:58:20.111 -> 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
*/
/// !!!!!!!!!!!!! look at code witch changes sda pin!!
.global ds3231_getDateTime
ds3231_getDateTime:
move r0, ds3231_error // test for init error SENSOR_STATUS_HW_ERROR
ld r0, r0, 0x00
jumpr ds3231_sensor_found_get, SENSOR_STATUS_HW_ERROR, lt
jumpr ds3231_sensor_found_get, SENSOR_STATUS_HW_ERROR, gt
ret
ds3231_sensor_found_get:
move r1, i2c_MultyHandler // set handler for multy
move r0, processBytesFromStack
st r0, r1, 0
move r1, DS3231_ADDR
push r1
move r1, DS3231_REG_TIME
push r1
move r0, 7
move r2, ds3231_year
psr
jump readMultyToStack
add r3,r3,2 // remove call parameters from stack
move r0, r2 // test for error
jumpr ds3231_fail_read,1,ge
store ds3231_error 0
ret
.global ds3231_setDateTime
ds3231_setDateTime:
move r0, ds3231_error // test for init error SENSOR_STATUS_HW_ERROR
jumpr ds3231_sensor_found_set, SENSOR_STATUS_HW_ERROR, lt
jumpr ds3231_sensor_found_set, SENSOR_STATUS_HW_ERROR, gt
ret
ds3231_sensor_found_set:
move r1, DS3231_ADDR
push r1
move r1, DS3231_REG_TIME
push r1
move r1, 7
push r1
move r2, ds3231_set_second
psr
jump writeMULTY
add r3,r3,3 // remove call parameters from stack
move r0,r2 // test for error
jumpr ds3231_fail_read,1,ge
store ds3231_error 0
ret
.global ds3231_fail_read
ds3231_fail_read:
store ds3231_error SENSOR_STATUS_READ_ERROR
ret