summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-08 01:48:14 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-08 01:48:14 +0000
commitbd153583896886e026503ec99e0870969d374a23 (patch)
tree6b4e7f5d57aeff25f0aba16fc7f4d8d53176f746
parentadded generic 887 code (diff)
split bootloader code into includes
git-svn-id: https://svn.spreadspace.org/pic/trunk@60 a09c6847-51d9-44de-8ef2-e725cf50f3c7
-rw-r--r--bootloader/bootloader-887.asm278
-rw-r--r--bootloader/com-887-uart.inc75
-rw-r--r--bootloader/generic-defines.inc47
-rw-r--r--bootloader/generic-init.inc61
-rw-r--r--bootloader/generic-mainloop.inc174
-rwxr-xr-xdownloader/downloader.py8
6 files changed, 367 insertions, 276 deletions
diff --git a/bootloader/bootloader-887.asm b/bootloader/bootloader-887.asm
index 03307df..dbe2fac 100644
--- a/bootloader/bootloader-887.asm
+++ b/bootloader/bootloader-887.asm
@@ -74,285 +74,19 @@ cnt EQU H'007F'
;; -------------------------------------
;; DEFINES (defines)
- ;; 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_VALUE_OOB EQU .7
-
- ;; CMD codes
-CMD_INVALID EQU .0
-
-CMD_IDENTIFY EQU .1
-CMD_BOOT EQU .2
-CMD_RESET EQU .3
-CMD_R_FLASH EQU .4
-CMD_W_FLASH EQU .5
-CMD_R_EEPROM EQU .6
-CMD_W_EEPROM EQU .7
-CMD_R_CONFIG EQU .8
-CMD_W_CONFIG EQU .9
-
-CMD_MAX EQU .9
-CMD_MIN_LEN EQU .3
-
- ;; -------------------------------------
- ;; Boot test
- org .0
- ;; btfsc BOOTPIN
- ;; goto USERVECT
- goto com_init
+#include "generic-defines.inc"
;; -------------------------------------
- ;; goto user ISR
- org .4
-isr
- goto ISRVECT
-
- ;; -------------------------------------
- ;; Bootloader (Generic Subroutines)
-send_answer ; generic answer message, leave len of data in W
- addlw .3
- movwf combuff + .1
- decf combuff + .1,w
- movwf cnt
- movlw combuff
- movwf FSR
- clrf csum
-send_answer_next
- movf INDF,w
- call com_tx_byte
- incf FSR,f
- decfsz cnt,f
- goto send_answer_next
-
- movf csum,w
- call com_tx_byte
- return
-
- ;; ------------------
-ack_cmd ; short answers which only contain return code
- movwf combuff + .2
- movlw .1
- call send_answer
- return
-
+ ;; Bootloader init
+#include "generic-init.inc"
;; -------------------------------------
;; Bootloader (com specific subroutines and init)
- ;; ------------------
-com_tx_byte ;send one byte and add it to csum
- btfss PIR1,TXIF
- goto com_tx_byte
- movwf TXREG
- xorwf csum,f
- return
-
- ;; ------------------
-com_rx_byte
- btfsc RCSTA,OERR
- goto uart_rx_oe
- btfss PIR1,RCIF
- goto com_rx_byte
- btfsc RCSTA,FERR
- goto uart_rx_fe
- movf RCREG,w
- return
-
-uart_rx_oe ; recover from overflow
- bcf RCSTA,CREN
- bsf RCSTA,CREN
- goto com_rx_byte
-
-uart_rx_fe ; recover from framing error
- movf RCREG,w
- goto com_rx_byte
-
- ;; ------------------
-com_init
- ;; 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
- 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
- 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
- movwf SPBRG
- clrf SPBRGH
-
- ;; bank 0
- bcf STATUS,RP0
- movlw b'10010000' ; enable Serial Port, 8bit, enable continues receive, disable address detection
- movwf RCSTA
+#include "com-887-uart.inc"
;; -------------------------------------
- ;; Bootloader (generic init)
-
-wait_new_cmd
- movlw combuff
- movwf FSR
- clrf combuff
- clrf current_cmdlen
- clrf flags
-
-wait_cmd
- call com_rx_byte
- movwf INDF ; process received byte
- incf FSR,f
- btfss F_CMD_STARTED
- goto wait_cmd_len
- movf current_cmdlen,f
- btfsc STATUS,Z
- goto new_cmd
- decfsz current_cmdlen,f
- goto wait_cmd
- goto exec_cmd
-
-wait_cmd_len ; command code received, now wait for length
- bsf F_CMD_STARTED
- goto wait_cmd
-
-new_cmd ; got new command code and length -> check it
- movf combuff,w
- sublw CMD_MAX
- btfss STATUS,C
- goto invalid_cmd
- movlw CMD_MIN_LEN ; check for minimum command len
- subwf combuff + .1,w
- btfss STATUS,C
- goto invalid_cmd
- movlw .2 ; 2 bytes already received
- subwf combuff + .1,w
- movwf current_cmdlen
- goto wait_cmd
-
-exec_cmd ; command is complete -> check csum
- movlw combuff
- movwf FSR
- movf combuff + .1,w
- movwf cnt
- clrf csum
-exec_cmd_check_csum
- movf INDF,w
- xorwf csum,f
- incf FSR,f
- decfsz cnt,f
- goto exec_cmd_check_csum
- movf csum,f
- btfss STATUS,Z
- goto csum_error
-
- movf combuff,w ; command is correct and complete -> dispatch
- addwf PCL,f
- goto wait_new_cmd
- goto cmd_identify ; identify
- goto cmd_boot ; boot
- goto HOOK_CMD_RESET ; reset
- goto HOOK_CMD_R_FLASH ; read flash segment
- goto HOOK_CMD_W_FLASH ; write flash segment
- goto HOOK_CMD_R_EEPROM ; read eeprom
- goto HOOK_CMD_W_EEPROM ; write eeprom
- goto HOOK_CMD_R_CONFIG ; read config
- goto HOOK_CMD_R_CONFIG ; write config
-
- ;; ** generic error messages *******
-invalid_cmd ; received command code is not known or len is bogus
- movlw E_INV_CMD
- call ack_cmd
- goto wait_new_cmd
-
-csum_error ; received command has an invalid check sum
- movlw E_BAD_CSUM
- call ack_cmd
- goto wait_new_cmd
-
-address_invalid ; received command uses invalid address (i.e. not aligned to 16bytes)
- movlw E_ADDR_INVALID
- call ack_cmd
- goto wait_new_cmd
-
-address_prohibited ; received command uses prohibited address (i.e. FLASH < 0x100)
- movlw E_ADDR_PROHIB
- call ack_cmd
- goto wait_new_cmd
-
- ;; ** generic command handlers ************
- ;; ** identify *******
-cmd_identify
- clrf csum
- movf combuff,w
- call com_tx_byte
-
- movlw .19
- call com_tx_byte
-
- movlw E_OK
- call com_tx_byte
-
- movlw VERSION_MIN
- call com_tx_byte
- movlw VERSION_MAJ
- call com_tx_byte
-
- movlw NAME_0
- call com_tx_byte
- movlw NAME_1
- call com_tx_byte
- movlw NAME_2
- call com_tx_byte
-
- movlw DEVID_L
- call com_tx_byte
- movlw DEVID_H
- call com_tx_byte
-
- movlw FLASH_SIZE_L
- call com_tx_byte
- movlw FLASH_SIZE_H
- call com_tx_byte
- movlw FSS
- call com_tx_byte
-
- movlw EEPROM_SIZE_L
- call com_tx_byte
- movlw EEPROM_SIZE_H
- call com_tx_byte
- movlw MESS
- call com_tx_byte
-
- movlw SUPPORTED_L
- call com_tx_byte
- movlw SUPPORTED_H
- call com_tx_byte
-
- movf csum,w
- call com_tx_byte
- goto wait_new_cmd
-
- ;; ** boot *******
-cmd_boot
- movlw E_OK
- call ack_cmd
- goto USERVECT
-
- ;; ** not implemented commands *******
-cmd_not_impl
- movlw E_NOT_IMPL
- call ack_cmd
- goto wait_new_cmd
+ ;; Bootloader (generic init/body)
+#include "generic-mainloop.inc"
;; -------------------------------------
;; chip specific commands
diff --git a/bootloader/com-887-uart.inc b/bootloader/com-887-uart.inc
new file mode 100644
index 0000000..b9d05b2
--- /dev/null
+++ b/bootloader/com-887-uart.inc
@@ -0,0 +1,75 @@
+ ;;
+ ;; spreadspace pic utils
+ ;;
+ ;;
+ ;; Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+ ;;
+ ;; This file is part of spreadspace pic utils.
+ ;;
+ ;; spreadspace pic utils is free software: you can redistribute it and/or modify
+ ;; it under the terms of the GNU General Public License as published by
+ ;; the Free Software Foundation, either version 3 of the License, or
+ ;; any later version.
+ ;;
+ ;; spreadspace pic utils is distributed in the hope that it will be useful,
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ;; GNU General Public License for more details.
+ ;;
+ ;; You should have received a copy of the GNU General Public License
+ ;; along with spreadspace pic utils. If not, see <http://www.gnu.org/licenses/>.
+ ;;
+
+ ;; --- transmit byte and add it to csum
+com_tx_byte
+ btfss PIR1,TXIF
+ goto com_tx_byte
+ movwf TXREG
+ xorwf csum,f
+ return
+
+ ;; ---- wait for byte to be received
+com_rx_byte
+ btfsc RCSTA,OERR
+ goto uart_rx_oe
+ btfss PIR1,RCIF
+ goto com_rx_byte
+ btfsc RCSTA,FERR
+ goto uart_rx_fe
+ movf RCREG,w
+ return
+
+uart_rx_oe ; recover from overflow
+ bcf RCSTA,CREN
+ bsf RCSTA,CREN
+ goto com_rx_byte
+
+uart_rx_fe ; recover from framing error
+ movf RCREG,w
+ goto com_rx_byte
+
+ ;; ----- initialize com (not a subroutine, com_init is called by generic_init
+com_init
+ ;; 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
+ 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
+ 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
+ movwf SPBRG
+ clrf SPBRGH
+
+ ;; bank 0
+ bcf STATUS,RP0
+ movlw b'10010000' ; enable Serial Port, 8bit, enable continues receive, disable address detection
+ movwf RCSTA
diff --git a/bootloader/generic-defines.inc b/bootloader/generic-defines.inc
new file mode 100644
index 0000000..daed57a
--- /dev/null
+++ b/bootloader/generic-defines.inc
@@ -0,0 +1,47 @@
+ ;;
+ ;; spreadspace pic utils
+ ;;
+ ;;
+ ;; Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+ ;;
+ ;; This file is part of spreadspace pic utils.
+ ;;
+ ;; spreadspace pic utils is free software: you can redistribute it and/or modify
+ ;; it under the terms of the GNU General Public License as published by
+ ;; the Free Software Foundation, either version 3 of the License, or
+ ;; any later version.
+ ;;
+ ;; spreadspace pic utils is distributed in the hope that it will be useful,
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ;; GNU General Public License for more details.
+ ;;
+ ;; You should have received a copy of the GNU General Public License
+ ;; along with spreadspace pic utils. If not, see <http://www.gnu.org/licenses/>.
+ ;;
+
+ ;; 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_VALUE_OOB EQU .7
+
+ ;; CMD codes
+CMD_INVALID EQU .0
+
+CMD_IDENTIFY EQU .1
+CMD_BOOT EQU .2
+CMD_RESET EQU .3
+CMD_R_FLASH EQU .4
+CMD_W_FLASH EQU .5
+CMD_R_EEPROM EQU .6
+CMD_W_EEPROM EQU .7
+CMD_R_CONFIG EQU .8
+CMD_W_CONFIG EQU .9
+
+CMD_MAX EQU .9
+CMD_MIN_LEN EQU .3
diff --git a/bootloader/generic-init.inc b/bootloader/generic-init.inc
new file mode 100644
index 0000000..c679dd9
--- /dev/null
+++ b/bootloader/generic-init.inc
@@ -0,0 +1,61 @@
+ ;;
+ ;; spreadspace pic utils
+ ;;
+ ;;
+ ;; Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+ ;;
+ ;; This file is part of spreadspace pic utils.
+ ;;
+ ;; spreadspace pic utils is free software: you can redistribute it and/or modify
+ ;; it under the terms of the GNU General Public License as published by
+ ;; the Free Software Foundation, either version 3 of the License, or
+ ;; any later version.
+ ;;
+ ;; spreadspace pic utils is distributed in the hope that it will be useful,
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ;; GNU General Public License for more details.
+ ;;
+ ;; You should have received a copy of the GNU General Public License
+ ;; along with spreadspace pic utils. If not, see <http://www.gnu.org/licenses/>.
+ ;;
+
+ org .0
+ ;; btfsc BOOTPIN
+ ;; goto USERVECT
+ goto com_init
+
+ ;; -------------------------------------
+ ;; goto user ISR
+ org .4
+isr
+ goto ISRVECT
+
+ ;; -------------------------------------
+ ;; Bootloader (Generic Subroutines)
+send_answer ; generic answer message, leave len of data in W
+ addlw .3
+ movwf combuff + .1
+ decf combuff + .1,w
+ movwf cnt
+ movlw combuff
+ movwf FSR
+ clrf csum
+send_answer_next
+ movf INDF,w
+ call com_tx_byte
+ incf FSR,f
+ decfsz cnt,f
+ goto send_answer_next
+
+ movf csum,w
+ call com_tx_byte
+ return
+
+ ;; ------------------
+ack_cmd ; short answers which only contain return code
+ movwf combuff + .2
+ movlw .1
+ call send_answer
+ return
+
diff --git a/bootloader/generic-mainloop.inc b/bootloader/generic-mainloop.inc
new file mode 100644
index 0000000..1e93648
--- /dev/null
+++ b/bootloader/generic-mainloop.inc
@@ -0,0 +1,174 @@
+ ;;
+ ;; spreadspace pic utils
+ ;;
+ ;;
+ ;; Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+ ;;
+ ;; This file is part of spreadspace pic utils.
+ ;;
+ ;; spreadspace pic utils is free software: you can redistribute it and/or modify
+ ;; it under the terms of the GNU General Public License as published by
+ ;; the Free Software Foundation, either version 3 of the License, or
+ ;; any later version.
+ ;;
+ ;; spreadspace pic utils is distributed in the hope that it will be useful,
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ;; GNU General Public License for more details.
+ ;;
+ ;; You should have received a copy of the GNU General Public License
+ ;; along with spreadspace pic utils. If not, see <http://www.gnu.org/licenses/>.
+ ;;
+
+wait_new_cmd
+ movlw combuff
+ movwf FSR
+ clrf combuff
+ clrf current_cmdlen
+ clrf flags
+
+wait_cmd
+ call com_rx_byte
+ movwf INDF ; process received byte
+ incf FSR,f
+ btfss F_CMD_STARTED
+ goto wait_cmd_len
+ movf current_cmdlen,f
+ btfsc STATUS,Z
+ goto new_cmd
+ decfsz current_cmdlen,f
+ goto wait_cmd
+ goto exec_cmd
+
+wait_cmd_len ; command code received, now wait for length
+ bsf F_CMD_STARTED
+ goto wait_cmd
+
+new_cmd ; got new command code and length -> check it
+ movf combuff,w
+ sublw CMD_MAX
+ btfss STATUS,C
+ goto invalid_cmd
+ movlw CMD_MIN_LEN ; check for minimum command len
+ subwf combuff + .1,w
+ btfss STATUS,C
+ goto invalid_cmd
+ movlw .2 ; 2 bytes already received
+ subwf combuff + .1,w
+ movwf current_cmdlen
+ goto wait_cmd
+
+exec_cmd ; command is complete -> check csum
+ movlw combuff
+ movwf FSR
+ movf combuff + .1,w
+ movwf cnt
+ clrf csum
+exec_cmd_check_csum
+ movf INDF,w
+ xorwf csum,f
+ incf FSR,f
+ decfsz cnt,f
+ goto exec_cmd_check_csum
+ movf csum,f
+ btfss STATUS,Z
+ goto csum_error
+
+ movf combuff,w ; command is correct and complete -> dispatch
+ addwf PCL,f
+ goto wait_new_cmd
+ goto cmd_identify ; identify
+ goto cmd_boot ; boot
+ goto HOOK_CMD_RESET ; reset
+ goto HOOK_CMD_R_FLASH ; read flash segment
+ goto HOOK_CMD_W_FLASH ; write flash segment
+ goto HOOK_CMD_R_EEPROM ; read eeprom
+ goto HOOK_CMD_W_EEPROM ; write eeprom
+ goto HOOK_CMD_R_CONFIG ; read config
+ goto HOOK_CMD_R_CONFIG ; write config
+
+ ;; ** generic error messages *******
+invalid_cmd ; received command code is not known or len is bogus
+ movlw E_INV_CMD
+ call ack_cmd
+ goto wait_new_cmd
+
+csum_error ; received command has an invalid check sum
+ movlw E_BAD_CSUM
+ call ack_cmd
+ goto wait_new_cmd
+
+address_invalid ; received command uses invalid address (i.e. not aligned to 16bytes)
+ movlw E_ADDR_INVALID
+ call ack_cmd
+ goto wait_new_cmd
+
+address_prohibited ; received command uses prohibited address (i.e. FLASH < 0x100)
+ movlw E_ADDR_PROHIB
+ call ack_cmd
+ goto wait_new_cmd
+
+ ;; ** generic command handlers ************
+ ;; ** identify *******
+cmd_identify
+ clrf csum
+ movf combuff,w
+ call com_tx_byte
+
+ movlw .19
+ call com_tx_byte
+
+ movlw E_OK
+ call com_tx_byte
+
+ movlw VERSION_MIN
+ call com_tx_byte
+ movlw VERSION_MAJ
+ call com_tx_byte
+
+ movlw NAME_0
+ call com_tx_byte
+ movlw NAME_1
+ call com_tx_byte
+ movlw NAME_2
+ call com_tx_byte
+
+ movlw DEVID_L
+ call com_tx_byte
+ movlw DEVID_H
+ call com_tx_byte
+
+ movlw FLASH_SIZE_L
+ call com_tx_byte
+ movlw FLASH_SIZE_H
+ call com_tx_byte
+ movlw FSS
+ call com_tx_byte
+
+ movlw EEPROM_SIZE_L
+ call com_tx_byte
+ movlw EEPROM_SIZE_H
+ call com_tx_byte
+ movlw MESS
+ call com_tx_byte
+
+ movlw SUPPORTED_L
+ call com_tx_byte
+ movlw SUPPORTED_H
+ call com_tx_byte
+
+ movf csum,w
+ call com_tx_byte
+ goto wait_new_cmd
+
+ ;; ** boot *******
+cmd_boot
+ movlw E_OK
+ call ack_cmd
+ goto USERVECT
+
+ ;; ** not implemented commands *******
+cmd_not_impl
+ movlw E_NOT_IMPL
+ call ack_cmd
+ goto wait_new_cmd
diff --git a/downloader/downloader.py b/downloader/downloader.py
index 459e0d2..93877a6 100755
--- a/downloader/downloader.py
+++ b/downloader/downloader.py
@@ -347,7 +347,7 @@ Options:
dev = open_serial(device, baudrate)
id = cmd_identify(dev, name)
- try:
- commands[cmd](dev, id, args[0])
- except KeyError:
- print >> sys.stderr, "ERROR: unkown command '%s'" % cmd
+# try:
+# commands[cmd](dev, id, args[0])
+# except KeyError:
+# print >> sys.stderr, "ERROR: unkown command '%s'" % cmd