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) //2us
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 sbrc writelow,0 ;test of zero send
119 sbi OW_DDR,OW_PIN ;yes pull line to low 2us faster
120 sbrs writelow,0 ;test egain 2us faster.....
121 rjmp pro_loop1 ;no ? goes next
122 ldi param,20 ;wait for 50 us
124 clr writelow ;reset write low indecator
125 cbi OW_DDR,OW_PIN ;release line
126 owwh ;wait for line is high (it can takes some time cause of the capacity of line)
128 tst smode ;smode=1 for slave sends to master
135 breq pro_loop_end ; now reading ... do nothing
136 pro_loop_send1: ;prebare next bit
137 sbrs rwbyte ,0; if bit 0 set in rwbyte then skip next command
144 ldi param,7 ;wait 15us
148 sbic OW_PINN,OW_PIN ;test line
151 brne pro_loop_end ;no handle need
154 brne pro_loop_send ; Nach dem Gelesen byte koennte gesendet werden muessen....
158 pro_loop_end_test_reset:
159 sbic OW_PINN,OW_PIN //leitung wieder high
163 brlo pro_loop_end_test_reset
173 sbic OW_PINN,OW_PIN //leitung wieder high
178 //leitung wieder high
192 ldi mode,OWM_READ_ROM_COMMAND
193 //Wait for all other devices presents impuls finished
201 ldi ZL,low(pro_stable)
202 ldi ZH,high(pro_stable)
209 rjmp pro_read_rom_command
212 rjmp pro_search_rom_s
213 rjmp pro_search_rom_r
214 rjmp pro_read_command
215 rjmp pro_write_scratchpad
216 rjmp pro_read_scratchpad
217 rjmp pro_programm_page
218 rjmp pro_recall_flash
220 pro_read_rom_command:
224 ldi mode,OWM_READ_COMMAND
227 cpi rwbyte,0xF0 ;Searchrom
229 ldi XL,low(sowid) ;init sram pointer
233 rjmp pro_serchrom_next_bit
235 cpi rwbyte,0x55 ;Matchrom
237 // rcall pro_owidinit
238 ldi XL,low(sowid) ;init sram pointer
240 ldi mode,OWM_MATCH_ROM
249 breq pro_match_rom_next
254 breq pro_match_rom_found
257 ldi mode,OWM_READ_COMMAND
262 cpi rwbyte,0x0F ;; Write to Scratchpad
264 ldi mode,OWM_WRITE_SCRATCHPAD
265 ldi XL,low(scratchpad) ;init sram pointer
266 ldi XH,high(scratchpad)
271 ldi mode,OWM_READ_SCRATCHPAD ;;Read from Scratchpad
272 ldi XL,low(scratchpad) ;init sram pointer
273 ldi XH,high(scratchpad)
281 ldi mode,OWM_RECALL_FLASH ;; copy Flash page in Scratchpad
282 ldi XL,low(scratchpad) ;init sram pointer
283 ldi XH,high(scratchpad)
286 cpi rwbyte,0x55 ; copy Scratchpad to Flash
289 rjmp pro_programm_page
292 cpi rwbyte,0x89 ; Reset Device /Boot (new) Firmware
296 cpi rwbyte,0x8B ; Clear the OWID saved in EEPROM / one ID1
305 ldi temp, (0<<EEPM1)|(0<<EEPM0)
315 cpi rwbyte,0x8C ; Clear the OWID saved in EEPROM / one ID2
323 pro_write_scratchpad:
325 cpi XL,SRAM_START+8+66
326 brlo pro_write_scratchpad_next
329 pro_write_scratchpad_next:
334 cpi XL,SRAM_START+8+66
335 brlo pro_read_scratchpad_next
339 pro_read_scratchpad_next:
345 .equ PAGESIZEB = PAGESIZE*2;PAGESIZEB is page size in BYTES, not words
346 // .org SMALLBOOTSTART
348 ;transfer data from RAM to Flash page buffer
349 ldi bytep, PAGESIZEB ;init loop variable
350 ldi YL,low(scratchpad) ;init sram pointer
351 ldi YH,high(scratchpad)
355 ldi spmcrval, (1<<PGERS) + (1<<SPMEN)
360 ldi spmcrval, (1<<SPMEN)
363 subi bytep, 2;use subi for PAGESIZEB<=256
366 subi ZL, low(PAGESIZEB) ;restore pointer
367 sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256
368 ldi spmcrval, (1<<PGWRT) + (1<<SPMEN)
370 ;read back and check, optional
372 subi YL, low(PAGESIZEB) ;restore pointer
373 sbci YH, high(PAGESIZEB)
379 subi bytep, 2;use subi for PAGESIZEB<=256
384 ;input: spmcrval determines SPM action
385 ;disable interrupts if enabled, store status
388 ;check for previous SPM complete
396 ;restore SREG (to enable interrupts if originally enabled)
408 cpi XL,SRAM_START+8+2
409 brlo pro_out_bitp1;pro_recall_flash_next
415 cpi XL,SRAM_START+8+66
416 brne pro_recall_flash_cl
420 pro_out_read_command:
421 ldi mode,OWM_READ_COMMAND
430 pro_serchrom_next_bit:
434 ror temp2 ;first bit in C
435 rol rwbyte ;C in first bit
438 ldi mode,OWM_SEARCH_ROM_R ;next mod Resive
444 lsr srbyte ;shift in C lowest bit
445 ror temp2 ; shift in temp2 as highest bit
446 andi rwbyte,0x80 ; clear other bits
448 breq pro_search_rom_s_goon
451 pro_search_rom_s_goon:
455 brne pro_serchrom_next_bit ;prepare next bit
457 andi temp2,0x40 ;;end
458 brne pro_search_rom_found
461 rjmp pro_serchrom_next_bit
463 pro_search_rom_found:
464 ldi mode,OWM_READ_COMMAND
469 ldi mode,OWM_SEARCH_ROM_S
470 ldi bitp,0 ;go to searchrom_s after bit get
473 pro_owid: .DB 0xA3, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xFA