1 // Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the
14 // * All advertising materials mentioning features or use of this
15 // software must display the following acknowledgement: This product
16 // includes software developed by tm3d.de and its contributors.
17 // * Neither the name of tm3d.de nor the names of its contributors may
18 // be used to endorse or promote products derived from this software
19 // without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 ;leitung auf Low ziehen
37 TESTZEROMARKER ; ueberspringe wenn zeromarker=0 ;sbic und cbi/sbi andern SREG nicht
39 push r_temp2 //; wichtig: Benutzte Register und das
40 in r_temp2,_SFR_IO_ADDR(SREG) //; Status-Register (SREG) sichern!
43 ;Weitere Register sichern
46 ; Wegen Power Down Mode Widerherstellen der fallenden Flanke und disable von POWER DONW
47 SET_FALLING_RESET_SLEEP
51 ;schauen ob noch ein Bit in der Pipeline
54 lds r_sendflag,sendflag
57 ldi r_temp,~OWT_MIN_RESET
61 breq receive_bit ; sendflag=0 Slave empfaengt
63 send_bit: ; bit senden
64 ;nachstes bit vorbereiten
66 brne send_bit_no_handle ;noch bits da
67 rcall handle_byte ; neues Byte muss bearbeitet werden
69 breq send_bit_low_loop ; Nach dem Gelesen byte koennte gesendet werden muessen....
70 send_bit_no_handle: ;noch bits da
71 ldi r_temp2,0 ; fuer die CRC berechnung in CRCS
75 ldi r_temp2,1 ;WICHTIG fuer CRC berechnung
76 send_bit_no_low: ;ueberspringen von r_wzero=1 wenn leitung nicht auf 0 gezogen wird
81 rjmp iend ;abkuerzung wenn leitung nicht low
84 cpi r_temp,(~OWT_MIN_RESET)+OWT_WRITE ;aller zwei us zaehlt der timer
85 brlo send_bit_low_loop ;wenn kleiner
86 cbi OW_DDR,OW_PINN ;Leitung auf hochohmig
89 receive_bit: ;or reset
90 ;beim lesen zuerst zeit bis zum lesen abwarten
91 ;(9us nach den 6 us vom low impuls)
93 cpi r_temp,(~OWT_MIN_RESET)+OWT_READ ;aller zwei us zaehlt der timer
94 brlo receive_bit ;wenn kleiner
96 ldi r_temp2,1 ;fuer CRC Berechnung
100 ldi r_temp2,0 ;fuer CRC Berechnung
104 brne recive_bit_no_handle ;bcount nicht 0
108 brne send_bit ; Nach dem Gelesen byte koennte gesendet werden muessen....
109 recive_bit_no_handle:
111 #ifdef _ZERO_POLLING_
112 ;--------------------------------------- Polling for set low... for 4us low impuls of DS2490
113 TESTZEROMARKER ; ueberspringe wenn zeromarker=0
117 sbic OW_PIN,OW_PINN ;warten bis leitung wieder h
118 rjmp zeropolling_wait ;leitung ist low ->Schleie
120 cpi r_temp,(~OWT_MIN_RESET)+50;aller zwei us zaehlt der timer
121 brsh zeropolling_timeout ;Timeout Reset?
124 sbis OW_PIN,OW_PINN ;warten bis leitung wieder l
125 rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe
127 cpi r_temp,(~OWT_MIN_RESET)+70 ;aller zwei us zaehlt der timer
128 brsh zeropolling_timeout ;Timeout
129 rjmp zeropolling_wait
133 rjmp int_internal_start
142 CLEAR_INTERRUPT_FLAG ; wichtig falls inzwischen wider ein Interrupt aufgelaufen ist
143 sts sendflag,r_sendflag
151 cbi OW_DDR,OW_PINN ;vorsichtsmassname Nicht dauerhaft auf low
152 pop r_temp2 //; die benutzten Register wiederherstellen
153 out _SFR_IO_ADDR(SREG),r_temp2
170 ldi zl,lo8(pm(handle_stable))
171 ldi zh,hi8(pm(handle_stable))
173 #if ((handle_stable&0xFE00)!=(handle_stable_end&0xFE00))
182 rjmp handle_end_no_bcount
187 handle_end_no_bcount: