1 .def srbyte = r12 ;byty for search rom algorithm
\r
2 .def writelow = r13; marker for send low
\r
3 .def zero =r14; always zero
\r
4 .def smode=r15; if 1 then send
\r
8 .def bitp = r19 ; bit counter ... shift...
\r
11 .def bytep = r23 ;byte counter
\r
12 #define spmcrval param
\r
15 .equ OWM_READ_ROM_COMMAND=0 ; 0 wegen schnellen test ist dieser wert 0! Daturch wird die Sprungdabelle nicht verwendet
\r
16 .equ OWM_SLEEP=1 ; Warten auf Reset
\r
17 .equ OWM_MATCH_ROM=2
\r
18 .equ OWM_SEARCH_ROM_S=3 ;send bit
\r
19 .equ OWM_SEARCH_ROM_R=4 ;resive master
\r
20 .equ OWM_READ_COMMAND=5
\r
21 .equ OWM_WRITE_SCRATCHPAD=6
\r
22 .equ OWM_READ_SCRATCHPAD=7
\r
23 .equ OWM_PROGRAMM_PAGE=8
\r
24 .equ OWM_RECALL_FLASH=9
\r
28 .equ OW_PIN = PORTB2
\r
29 .equ OW_PORT = PORTB
\r
30 .equ OW_PINN = PINB
\r
32 ;.equ SRAM_START = 0x60
\r
54 ;---------------------------------------------------
\r
56 ;---------------------------------------------------
\r
62 rjmp start ; Reset-Vector
\r
91 set_clock 0x00 ;8mhz
\r
93 ldi temp,(1<<CS01) //1us
\r
95 ldi temp, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse
\r
97 ldi temp, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse
\r
105 ldi ZL,low(pro_owid*2)
\r
106 ldi ZH,high(pro_owid*2)
\r
110 pro_copy_loop: ;copy ID on SRAM for better handling
\r
113 cpi XL,SRAM_START+8
\r
117 owwl ;wait for line goes low (polling)
\r
118 sbrs writelow,0 ;test of zero send
\r
119 rjmp pro_loop1 ;no ? goes next
\r
120 sbi OW_DDR,OW_PIN ;yes pull line to low
\r
121 ldi param,45 ;wait for 50 us
\r
123 clr writelow ;reset write low indecator
\r
124 cbi OW_DDR,OW_PIN ;release line
\r
125 owwh ;wait for line is high (it can takes some time cause of the capacity of line)
\r
127 tst smode ;smode=1 for slave sends to master
\r
131 brne pro_loop_send1
\r
134 breq pro_loop_end ; now reading ... do nothing
\r
135 pro_loop_send1: ;prebare next bit
\r
136 sbrs rwbyte ,0; if bit 0 set in rwbyte then skip next command
\r
143 ldi param,15 ;wait 15us
\r
147 sbic OW_PINN,OW_PIN ;test line
\r
150 brne pro_loop_end ;no handle need
\r
153 brne pro_loop_send ; Nach dem Gelesen byte koennte gesendet werden muessen....
\r
157 pro_loop_end_test_reset:
\r
158 sbic OW_PINN,OW_PIN //leitung wieder high
\r
162 brlo pro_loop_end_test_reset
\r
172 sbic OW_PINN,OW_PIN //leitung wieder high
\r
177 //leitung wieder high
\r
191 ldi mode,OWM_READ_ROM_COMMAND
\r
192 //Wait for all other devices presents impuls finished
\r
200 ldi ZL,low(pro_stable)
\r
201 ldi ZH,high(pro_stable)
\r
208 rjmp pro_read_rom_command
\r
211 rjmp pro_search_rom_s
\r
212 rjmp pro_search_rom_r
\r
213 rjmp pro_read_command
\r
214 rjmp pro_write_scratchpad
\r
215 rjmp pro_read_scratchpad
\r
216 rjmp pro_programm_page
\r
217 rjmp pro_recall_flash
\r
219 pro_read_rom_command:
\r
223 ldi mode,OWM_READ_COMMAND
\r
226 cpi rwbyte,0xF0 ;Searchrom
\r
228 ldi XL,low(sowid) ;init sram pointer
\r
232 rjmp pro_serchrom_next_bit
\r
234 cpi rwbyte,0x55 ;Matchrom
\r
236 // rcall pro_owidinit
\r
237 ldi XL,low(sowid) ;init sram pointer
\r
239 ldi mode,OWM_MATCH_ROM
\r
240 rjmp pro_out_bytep0
\r
248 breq pro_match_rom_next
\r
251 pro_match_rom_next:
\r
252 cpi XL,SRAM_START+8
\r
253 breq pro_match_rom_found
\r
255 pro_match_rom_found:
\r
256 ldi mode,OWM_READ_COMMAND
\r
261 cpi rwbyte,0x0F ;; Write to Scratchpad
\r
263 ldi mode,OWM_WRITE_SCRATCHPAD
\r
264 ldi XL,low(scratchpad) ;init sram pointer
\r
265 ldi XH,high(scratchpad)
\r
266 rjmp pro_out_bytep0
\r
270 ldi mode,OWM_READ_SCRATCHPAD ;;Read from Scratchpad
\r
271 ldi XL,low(scratchpad) ;init sram pointer
\r
272 ldi XH,high(scratchpad)
\r
275 rjmp pro_out_bytep0
\r
280 ldi mode,OWM_RECALL_FLASH ;; copy Flash page in Scratchpad
\r
281 ldi XL,low(scratchpad) ;init sram pointer
\r
282 ldi XH,high(scratchpad)
\r
283 rjmp pro_out_bytep0
\r
285 cpi rwbyte,0x55 ; copy Scratchpad to Flash
\r
288 rjmp pro_programm_page
\r
291 cpi rwbyte,0x89 ; Reset Device /Boot (new) Firmware
\r
295 cpi rwbyte,0x8B ; Clear the OWID saved in EEPROM / one ID1
\r
304 ldi temp, (0<<EEPM1)|(0<<EEPM0)
\r
314 cpi rwbyte,0x8C ; Clear the OWID saved in EEPROM / one ID2
\r
322 pro_write_scratchpad:
\r
324 cpi XL,SRAM_START+8+66
\r
325 brlo pro_write_scratchpad_next
\r
328 pro_write_scratchpad_next:
\r
332 pro_read_scratchpad:
\r
333 cpi XL,SRAM_START+8+66
\r
334 brlo pro_read_scratchpad_next
\r
338 pro_read_scratchpad_next:
\r
344 .equ PAGESIZEB = PAGESIZE*2;PAGESIZEB is page size in BYTES, not words
\r
345 // .org SMALLBOOTSTART
\r
347 ;transfer data from RAM to Flash page buffer
\r
348 ldi bytep, PAGESIZEB ;init loop variable
\r
349 ldi YL,low(scratchpad) ;init sram pointer
\r
350 ldi YH,high(scratchpad)
\r
354 ldi spmcrval, (1<<PGERS) + (1<<SPMEN)
\r
359 ldi spmcrval, (1<<SPMEN)
\r
362 subi bytep, 2;use subi for PAGESIZEB<=256
\r
364 ;execute page write
\r
365 subi ZL, low(PAGESIZEB) ;restore pointer
\r
366 sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256
\r
367 ldi spmcrval, (1<<PGWRT) + (1<<SPMEN)
\r
369 ;read back and check, optional
\r
370 ldi bytep, PAGESIZEB
\r
371 subi YL, low(PAGESIZEB) ;restore pointer
\r
372 sbci YH, high(PAGESIZEB)
\r
378 subi bytep, 2;use subi for PAGESIZEB<=256
\r
383 ;input: spmcrval determines SPM action
\r
384 ;disable interrupts if enabled, store status
\r
387 ;check for previous SPM complete
\r
392 ;SPM timed sequence
\r
393 out SPMCSR, spmcrval
\r
395 ;restore SREG (to enable interrupts if originally enabled)
\r
407 cpi XL,SRAM_START+8+2
\r
408 brlo pro_out_bitp1;pro_recall_flash_next
\r
410 lds ZH,scratchpad+1
\r
411 pro_recall_flash_cl:
\r
414 cpi XL,SRAM_START+8+66
\r
415 brne pro_recall_flash_cl
\r
419 pro_out_read_command:
\r
420 ldi mode,OWM_READ_COMMAND
\r
429 pro_serchrom_next_bit:
\r
433 ror temp2 ;first bit in C
\r
434 rol rwbyte ;C in first bit
\r
437 ldi mode,OWM_SEARCH_ROM_R ;next mod Resive
\r
443 lsr srbyte ;shift in C lowest bit
\r
444 ror temp2 ; shift in temp2 as highest bit
\r
445 andi rwbyte,0x80 ; clear other bits
\r
447 breq pro_search_rom_s_goon
\r
450 pro_search_rom_s_goon:
\r
454 brne pro_serchrom_next_bit ;prepare next bit
\r
456 andi temp2,0x40 ;;end
\r
457 brne pro_search_rom_found
\r
460 rjmp pro_serchrom_next_bit
\r
462 pro_search_rom_found:
\r
463 ldi mode,OWM_READ_COMMAND
\r
464 rjmp pro_out_bytep0
\r
468 ldi mode,OWM_SEARCH_ROM_S
\r
469 ldi bitp,0 ;go to searchrom_s after bit get
\r
472 pro_owid: .DB 0xA3, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xFA
\r