Many changes from 2018
[owSlave2.git] / DS2450 / OWDS2450.S
1
2 // Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the
14 // distribution.
15 // * All advertising materials mentioning features or use of this
16 // software must display the following acknowledgement: This product
17 // includes software developed by tm3d.de and its contributors.
18 // * Neither the name of tm3d.de nor the names of its contributors may
19 // be used to endorse or promote products derived from this software
20 // without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34 #define _CHANGEABLE_ID_
35 #define _ZERO_POLLING_
36 //#define __4MHZ__
37 //#define _DB_
38 #include "../common/OWConfig.s"
39 #include "../common/OWCRC16.s"
40
41 .extern pack,8
42 .comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....)
43 .comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte....
44 //.extern am2302_temp,2
45
46
47
48 .macro CHIP_INIT
49 .endm
50
51 .macro COMMAND_TABLE
52 rjmp h_readmemoryaddr
53 rjmp h_readmemory
54 rjmp h_readmemorycrc1
55 rjmp h_readmemorycrc2
56 rjmp h_writememoryaddr
57 rjmp h_writememory
58 rjmp h_writememorycrc1
59 rjmp h_writememorycrc2
60 rjmp h_writememoryreadback
61 rjmp h_convert
62 rjmp h_convertcrc1
63 rjmp h_convertcrc2
64 rjmp h_convert_conv
65 .endm
66
67 #include "../common/OWRomFunctions.s"
68 #include "../common/OWTimerInterrupt.s"
69
70
71
72 ; Ab hier Geraeteabhaenging
73 #define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0
74 #define OW_READ_MEMORY OW_FIRST_COMMAND+1
75 #define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2
76 #define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3
77 #define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4
78 #define OW_WRITE_MEMORY OW_FIRST_COMMAND+5
79 #define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6
80 #define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7
81 #define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8
82 #define OW_CONVERT OW_FIRST_COMMAND+9
83 #define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10
84 #define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11
85 #define OW_CONVERT_CONV OW_FIRST_COMMAND+12
86
87 ;---------------------------------------------------
88 ; READ COMMAND and start operation
89 ;---------------------------------------------------
90
91
92 h_readcommand:
93 clr r_bytep
94 #ifndef _DIS_FLASH_
95 FLASH_COMMANDS ; muss zu erst sein....
96 #endif
97 cset 0xAA,OW_READ_MEMORY_ADDR
98 cset 0x55,OW_WRITE_MEMORY_ADDR
99 cset 0x3C,OW_CONVERT
100 FW_CONFIG_INFO
101 #ifdef _CHANGEABLE_ID_
102 CHANGE_ID_COMMANDS
103 #endif
104 ldi r_mode,OW_SLEEP
105 rjmp handle_end
106
107
108 h_readmemoryaddr:
109 cpi r_bytep,0 ;erstes Adressbyte ?
110 brne h_readmemory_addr_byte1 ;nein dann weiter
111 andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen
112 sts addr,r_rwbyte ;speichern des ersten bytes
113 rjmp handle_end_inc
114 h_readmemory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert!
115 ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory
116 ;;ldi r_bcount,1 ;ist unten
117 ldi r_sendflag,1 ;jetzt sendet der Slave zum Master
118 clr r_bytep
119 rjmp h_readmemory2
120 h_readmemory:
121 lds r_bytep,addr
122 inc r_bytep
123 sts addr,r_bytep
124 andi r_bytep,0x07
125 breq h_readmemory_init_crc
126 h_readmemory2:
127 lds r_bytep,addr
128 ;andi r_bytep,0x1F ist oben
129 configZ pack,r_bytep
130 ld r_rwbyte,Z
131 ;ldi r_bcount,1
132 rjmp handle_end ;sendet das Byte und geht zu h_readmemory
133 h_readmemory_init_crc:; init erstes CRC byte
134 lds r_rwbyte,crc
135 com r_rwbyte
136 lds r_temp,crc+1
137 com r_temp
138 sts crcsave,r_temp
139 ldi r_mode,OW_READ_MEMORY_CRC1
140 ;ldi r_bcount,1
141 rjmp handle_end
142 h_readmemory_end:
143 //ldi r_mode,OW_SLEEP
144 //clr r_sendflag
145 rjmp handle_end_sleep
146 h_readmemorycrc1:;init zweites CRC Byte
147 lds r_rwbyte,crcsave
148 ;ldi r_bcount,1
149 ldi r_mode,OW_READ_MEMORY_CRC2
150 rjmp handle_end
151 h_readmemorycrc2:;weiteres senden..... nach zweitem Byte
152 lds r_temp,addr
153 andi r_temp,0xE0
154 brne h_readmemory_end; ende des speichers
155 ldi r_mode,OW_READ_MEMORY
156 CRCInit1 ;Start with new CRC
157 rjmp h_readmemory2
158
159 h_writememoryaddr:
160 cpi r_bytep,0 ;erstes Adressbyte ?
161 brne h_writememory_addr_byte1 ;nein dann weiter
162 andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen
163 sts addr,r_rwbyte ;speichern des ersten bytes
164 inc r_bytep
165 ;ldi r_bcount,1
166 rjmp handle_end
167 h_writememory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert!
168 ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory
169 ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren.....
170 lds r_bytep,addr
171 rjmp handle_end ;read Memory Byte
172 h_writememory:
173 lds r_bytep,addr
174 configZ pack,r_bytep
175 st Z,r_rwbyte
176 ;ldi r_bcount,1
177 ldi r_mode,OW_WRITE_MEMORY_CRC1
178 ldi r_sendflag,1 ;jetzt sendet der Slave zum Master
179 lds r_rwbyte,crc
180 com r_rwbyte
181 lds r_temp,crc+1
182 com r_temp
183 sts crcsave,r_temp
184 rjmp handle_end
185 h_writememorycrc1:
186 lds r_rwbyte,crcsave
187 ;ldi r_bcount,1
188 ldi r_mode,OW_WRITE_MEMORY_CRC2
189 rjmp handle_end
190 h_writememorycrc2:
191 lds r_temp,addr
192 configZ pack,r_temp
193 ld r_rwbyte,Z
194 ;ldi r_bcount,1
195 ldi r_mode,OW_WRITE_MEMORY_READBACK
196 rjmp handle_end
197 h_writememoryreadback:
198 ldi r_temp,0x00
199 sts crc+1,r_temp
200 lds r_temp,addr
201 inc r_temp
202 sts addr,r_temp
203 sts crc,r_temp
204 ldi r_sendflag,0
205 ;ldi r_bcount,1
206 ldi r_mode,OW_WRITE_MEMORY
207 rjmp handle_end
208
209 h_convert:
210 cpi r_bytep,0 ;erstes Adressbyte ?
211 brne h_convert_byte1 ;nein dann weiter
212 inc r_bytep
213 sts pack+0x20,r_rwbyte
214 ;ldi r_bcount,1
215 rjmp handle_end
216 h_convert_byte1: ;zweies byte glesen go crc#
217 sts pack+0x21,r_rwbyte
218 lds r_rwbyte,crc
219 com r_rwbyte
220 lds r_temp,crc+1
221 com r_temp
222 sts crcsave,r_temp
223 ldi r_mode,OW_CONVERT_CRC1
224 ;ldi r_bcount,1
225 ldi r_sendflag,1
226 rjmp handle_end
227 h_convertcrc1:
228 lds r_rwbyte,crcsave
229 ;ldi r_bcount,1
230 ldi r_mode,OW_CONVERT_CRC2
231 rjmp handle_end
232 h_convertcrc2:
233 ldi r_temp,1
234 sts gcontrol,r_temp
235 ;ldi r_bcount,1
236 ldi r_mode,OW_CONVERT_CONV
237 ;clr r_sendflag
238 ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling
239 h_convert_conv:
240 ldi r_bcount,0
241 ldi r_rwbyte,0
242 rjmp handle_end_no_bcount
243
244
245
246
247 #include "../common/OWPinInterrupt.s"
248 .end