From c039a0a12d077576563bb427f40cc078cc04e798 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 4 Jul 2013 19:52:17 +0000 Subject: cleanups git-svn-id: https://svn.spreadspace.org/pic/trunk@35 a09c6847-51d9-44de-8ef2-e725cf50f3c7 --- bootloader/bootloader.asm | 114 +++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 63 deletions(-) (limited to 'bootloader') diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm index f21e789..87ee0f6 100644 --- a/bootloader/bootloader.asm +++ b/bootloader/bootloader.asm @@ -89,13 +89,14 @@ inbuff_end EQU H'006F' current_cmd EQU H'0070' current_cmdlen EQU H'0071' csum EQU H'0072' +ret EQU H'0073' -cnt1 EQU H'007E' -cnt2 EQU H'007F' +cnt2 EQU H'007E' +cnt1 EQU H'007F' ;; ------------------------------------- ;; Boot test - org .0 + org .0 ;; btfsc BOOTPIN ;; goto USERVECT goto boot @@ -116,13 +117,12 @@ uart_tx_byte return ack_cmd + movwf ret clrf csum movf inbuff,w call uart_tx_byte - - movlw E_OK + movf ret,w call uart_tx_byte - movf csum,w call uart_tx_byte return @@ -159,15 +159,15 @@ translate_cmd_codes get_cmdlen addwf PCL,f - 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 .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 | get_name addwf PCL,f @@ -175,44 +175,44 @@ get_name retlw 'c' retlw 'i' retlw 'p' - retlw 'x' - retlw 'o' - retlw 'n' - retlw 'i' - retlw 'u' - retlw 'q' + retlw '-' + retlw 'd' + retlw 'a' retlw 'e' + retlw 'r' + retlw 'p' + retlw 's' ;; ------------------------------------- ;; Bootloader (init) boot ;; bank 3 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'00001000' ; TX non-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 + movlw b'01110000' ; set internal OSC to 8MHz movwf OSCCON 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 .34 ; Baudrate = 57600 (@ 8MHz) -> -0,79 % Error + ;; movlw .51 ; Baudrate = 38400 (@ 8MHz) -> -0,002 % Error + ;; movlw .103 ; Baudrate = 19200 (@ 8MHz) -> 0,16 % Error movwf SPBRG clrf SPBRGH - bcf TRISD,0 ; DEBUG!!!! + bcf TRISD,0 ; DEBUG!!!! ;; bank 0 bcf STATUS,RP0 - movlw b'10010000' ; enable Serial Port, 8bit, enable continues receive, disable address detection + movlw b'10010000' ; enable Serial Port, 8bit, enable continues receive, disable address detection movwf RCSTA - bsf PORTD,0 ; DEBUG!!!! - + bsf PORTD,0 ; DEBUG!!!! + ;; INIT Finished wait_new_cmd movlw inbuff @@ -228,12 +228,12 @@ wait_cmd goto uart_rx_oe goto wait_cmd -uart_rx_oe +uart_rx_oe ; recover from overflow bcf RCSTA,CREN bsf RCSTA,CREN goto wait_new_cmd -uart_rx_byte +uart_rx_byte ; process received command btfsc RCSTA,FERR goto uart_rx_fe movf RCREG,w ; TODO: check parity?? @@ -246,50 +246,28 @@ uart_rx_byte goto wait_cmd goto exec_cmd -uart_rx_fe +uart_rx_fe ; recover from framing error movf RCREG,w goto wait_new_cmd -new_cmd +new_cmd ; got new command code call translate_cmd_codes movwf current_cmd xorlw CMD_INVALID btfsc STATUS,Z goto invalid_cmd - movf current_cmd,w + movf current_cmd,w ; initializing cmdlen call get_cmdlen movwf current_cmdlen goto wait_cmd -invalid_cmd - clrf csum - movf inbuff,w - call uart_tx_byte - +invalid_cmd ; received command code is not known movlw E_INV_CMD - call uart_tx_byte - - movf csum,w - call uart_tx_byte + call ack_cmd goto wait_new_cmd -exec_cmd - ;; DEBUG !!!! - 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 - ;; DEBUG !!!! - ;; TODO: check csum - movf current_cmd,w +exec_cmd ; command is correct and complete + movf current_cmd,w ; dispatch commands addwf PCL,f goto cmd_identify goto cmd_boot @@ -302,6 +280,8 @@ dbgcnt2 ;; goto cmd_w_config goto wait_new_cmd + ;; ** Command Handlers ******************** + ;; ** identify ******* cmd_identify clrf csum movlw CCMD_IDENTIFY @@ -346,28 +326,36 @@ cmd_identify_send_name call uart_tx_byte goto wait_new_cmd - + ;; ** boot ******* cmd_boot + movlw E_OK call ack_cmd goto USERVECT + ;; ** reset ******* cmd_reset + movlw E_OK call ack_cmd movlw b'00000001' movwf WDTCON ; why does this not work????? cmd_reset_wait goto cmd_reset_wait + ;; ** read flash ******* cmd_r_flash goto wait_new_cmd + ;; ** write flash ******* cmd_w_flash goto wait_new_cmd + ;; ** read eeprom ******* cmd_r_eeprom goto wait_new_cmd + ;; ** write eeprom ******* cmd_w_eeprom + ;; depending on the command may actually not be complete goto wait_new_cmd ;; cmd_r_config -- cgit v1.2.3