summaryrefslogtreecommitdiff
path: root/bootloader
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-07 01:48:13 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-07 01:48:13 +0000
commitfc547cad2fffcaa354b170694796beddf37dd4a1 (patch)
tree3d94e7692ce139cf11e29f401a4a73356b136971 /bootloader
parentskipping 'invalid' code doesn't work on some hardware (diff)
added length field for messages
git-svn-id: https://svn.spreadspace.org/pic/trunk@46 a09c6847-51d9-44de-8ef2-e725cf50f3c7
Diffstat (limited to 'bootloader')
-rw-r--r--bootloader/bootloader.asm129
1 files changed, 48 insertions, 81 deletions
diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm
index f8b609c..ff23d61 100644
--- a/bootloader/bootloader.asm
+++ b/bootloader/bootloader.asm
@@ -37,11 +37,10 @@ VERSION_MAJ EQU .0
VERSION_MIN EQU .1
DEVID_H EQU H'20'
DEVID_L EQU H'82'
-FSS EQU .16
-MESS_H EQU .0
-MESS_L EQU .64
+FSS EQU .16 ; writing is done 8 words at a time but 16 words get erased
+MESS EQU .64 ; this limit is because of to combuff size and single byte len field for messages
SUPPORTED_H EQU .0
-SUPPORTED_L EQU b'00011110' ; read/write flash, read/write eeprom
+SUPPORTED_L EQU b'00000110' ; only read/write flash is supported by now
;; ERROR codes
E_OK EQU .0
@@ -76,7 +75,7 @@ current_cmdlen EQU H'0070'
csum EQU H'0071'
flags EQU H'007D'
-#define F_WEEP flags,0
+#define F_NEW_CMD flags,0
cnt2 EQU H'007E'
cnt1 EQU H'007F'
@@ -104,6 +103,9 @@ uart_tx_byte
return
send_answer
+ addlw .3
+ movwf combuff + .1
+ decf combuff + .1,w
movwf cnt1
movlw combuff
movwf FSR
@@ -119,19 +121,6 @@ send_answer_next
call uart_tx_byte
return
-get_cmdlen
- addwf PCL,f
- retlw .0 ; invalid
- retlw .1 ; identify: <csum>
- retlw .1 ; boot: <csum>
- retlw .1 ; reset: <csum>
- retlw .3 ; read flash: addr | <csum>
- retlw .3 + .2*FSS ; write flash: addr | data | <csum>
- retlw .5 ; read eeprom: addr | len | <csum>
- retlw .5 ; write eeprom: addr | len | data | <csum> (minimal)
- retlw .2 ; read config: nr | <csum>
- retlw .4 ; write config: nr | word | <csum>
-
get_name
addwf PCL,f
nop
@@ -197,6 +186,8 @@ uart_rx_byte ; process received command
movf RCREG,w
movwf INDF
incf FSR,f
+ btfss F_NEW_CMD
+ goto wait_cmd_len
movf current_cmdlen,f
btfsc STATUS,Z
goto new_cmd
@@ -208,39 +199,43 @@ uart_rx_fe ; recover from framing error
movf RCREG,w
goto wait_new_cmd
+wait_cmd_len
+ bsf F_NEW_CMD
+ goto wait_cmd
+
new_cmd ; got new command code
movf combuff,w
sublw CMD_MAX
btfss STATUS,C
goto invalid_cmd
- movf combuff,w
- call get_cmdlen
+ decfsz combuff + .1,w
+ goto load_cmdlen
+ goto invalid_cmd
+load_cmdlen
movwf current_cmdlen
+ decfsz current_cmdlen,f
goto wait_cmd
-
-invalid_cmd ; received command code is not known
+invalid_cmd ; received command code is not known or len is bogus
movlw E_INV_CMD
- movwf combuff + .1
- movlw .2
+ movwf combuff + .2
+ movlw .1
call send_answer
goto wait_new_cmd
exec_cmd ; command is correct and complete
- ;; TODO: check csum -> csum for write eeprom will not be correct because
- ;; it isn't finished yet....???
+ ;; TODO: check csum
movf combuff,w ; dispatch commands
addwf PCL,f
goto wait_new_cmd
- goto cmd_identify
- goto cmd_boot
- goto cmd_reset
- goto cmd_r_flash
- goto cmd_w_flash
- goto cmd_r_eeprom
- goto cmd_w_eeprom
- goto cmd_r_config
- goto cmd_w_config
- goto wait_new_cmd
+ goto cmd_identify ; identify
+ goto cmd_boot ; boot
+ goto cmd_not_impl ; reset
+ goto cmd_r_flash ; read flash segment
+ goto cmd_w_flash ; write flash segment
+ goto cmd_not_impl ; read eeprom
+ goto cmd_not_impl ; write eeprom
+ goto cmd_not_impl ; read config
+ goto cmd_not_impl ; write config
;; ** Command Handlers ********************
;; ** identify *******
@@ -249,6 +244,9 @@ cmd_identify
movf combuff,w
call uart_tx_byte
+ movlw .22
+ call uart_tx_byte
+
movlw E_OK
call uart_tx_byte
@@ -273,10 +271,7 @@ cmd_identify_send_name
movlw FSS
call uart_tx_byte
-
- movlw MESS_L
- call uart_tx_byte
- movlw MESS_H
+ movlw MESS
call uart_tx_byte
movlw SUPPORTED_L
@@ -291,8 +286,8 @@ cmd_identify_send_name
;; ** boot *******
cmd_boot
movlw E_OK
- movwf combuff + .1
- movlw .2
+ movwf combuff + .2
+ movlw .1
call send_answer
goto USERVECT
@@ -308,39 +303,11 @@ cmd_w_flash
call send_answer
goto wait_new_cmd
- ;; ** read eeprom *******
-cmd_r_eeprom
- ;; call read_eeprom
- movlw E_ADDR_INVALID
- movwf combuff + .1
- movlw .2
- call send_answer
- goto wait_new_cmd
-
- ;; ** write eeprom *******
-cmd_w_eeprom
- btfss F_WEEP
- goto cmd_w_eeprom_len
- ;; call write_eeprom
- movlw E_ADDR_INVALID
- movwf combuff + .1
- movlw .2
- call send_answer
- goto wait_new_cmd
-
-cmd_w_eeprom_len
- movf combuff + .3,w
- movwf current_cmdlen
- bsf F_WEEP
- goto wait_cmd
-
;; ** not implemented commands *******
-cmd_reset
-cmd_r_config
-cmd_w_config
+cmd_not_impl
movlw E_NOT_IMPL
- movwf combuff + .1
- movlw .2
+ movwf combuff + .2
+ movlw .1
call send_answer
goto wait_new_cmd
@@ -352,7 +319,7 @@ read_flash_segment
movwf cnt1
movlw b'01011000'
movwf STATUS
- movlw combuff + .1
+ movlw combuff + .2
movwf FSR
movf INDF,w
movwf EEADR
@@ -379,8 +346,8 @@ read_flash_segment_next
decfsz cnt1,f
goto read_flash_segment_loop
bcf STATUS,RP1
- clrf combuff + .1 ; = E_OK
- retlw .2 + .2*FSS ; bytes to send
+ clrf combuff + .2 ; = E_OK
+ retlw .1 + .2*FSS ; bytes to send
;; flash write --------
write_flash_segment
@@ -388,7 +355,7 @@ write_flash_segment
movwf cnt1
movlw b'01011000'
movwf STATUS
- movlw combuff + .1
+ movlw combuff + .2
movwf FSR
movf INDF,w
movwf EEADR
@@ -397,7 +364,7 @@ write_flash_segment
movwf EEADRH
write_flash_segment_loop
- incf FSR,f ; load data into EEDAT:EEDATH
+ incf FSR,f ; load code word into EEDAT:EEDATH
movf INDF,w
movwf EEDAT
incf FSR,f
@@ -423,13 +390,13 @@ write_flash_segment_next
decfsz cnt1,f
goto write_flash_segment_loop
bsf STATUS,RP0
- clrw
+ clrw ; check if a write error occured
btfsc EECON1,WRERR
movlw E_FLASH_WERR
bcf STATUS,RP1
bcf STATUS,RP0
- movwf combuff + .1 ; = E_OK
- retlw .2 ; bytes to send
+ movwf combuff + .2 ; = E_OK
+ retlw .1 ; bytes to send
;; -------------------------------------
;; -------------------------------------