1 // Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
\r
2 // All rights reserved.
\r
4 // Redistribution and use in source and binary forms, with or without
\r
5 // modification, are permitted provided that the following conditions are
\r
8 // * Redistributions of source code must retain the above copyright
\r
9 // notice, this list of conditions and the following disclaimer.
\r
10 // * Redistributions in binary form must reproduce the above copyright
\r
11 // notice, this list of conditions and the following disclaimer in the
\r
12 // documentation and/or other materials provided with the
\r
14 // * All advertising materials mentioning features or use of this
\r
15 // software must display the following acknowledgement: This product
\r
16 // includes software developed by tm3d.de and its contributors.
\r
17 // * Neither the name of tm3d.de nor the names of its contributors may
\r
18 // be used to endorse or promote products derived from this software
\r
19 // without specific prior written permission.
\r
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\r
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
\r
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
\r
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
\r
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
34 #define _CHANGEABLE_ID_
\r
35 #define _ZERO_POLLING_
\r
36 #include "../common/OWConfig.s"
\r
37 #include "../common/OWCRC16.s"
\r
45 .macro COMMAND_TABLE
\r
46 rjmp h_writescratchpad
\r
47 rjmp h_writescratchpad_crc
\r
48 rjmp h_readscratchpad
\r
49 rjmp h_copyscratchpad
\r
50 rjmp h_readmemory_addr
\r
52 rjmp h_readmemorycounter_addr
\r
53 rjmp h_readmemorycounter
\r
54 rjmp h_readmemorycounter_ex
\r
57 #include "../common/OWRomFunctions.s"
\r
58 #include "../common/OWTimerInterrupt.s"
\r
62 ; Ab hier Geraeteabhaenging
\r
63 #define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+0
\r
64 #define OW_WRITE_SCRATCHPAD_CRC OW_FIRST_COMMAND+1
\r
65 #define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+2
\r
66 #define OW_COPY_SCRATCHPAD OW_FIRST_COMMAND+3
\r
67 #define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+4
\r
68 #define OW_READ_MEMORY OW_FIRST_COMMAND+5
\r
69 #define OW_READ_MEMORYCOUNTER_ADDR OW_FIRST_COMMAND+6
\r
70 #define OW_READ_MEMORYCOUNTER OW_FIRST_COMMAND+7
\r
71 #define OW_READ_MEMORYCOUNTER_EX OW_FIRST_COMMAND+8
\r
73 ;---------------------------------------------------
\r
74 ; READ COMMAND and start operation
\r
75 ;---------------------------------------------------
\r
81 FLASH_COMMANDS ; muss zu erst sein....
\r
83 cset 0x0F,OW_WRITE_SCRATCHPAD
\r
84 cjmp 0xAA,hrc_set_readscratchpad
\r
85 cset 0x5A,OW_COPY_SCRATCHPAD
\r
86 cset 0xF0,OW_READ_MEMORY_ADDR
\r
87 cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR
\r
89 #ifdef _CHANGEABLE_ID_
\r
95 hrc_set_readscratchpad:
\r
96 ldi r_mode,OW_READ_SCRATCHPAD
\r
98 rjmp h_readscratchpad
\r
101 configZ pack,r_bytep
\r
105 breq h_writescratchpad_block
\r
106 brsh h_writescratchpad_set_eoffset ;;33
\r
107 rjmp handle_end ;handle_end zu weit entfernt fuer br...
\r
108 h_writescratchpad_set_eoffset:
\r
110 breq h_writescratchpad_setcrc
\r
113 sts pack+2,r_temp ;AA und PF cleared
\r
115 ;Start writeing to 32 Byte Block ; skip status byte
\r
116 h_writescratchpad_block:
\r
117 lds r_temp,pack ; Adresse low byte
\r
118 andi r_temp,0x1F ;32 byte
\r
119 add r_bytep,r_temp ;Zur angegebenen Startadresse springen
\r
120 ;ori r_temp,0x20 ; Set PF flag
\r
121 sts pack+2,r_temp ;E4:E0 vorher setzen
\r
122 ; Byte 3 ueberspringen
\r
123 rjmp handle_end_inc
\r
125 h_writescratchpad_setcrc:
\r
131 com r_temp ; invertieren , komischer name.....
\r
133 ldi r_mode,OW_WRITE_SCRATCHPAD_CRC
\r
136 h_writescratchpad_crc:
\r
138 breq h_writescratchpad_crc_end
\r
139 configZ pack,r_bytep
\r
141 rjmp handle_end_inc
\r
142 h_writescratchpad_crc_end:
\r
143 rjmp handle_end_sleep
\r
148 breq h_readscratchpad_end
\r
150 brne h_readscratchpad_read_byte
\r
151 h_readscratchpad_set_offset:
\r
157 h_readscratchpad_read_byte:
\r
158 configZ pack,r_bytep
\r
160 rjmp handle_end_inc
\r
161 h_readscratchpad_end:
\r
162 rjmp handle_end_sleep
\r
168 brsh h_copyscratchpad_ok
\r
169 configZ pack,r_bytep
\r
173 brne h_copyscratchpad_nok
\r
175 breq h_copyscratchpad_ok
\r
178 h_copyscratchpad_ok:
\r
182 h_copyscratchpad_nok:
\r
186 rjmp handle_end_sleep
\r
191 brne h_readmrmory_addr_byte1
\r
193 rjmp handle_end_inc
\r
194 h_readmrmory_addr_byte1:
\r
195 sts pack+1,r_rwbyte
\r
196 ldi r_mode,OW_READ_MEMORY
\r
207 rjmp h_readmemory_end
\r
213 configZ pack+3,r_bytep
\r
217 rjmp handle_end_sleep
\r
226 h_readmemorycounter_addr:
\r
228 brne h_readmrmorycounter_addr_byte1
\r
233 h_readmrmorycounter_addr_byte1:
\r
234 sts pack+1,r_rwbyte
\r
235 ldi r_mode,OW_READ_MEMORYCOUNTER
\r
239 rjmp h_readmemorycounter2
\r
240 h_readmemorycounter:
\r
243 ldi r_temp,1 ;inc leider kein c flag
\r
249 breq h_readmemorycounter_next
\r
252 h_readmemorycounter2: ;Lesen von dem worauf die erstenzwei bytes zeigen
\r
255 configZ pack+3,r_bytep
\r
259 //h_readmemorycounter_end:
\r
260 // ldi r_mode,OW_SLEEP
\r
263 h_readmemorycounter_next: ; rest lesen
\r
264 ldi r_mode,OW_READ_MEMORYCOUNTER_EX
\r
274 brne h_readmemorycounter_cFF
\r
280 configZ counters,r_temp2
\r
282 sts pack+35,r_temp
\r
284 sts pack+36,r_temp
\r
286 sts pack+37,r_temp
\r
288 sts pack+38,r_temp
\r
289 rjmp h_readmemorycounter_ex
\r
290 h_readmemorycounter_cFF:
\r
292 sts pack+35,r_temp
\r
293 sts pack+36,r_temp
\r
294 sts pack+37,r_temp
\r
295 sts pack+38,r_temp
\r
297 h_readmemorycounter_ex:
\r
300 breq h_readmemorycounter_ex_end
\r
302 brne h_readmemorycounter_ex2
\r
309 h_readmemorycounter_ex2:
\r
311 configZ pack,r_bytep
\r
314 h_readmemorycounter_ex_end:
\r
317 ldi r_temp,1 ;inc leider kein c flag
\r
321 sbrc r_temp2,1 ;am ene von allem
\r
322 rjmp h_readmemorycounter_ex_sleep
\r
324 ldi r_mode,OW_READ_MEMORYCOUNTER
\r
327 rjmp h_readmemorycounter2
\r
328 h_readmemorycounter_ex_sleep:
\r
329 ldi r_mode,OW_SLEEP
\r
337 #include "../common/OWPinInterrupt.s"
\r