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