From 3726891b8258a1ae8a531cbac5bf76d077ab4e3b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 5 Jul 2013 02:11:05 +0000 Subject: shorter version of command code check some cleanups git-svn-id: https://svn.spreadspace.org/pic/trunk@42 a09c6847-51d9-44de-8ef2-e725cf50f3c7 --- bootloader/bootloader.asm | 63 +++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm index 20bd0fd..0ea30a7 100644 --- a/bootloader/bootloader.asm +++ b/bootloader/bootloader.asm @@ -76,8 +76,7 @@ current_cmdlen EQU H'0070' csum EQU H'0071' flags EQU H'007D' -#define F_INVALID_CMD flags,0 -#define F_WEEP flags,7 +#define F_WEEP flags,0 cnt2 EQU H'007E' cnt1 EQU H'007F' @@ -120,25 +119,18 @@ send_answer_next call uart_tx_byte return -check_cmd_code - movf combuff,w - sublw CMD_MAX - btfss STATUS,C - bsf F_INVALID_CMD - return - get_cmdlen addwf PCL,f - retlw .0 ; invalid - retlw .1 ; identify: - retlw .1 ; boot: - retlw .1 ; reset: - retlw .3 ; read flash: addr | + retlw .0 ; invalid + retlw .1 ; identify: + retlw .1 ; boot: + retlw .1 ; reset: + retlw .3 ; read flash: addr | retlw .3 + .2*FSS ; write flash: addr | data | - retlw .5 ; read eeprom: addr | len | - retlw .5 ; write eeprom: addr | len | data | (minimal) - retlw .2 ; read config: nr | - retlw .4 ; write config: nr | word | + retlw .5 ; read eeprom: addr | len | + retlw .5 ; write eeprom: addr | len | data | (minimal) + retlw .2 ; read config: nr | + retlw .4 ; write config: nr | word | get_name addwf PCL,f @@ -160,18 +152,18 @@ boot bsf STATUS,RP0 bsf STATUS,RP1 movlw b'00001000' ; TX non-inverted, 16bit Baudrate, no auto baud detect - ;; movlw b'00011000' ; TX inverted, 16bit Baudrate, no auto baud detect + ;; movlw b'00011000' ; TX inverted, 16bit Baudrate, no auto baud detect movwf BAUDCTL ;; bank 1 bcf STATUS,RP1 movlw b'01110000' ; set internal OSC to 8MHz movwf OSCCON - movlw b'00100100' ; Baudrate = High Speed, async mode, transmit enabled, 8bit + movlw b'00100100' ; Baudrate = High Speed, async mode, transmit enabled, 8bit movwf TXSTA movlw .34 ; Baudrate = 57600 (@ 8MHz) -> -0,79 % Error - ;; movlw .51 ; Baudrate = 38400 (@ 8MHz) -> -0,002 % Error - ;; movlw .103 ; Baudrate = 19200 (@ 8MHz) -> 0,16 % Error + ;; movlw .51 ; Baudrate = 38400 (@ 8MHz) -> -0,002 % Error + ;; movlw .103 ; Baudrate = 19200 (@ 8MHz) -> 0,16 % Error movwf SPBRG clrf SPBRGH @@ -194,12 +186,12 @@ wait_cmd goto uart_rx_oe goto wait_cmd -uart_rx_oe ; recover from overflow +uart_rx_oe ; recover from overflow bcf RCSTA,CREN bsf RCSTA,CREN goto wait_new_cmd -uart_rx_byte ; process received command +uart_rx_byte ; process received command btfsc RCSTA,FERR goto uart_rx_fe movf RCREG,w @@ -212,32 +204,33 @@ uart_rx_byte ; process received command goto wait_cmd goto exec_cmd -uart_rx_fe ; recover from framing error +uart_rx_fe ; recover from framing error movf RCREG,w goto wait_new_cmd -new_cmd ; got new command code - call check_cmd_code - btfsc F_INVALID_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 movwf current_cmdlen goto wait_cmd -invalid_cmd ; received command code is not known +invalid_cmd ; received command code is not known movlw E_INV_CMD movwf combuff + .1 movlw .2 call send_answer goto wait_new_cmd -exec_cmd ; command is correct and complete +exec_cmd ; command is correct and complete ;; TODO: check csum -> csum for write eeprom will not be correct because ;; it isn't finished yet....??? - movf combuff,w ; dispatch commands + movf combuff,w ; dispatch commands addwf PCL,f - nop + goto wait_new_cmd goto cmd_identify goto cmd_boot goto cmd_reset @@ -310,7 +303,7 @@ cmd_reset movlw .2 call send_answer movlw b'00000001' - movwf WDTCON ; why does this not work????? + movwf WDTCON ; why does this not work????? cmd_reset_wait goto cmd_reset_wait @@ -398,8 +391,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 + .1 ; = E_OK + retlw .2 + .2*FSS ; bytes to send ;; ------------------------------------- ;; ------------------------------------- -- cgit v1.2.3