summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-06 23:39:25 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-06 23:39:25 +0000
commitdb49918edb501d8763fcac9244f511c861061bb6 (patch)
treee51978334039ff6c7b11347f0f8e69e8202a58ea
parentread_flash_segment works now (diff)
writing to flash works now
git-svn-id: https://svn.spreadspace.org/pic/trunk@44 a09c6847-51d9-44de-8ef2-e725cf50f3c7
-rw-r--r--bootloader/bootloader.asm73
1 files changed, 57 insertions, 16 deletions
diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm
index 0ea30a7..dc7d119 100644
--- a/bootloader/bootloader.asm
+++ b/bootloader/bootloader.asm
@@ -41,7 +41,7 @@ FSS EQU .8
MESS_H EQU .0
MESS_L EQU .64
SUPPORTED_H EQU .0
-SUPPORTED_L EQU b'00011111' ; reset, read/write flash, read/write eeprom
+SUPPORTED_L EQU b'00011110' ; read/write flash, read/write eeprom
;; ERROR codes
E_OK EQU .0
@@ -296,17 +296,6 @@ cmd_boot
call send_answer
goto USERVECT
- ;; ** reset *******
-cmd_reset
- movlw E_OK
- movwf combuff + .1
- movlw .2
- call send_answer
- movlw b'00000001'
- movwf WDTCON ; why does this not work?????
-cmd_reset_wait
- goto cmd_reset_wait
-
;; ** read flash *******
cmd_r_flash
call read_flash_segment
@@ -315,10 +304,7 @@ cmd_r_flash
;; ** write flash *******
cmd_w_flash
- ;; call write_flash_segment
- movlw E_ADDR_INVALID
- movwf combuff + .1
- movlw .2
+ call write_flash_segment
call send_answer
goto wait_new_cmd
@@ -349,6 +335,7 @@ cmd_w_eeprom_len
goto wait_cmd
;; ** not implemented commands *******
+cmd_reset
cmd_r_config
cmd_w_config
movlw E_NOT_IMPL
@@ -359,6 +346,7 @@ cmd_w_config
;; -------------------------------------
;; actual flash/eeprom functions
+ ;; flash read --------
read_flash_segment
movlw FSS
movwf cnt1
@@ -394,6 +382,59 @@ read_flash_segment_next
clrf combuff + .1 ; = E_OK
retlw .2 + .2*FSS ; bytes to send
+ ;; flash write --------
+write_flash_segment
+ movlw FSS ; initialize EEADR:EEADRH and FSR
+ movwf cnt1
+ movlw b'01011000'
+ movwf STATUS
+ movlw combuff + .1
+ movwf FSR
+ movf INDF,w
+ movwf EEADR
+ incf FSR,f
+ movf INDF,w
+ movwf EEADRH
+
+write_flash_segment_loop
+ incf FSR,f ; load data into EEDAT:EEDATH
+ movf INDF,w
+ movwf EEDAT
+ incf FSR,f
+ movf INDF,w
+ movwf EEDATH
+
+ bsf STATUS,RP0 ; if code word is 0xFFFF, read the current value first
+ btfss INDF,7 ; this will leave this word unchanged
+ goto write_flash_segment_write
+
+ bsf EECON1,EEPGD
+ bsf EECON1,RD
+ nop
+ nop
+
+write_flash_segment_write
+ bsf EECON1,EEPGD ; now start the acutal write sequence
+ bsf EECON1,WREN
+ movlw H'55'
+ movwf EECON2
+ movlw H'AA'
+ movwf EECON2
+ bsf EECON1,WR
+ nop
+ nop
+ bcf EECON1,WREN
+ bcf STATUS,RP0
+ incfsz EEADR,f ; increment flash address
+ goto write_flash_segment_next
+ incf EEADRH,f
+write_flash_segment_next
+ decfsz cnt1,f
+ goto write_flash_segment_loop
+ bcf STATUS,RP1
+ clrf combuff + .1 ; = E_OK
+ retlw .2 ; bytes to send
+
;; -------------------------------------
;; -------------------------------------
;; dummy user code