-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the
-// distribution.
-// * All advertising materials mentioning features or use of this
-// software must display the following acknowledgement: This product
-// includes software developed by tm3d.de and its contributors.
-// * Neither the name of tm3d.de nor the names of its contributors may
-// be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-.global PIN_INTERRIPT
-PIN_INTERRIPT:
- ;leitung auf Low ziehen
- TESTZEROMARKER ; ueberspringe wenn zeromarker=0 ;sbic und cbi/sbi andern SREG nicht
- sbi OW_DDR,OW_PINN
- push r_temp2 //; wichtig: Benutzte Register und das
- in r_temp2,_SFR_IO_ADDR(SREG) //; Status-Register (SREG) sichern!
- ;Zeromarker loeschen
- RESETZEROMARKER
- ;Weitere Register sichern
- push r_temp2
- push r_temp
- sdb
- ; Wegen Power Down Mode Widerherstellen der fallenden Flanke und disable von POWER DONW
- SET_FALLING_RESET_SLEEP
- push r_bcount
- push r_rwbyte
- push r_sendflag
- ;schauen ob noch ein Bit in der Pipeline
- lds r_bcount,bcount
- lds r_rwbyte,rwbyte
- lds r_sendflag,sendflag
-int_internal_start:
- ;Timer zuruecksetzen
- ldi r_temp,~OWT_MIN_RESET
- out TCNT_REG,r_temp
- EN_TIM_INT
- tst r_sendflag
- breq receive_bit ; sendflag=0 Slave empfaengt
-
-send_bit: ; bit senden
- ;nachstes bit vorbereiten
- tst r_bcount
- brne send_bit_no_handle ;noch bits da
- rcall handle_byte ; neues Byte muss bearbeitet werden
- tst r_sendflag
- breq send_bit_low_loop ; Nach dem Gelesen byte koennte gesendet werden muessen....
-send_bit_no_handle: ;noch bits da
- ldi r_temp2,0 ; fuer die CRC berechnung in CRCS
- ror r_rwbyte
- brcs send_bit_no_low
- SETZEROMARKER
- ldi r_temp2,1 ;WICHTIG fuer CRC berechnung
-send_bit_no_low: ;ueberspringen von r_wzero=1 wenn leitung nicht auf 0 gezogen wird
- CRCS
- ;naechstes byte ....
- lsl r_bcount
- sbis OW_DDR,OW_PINN
- rjmp iend ;abkuerzung wenn leitung nicht low
-send_bit_low_loop:
- in r_temp,TCNT_REG
- cpi r_temp,(~OWT_MIN_RESET)+OWT_WRITE ;aller zwei us zaehlt der timer
- brlo send_bit_low_loop ;wenn kleiner
- cbi OW_DDR,OW_PINN ;Leitung auf hochohmig
- rjmp iend
-
-receive_bit: ;or reset
- ;beim lesen zuerst zeit bis zum lesen abwarten
- ;(9us nach den 6 us vom low impuls)
- in r_temp,TCNT_REG
- cpi r_temp,(~OWT_MIN_RESET)+OWT_READ ;aller zwei us zaehlt der timer
- brlo receive_bit ;wenn kleiner
- lsr r_rwbyte
- ldi r_temp2,1 ;fuer CRC Berechnung
- sbis OW_PIN,OW_PINN
- rjmp receive_bit_crc
- ori r_rwbyte,0x80
- ldi r_temp2,0 ;fuer CRC Berechnung
-receive_bit_crc:
- CRCR
- lsl r_bcount
- brne recive_bit_no_handle ;bcount nicht 0
- ;naechstes byte ....
- rcall handle_byte
- tst r_sendflag
- brne send_bit ; Nach dem Gelesen byte koennte gesendet werden muessen....
-recive_bit_no_handle:
-iend:
-#ifdef _ZERO_POLLING_
- ;--------------------------------------- Polling for set low... for 4us low impuls of DS2490
- TESTZEROMARKER ; ueberspringe wenn zeromarker=0
- rjmp zeropolling
- rjmp no_zerromaker
-zeropolling:
- sbic OW_PIN,OW_PINN ;warten bis leitung wieder h
- rjmp zeropolling_wait ;leitung ist low ->Schleie
- in r_temp,TCNT_REG
- cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_LOW_TO;aller zwei us zaehlt der timer
- brsh zeropolling_timeout ;Timeout Reset?
- rjmp zeropolling
-zeropolling_wait:
- sbis OW_PIN,OW_PINN ;warten bis leitung wieder l
- rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe
- in r_temp,TCNT_REG
- cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_HIGH_TO ;aller zwei us zaehlt der timer
- sbis OW_PIN,OW_PINN ;noch eine Abfrage, da sonst schleife zu lang (sbis aendert keine flags)
- rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe
- brlo zeropolling_wait
- rjmp zeropolling_timeout
-zeropolling_low_imp:
- sbi OW_DDR,OW_PINN
- RESETZEROMARKER
- rjmp int_internal_start
-
-zeropolling_timeout:
- //in r_temp,TCNT_REG
- //clr r_sendflag
- //RESETZEROMARKER
-
-no_zerromaker:
-#endif
- CLEAR_INTERRUPT_FLAG ; wichtig falls inzwischen wider ein Interrupt aufgelaufen ist
- sts sendflag,r_sendflag
- sts bcount,r_bcount
- sts rwbyte,r_rwbyte
- pop r_sendflag
- pop r_rwbyte
- pop r_bcount
- pop r_temp
- cdb
- cbi OW_DDR,OW_PINN ;vorsichtsmassname Nicht dauerhaft auf low
- pop r_temp2 //; die benutzten Register wiederherstellen
- out _SFR_IO_ADDR(SREG),r_temp2
- pop r_temp2
- reti
-
-
-
-
-handle_byte:
- push zl
- push zh
- push r_mode
- push r_bytep
- //cdb
- lds r_mode,mode
- lds r_bytep,bytep
-
-
- ldi zl,lo8(pm(handle_stable))
- ldi zh,hi8(pm(handle_stable))
- add zl,r_mode
-#if ((handle_stable&0xFE00)!=(handle_stable_end&0xFE00))
- ldi r_temp,0
- adc zh,r_temp
-#endif
- ijmp
-handle_end_sleep:
- clr r_bcount
- ldi r_mode,OW_SLEEP
- clr r_sendflag
- rjmp handle_end_no_bcount
-handle_end_inc:
- inc r_bytep
-handle_end:
- ldi r_bcount,1
-handle_end_no_bcount:
- sts mode,r_mode
- sts bytep,r_bytep
- //sdb
- pop r_bytep
- pop r_mode
- pop zh
- pop zl
- ret
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+// * Redistributions of source code must retain the above copyright \r
+// notice, this list of conditions and the following disclaimer. \r
+// * Redistributions in binary form must reproduce the above copyright \r
+// notice, this list of conditions and the following disclaimer in the \r
+// documentation and/or other materials provided with the \r
+// distribution. \r
+// * All advertising materials mentioning features or use of this \r
+// software must display the following acknowledgement: This product \r
+// includes software developed by tm3d.de and its contributors. \r
+// * Neither the name of tm3d.de nor the names of its contributors may \r
+// be used to endorse or promote products derived from this software \r
+// without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+ \r
+.global PIN_INTERRIPT \r
+PIN_INTERRIPT:\r
+ ;leitung auf Low ziehen\r
+ TESTZEROMARKER ; ueberspringe wenn zeromarker=0 ;sbic und cbi/sbi andern SREG nicht\r
+ sbi OW_DDR,OW_PINN \r
+ push r_temp2 //; wichtig: Benutzte Register und das\r
+ in r_temp2,_SFR_IO_ADDR(SREG) //; Status-Register (SREG) sichern!\r
+ ;Zeromarker loeschen\r
+ RESETZEROMARKER \r
+ ;Weitere Register sichern\r
+ push r_temp2 \r
+ push r_temp\r
+ sdb\r
+ ; Wegen Power Down Mode Widerherstellen der fallenden Flanke und disable von POWER DONW \r
+ SET_FALLING_RESET_SLEEP\r
+ push r_bcount\r
+ push r_rwbyte\r
+ push r_sendflag\r
+ ;schauen ob noch ein Bit in der Pipeline \r
+ lds r_bcount,bcount\r
+ lds r_rwbyte,rwbyte\r
+ lds r_sendflag,sendflag\r
+int_internal_start:\r
+ ;Timer zuruecksetzen\r
+ ldi r_temp,~OWT_MIN_RESET\r
+ out TCNT_REG,r_temp\r
+ EN_TIM_INT\r
+ tst r_sendflag\r
+ breq receive_bit ; sendflag=0 Slave empfaengt\r
+\r
+send_bit: ; bit senden\r
+ ;nachstes bit vorbereiten\r
+ tst r_bcount\r
+ brne send_bit_no_handle ;noch bits da \r
+ rcall handle_byte ; neues Byte muss bearbeitet werden\r
+ tst r_sendflag \r
+ breq send_bit_low_loop ; Nach dem Gelesen byte koennte gesendet werden muessen....\r
+send_bit_no_handle: ;noch bits da\r
+ ldi r_temp2,0 ; fuer die CRC berechnung in CRCS\r
+ ror r_rwbyte\r
+ brcs send_bit_no_low\r
+ SETZEROMARKER\r
+ ldi r_temp2,1 ;WICHTIG fuer CRC berechnung\r
+send_bit_no_low: ;ueberspringen von r_wzero=1 wenn leitung nicht auf 0 gezogen wird\r
+ CRCS\r
+ ;naechstes byte ....\r
+ lsl r_bcount\r
+ sbis OW_DDR,OW_PINN\r
+ rjmp iend ;abkuerzung wenn leitung nicht low\r
+send_bit_low_loop:\r
+ in r_temp,TCNT_REG\r
+ cpi r_temp,(~OWT_MIN_RESET)+OWT_WRITE ;aller zwei us zaehlt der timer\r
+ brlo send_bit_low_loop ;wenn kleiner \r
+ cbi OW_DDR,OW_PINN ;Leitung auf hochohmig \r
+ rjmp iend\r
+\r
+receive_bit: ;or reset \r
+ ;beim lesen zuerst zeit bis zum lesen abwarten \r
+ ;(9us nach den 6 us vom low impuls) \r
+ in r_temp,TCNT_REG\r
+ cpi r_temp,(~OWT_MIN_RESET)+OWT_READ ;aller zwei us zaehlt der timer\r
+ brlo receive_bit ;wenn kleiner \r
+ lsr r_rwbyte \r
+ ldi r_temp2,1 ;fuer CRC Berechnung\r
+ sbis OW_PIN,OW_PINN\r
+ rjmp receive_bit_crc\r
+ ori r_rwbyte,0x80\r
+ ldi r_temp2,0 ;fuer CRC Berechnung\r
+receive_bit_crc:\r
+ CRCR\r
+ lsl r_bcount\r
+ brne recive_bit_no_handle ;bcount nicht 0\r
+ ;naechstes byte ....\r
+ rcall handle_byte\r
+ tst r_sendflag \r
+ brne send_bit ; Nach dem Gelesen byte koennte gesendet werden muessen....\r
+recive_bit_no_handle: \r
+iend:\r
+#ifdef _ZERO_POLLING_\r
+ ;--------------------------------------- Polling for set low... for 4us low impuls of DS2490\r
+ TESTZEROMARKER ; ueberspringe wenn zeromarker=0 \r
+ rjmp zeropolling\r
+ rjmp no_zerromaker\r
+zeropolling:\r
+ sbrc r_sendflag,1 ; sendflag bit 1 -> switch off zeropolling in software eg for asking convert is donne (DS2450, DS18B20 and others)\r
+ rjmp no_zerromaker\r
+zeropolling_h_loop:\r
+ sbic OW_PIN,OW_PINN ;warten bis leitung wieder h \r
+ rjmp zeropolling_wait ;leitung ist low ->Schleie\r
+ in r_temp,TCNT_REG\r
+ cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_LOW_TO;aller zwei us zaehlt der timer\r
+ brsh zeropolling_timeout ;Timeout Reset?\r
+ rjmp zeropolling_h_loop\r
+zeropolling_wait:\r
+ sbis OW_PIN,OW_PINN ;warten bis leitung wieder l\r
+ rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe\r
+ in r_temp,TCNT_REG\r
+ cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_HIGH_TO ;aller zwei us zaehlt der timer\r
+ sbis OW_PIN,OW_PINN ;noch eine Abfrage, da sonst schleife zu lang (sbis aendert keine flags)\r
+ rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe\r
+ brlo zeropolling_wait\r
+ rjmp zeropolling_timeout \r
+zeropolling_low_imp:\r
+ sbi OW_DDR,OW_PINN \r
+ RESETZEROMARKER \r
+ rjmp int_internal_start\r
+\r
+zeropolling_timeout:\r
+ //in r_temp,TCNT_REG\r
+ //clr r_sendflag\r
+ //RESETZEROMARKER \r
+\r
+no_zerromaker: \r
+#endif\r
+ CLEAR_INTERRUPT_FLAG ; wichtig falls inzwischen wider ein Interrupt aufgelaufen ist\r
+ sts sendflag,r_sendflag\r
+ sts bcount,r_bcount\r
+ sts rwbyte,r_rwbyte\r
+ pop r_sendflag\r
+ pop r_rwbyte\r
+ pop r_bcount\r
+ pop r_temp\r
+ cdb\r
+ cbi OW_DDR,OW_PINN ;vorsichtsmassname Nicht dauerhaft auf low\r
+ pop r_temp2 //; die benutzten Register wiederherstellen\r
+ out _SFR_IO_ADDR(SREG),r_temp2\r
+ pop r_temp2\r
+ reti\r
+\r
+\r
+\r
+\r
+handle_byte:\r
+ push zl\r
+ push zh\r
+ push r_mode\r
+ push r_bytep\r
+ //cdb\r
+ lds r_mode,mode\r
+ lds r_bytep,bytep\r
+\r
+\r
+ ldi zl,lo8(pm(handle_stable)) \r
+ ldi zh,hi8(pm(handle_stable)) \r
+ add zl,r_mode\r
+#if ((handle_stable&0xFE00)!=(handle_stable_end&0xFE00))\r
+ ldi r_temp,0 \r
+ adc zh,r_temp\r
+#endif\r
+ ijmp \r
+handle_end_sleep:\r
+ clr r_bcount\r
+ ldi r_mode,OW_SLEEP\r
+ clr r_sendflag\r
+ rjmp handle_end_no_bcount\r
+handle_end_inc:\r
+ inc r_bytep\r
+handle_end:\r
+ ldi r_bcount,1\r
+handle_end_no_bcount:\r
+ sts mode,r_mode\r
+ sts bytep,r_bytep\r
+ //sdb\r
+ pop r_bytep\r
+ pop r_mode\r
+ pop zh\r
+ pop zl\r
+ ret\r