Many changes from 2018
[owSlave2.git] / common / OWDS2450.S
1
2 // Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the
14 // distribution.
15 // * All advertising materials mentioning features or use of this
16 // software must display the following acknowledgement: This product
17 // includes software developed by tm3d.de and its contributors.
18 // * Neither the name of tm3d.de nor the names of its contributors may
19 // be used to endorse or promote products derived from this software
20 // without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34 #define _CHANGEABLE_ID_
35 #define _ZERO_POLLING_
36
37 #include "../common/OWConfig.s"
38 #include "../common/OWCRC16.s"
39
40 .extern pack,8
41 .comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....)
42 .comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte....
43 //.extern am2302_temp,2
44
45
46
47 .macro CHIP_INIT
48 .endm
49
50 .macro COMMAND_TABLE
51 rjmp h_readmemoryaddr
52 rjmp h_readmemory
53 rjmp h_readmemorycrc1
54 rjmp h_readmemorycrc2
55 rjmp h_writememoryaddr
56 rjmp h_writememory
57 rjmp h_writememorycrc1
58 rjmp h_writememorycrc2
59 rjmp h_writememoryreadback
60 rjmp h_convert
61 rjmp h_convertcrc1
62 rjmp h_convertcrc2
63 rjmp h_convert_conv
64 .endm
65
66 #include "../common/OWRomFunctions.s"
67 #include "../common/OWTimerInterrupt.s"
68
69
70
71 ; Ab hier Geraeteabhaenging
72 #define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0
73 #define OW_READ_MEMORY OW_FIRST_COMMAND+1
74 #define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2
75 #define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3
76 #define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4
77 #define OW_WRITE_MEMORY OW_FIRST_COMMAND+5
78 #define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6
79 #define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7
80 #define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8
81 #define OW_CONVERT OW_FIRST_COMMAND+9
82 #define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10
83 #define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11
84 #define OW_CONVERT_CONV OW_FIRST_COMMAND+12
85
86 ;---------------------------------------------------
87 ; READ COMMAND and start operation
88 ;---------------------------------------------------
89
90
91 h_readcommand:
92 clr r_bytep
93 #ifndef _DIS_FLASH_
94 FLASH_COMMANDS ; muss zu erst sein....
95 #endif
96 cset 0xAA,OW_READ_MEMORY_ADDR
97 cset 0x55,OW_WRITE_MEMORY_ADDR
98 cset 0x3C,OW_CONVERT
99 FW_CONFIG_INFO
100 #ifdef _CHANGEABLE_ID_
101 CHANGE_ID_COMMANDS
102 #endif
103 ldi r_mode,OW_SLEEP
104 rjmp handle_end
105
106
107 h_readmemoryaddr:
108 cpi r_bytep,0 ;erstes Adressbyte ?
109 brne h_readmemory_addr_byte1 ;nein dann weiter
110 andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen
111 sts addr,r_rwbyte ;speichern des ersten bytes
112 rjmp handle_end_inc
113 h_readmemory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert!
114 ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory
115 ;;ldi r_bcount,1 ;ist unten
116 ldi r_sendflag,1 ;jetzt sendet der Slave zum Master
117 clr r_bytep
118 rjmp h_readmemory2
119 h_readmemory:
120 lds r_bytep,addr
121 inc r_bytep
122 sts addr,r_bytep
123 andi r_bytep,0x07
124 breq h_readmemory_init_crc
125 h_readmemory2:
126 lds r_bytep,addr
127 ;andi r_bytep,0x1F ist oben
128 configZ pack,r_bytep
129 ld r_rwbyte,Z
130 ;ldi r_bcount,1
131 rjmp handle_end ;sendet das Byte und geht zu h_readmemory
132 h_readmemory_init_crc:; init erstes CRC byte
133 lds r_rwbyte,crc
134 com r_rwbyte
135 lds r_temp,crc+1
136 com r_temp
137 sts crcsave,r_temp
138 ldi r_mode,OW_READ_MEMORY_CRC1
139 ;ldi r_bcount,1
140 rjmp handle_end
141 h_readmemory_end:
142 ldi r_mode,OW_SLEEP
143 clr r_sendflag
144 rjmp handle_end
145 h_readmemorycrc1:;init zweites CRC Byte
146 lds r_rwbyte,crcsave
147 ;ldi r_bcount,1
148 ldi r_mode,OW_READ_MEMORY_CRC2
149 rjmp handle_end
150 h_readmemorycrc2:;weiteres senden..... nach zweitem Byte
151 lds r_temp,addr
152 andi r_temp,0xE0
153 brne h_readmemory_end; ende des speichers
154 ldi r_mode,OW_READ_MEMORY
155 CRCInit1 ;Start with new CRC
156 rjmp h_readmemory2
157
158 h_writememoryaddr:
159 cpi r_bytep,0 ;erstes Adressbyte ?
160 brne h_writememory_addr_byte1 ;nein dann weiter
161 andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen
162 sts addr,r_rwbyte ;speichern des ersten bytes
163 inc r_bytep
164 ;ldi r_bcount,1
165 rjmp handle_end
166 h_writememory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert!
167 ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory
168 ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren.....
169 lds r_bytep,addr
170 rjmp handle_end ;read Memory Byte
171 h_writememory:
172 lds r_bytep,addr
173 configZ pack,r_bytep
174 st Z,r_rwbyte
175 ;ldi r_bcount,1
176 ldi r_mode,OW_WRITE_MEMORY_CRC1
177 ldi r_sendflag,1 ;jetzt sendet der Slave zum Master
178 lds r_rwbyte,crc
179 com r_rwbyte
180 lds r_temp,crc+1
181 com r_temp
182 sts crcsave,r_temp
183 rjmp handle_end
184 h_writememorycrc1:
185 lds r_rwbyte,crcsave
186 ;ldi r_bcount,1
187 ldi r_mode,OW_WRITE_MEMORY_CRC2
188 rjmp handle_end
189 h_writememorycrc2:
190 lds r_temp,addr
191 configZ pack,r_temp
192 ld r_rwbyte,Z
193 ;ldi r_bcount,1
194 ldi r_mode,OW_WRITE_MEMORY_READBACK
195 rjmp handle_end
196 h_writememoryreadback:
197 ldi r_temp,0x00
198 sts crc+1,r_temp
199 lds r_temp,addr
200 inc r_temp
201 sts addr,r_temp
202 sts crc,r_temp
203 ldi r_sendflag,0
204 ;ldi r_bcount,1
205 ldi r_mode,OW_WRITE_MEMORY
206 rjmp handle_end
207
208 h_convert:
209 cpi r_bytep,0 ;erstes Adressbyte ?
210 brne h_convert_byte1 ;nein dann weiter
211 inc r_bytep
212 sts pack+0x20,r_rwbyte
213 ;ldi r_bcount,1
214 rjmp handle_end
215 h_convert_byte1: ;zweies byte glesen go crc#
216 sts pack+0x21,r_rwbyte
217 lds r_rwbyte,crc
218 com r_rwbyte
219 lds r_temp,crc+1
220 com r_temp
221 sts crcsave,r_temp
222 ldi r_mode,OW_CONVERT_CRC1
223 ;ldi r_bcount,1
224 ldi r_sendflag,1
225 rjmp handle_end
226 h_convertcrc1:
227 lds r_rwbyte,crcsave
228 ;ldi r_bcount,1
229 ldi r_mode,OW_CONVERT_CRC2
230 rjmp handle_end
231 h_convertcrc2:
232 ldi r_temp,1
233 sts gcontrol,r_temp
234 ;ldi r_bcount,1
235 ldi r_mode,OW_CONVERT_CONV
236 ;clr r_sendflag
237 ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling
238 h_convert_conv:
239 ldi r_bcount,0
240 ldi r_rwbyte,0
241 rjmp handle_end_no_bcount
242
243
244
245
246 #include "../common/OWPinInterrupt.s"
247 .end