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
47 ; Wegen Power Down Mode Widerherstellen der fallenden Flanke und disable von POWER DONW
48 SET_FALLING_RESET_SLEEP
52 ;schauen ob noch ein Bit in der Pipeline
55 lds r_sendflag,sendflag
58 ldi r_temp,~OWT_MIN_RESET
62 breq receive_bit ; sendflag=0 Slave empfaengt
64 send_bit: ; bit senden
65 ;nachstes bit vorbereiten
67 brne send_bit_no_handle ;noch bits da
68 rcall handle_byte ; neues Byte muss bearbeitet werden
70 breq send_bit_low_loop ; Nach dem Gelesen byte koennte gesendet werden muessen....
71 send_bit_no_handle: ;noch bits da
72 ldi r_temp2,0 ; fuer die CRC berechnung in CRCS
76 ldi r_temp2,1 ;WICHTIG fuer CRC berechnung
77 send_bit_no_low: ;ueberspringen von r_wzero=1 wenn leitung nicht auf 0 gezogen wird
82 rjmp iend ;abkuerzung wenn leitung nicht low
85 cpi r_temp,(~OWT_MIN_RESET)+OWT_WRITE ;aller zwei us zaehlt der timer
86 brlo send_bit_low_loop ;wenn kleiner
87 cbi OW_DDR,OW_PINN ;Leitung auf hochohmig
90 receive_bit: ;or reset
91 ;beim lesen zuerst zeit bis zum lesen abwarten
92 ;(9us nach den 6 us vom low impuls)
94 cpi r_temp,(~OWT_MIN_RESET)+OWT_READ ;aller zwei us zaehlt der timer
95 brlo receive_bit ;wenn kleiner
97 ldi r_temp2,1 ;fuer CRC Berechnung
101 ldi r_temp2,0 ;fuer CRC Berechnung
105 brne recive_bit_no_handle ;bcount nicht 0
109 brne send_bit ; Nach dem Gelesen byte koennte gesendet werden muessen....
110 recive_bit_no_handle:
112 #ifdef _ZERO_POLLING_
113 ;--------------------------------------- Polling for set low... for 4us low impuls of DS2490
114 TESTZEROMARKER ; ueberspringe wenn zeromarker=0
118 sbic OW_PIN,OW_PINN ;warten bis leitung wieder h
119 rjmp zeropolling_wait ;leitung ist low ->Schleie
121 cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_LOW_TO;aller zwei us zaehlt der timer
122 brsh zeropolling_timeout ;Timeout Reset?
125 sbis OW_PIN,OW_PINN ;warten bis leitung wieder l
126 rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe
128 cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_HIGH_TO ;aller zwei us zaehlt der timer
129 sbis OW_PIN,OW_PINN ;noch eine Abfrage, da sonst schleife zu lang (sbis aendert keine flags)
130 rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe
131 brlo zeropolling_wait
132 rjmp zeropolling_timeout
136 rjmp int_internal_start
145 CLEAR_INTERRUPT_FLAG ; wichtig falls inzwischen wider ein Interrupt aufgelaufen ist
146 sts sendflag,r_sendflag
154 cbi OW_DDR,OW_PINN ;vorsichtsmassname Nicht dauerhaft auf low
155 pop r_temp2 //; die benutzten Register wiederherstellen
156 out _SFR_IO_ADDR(SREG),r_temp2
173 ldi zl,lo8(pm(handle_stable))
174 ldi zh,hi8(pm(handle_stable))
176 #if ((handle_stable&0xFE00)!=(handle_stable_end&0xFE00))
185 rjmp handle_end_no_bcount
190 handle_end_no_bcount: