Rename Files of different Devices
[owSlave2.git] / common / OWSet_ATTINYX5.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 __4M__
35
36 #define OW_PORT _SFR_IO_ADDR(PORTB) //1 Wire Port
37 #define OW_PIN _SFR_IO_ADDR(PINB) //1 Wire Pin as number
38 #define OW_PINN PORTB2
39 #define OW_DDR _SFR_IO_ADDR(DDRB)  //pin direction register
40 #define TCNT_REG _SFR_IO_ADDR(TCNT0)
41
42 #define DB_PORT _SFR_IO_ADDR(PORTB) //1 Wire Port
43 #define DB_PIN _SFR_IO_ADDR(PINB) //1 Wire Pin as number
44 #define DB_PINN PORTB1
45
46 #define SETZEROMARKER sbi _SFR_IO_ADDR(DDRB),5
47 #define RESETZEROMARKER cbi _SFR_IO_ADDR(DDRB),5
48 #define TESTZEROMARKER sbic _SFR_IO_ADDR(DDRB),5
49
50 ;#define sdb sbi _SFR_IO_ADDR(PORTB),1
51 ;#define cdb cbi _SFR_IO_ADDR(PORTB),1
52
53 #define TIMER_INTERRUPT TIM0_OVF_vect
54 #define PIN_INTERRIPT INT0_vect
55
56 #ifdef __4M__
57
58 #define OWT_MIN_RESET 70 
59 #define OWT_RESET2 40
60 #define OWT_RESET_PRESENT 15
61 #define OWT_PRESENT 50
62 #define OWT_WRITE 18
63 #define OWT_READ 5
64
65 #else
66
67 #define OWT_MIN_RESET 140
68 #define OWT_RESET2 80
69 #define OWT_RESET_PRESENT 30
70 #define OWT_PRESENT 130
71 #define OWT_WRITE 35
72 #define OWT_READ 12
73
74 #endif
75
76
77 .macro CLEAR_TOV_FLAG
78         ldi r_temp,(1<<TOV0)
79         out _SFR_IO_ADDR(TIFR),r_temp
80 .endm
81
82 .macro JMP_NO_TOV
83         in r_temp, _SFR_IO_ADDR(TIFR)
84         sbrc r_temp,TOV0 ; wenn ueberlauf gleiich weiter
85 .endm
86
87 .macro CLEAR_INTERRUPT_FLAG 
88         ldi r_temp,(1<<INTF0);inerrupt flags durch 1 loeschen..... 0 macht nix
89         out _SFR_IO_ADDR(GIFR),r_temp
90 .endm
91
92 .macro EN_TIM_INT
93         in r_temp,_SFR_IO_ADDR(TIMSK)
94         sbr r_temp,(1<<TOIE0)
95         out _SFR_IO_ADDR(TIMSK),r_temp
96         ldi r_temp,(1<<TOV0) ;inerrupt flags durch 1 loeschen..... 0 macht nix
97         out _SFR_IO_ADDR(TIFR),r_temp
98 .endm
99
100 .macro DIS_TIM_INT
101         in r_temp,_SFR_IO_ADDR(TIMSK)
102         cbr r_temp,(1<<TOIE0)
103         out _SFR_IO_ADDR(TIMSK),r_temp
104 .endm
105
106
107 .macro SET_FALLING
108         in r_temp,_SFR_IO_ADDR(MCUCR)
109         ori r_temp,(1<<ISC01)
110         out     _SFR_IO_ADDR(MCUCR),r_temp
111 .endm
112
113
114 .macro SET_FALLING_RESET_SLEEP
115         in r_temp,_SFR_IO_ADDR(MCUCR)
116         ori r_temp,(1<<ISC01)
117         andi r_temp,~(1<<SM1)
118         out     _SFR_IO_ADDR(MCUCR),r_temp
119 .endm
120
121
122 .macro HW_INIT
123         ;set clock to 8 MHz
124         ldi r_temp,0x80;
125         out _SFR_IO_ADDR(CLKPR),r_temp
126 #ifdef __4M__
127         ldi r_temp,(1<<CLKPS0)
128 #else
129         ldi r_temp,0
130 #endif
131         out _SFR_IO_ADDR(CLKPR),r_temp
132         ;Disable Timer int
133         ldi r_temp,0
134         out _SFR_IO_ADDR(TIMSK),r_temp ;; is default
135         ;Enable Pin int
136         ldi r_temp,(1<<INT0)
137         out _SFR_IO_ADDR(GIMSK),r_temp
138         ;Set Timerclock to Clock / 8 (2us)
139         ldi r_temp,(1<<CS01)
140         out _SFR_IO_ADDR(TCCR0B),r_temp
141         ;OWPin as input
142         cbi OW_DDR,OW_PINN ;; is default.... 
143         ;set falling edge
144         ldi r_temp,(1<<ISC01)
145         out _SFR_IO_ADDR(MCUCR),r_temp
146 .endm