Rename Files of different Devices
[owSlave2.git] / DS2423 / OWDS2423.S
1
2 // Copyright (c) 2015, 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 #include "../common/OWConfig.s"
36 #include "../common/OWCRC16.s"
37
38 .extern pack,45
39 .extern counters,8
40
41 .macro CHIP_INIT        
42 .endm
43
44 .macro COMMAND_TABLE
45                 rjmp h_writescratchpad
46                 rjmp h_writescratchpad_crc
47                 rjmp h_readscratchpad
48                 rjmp h_copyscratchpad
49                 rjmp h_readmemory_addr
50                 rjmp h_readmemory
51                 rjmp h_readmemorycounter_addr
52                 rjmp h_readmemorycounter
53                 rjmp h_readmemorycounter_ex
54 .endm
55
56 #include "../common/OWRomFunctions.s"
57 #include "../common/OWTimerInterrupt.s"
58
59
60
61 ; Ab hier Geraeteabhaenging
62 #define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+0
63 #define OW_WRITE_SCRATCHPAD_CRC OW_FIRST_COMMAND+1
64 #define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+2
65 #define OW_COPY_SCRATCHPAD OW_FIRST_COMMAND+3
66 #define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+4
67 #define OW_READ_MEMORY OW_FIRST_COMMAND+5
68 #define OW_READ_MEMORYCOUNTER_ADDR OW_FIRST_COMMAND+6
69 #define OW_READ_MEMORYCOUNTER OW_FIRST_COMMAND+7
70 #define OW_READ_MEMORYCOUNTER_EX OW_FIRST_COMMAND+8
71
72 ;---------------------------------------------------
73 ;       READ COMMAND and start operation
74 ;---------------------------------------------------
75
76
77 h_readcommand:
78         clr r_bytep
79 #ifndef _DIS_FLASH_
80         FLASH_COMMANDS ; muss zu erst sein....
81 #endif
82         cset 0x0F,OW_WRITE_SCRATCHPAD
83         cjmp 0xAA,hrc_set_readscratchpad
84         cset 0x5A,OW_COPY_SCRATCHPAD
85         cset 0xF0,OW_READ_MEMORY_ADDR
86         cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR
87         FW_CONFIG_INFO
88 #ifdef _CHANGEABLE_ID_
89         CHANGE_ID_COMMANDS
90 #endif
91         ldi r_mode,OW_SLEEP
92         rjmp handle_end
93
94 hrc_set_readscratchpad:
95         ldi r_mode,OW_READ_SCRATCHPAD
96         ldi r_sendflag,1
97         rjmp h_readscratchpad
98
99 h_writescratchpad:
100         configZ pack,r_bytep
101         inc  r_bytep
102         st   Z,r_rwbyte
103         cpi  r_bytep,2
104         breq h_writescratchpad_block
105         brsh h_writescratchpad_set_eoffset ;;33
106         rjmp handle_end  ;handle_end zu weit entfernt fuer br...
107 h_writescratchpad_set_eoffset:
108         cpi  r_bytep,35
109         breq h_writescratchpad_setcrc
110         mov r_temp,r_bytep
111         subi r_temp,4
112         sts pack+2,r_temp ;AA und PF cleared
113         rjmp handle_end
114 ;Start writeing to 32 Byte Block ; skip status byte     
115 h_writescratchpad_block:
116         lds r_temp,pack ; Adresse low byte
117         andi r_temp,0x1F ;32 byte
118         add r_bytep,r_temp ;Zur angegebenen Startadresse springen
119         ;ori r_temp,0x20 ; Set PF flag
120         sts pack+2,r_temp  ;E4:E0 vorher setzen
121         ; Byte 3 ueberspringen
122         rjmp handle_end_inc
123
124 h_writescratchpad_setcrc:
125         ;copy crc to pack
126         lds r_temp,crc
127         com r_temp
128         sts pack+43,r_temp
129         lds r_temp,crc+1
130         com r_temp ; invertieren , komischer name.....
131         sts pack+44,r_temp
132         ldi  r_mode,OW_WRITE_SCRATCHPAD_CRC
133         ldi r_sendflag,1
134         ldi r_bytep,43
135 h_writescratchpad_crc:
136         cpi r_bytep,45
137         breq h_writescratchpad_crc_end
138         configZ pack,r_bytep
139         ld r_rwbyte,Z
140         rjmp handle_end_inc
141 h_writescratchpad_crc_end:
142         rjmp handle_end_sleep
143         
144         
145 h_readscratchpad:
146         cpi r_bytep,35
147         breq h_readscratchpad_end
148         cpi r_bytep,3
149         brne h_readscratchpad_read_byte
150 h_readscratchpad_set_offset:
151         lds r_temp,pack
152         andi r_temp,0x1F
153         ldi r_temp2,3
154         add r_temp,r_temp2
155         mov r_bytep,r_temp
156 h_readscratchpad_read_byte:
157         configZ pack,r_bytep
158         ld r_rwbyte,Z
159         rjmp handle_end_inc
160 h_readscratchpad_end:
161         rjmp handle_end_sleep
162
163
164
165 h_copyscratchpad:
166         cpi  r_bytep,3
167         brsh h_copyscratchpad_ok
168         configZ pack,r_bytep
169         inc  r_bytep
170         ld   r_temp,Z
171         cp r_temp,r_rwbyte
172         brne h_copyscratchpad_nok
173         cpi  r_bytep,3
174         breq h_copyscratchpad_ok
175         ldi  r_bcount,1 
176         rjmp handle_end
177 h_copyscratchpad_ok:
178         ldi r_rwbyte,0xAA
179         ldi r_sendflag,1
180         rjmp handle_end
181 h_copyscratchpad_nok:
182         lds r_temp,pack+3
183         andi r_temp,~0x80
184         sts pack+3,r_temp
185         rjmp handle_end_sleep
186
187
188 h_readmemory_addr:
189         cpi r_bytep,0
190         brne h_readmrmory_addr_byte1
191         sts pack,r_rwbyte
192         rjmp handle_end_inc
193 h_readmrmory_addr_byte1:
194         sts pack+1,r_rwbyte
195         ldi r_mode,OW_READ_MEMORY
196         ldi r_sendflag,1
197         clr r_bytep
198         rjmp h_readmemory2
199 h_readmemory:
200         lds r_bytep,pack
201         lds r_temp2,pack+1
202         inc r_bytep
203         clr r_temp
204         adc r_temp2,r_temp
205         sbrc r_temp2,1
206         rjmp h_readmemory_end
207         sts pack+1,r_temp
208         sts pack,r_bytep
209 h_readmemory2:
210         lds r_bytep,pack
211         andi r_bytep,0x1F
212         configZ pack+3,r_bytep
213         ld   r_rwbyte,Z
214         rjmp handle_end
215 h_readmemory_end:
216         rjmp handle_end_sleep
217
218
219
220
221
222
223
224
225 h_readmemorycounter_addr:
226         cpi r_bytep,0
227         brne h_readmrmorycounter_addr_byte1
228         sts pack,r_rwbyte
229         inc r_bytep
230         ;ldi r_bcount,1
231         rjmp handle_end
232 h_readmrmorycounter_addr_byte1:
233         sts pack+1,r_rwbyte
234         ldi r_mode,OW_READ_MEMORYCOUNTER
235         ;ldi r_bcount,1 
236         ldi r_sendflag,1
237         clr r_bytep
238         rjmp h_readmemorycounter2
239 h_readmemorycounter:
240         lds r_bytep,pack
241         lds r_temp2,pack+1
242         ldi r_temp,1  ;inc leider kein c flag
243         add r_bytep,r_temp
244         clr r_temp
245         adc r_temp2,r_temp
246         mov r_temp,r_bytep
247         andi r_temp,0x1F
248         breq h_readmemorycounter_next
249         sts pack+1,r_temp2
250         sts pack,r_bytep
251 h_readmemorycounter2:  ;Lesen von dem worauf die erstenzwei bytes zeigen
252         lds r_bytep,pack
253         andi r_bytep,0x1F
254         configZ pack+3,r_bytep
255         ld   r_rwbyte,Z
256         ;ldi r_bcount,1
257         rjmp handle_end
258 //h_readmemorycounter_end:
259 //      ldi  r_mode,OW_SLEEP
260 //      clr r_sendflag
261 //      rjmp handle_end
262 h_readmemorycounter_next:  ; rest lesen
263         ldi  r_mode,OW_READ_MEMORYCOUNTER_EX
264         ldi r_bytep,34
265         lds r_temp2,pack
266         lds r_temp,pack+1
267         //lsr r_temp
268         //ror r_temp2
269
270         lsl r_temp2
271         rol r_temp
272         cpi r_temp,3
273         brne h_readmemorycounter_cFF
274         andi r_temp2,0xC0
275         swap r_temp2
276
277         ;cpi r_temp,0xE0
278
279         configZ counters,r_temp2
280         ld r_temp,Z+
281         sts pack+35,r_temp      
282         ld r_temp,Z+
283         sts pack+36,r_temp      
284         ld r_temp,Z+
285         sts pack+37,r_temp      
286         ld r_temp,Z+
287         sts pack+38,r_temp      
288         rjmp h_readmemorycounter_ex
289 h_readmemorycounter_cFF:
290         ldi r_temp,0xFF
291         sts pack+35,r_temp      
292         sts pack+36,r_temp      
293         sts pack+37,r_temp      
294         sts pack+38,r_temp      
295
296 h_readmemorycounter_ex:
297         inc r_bytep
298         cpi r_bytep,45
299         breq h_readmemorycounter_ex_end
300         cpi r_bytep,43
301         brne h_readmemorycounter_ex2
302         lds r_temp,crc
303         com r_temp
304         sts pack+43,r_temp
305         lds r_temp,crc+1
306         com r_temp
307         sts pack+44,r_temp
308 h_readmemorycounter_ex2:
309         ;ldi r_bcount,1
310         configZ pack,r_bytep
311         ld   r_rwbyte,Z
312         rjmp handle_end
313 h_readmemorycounter_ex_end:
314         lds r_bytep,pack
315         lds r_temp2,pack+1
316         ldi r_temp,1  ;inc leider kein c flag
317         add r_bytep,r_temp
318         clr r_temp
319         adc r_temp2,r_temp
320         sbrc r_temp2,1 ;am ene von allem 
321         rjmp h_readmemorycounter_ex_sleep
322         CRCInit1
323         ldi  r_mode,OW_READ_MEMORYCOUNTER
324         sts pack+1,r_temp2
325         sts pack,r_bytep
326         rjmp h_readmemorycounter2
327 h_readmemorycounter_ex_sleep:
328         ldi r_mode,OW_SLEEP
329         clr r_sendflag
330         rjmp handle_end
331
332
333
334         
335
336 #include "../common/OWPinInterrupt.s"
337 .end