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
35 .macro cjmp val,addr
\r
39 .macro cljmp val,addr; Weiter sprung, wenn das ziel zu weit entfernt fuer brxx
\r
46 .macro cset val,mod ;Nur der Mode wird gesetzt. Abkuerzung da oft nur das noch bleibt
\r
58 #define OW_READ_ROM_COMMAND 1
\r
59 #define OW_MATCHROM 2
\r
60 #define OW_SEARCHROMS 3 ;next send two bit
\r
61 #define OW_SEARCHROMR 4 ; next resive master answer
\r
62 #define OW_READ_COMMAND1 5
\r
63 #define OW_READ_COMMAND2 6
\r
64 #define OW_READ_COMMAND12 7 ;Skip ROM.... eigentlich nicht mit mehreren geraeten, aber bei loxone schon (CC 44)
\r
65 #define OW_FWCONFIGINFO1 8
\r
66 #define OW_FWCONFIGINFO2 9
\r
70 #ifdef _CHANGEABLE_ID_
\r
71 #define OW_WRITE_NEWID 10
\r
72 #define OW_READ_NEWID 11
\r
73 #define OW_SET_NEWID 12
\r
74 #define OW_FIRST_COMMAND 13
\r
78 .macro CHANGE_ID_COMMANDS
\r
79 cset 0x75,OW_WRITE_NEWID
\r
80 cljmp 0xA7,hrc_set_readid
\r
81 cljmp 0x79,hrc_set_setid
\r
86 #define OW_FIRST_COMMAND 10
\r
90 ; test auf run flasher command 0x88 in h_readcommand
\r
91 .macro FLASH_COMMANDS
\r
94 rjmp hrc_jmp_flasher
\r
95 1: ldi r_temp,0 ;Anderes Kommando flashmarker zuruecksetzen...
\r
96 sts flashmarker,r_temp
\r
101 .macro FW_CONFIG_INFO1
\r
102 cljmp 0x85,hrc_fw_configinfo1
\r
104 .macro FW_CONFIG_INFO2
\r
105 cljmp 0x85,hrc_fw_configinfo2
\r
108 #ifdef _CHANGEABLE_ID_
\r
109 ; lesen der ID aus dem EEPROM beim Start
\r
111 ldi r_temp2,lo8(E2END)
\r
114 out _SFR_IO_ADDR(EEARH), zh
\r
118 rjmp read_EEPROM_ID_loop
\r
120 ldi r_temp2,lo8(E2END)
\r
123 out _SFR_IO_ADDR(EEARH), zh
\r
127 read_EEPROM_ID_loop:
\r
128 sbic _SFR_IO_ADDR(EECR), EEPE
\r
129 rjmp read_EEPROM_ID_loop
\r
130 out _SFR_IO_ADDR(EEARL),r_temp2
\r
131 sbi _SFR_IO_ADDR(EECR), EERE
\r
132 in r_rwbyte,_SFR_IO_ADDR(EEDR)
\r
134 breq read_EEPROM_ID_end
\r
139 brne read_EEPROM_ID_loop
\r
140 read_EEPROM_ID_end:
\r
151 rjmp handle_end_no_bcount // sleep eventuell reset, nichts tun und auf Timeout warten
\r
152 rjmp h_readromcommand
\r
156 rjmp h_readcommand1
\r
157 rjmp h_readcommand2
\r
158 #ifdef _HANDLE_CC_COMMAND_
\r
159 rjmp h_readcommand12
\r
161 rjmp handle_end_no_bcount
\r
163 rjmp h_fwconfiginfo1
\r
164 rjmp h_fwconfiginfo2
\r
165 #ifdef _CHANGEABLE_ID_
\r
176 cjmp 0x55,hrc_set_matchrom
\r
177 cjmp 0xF0,hrc_set_searchrom
\r
178 cjmp 0xEC,hrc_set_alarm_search
\r
179 #ifdef _HANDLE_CC_COMMAND_
\r
180 cjmp 0xCC,hrc_start_read_command12
\r
182 rjmp handle_end_sleep
\r
184 #ifndef _DIS_FLASH_
\r
185 ;sprung zum flasher
\r
187 lds r_temp,flashmarker
\r
189 brne hrc_jmp_flasher_inc
\r
194 ret ; Direkter Sprung zum Bootloader
\r
195 hrc_jmp_flasher_inc:
\r
197 sts flashmarker,r_temp
\r
198 rjmp handle_end_sleep
\r
203 sts srbyte,r_temp ; Beide geraete nehmen an searchrom teil
\r
204 ldi r_mode,OW_MATCHROM
\r
209 hrc_set_searchrom:
\r
211 sts srbyte,r_temp ; Beide geraete nehmen an searchrom teil
\r
212 configZ idtable,r_bytep
\r
213 rjmp h_searchrom_next_bit
\r
215 hrc_start_read_command: ;Skip rom und Matchrom ok...
\r
218 breq hrc_start_read_command1
\r
220 breq hrc_start_read_command2
\r
221 rjmp handle_end_sleep
\r
223 hrc_start_read_command1:
\r
224 ldi r_mode,OW_READ_COMMAND1
\r
226 hrc_start_read_command2:
\r
227 ldi r_mode,OW_READ_COMMAND2
\r
230 #ifdef _HANDLE_CC_COMMAND_
\r
231 hrc_start_read_command12:
\r
232 ldi r_mode,OW_READ_COMMAND12
\r
236 hrc_set_alarm_search:
\r
237 lds r_temp,alarmflag
\r
239 brne hrc_set_searchrom ;alarm flag nicht 0 also gehe zu searchrom
\r
241 rjmp handle_end_sleep
\r
243 hrc_fw_configinfo1:
\r
244 ldi r_mode,OW_FWCONFIGINFO1
\r
247 rjmp h_fwconfiginfo1
\r
249 hrc_fw_configinfo2:
\r
250 ldi r_mode,OW_FWCONFIGINFO2
\r
253 rjmp h_fwconfiginfo2
\r
256 ;---------------------------------------------------
\r
258 ;---------------------------------------------------
\r
262 lds r_bcount,srbyte
\r
263 sbrs r_bcount,0 ;ueberspringe wenn bit 1 =0 also geraet 1 nich mehr im rennen
\r
264 rjmp h_matchrom_id2
\r
265 configZ owid1,r_bytep
\r
267 cp r_temp2,r_rwbyte
\r
268 breq h_matchrom_id2
\r
269 cbr r_bcount,1 ; loesche geraet
\r
270 breq h_matchrom_sleep
\r
272 configZ owid2,r_bytep
\r
274 cp r_temp2,r_rwbyte
\r
276 cbr r_bcount,2 ; loesche geraet
\r
277 breq h_matchrom_sleep
\r
280 sts srbyte,r_bcount
\r
282 breq hrc_start_read_command ;Starten von Read Command
\r
283 rjmp handle_end_inc
\r
286 sts srbyte,r_bcount
\r
287 rjmp handle_end_sleep
\r
290 ;---------------------------------------------------
\r
292 ;---------------------------------------------------
\r
295 h_searchrom_next_bit: ;Setup next Bit of ID
\r
297 lds r_temp,srbyte ;srbyte ist ein zeiger auf die bits fuer ein bit im Table
\r
298 h_searchrom_next_bit_l2:
\r
300 breq h_searchrom_next_bit_l1
\r
304 rjmp h_searchrom_next_bit_l2
\r
305 h_searchrom_next_bit_l1:
\r
307 rol r_rwbyte ; negiertes bit in rwbyte
\r
309 rol r_rwbyte ; bit in rwbyte
\r
311 ldi r_bcount,0x40 ; zwei bits sensden dann zu Searchromr
\r
312 ldi r_mode,OW_SEARCHROMR
\r
313 rjmp handle_end_no_bcount
\r
317 h_searchroms: ; Modus Send zwei bit
\r
318 configZ idtable,r_bytep
\r
322 breq h_searchroms_idd
\r
324 breq h_searchroms_id1
\r
326 breq h_searchroms_id2
\r
327 rjmp handle_end_sleep ; zur Sicherheit.....
\r
330 breq h_searchroms_idd_zero
\r
332 sbrc r_temp2,0 ;springe wenn nicht beide bits 0 (id 1 negiert und id 2 negiert)
\r
333 rjmp handle_end_sleep ;
\r
334 sbrc r_temp2,4 ;id1 set? then skip
\r
335 cbr r_temp,1 ; loesche bit 1 in srbyte
\r
336 sbrc r_temp2,2 ; springe wenn id 2 gesetzt ist
\r
337 cbr r_temp,2 ; loesche bit 2 in srbyte
\r
339 rjmp h_searchroms_idX_end
\r
340 h_searchroms_idd_zero:
\r
341 sbrc r_temp2,1 ;springe wenn nicht beide 1 (id 1 und id 2 )
\r
342 rjmp handle_end_sleep ;beide 1 gehe schlafen
\r
343 sbrs r_temp2,4 ;id1 0? then skip
\r
344 cbr r_temp,1 ; loesche bit 1 in srbyte
\r
345 sbrs r_temp2,2 ; springe wenn id 2 null ist
\r
346 cbr r_temp,2 ; loesche bit 2 in srbyte
\r
348 rjmp h_searchroms_idX_end
\r
351 breq h_searchroms_id1_zero
\r
353 sbrs r_temp2,5 ;id1 set? then skip
\r
354 rjmp handle_end_sleep ;
\r
355 rjmp h_searchroms_idX_end
\r
356 h_searchroms_id1_zero:
\r
357 sbrs r_temp2,4 ;id1 set? then skip
\r
358 rjmp handle_end_sleep ;
\r
359 rjmp h_searchroms_idX_end
\r
362 breq h_searchroms_id2_zero
\r
364 sbrs r_temp2,3 ;id1 set? then skip
\r
365 rjmp handle_end_sleep ;
\r
366 rjmp h_searchroms_idX_end
\r
367 h_searchroms_id2_zero:
\r
368 sbrs r_temp2,2 ;id1 set? then skip
\r
369 rjmp handle_end_sleep ;
\r
370 rjmp h_searchroms_idX_end
\r
371 h_searchroms_idX_end:
\r
374 brne h_searchroms_idX_end1
\r
375 rjmp handle_end_sleep
\r
376 h_searchroms_idX_end1:
\r
379 breq h_searchrom_end_ok ;unterschied nur das letzt bit wird wohl nie vorkommen
\r
380 rjmp h_searchrom_next_bit
\r
382 h_searchrom_end_ok:
\r
384 rjmp hrc_start_read_command
\r
386 h_searchromr: ; stelle um auf empfangen
\r
388 ldi r_mode,OW_SEARCHROMS
\r
389 ldi r_bcount,0 ;gehe nach einem bit zu SEARCHROMS
\r
390 rjmp handle_end_no_bcount
\r
393 ;---------------------------------------------------
\r
395 ;---------------------------------------------------
\r
398 configZ config_info1,r_bytep
\r
399 rjmp h_fwconfiginfo_go
\r
401 configZ config_info2,r_bytep
\r
405 breq h_fwconfiginfo_crc
\r
408 breq h_fwconfiginfo_all
\r
409 #elif defined _CRC16_
\r
411 breq h_fwconfiginfo_all
\r
414 breq h_fwconfiginfo_all
\r
415 #warning No CRC known code implemented
\r
417 h_fwconfiginfo_end:
\r
418 //configZ config_info1,r_bytep //crc16 wird in config_info1 gespeichert, auch bei config_info2
\r
420 rjmp handle_end_inc
\r
421 h_fwconfiginfo_crc:
\r
424 rjmp handle_end_inc
\r
425 #elif defined _CRC16_
\r
428 sts config_info1+24,r_temp
\r
431 sts config_info1+25,r_temp
\r
432 rjmp h_fwconfiginfo_end
\r
434 h_fwconfiginfo_all:
\r
435 rjmp handle_end_sleep
\r
438 ;---------------------------------------------------
\r
439 ; CHANGE ROM FUNCTIONS
\r
440 ;---------------------------------------------------
\r
443 #ifdef _CHANGEABLE_ID_
\r
446 configZ newid,r_bytep
\r
450 rjmp handle_end_inc
\r
452 rjmp handle_end_sleep
\r
456 ldi r_mode,OW_READ_NEWID
\r
461 configZ newid,r_bytep
\r
463 rjmp handle_end_inc
\r
466 rjmp handle_end_sleep
\r
469 ldi r_mode,OW_SET_NEWID
\r
470 ;ldi r_bytep,1 ;start to write in 2
\r
471 rjmp handle_end_inc ;set r_bytep to 1!!!
\r
474 lds r_bcount,srbyte
\r
478 configZ owid1,r_bytep
\r
481 configZ owid2,r_bytep
\r
485 brne h_setid_bad_code_all
\r
491 breq h_setid_copy_id
\r
492 rjmp h_setid_bad_code_all ;sollte eigentlich nicht passieren
\r
500 ldi r_temp2,lo8(E2END)
\r
506 ;ldi r_temp,0 ;kommt nicht vor das ein E2ROM genau n*256+(0 bis 7) byte gross ist
\r
508 out _SFR_IO_ADDR(EEARH),zh
\r
512 h_setid_EEPROM_write:
\r
513 sbic _SFR_IO_ADDR(EECR), EEPE
\r
514 rjmp h_setid_EEPROM_write
\r
515 ldi r_temp, (0<<EEPM1)|(0<<EEPM0)
\r
516 out _SFR_IO_ADDR(EECR), r_temp
\r
517 ;nur adresse L schreiben H bleibt aus oben genannten grund gleich.
\r
518 out _SFR_IO_ADDR(EEARL),r_temp2
\r
520 out _SFR_IO_ADDR(EEDR), r_rwbyte
\r
521 sbi _SFR_IO_ADDR(EECR), EEMPE
\r
522 sbi _SFR_IO_ADDR(EECR), EEPE
\r
526 brne h_setid_EEPROM_write
\r
527 //rcall read_EEPROM_ID1
\r
528 //rcall read_EEPROM_ID2
\r
538 h_setid_bad_code_all:
\r
539 rjmp handle_end_sleep
\r
557 #ifndef _DIS_FLASH_
\r
558 ; check for bootloader jumper
\r
559 ;vor allen anderen Registerconfigs
\r
562 ldi r_temp,(1<<PUD) ;enable pullup
\r
563 out _SFR_IO_ADDR(MCUCR) ,r_temp
\r
564 sbi _SFR_IO_ADDR(PORTA),PINA5 ;internal pullup on PINA5
\r
565 sbi _SFR_IO_ADDR(PORTA),PINA4 ;internal pullup on PINA4
\r
567 sbis _SFR_IO_ADDR(PINA),PINA5
\r
568 rjmp owinit_botest_end ;PinA5 nicht auf 1
\r
569 sbis _SFR_IO_ADDR(PINA),PINA4
\r
570 rjmp owinit_botest_end ;PinA4 nicht auf 1
\r
571 cbi _SFR_IO_ADDR(PORTA),PINA4
\r
572 sbi _SFR_IO_ADDR(DDRA),PINA4 ;PINA4 AUSGANG und 0
\r
574 sbic _SFR_IO_ADDR(PINA),PINA5
\r
575 rjmp owinit_botest_end ;PINA5 nicht 0.... nicht verbunden
\r
576 cbi _SFR_IO_ADDR(DDRA),PINA4
\r
581 ret ; Direkter Sprung zum Bootloader*/
\r
584 HW_INIT //Microcontroller specific
\r
585 CHIP_INIT //1-Wire device specific
\r
594 #ifdef _CHANGEABLE_ID_
\r
595 rcall read_EEPROM_ID1
\r
596 rcall read_EEPROM_ID2
\r
600 ldi zl,lo8(idtable)
\r
601 ldi zh,hi8(idtable)
\r
621 rol r_mode ;6. Bit id1
\r
623 rol r_mode ; 5. Bit id1negiert
\r
625 rol r_mode ;;4. Bit id2
\r
627 rol r_mode ;3. Bit id2 negiert
\r
629 rol r_mode ;zweites bit id1 und id2
\r
631 rol r_mode ;erstes bit id1 negiert und id2 negiert
\r
637 ;copy ids in config bytes
\r
640 ldi yl,lo8(config_info2+17)
\r
641 ldi yh,hi8(config_info2+17)
\r
647 brne owinit_cpconfig1
\r
650 ldi yl,lo8(config_info1+17)
\r
651 ldi yh,hi8(config_info1+17)
\r
657 brne owinit_cpconfig2
\r
663 sts alarmflag,r_temp
\r
674 .global EXTERN_SLEEP
\r
679 sts mode,r_temp ;SLEEP
\r
680 sts gcontrol,r_temp
\r
681 sts sendflag,r_temp
\r