2 // Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
\r
3 // All rights reserved.
\r
5 // Redistribution and use in source and binary forms, with or without
\r
6 // modification, are permitted provided that the following conditions are
\r
9 // * Redistributions of source code must retain the above copyright
\r
10 // notice, this list of conditions and the following disclaimer.
\r
11 // * Redistributions in binary form must reproduce the above copyright
\r
12 // notice, this list of conditions and the following disclaimer in the
\r
13 // documentation and/or other materials provided with the
\r
15 // * All advertising materials mentioning features or use of this
\r
16 // software must display the following acknowledgement: This product
\r
17 // includes software developed by tm3d.de and its contributors.
\r
18 // * Neither the name of tm3d.de nor the names of its contributors may
\r
19 // be used to endorse or promote products derived from this software
\r
20 // without specific prior written permission.
\r
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\r
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
\r
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
\r
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
\r
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
34 #define _CHANGEABLE_ID_
\r
35 #define _ZERO_POLLING_
\r
36 #if defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny84A__)
\r
38 #define _NO_CONFIGBYTES_
\r
41 //#define _HANDLE_CC_COMMAND_
\r
44 #include "../common/OWConfig.s"
\r
45 #include "../common/OWCRC16.s"
\r
48 .extern counters1,16
\r
51 .extern counters2,16
\r
53 #define pack2 pack1
\r
54 ;same EEPROM for Attiny44
\r
56 .macro CHIP_INIT ;r_temp is pushed other Registers should be saved
\r
59 .macro COMMAND_TABLE
\r
60 rjmp h_writescratchpad1
\r
61 rjmp h_writescratchpad_crc1
\r
62 rjmp h_readscratchpad1
\r
63 rjmp h_copyscratchpad1
\r
64 rjmp h_readmemory_addr1
\r
66 rjmp h_readmemorycounter_addr1
\r
67 rjmp h_readmemorycounter1
\r
68 rjmp h_readmemorycounter_ex1
\r
70 rjmp h_writescratchpad2
\r
71 rjmp h_writescratchpad_crc2
\r
72 rjmp h_readscratchpad2
\r
73 rjmp h_copyscratchpad2
\r
74 rjmp h_readmemory_addr2
\r
76 rjmp h_readmemorycounter_addr2
\r
77 rjmp h_readmemorycounter2
\r
78 rjmp h_readmemorycounter_ex2
\r
81 #include "../common/OWRomFunctionsDual.s"
\r
82 #include "../common/OWTimerInterrupt.s"
\r
86 ; Ab hier Geraeteabhaenging
\r
87 #define OW_WRITE_SCRATCHPAD1 OW_FIRST_COMMAND+0
\r
88 #define OW_WRITE_SCRATCHPAD_CRC1 OW_FIRST_COMMAND+1
\r
89 #define OW_READ_SCRATCHPAD1 OW_FIRST_COMMAND+2
\r
90 #define OW_COPY_SCRATCHPAD1 OW_FIRST_COMMAND+3
\r
91 #define OW_READ_MEMORY_ADDR1 OW_FIRST_COMMAND+4
\r
92 #define OW_READ_MEMORY1 OW_FIRST_COMMAND+5
\r
93 #define OW_READ_MEMORYCOUNTER_ADDR1 OW_FIRST_COMMAND+6
\r
94 #define OW_READ_MEMORYCOUNTER1 OW_FIRST_COMMAND+7
\r
95 #define OW_READ_MEMORYCOUNTER_EX1 OW_FIRST_COMMAND+8
\r
97 #define OW_WRITE_SCRATCHPAD2 OW_FIRST_COMMAND+9
\r
98 #define OW_WRITE_SCRATCHPAD_CRC2 OW_FIRST_COMMAND+10
\r
99 #define OW_READ_SCRATCHPAD2 OW_FIRST_COMMAND+11
\r
100 #define OW_COPY_SCRATCHPAD2 OW_FIRST_COMMAND+12
\r
101 #define OW_READ_MEMORY_ADDR2 OW_FIRST_COMMAND+13
\r
102 #define OW_READ_MEMORY2 OW_FIRST_COMMAND+14
\r
103 #define OW_READ_MEMORYCOUNTER_ADDR2 OW_FIRST_COMMAND+15
\r
104 #define OW_READ_MEMORYCOUNTER2 OW_FIRST_COMMAND+16
\r
105 #define OW_READ_MEMORYCOUNTER_EX2 OW_FIRST_COMMAND+17
\r
108 ;---------------------------------------------------
\r
109 ; READ COMMAND and start operation
\r
110 ;---------------------------------------------------
\r
114 #ifndef _DIS_FLASH_
\r
115 FLASH_COMMANDS ; muss zu erst sein....
\r
117 cset 0x0F,OW_WRITE_SCRATCHPAD1
\r
118 cjmp 0xAA,hrc_set_readscratchpad1
\r
119 cset 0x5A,OW_COPY_SCRATCHPAD1
\r
120 cset 0xF0,OW_READ_MEMORY_ADDR1
\r
121 cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR1
\r
123 #ifdef _CHANGEABLE_ID_
\r
126 ldi r_mode,OW_SLEEP
\r
129 hrc_set_readscratchpad1:
\r
130 ldi r_mode,OW_READ_SCRATCHPAD1
\r
132 rjmp h_readscratchpad1
\r
134 h_writescratchpad1:
\r
135 configZ pack1,r_bytep
\r
139 breq h_writescratchpad_block1
\r
140 brsh h_writescratchpad_set_eoffset1 ;;33
\r
141 rjmp handle_end ;handle_end zu weit entfernt fuer br...
\r
142 h_writescratchpad_set_eoffset1:
\r
144 breq h_writescratchpad_setcrc1
\r
147 sts pack1+2,r_temp ;AA und PF cleared
\r
149 ;Start writeing to 32 Byte Block ; skip status byte
\r
150 h_writescratchpad_block1:
\r
151 lds r_temp,pack1 ; Adresse low byte
\r
152 andi r_temp,0x1F ;32 byte
\r
153 add r_bytep,r_temp ;Zur angegebenen Startadresse springen
\r
154 ;ori r_temp,0x20 ; Set PF flag
\r
155 sts pack1+2,r_temp ;E4:E0 vorher setzen
\r
156 ; Byte 3 ueberspringen
\r
157 rjmp handle_end_inc
\r
159 h_writescratchpad_setcrc1:
\r
163 sts pack1+43,r_temp
\r
165 com r_temp ; invertieren , komischer name.....
\r
166 sts pack1+44,r_temp
\r
167 ldi r_mode,OW_WRITE_SCRATCHPAD_CRC1
\r
170 h_writescratchpad_crc1:
\r
172 breq h_writescratchpad_crc_end1
\r
173 configZ pack1,r_bytep
\r
175 rjmp handle_end_inc
\r
176 h_writescratchpad_crc_end1:
\r
177 rjmp handle_end_sleep
\r
182 breq h_readscratchpad_end1
\r
184 brne h_readscratchpad_read_byte1
\r
185 h_readscratchpad_set_offset1:
\r
191 h_readscratchpad_read_byte1:
\r
192 configZ pack1,r_bytep
\r
194 rjmp handle_end_inc
\r
195 h_readscratchpad_end1:
\r
196 rjmp handle_end_sleep
\r
202 brsh h_copyscratchpad_ok1
\r
203 configZ pack1,r_bytep
\r
207 brne h_copyscratchpad_nok1
\r
209 breq h_copyscratchpad_ok1
\r
212 h_copyscratchpad_ok1:
\r
216 h_copyscratchpad_nok1:
\r
220 rjmp handle_end_sleep
\r
223 h_readmemory_addr1:
\r
225 brne h_readmrmory_addr_byte11
\r
227 rjmp handle_end_inc
\r
228 h_readmrmory_addr_byte11:
\r
229 sts pack1+1,r_rwbyte
\r
230 ldi r_mode,OW_READ_MEMORY1
\r
233 rjmp h_readmemory21
\r
236 lds r_temp2,pack1+1
\r
241 rjmp h_readmemory_end1
\r
247 configZ pack1+3,r_bytep
\r
251 rjmp handle_end_sleep
\r
260 h_readmemorycounter_addr1:
\r
262 brne h_readmrmorycounter_addr_byte11
\r
267 h_readmrmorycounter_addr_byte11:
\r
268 sts pack1+1,r_rwbyte
\r
269 ldi r_mode,OW_READ_MEMORYCOUNTER1
\r
273 rjmp h_readmemorycounter21
\r
274 h_readmemorycounter1:
\r
276 lds r_temp2,pack1+1
\r
277 ldi r_temp,1 ;inc leider kein c flag
\r
283 breq h_readmemorycounter_next1
\r
284 sts pack1+1,r_temp2
\r
286 h_readmemorycounter21: ;Lesen von dem worauf die erstenzwei bytes zeigen
\r
289 configZ pack1+3,r_bytep
\r
293 //h_readmemorycounter_end:
\r
294 // ldi r_mode,OW_SLEEP
\r
297 h_readmemorycounter_next1: ; rest lesen
\r
298 ldi r_mode,OW_READ_MEMORYCOUNTER_EX1
\r
305 brne h_readmemorycounter_cFF1
\r
311 configZ counters1,r_temp2
\r
313 sts pack1+35,r_temp
\r
315 sts pack1+36,r_temp
\r
317 sts pack1+37,r_temp
\r
319 sts pack1+38,r_temp
\r
320 rjmp h_readmemorycounter_ex1
\r
321 h_readmemorycounter_cFF1:
\r
323 sts pack1+35,r_temp
\r
324 sts pack1+36,r_temp
\r
325 sts pack1+37,r_temp
\r
326 sts pack1+38,r_temp
\r
328 h_readmemorycounter_ex1:
\r
331 breq h_readmemorycounter_ex_end1
\r
333 brne h_readmemorycounter_ex21
\r
336 sts pack1+43,r_temp
\r
339 sts pack1+44,r_temp
\r
340 h_readmemorycounter_ex21:
\r
342 configZ pack1,r_bytep
\r
345 h_readmemorycounter_ex_end1:
\r
347 lds r_temp2,pack1+1
\r
348 ldi r_temp,1 ;inc leider kein c flag
\r
352 sbrc r_temp2,1 ;am ene von allem
\r
353 rjmp h_readmemorycounter_ex_sleep1
\r
355 ldi r_mode,OW_READ_MEMORYCOUNTER1
\r
356 sts pack1+1,r_temp2
\r
358 rjmp h_readmemorycounter21
\r
359 h_readmemorycounter_ex_sleep1:
\r
360 ldi r_mode,OW_SLEEP
\r
367 ;*****************************************************************************************************************************************************************************************
\r
368 ;*****************************************************************************************************************************************************************************************
\r
369 ;*****************************************************************************************************************************************************************************************
\r
370 ;*****************************************************************************************************************************************************************************************
\r
371 ;*****************************************************************************************************************************************************************************************
\r
378 #ifndef _DIS_FLASH_
\r
379 FLASH_COMMANDS ; muss zu erst sein....
\r
381 cset 0x0F,OW_WRITE_SCRATCHPAD2
\r
382 cjmp 0xAA,hrc_set_readscratchpad2
\r
383 cset 0x5A,OW_COPY_SCRATCHPAD2
\r
384 cset 0xF0,OW_READ_MEMORY_ADDR2
\r
385 cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR2
\r
387 #ifdef _CHANGEABLE_ID_
\r
390 ldi r_mode,OW_SLEEP
\r
393 hrc_set_readscratchpad2:
\r
394 ldi r_mode,OW_READ_SCRATCHPAD2
\r
396 rjmp h_readscratchpad2
\r
398 h_writescratchpad2:
\r
399 configZ pack2,r_bytep
\r
403 breq h_writescratchpad_block2
\r
404 brsh h_writescratchpad_set_eoffset2 ;;33
\r
405 rjmp handle_end ;handle_end zu weit entfernt fuer br...
\r
406 h_writescratchpad_set_eoffset2:
\r
408 breq h_writescratchpad_setcrc2
\r
411 sts pack2+2,r_temp ;AA und PF cleared
\r
413 ;Start writeing to 32 Byte Block ; skip status byte
\r
414 h_writescratchpad_block2:
\r
415 lds r_temp,pack2 ; Adresse low byte
\r
416 andi r_temp,0x1F ;32 byte
\r
417 add r_bytep,r_temp ;Zur angegebenen Startadresse springen
\r
418 ;ori r_temp,0x20 ; Set PF flag
\r
419 sts pack2+2,r_temp ;E4:E0 vorher setzen
\r
420 ; Byte 3 ueberspringen
\r
421 rjmp handle_end_inc
\r
423 h_writescratchpad_setcrc2:
\r
427 sts pack2+43,r_temp
\r
429 com r_temp ; invertieren , komischer name.....
\r
430 sts pack2+44,r_temp
\r
431 ldi r_mode,OW_WRITE_SCRATCHPAD_CRC2
\r
434 h_writescratchpad_crc2:
\r
436 breq h_writescratchpad_crc_end2
\r
437 configZ pack2,r_bytep
\r
439 rjmp handle_end_inc
\r
440 h_writescratchpad_crc_end2:
\r
441 rjmp handle_end_sleep
\r
446 breq h_readscratchpad_end2
\r
448 brne h_readscratchpad_read_byte2
\r
449 h_readscratchpad_set_offset2:
\r
455 h_readscratchpad_read_byte2:
\r
456 configZ pack2,r_bytep
\r
458 rjmp handle_end_inc
\r
459 h_readscratchpad_end2:
\r
460 rjmp handle_end_sleep
\r
466 brsh h_copyscratchpad_ok2
\r
467 configZ pack2,r_bytep
\r
471 brne h_copyscratchpad_nok2
\r
473 breq h_copyscratchpad_ok2
\r
476 h_copyscratchpad_ok2:
\r
480 h_copyscratchpad_nok2:
\r
484 rjmp handle_end_sleep
\r
487 h_readmemory_addr2:
\r
489 brne h_readmrmory_addr_byte12
\r
491 rjmp handle_end_inc
\r
492 h_readmrmory_addr_byte12:
\r
493 sts pack2+1,r_rwbyte
\r
494 ldi r_mode,OW_READ_MEMORY2
\r
497 rjmp h_readmemory22
\r
500 lds r_temp2,pack2+1
\r
505 rjmp h_readmemory_end2
\r
511 configZ pack2+3,r_bytep
\r
515 rjmp handle_end_sleep
\r
524 h_readmemorycounter_addr2:
\r
526 brne h_readmrmorycounter_addr_byte12
\r
531 h_readmrmorycounter_addr_byte12:
\r
532 sts pack2+1,r_rwbyte
\r
533 ldi r_mode,OW_READ_MEMORYCOUNTER2
\r
537 rjmp h_readmemorycounter22
\r
538 h_readmemorycounter2:
\r
540 lds r_temp2,pack2+1
\r
541 ldi r_temp,1 ;inc leider kein c flag
\r
547 breq h_readmemorycounter_next2
\r
548 sts pack2+1,r_temp2
\r
550 h_readmemorycounter22: ;Lesen von dem worauf die erstenzwei bytes zeigen
\r
553 configZ pack2+3,r_bytep
\r
557 //h_readmemorycounter_end:
\r
558 // ldi r_mode,OW_SLEEP
\r
561 h_readmemorycounter_next2: ; rest lesen
\r
562 ldi r_mode,OW_READ_MEMORYCOUNTER_EX2
\r
572 brne h_readmemorycounter_cFF2
\r
578 configZ counters2,r_temp2
\r
580 sts pack2+35,r_temp
\r
582 sts pack2+36,r_temp
\r
584 sts pack2+37,r_temp
\r
586 sts pack2+38,r_temp
\r
587 rjmp h_readmemorycounter_ex2
\r
588 h_readmemorycounter_cFF2:
\r
590 sts pack2+35,r_temp
\r
591 sts pack2+36,r_temp
\r
592 sts pack2+37,r_temp
\r
593 sts pack2+38,r_temp
\r
595 h_readmemorycounter_ex2:
\r
598 breq h_readmemorycounter_ex_end2
\r
600 brne h_readmemorycounter_ex22
\r
603 sts pack2+43,r_temp
\r
606 sts pack2+44,r_temp
\r
607 h_readmemorycounter_ex22:
\r
609 configZ pack2,r_bytep
\r
612 h_readmemorycounter_ex_end2:
\r
614 lds r_temp2,pack2+1
\r
615 ldi r_temp,1 ;inc leider kein c flag
\r
619 sbrc r_temp2,1 ;am ene von allem
\r
620 rjmp h_readmemorycounter_ex_sleep2
\r
622 ldi r_mode,OW_READ_MEMORYCOUNTER2
\r
623 sts pack2+1,r_temp2
\r
625 rjmp h_readmemorycounter22
\r
626 h_readmemorycounter_ex_sleep2:
\r
627 ldi r_mode,OW_SLEEP
\r
634 #include "../common/OWPinInterrupt.s"
\r