summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-04 00:42:37 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-04 00:42:37 +0000
commit5e516e6bebee209aaa0738d1039c66f814ca1c3c (patch)
treeb0352cded9d9b7cde5427295cb48e5b75843297d
parentadded lookup table for commandlength (diff)
handling of invalid commands
git-svn-id: https://svn.spreadspace.org/pic/trunk@31 a09c6847-51d9-44de-8ef2-e725cf50f3c7
-rw-r--r--bootloader/bootloader.asm72
1 files changed, 61 insertions, 11 deletions
diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm
index b32affd..684501d 100644
--- a/bootloader/bootloader.asm
+++ b/bootloader/bootloader.asm
@@ -72,6 +72,8 @@ CMD_R_CONFIG EQU 7
CCMD_W_CONFIG EQU 'C'
CMD_W_CONFIG EQU 8
+CMD_INVALID EQU H'FF'
+
;; Variables
inbuff EQU H'0020'
inbuff_end EQU H'006F'
@@ -133,15 +135,15 @@ translate_cmd_codes
xorlw CCMD_W_CONFIG ^ CCMD_R_CONFIG
btfsc STATUS,Z
retlw CMD_W_CONFIG
- retlw H'FF'
+ retlw CMD_INVALID
-get_cmd_len
+get_cmdlen
addwf PCL,f
retlw 1 ; identify: <csum>
retlw 1 ; boot: <csum>
retlw 1 ; reset: <csum>
retlw 3 ; read flash: addr | <csum>
- retlw 3 + FSS ; write flash: addr | data | <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>
@@ -169,11 +171,23 @@ boot
movwf SPBRG
clrf SPBRGH
+ bcf TRISD,0 ; DEBUG!!!!
+
;; bank 0
bcf STATUS,RP0
movlw b'10010000' ; enable Serial Port, 8bit, enable continues receive, disable address detection
movwf RCSTA
+ bsf PORTD,0 ; DEBUG!!!!
+
+
+wait_new_cmd
+ movlw inbuff
+ movwf FSR
+ movlw CMD_INVALID
+ movwf current_cmd
+ clrf current_cmdlen
+
wait_cmd
btfsc PIR1,RCIF
goto uart_rx_byte
@@ -184,27 +198,63 @@ wait_cmd
uart_rx_oe
bcf RCSTA,CREN
bsf RCSTA,CREN
- goto wait_cmd
+ goto wait_new_cmd
uart_rx_byte
btfsc RCSTA,FERR
goto uart_rx_fe
movf RCREG,w ; TODO: check parity??
- ; TODO: move to input string
- ;; TODO: check if command is finished and jump
- ;; to 'exec_cmd'
- call translate_cmd_codes
- call uart_tx_byte
+ movwf INDF
+ incf FSR,f
+ movf current_cmdlen,f
+ btfsc STATUS,Z
+ goto new_cmd
+ decfsz current_cmdlen,f
goto wait_cmd
goto exec_cmd
uart_rx_fe
movf RCREG,w
+ goto wait_new_cmd
+
+new_cmd
+ call translate_cmd_codes
+ movwf current_cmd
+ xorlw CMD_INVALID
+ btfsc STATUS,Z
+ goto invalid_cmd
+ movf current_cmd,w
+ call get_cmdlen
+ movwf current_cmdlen
goto wait_cmd
+invalid_cmd
+ movf inbuff,w
+ call uart_tx_byte
+ movlw E_INV_CMD
+ call uart_tx_byte
+ movlw E_INV_CMD
+ xorwf inbuff,w
+ call uart_tx_byte
+ goto wait_new_cmd
+
exec_cmd
;; TODO: execute received command
- goto wait_cmd
+ bcf PORTD,0
+ movlw .255
+ movwf cnt1
+dbgcnt1
+ movlw .255
+ movwf cnt2
+dbgcnt2
+ decfsz cnt2,f
+ goto dbgcnt2
+ decfsz cnt1,f
+ goto dbgcnt1
+ bsf PORTD,0
+
+ goto wait_new_cmd
+
;; -------------------------------------
;; dummy user code
@@ -215,7 +265,7 @@ exec_cmd
bcf STATUS,RP0
userloop
movlw b'00000001'
- xorwf TRISD,f
+ xorwf PORTD,f
movlw .255
movwf cnt1
usercnt1