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