Change Time Values so it works for all Adapters
[owSlave2.git] / common / OWSet_ATTINYX4.s
1 // Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
2 // All rights reserved. 
3 // 
4 // Redistribution and use in source and binary forms, with or without 
5 // modification, are permitted provided that the following conditions are 
6 // met: 
7 // 
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 
13 //    distribution. 
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. 
20 // 
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. 
32
33
34 #define OW_PORT _SFR_IO_ADDR(PORTB) //1 Wire Port
35 #define OW_PIN _SFR_IO_ADDR(PINB) //1 Wire Pin as number
36 #define OW_PINN PORTB2
37 #define OW_DDR _SFR_IO_ADDR(DDRB)  //pin direction register
38 #define TCNT_REG _SFR_IO_ADDR(TCNT0)
39
40
41 #define DB_PORT _SFR_IO_ADDR(PORTB) //DEBUG
42 #define DB_PIN _SFR_IO_ADDR(PINB) //DEBUG
43 #define DB_DDR _SFR_IO_ADDR(DDRB) //DEBUG
44 #define DB_PINN PORTB1
45
46 #define SETZEROMARKER sbi _SFR_IO_ADDR(DDRB),3
47 #define RESETZEROMARKER cbi _SFR_IO_ADDR(DDRB),3
48 #define TESTZEROMARKER sbic _SFR_IO_ADDR(DDRB),3
49
50 #ifdef _DB_
51 #define sdb sbi _SFR_IO_ADDR(PORTB),DB_PINN
52 #define cdb cbi _SFR_IO_ADDR(PORTB),DB_PINN
53 #else
54 #define sdb
55 #define cdb
56 #endif
57
58 #define TIMER_INTERRUPT TIM0_OVF_vect
59 #define PIN_INTERRIPT EXT_INT0_vect
60
61
62 //#define OWT_MIN_RESET 160 
63 //#define OWT_RESET2 40
64 //#define OWT_RESET_PRESENT 15
65 //#define OWT_PRESENT 50
66 //#define OWT_WRITE 18
67 //#define OWT_READ 4
68
69 #define OWT_MIN_RESET 180
70 #define OWT_RESET2 80
71 #define OWT_RESET_PRESENT 30
72 #define OWT_PRESENT 130
73 #define OWT_WRITE 35
74 #define OWT_READ 12
75 #define OWT_ZP_WAIT_LOW_TO 60  ; Zeit fuer die Maximale Lowzeit bei der Zerro Polling pruefung. Ist die Leitung laenger low, ist es vieleicht ein Reset 
76 #define OWT_ZP_WAIT_HIGH_TO 90 ; Zeit fuer die Maximale Hight zeit bis zu einem Low Impuls vom Master. Nach laengeren Pausen wird nicht mehr gepollt sondern der Interrup vererndet.
77
78
79 .macro CLEAR_TOV_FLAG
80         ldi r_temp,1
81         out _SFR_IO_ADDR(TIFR0),r_temp
82 .endm
83
84 .macro JMP_NO_TOV
85         in r_temp, _SFR_IO_ADDR(TIFR0)
86         sbrc r_temp,TOV0 ; wenn ueberlauf gleiich weiter
87 .endm
88
89 .macro CLEAR_INTERRUPT_FLAG 
90         ldi r_temp,(1<<INTF0);inerrupt flags durch 1 loeschen..... 0 macht nix
91         out _SFR_IO_ADDR(GIFR),r_temp
92 .endm
93
94 .macro EN_TIM_INT
95         in r_temp,_SFR_IO_ADDR(TIMSK0)
96         sbr r_temp,(1<<TOIE0)
97         out _SFR_IO_ADDR(TIMSK0),r_temp
98         ldi r_temp,(1<<TOV0) ;inerrupt flags durch 1 loeschen..... 0 macht nix
99         out _SFR_IO_ADDR(TIFR0),r_temp
100 .endm
101
102 .macro DIS_TIM_INT
103         in r_temp,_SFR_IO_ADDR(TIMSK0)
104         cbr r_temp,(1<<TOIE0)
105         out _SFR_IO_ADDR(TIMSK0),r_temp
106 .endm
107
108 .macro SET_FALLING_RESET_SLEEP
109         in r_temp,_SFR_IO_ADDR(MCUCR)
110         ori r_temp,(1<<ISC01)
111         andi r_temp,~(1<<SM1)
112         out     _SFR_IO_ADDR(MCUCR),r_temp
113 .endm
114
115 .macro HW_INIT
116         ;set clock to 8 MHz
117         ldi r_temp,0x80;
118         out _SFR_IO_ADDR(CLKPR),r_temp
119         //ldi r_temp,(1<<CLKPS0)
120         ldi r_temp,0
121         out _SFR_IO_ADDR(CLKPR),r_temp
122         ;Disable Timer int
123         ldi r_temp,0
124         out _SFR_IO_ADDR(TIMSK0),r_temp ;; is default
125         ;Enable Pin int
126         ldi r_temp,(1<<INT0)
127         out _SFR_IO_ADDR(GIMSK),r_temp
128         ;Set Timerclock to Clock / 8 (2us bei 4MHz) bzw 1us bei 8 MHz
129         ldi r_temp,(1<<CS01)
130         out _SFR_IO_ADDR(TCCR0B),r_temp
131         ;OWPin as input
132         cbi OW_DDR,OW_PINN ;; is default.... 
133         cbi OW_PORT,OW_PINN ;; vereinfachung im Hauptprogram (PORTB=0xFF) wegen pullup
134         ;set falling edge
135         ldi r_temp,(1<<ISC01)
136         out _SFR_IO_ADDR(MCUCR),r_temp
137 #ifdef _DB_
138         sbi DB_DDR,DB_PINN
139 #endif
140 .endm
141
142
143