From 8543e8ea31c8e894256f88efd42f69f328a51a3b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 4 Jul 2013 02:15:58 +0000 Subject: identify works now git-svn-id: https://svn.spreadspace.org/pic/trunk@33 a09c6847-51d9-44de-8ef2-e725cf50f3c7 --- bootloader/bootloader.asm | 179 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 141 insertions(+), 38 deletions(-) (limited to 'bootloader') diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm index 684501d..ed65ed1 100644 --- a/bootloader/bootloader.asm +++ b/bootloader/bootloader.asm @@ -32,45 +32,53 @@ #define BOOTPIN PORTC,7 USERVECT EQU H'100' ISRVECT EQU USERVECT + H'4' -FSS EQU 8 -MESS EQU 64 + +VERSION_MAJ EQU .0 +VERSION_MIN EQU .1 +DEVID_H EQU H'20' +DEVID_L EQU H'82' +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 ;; ERROR codes -E_OK EQU 0 -E_INV_CMD EQU 1 -E_BAD_CSUM EQU 2 -E_NOT_IMPL EQU 3 -E_FLASH_WERR EQU 4 -E_ADDR_INVALID EQU 5 -E_ADDR_PROHIB EQU 6 +E_OK EQU .0 +E_INV_CMD EQU .1 +E_BAD_CSUM EQU .2 +E_NOT_IMPL EQU .3 +E_FLASH_WERR EQU .4 +E_ADDR_INVALID EQU .5 +E_ADDR_PROHIB EQU .6 ;; CMD codes CCMD_IDENTIFY EQU 'i' -CMD_IDENTIFY EQU 0 +CMD_IDENTIFY EQU .0 CCMD_BOOT EQU 'b' -CMD_BOOT EQU 1 +CMD_BOOT EQU .1 CCMD_RESET EQU 'r' -CMD_RESET EQU 2 +CMD_RESET EQU .2 CCMD_R_FLASH EQU 'f' -CMD_R_FLASH EQU 3 +CMD_R_FLASH EQU .3 CCMD_W_FLASH EQU 'F' -CMD_W_FLASH EQU 4 +CMD_W_FLASH EQU .4 CCMD_R_EEPROM EQU 'e' -CMD_R_EEPROM EQU 5 +CMD_R_EEPROM EQU .5 CCMD_W_EEPROM EQU 'E' -CMD_W_EEPROM EQU 6 +CMD_W_EEPROM EQU .6 CCMD_R_CONFIG EQU 'c' -CMD_R_CONFIG EQU 7 +CMD_R_CONFIG EQU .7 CCMD_W_CONFIG EQU 'C' -CMD_W_CONFIG EQU 8 +CMD_W_CONFIG EQU .8 CMD_INVALID EQU H'FF' @@ -80,22 +88,21 @@ inbuff_end EQU H'006F' current_cmd EQU H'0070' current_cmdlen EQU H'0071' - - +csum EQU H'0072' cnt1 EQU H'0070' cnt2 EQU H'0071' ;; ------------------------------------- ;; Boot test - org 0 + org .0 ;; btfsc BOOTPIN ;; goto USERVECT goto boot ;; ------------------------------------- ;; goto user ISR - org 4 + org .4 isr goto ISRVECT @@ -105,6 +112,7 @@ uart_tx_byte btfss PIR1,TXIF goto uart_tx_byte movwf TXREG + xorwf csum,f return translate_cmd_codes @@ -139,16 +147,29 @@ 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 + nop + retlw 'c' + retlw 'i' + retlw 'p' + retlw 'x' + retlw 'o' + retlw 'n' + retlw 'i' + retlw 'u' + retlw 'q' + retlw 'e' ;; ------------------------------------- ;; Bootloader (init) boot @@ -165,9 +186,9 @@ boot 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 @@ -229,17 +250,19 @@ new_cmd goto wait_cmd invalid_cmd + clrf csum movf inbuff,w call uart_tx_byte + movlw E_INV_CMD call uart_tx_byte - movlw E_INV_CMD - xorwf inbuff,w + + movf csum,w call uart_tx_byte goto wait_new_cmd exec_cmd - ;; TODO: execute received command + ;; DEBUG !!!! bcf PORTD,0 movlw .255 movwf cnt1 @@ -252,9 +275,89 @@ dbgcnt2 decfsz cnt1,f goto dbgcnt1 bsf PORTD,0 + ;; DEBUG !!!! + ;; TODO: check csum + movf current_cmd,w + addwf PCL,f + 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 + +cmd_identify + clrf csum + movlw CCMD_IDENTIFY + call uart_tx_byte + + movlw E_OK + call uart_tx_byte + + movlw VERSION_MIN + call uart_tx_byte + movlw VERSION_MAJ + call uart_tx_byte + + movlw .10 + movwf cnt1 +cmd_identify_send_name + movf cnt1,w + call get_name + call uart_tx_byte + decfsz cnt1,f + goto cmd_identify_send_name + + movlw DEVID_L + call uart_tx_byte + movlw DEVID_H + call uart_tx_byte + movlw FSS + call uart_tx_byte + + movlw MESS_L + call uart_tx_byte + movlw MESS_H + call uart_tx_byte + + movlw SUPPORTED_L + call uart_tx_byte + movlw SUPPORTED_H + call uart_tx_byte + + movf csum,w + call uart_tx_byte + goto wait_new_cmd + + +cmd_boot goto wait_new_cmd +cmd_reset + goto wait_new_cmd + +cmd_r_flash + goto wait_new_cmd + +cmd_w_flash + goto wait_new_cmd + +cmd_r_eeprom + goto wait_new_cmd + +cmd_w_eeprom + goto wait_new_cmd + +cmd_r_config + goto wait_new_cmd + +cmd_w_config + goto wait_new_cmd ;; ------------------------------------- ;; dummy user code -- cgit v1.2.3