- OWINIT save Register used in C
[owSlave2.git] / common / OWRomFunctionsDual.s
index c28d855..1a9b0d4 100644 (file)
 #define OW_SEARCHROMR 4  ; next resive master answer
 #define OW_READ_COMMAND1 5
 #define OW_READ_COMMAND2 6
+#define OW_FWCONFIGINFO1 7
+#define OW_FWCONFIGINFO2 8
 
+.comm idtable,64
 
 #ifdef _CHANGEABLE_ID_
-#define OW_WRITE_NEWID 7
-#define OW_READ_NEWID 8
-#define OW_SET_NEWID 9
-#define OW_FIRST_COMMAND 10
+#define OW_WRITE_NEWID 9
+#define OW_READ_NEWID 10
+#define OW_SET_NEWID 11
+#define OW_FIRST_COMMAND 12
 .comm newid,8
-.comm idtable,64
        
 .macro CHANGE_ID_COMMANDS
        cset 0x75,OW_WRITE_NEWID
@@ -79,7 +81,7 @@
 
 
 #else
-#define OW_FIRST_COMMAND 7
+#define OW_FIRST_COMMAND 9
 #endif
 
 #ifndef _DIS_FLASH_
 #endif
 
 
+.macro FW_CONFIG_INFO1
+       cljmp 0x85,hrc_fw_configinfo1
+.endm
+.macro FW_CONFIG_INFO2
+       cljmp 0x85,hrc_fw_configinfo2
+.endm
 
 #ifdef _CHANGEABLE_ID_
 ; lesen der ID aus dem EEPROM beim Start
@@ -145,6 +153,8 @@ handle_stable:
                rjmp h_searchromr
                rjmp h_readcommand1 
                rjmp h_readcommand2
+               rjmp h_fwconfiginfo1
+               rjmp h_fwconfiginfo2
 #ifdef _CHANGEABLE_ID_
                rjmp h_writeid
                rjmp h_readid
@@ -168,7 +178,7 @@ hrc_jmp_flasher:
        lds r_temp,flashmarker
        cpi r_temp,2
        brne hrc_jmp_flasher_inc
-       ldi r_temp,0xE0
+       ldi r_temp,0xC0
        push r_temp
        ldi r_temp,0x0E
        push r_temp
@@ -216,6 +226,19 @@ hrc_set_alarm_search:
        ; sonst tue nichts
        rjmp handle_end_sleep
 
+hrc_fw_configinfo1:
+       ldi r_mode,OW_FWCONFIGINFO1
+       ldi r_sendflag,1
+       CRCInit2
+       rjmp h_fwconfiginfo1
+
+hrc_fw_configinfo2:
+       ldi r_mode,OW_FWCONFIGINFO2
+       ldi r_sendflag,1
+       CRCInit2
+       rjmp h_fwconfiginfo2
+
+
 ;---------------------------------------------------
 ;   MATCH ROM
 ;---------------------------------------------------
@@ -353,6 +376,43 @@ h_searchromr:  ; stelle um auf empfangen
        rjmp handle_end_no_bcount
 
 
+;---------------------------------------------------
+;   FW_CONFIG_INFO
+;---------------------------------------------------
+
+h_fwconfiginfo1:
+       configZ config_info1,r_bytep
+       rjmp h_fwconfiginfo_go
+h_fwconfiginfo2:
+       configZ config_info2,r_bytep
+
+h_fwconfiginfo_go:
+       cpi  r_bytep,16
+       breq h_fwconfiginfo_crc
+#ifdef _CRC8_
+       cpi  r_bytep,17
+       breq h_fwconfiginfo_all
+#elif defined _CRC16_
+       cpi  r_bytep,17
+       breq h_fwconfiginfo_crc2
+       cpi  r_bytep,18
+       breq h_fwconfiginfo_all
+#else
+       cpi  r_bytep,16
+       breq h_fwconfiginfo_all
+#warning No CRC known code implemented
+#endif
+       ld   r_rwbyte,Z
+       rjmp handle_end_inc
+h_fwconfiginfo_crc:
+       lds r_rwbyte,crc
+       rjmp handle_end_inc
+h_fwconfiginfo_crc2:
+       lds r_rwbyte,crc+1
+       rjmp handle_end_inc
+h_fwconfiginfo_all:
+       rjmp handle_end_sleep
+
 
 ;---------------------------------------------------
 ;   CHANGE ROM FUNCTIONS
@@ -447,19 +507,11 @@ h_setid_EEPROM_write:
        //rcall read_EEPROM_ID2
        push r_idm1
        push r_idm2
-       push r_idn1
-       push r_idn2
        push xl
        push xh
-       push yl
-       push yh
        rcall init_idtable
-       pop yh
-       pop yl
        pop xh
        pop xl
-       pop r_idn2
-       pop r_idn1
        pop r_idm2
        pop r_idm1
 h_setid_bad_code_all:
@@ -480,10 +532,12 @@ spause:
 
 .global OWINIT
 OWINIT:
+       
 #ifndef _DIS_FLASH_
 ; check for bootloader jumper
        ;vor allen anderen Registerconfigs
-       
+       push r_temp
+
        ldi r_temp,(1<<PUD) ;enable pullup 
        out _SFR_IO_ADDR(MCUCR) ,r_temp
        sbi _SFR_IO_ADDR(PORTA),PINA5 ;internal pullup on PINA5
@@ -499,7 +553,7 @@ OWINIT:
        sbic _SFR_IO_ADDR(PINA),PINA5 
        rjmp owinit_botest_end ;PINA5 nicht 0.... nicht verbunden
        cbi _SFR_IO_ADDR(DDRA),PINA4
-       ldi r_temp,0xE0
+       ldi r_temp,0xC0
        push r_temp
        ldi r_temp,0x0E
        push r_temp
@@ -508,8 +562,15 @@ owinit_botest_end:
 #endif
        HW_INIT  //Microcontroller specific
        CHIP_INIT //1-Wire device specific
-#ifdef _CHANGEABLE_ID_
+       pop r_temp
 init_idtable:
+       push yl
+       push yh
+       push r_temp
+       push r_rwbyte
+       push r_idn1
+       push r_idn2
+#ifdef _CHANGEABLE_ID_
        rcall read_EEPROM_ID1
        rcall read_EEPROM_ID2
 #endif
@@ -552,6 +613,27 @@ owinit_odgen2:
        brne owinit_odgen2
        dec r_bytep
        brne owinit_odgen1
+       ;copy ids in config bytes
+       ldi  xl,lo8(owid1)
+       ldi  xh,hi8(owid1)
+       ldi      yl,lo8(config_info2+9)
+       ldi  yh,hi8(config_info2+9)
+       ldi r_temp,7
+owinit_cpconfig1:
+       ld r_rwbyte,X+
+       st Y+,r_rwbyte
+       dec r_temp
+       brne owinit_cpconfig1
+       ldi  xl,lo8(owid2)
+       ldi  xh,hi8(owid2)
+       ldi      yl,lo8(config_info1+9)
+       ldi  yh,hi8(config_info1+9)
+       ldi r_temp,7
+owinit_cpconfig2:
+       ld r_rwbyte,X+
+       st Y+,r_rwbyte
+       dec r_temp
+       brne owinit_cpconfig2
 
 
        ldi r_temp,0
@@ -559,4 +641,25 @@ owinit_odgen2:
        sts bcount,r_temp
        sts alarmflag,r_temp
        RESETZEROMARKER
+       pop r_idn2
+       pop r_idn1
+       pop r_rwbyte
+       pop r_temp
+       pop yh
+       pop yl
+       
        ret
+
+.global EXTERN_SLEEP
+EXTERN_SLEEP:
+       cli
+       push r_temp
+       ldi r_temp,0
+       sts mode,r_temp ;SLEEP
+       sts gcontrol,r_temp
+       sts sendflag,r_temp
+       sts bcount,r_temp
+       RESETZEROMARKER
+       pop r_temp
+       sei
+       ret
\ No newline at end of file