summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-11 01:16:48 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-11 01:16:48 +0000
commitf7dc5cdbfd6db4eebaa872474f36a474acf7ec88 (patch)
treeb53fc8b15d653d94da54079876b675b4c05b0a3a
parentcleanup (diff)
added inital support for 16f1847
git-svn-id: https://svn.spreadspace.org/pic/trunk@75 a09c6847-51d9-44de-8ef2-e725cf50f3c7
-rw-r--r--bootloader/Makefile-94726
-rw-r--r--bootloader/bootloader-947.asm110
-rw-r--r--bootloader/cmds-16f1847.inc121
-rw-r--r--bootloader/com-16f1847-uart.inc76
4 files changed, 333 insertions, 0 deletions
diff --git a/bootloader/Makefile-947 b/bootloader/Makefile-947
new file mode 100644
index 0000000..4f18a7b
--- /dev/null
+++ b/bootloader/Makefile-947
@@ -0,0 +1,26 @@
+##
+## 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/>.
+##
+
+PROJECT := bootloader-947
+PROC_TYPE := 16F1847
+
+include ../include.mk
diff --git a/bootloader/bootloader-947.asm b/bootloader/bootloader-947.asm
new file mode 100644
index 0000000..4a1747e
--- /dev/null
+++ b/bootloader/bootloader-947.asm
@@ -0,0 +1,110 @@
+ ;;
+ ;; 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/>.
+ ;;
+ ;; -------------------------------------
+ ;; PREAMBLE
+
+ LIST p=16F1847
+ include "p16f1847.inc"
+ __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
+ __config _CONFIG2, _WRT_BOOT & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_OFF
+
+ ;; -------------------------------------
+ ;; DEFINES (chip/com specific)
+#define BOOTPIN PORTC,7
+USERVECT EQU H'200'
+ISRVECT EQU USERVECT + H'4'
+FLASH_BOUNDARY EQU b'00011111' ; flash write boundary is at 32 bytes boundaries
+
+VERSION_MAJ EQU .0
+VERSION_MIN EQU .1
+NAME_0 EQU '9'
+NAME_1 EQU '4'
+NAME_2 EQU '7'
+DEVID_L EQU H'82'
+DEVID_H EQU H'14'
+FLASH_SIZE_L EQU H'00'
+FLASH_SIZE_H EQU H'20' ; 0x2000 -> 8192 Words of Flash
+FSS EQU .32 ; there 32 write latches
+EEPROM_SIZE_L EQU H'00'
+EEPROM_SIZE_H EQU H'01' ; 0x0100 -> 256 Bytes of EEPROM
+MESS EQU .64 ; this limit is because of to combuff size and single byte len field for messages
+SUPPORTED_H EQU .0
+SUPPORTED_L EQU b'00000110' ; only read/write flash is supported by now
+
+#define HOOK_CMD_RESET cmd_not_impl
+#define HOOK_CMD_R_FLASH cmd_r_flash
+#define HOOK_CMD_W_FLASH cmd_w_flash
+#define HOOK_CMD_R_EEPROM cmd_not_impl
+#define HOOK_CMD_W_EEPROM cmd_not_impl
+#define HOOK_CMD_R_CONFIG cmd_not_impl
+#define HOOK_CMD_W_CONFIG cmd_not_impl
+
+ ;; Variables
+combuff EQU H'0020'
+current_cmdlen EQU H'0070'
+csum EQU H'0071'
+flags EQU H'007D'
+cnt EQU H'007F'
+
+ ;; for compatibility with older MCUs
+#define FSR FSR0L
+#define INDF INDF0
+
+ ;; -------------------------------------
+ ;; DEFINES (defines)
+#include "generic-defines.inc"
+
+ ;; -------------------------------------
+ ;; Bootloader init
+#include "generic-init.inc"
+
+ ;; -------------------------------------
+ ;; Bootloader (com specific subroutines and init)
+#include "com-16f1847-uart.inc"
+
+ ;; -------------------------------------
+ ;; Bootloader (generic init/body)
+#include "generic-mainloop.inc"
+
+ ;; -------------------------------------
+ ;; chip specific commands
+#include "cmds-16f1847.inc"
+
+ ;; -------------------------------------
+ ;; -------------------------------------
+ ;; dummy user code
+ org USERVECT
+ movlb .1
+ movlw b'11111110'
+ movwf TRISB
+ movlb .0
+userloop
+ call com_rx_byte
+ call com_tx_byte
+ movlw b'00000001'
+ xorwf PORTB,f
+ goto userloop
+ ;; goto USERVECT
+
+ ;; -------------------------------------
+ ;; END
+ end
diff --git a/bootloader/cmds-16f1847.inc b/bootloader/cmds-16f1847.inc
new file mode 100644
index 0000000..2e6d7e4
--- /dev/null
+++ b/bootloader/cmds-16f1847.inc
@@ -0,0 +1,121 @@
+ ;;
+ ;; 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/>.
+ ;;
+
+ ;; flash read --------
+cmd_r_flash
+;; movlw FSS ; initialize EEADR:EEADRH and FSR
+;; movwf cnt
+;; movlw b'01011000'
+;; movwf STATUS
+;; movlw combuff + .2
+;; movwf FSR
+;; movf INDF,w
+;; movwf EEADR
+;; incf FSR,f
+;; movf INDF,w
+;; movwf EEADRH
+;; read_flash_segment_loop
+;; bsf STATUS,RP0 ; perform the actual read
+;; bsf EECON1,EEPGD
+;; bsf EECON1,RD
+;; nop
+;; nop
+;; bcf STATUS,RP0
+;; movf EEDAT,w ; load code word from EEDAT:EEDATH to combuff
+;; movwf INDF
+;; incf FSR,f
+;; movf EEDATH,w
+;; movwf INDF
+;; incf FSR,f
+;; incfsz EEADR,f ; increment flash address
+;; goto read_flash_segment_next
+;; incf EEADRH,f
+g;; read_flash_segment_next
+;; decfsz cnt,f
+;; goto read_flash_segment_loop
+;; bcf STATUS,RP1
+;; clrf combuff + .2 ; = E_OK
+;; movlw .1 + .2*FSS ; bytes to send
+;; call send_answer
+ movlw E_NOT_IMPL
+ call ack_cmd
+ goto wait_new_cmd
+
+ ;; flash write --------
+cmd_w_flash
+;; movf combuff + .3,f ; if addr[15:8] == 0 -> boot loader section
+;; btfsc STATUS,Z
+;; goto address_prohibited
+;; movlw FLASH_BOUNDARY ; addr on boundary?
+;; andwf combuff + .2,w
+;; btfss STATUS,Z
+;; goto address_invalid
+;; movlw FSS ; initialize EEADR:EEADRH and FSR
+;; movwf cnt
+;; movlw b'01011000'
+;; movwf STATUS
+;; movlw combuff + .2
+;; movwf FSR
+;; movf INDF,w
+;; movwf EEADR
+;; incf FSR,f
+;; movf INDF,w
+;; movwf EEADRH
+
+;; write_flash_segment_loop
+;; incf FSR,f ; load code word into EEDAT:EEDATH
+;; movf INDF,w
+;; movwf EEDAT
+;; incf FSR,f
+;; movf INDF,w
+;; movwf EEDATH
+
+;; bsf STATUS,RP0 ; now start the acutal write sequence
+;; bsf EECON1,EEPGD
+;; bsf EECON1,WREN
+;; movlw H'55'
+;; movwf EECON2
+;; movlw H'AA'
+;; movwf EECON2
+;; bsf EECON1,WR
+;; nop
+;; nop
+;; bcf EECON1,WREN
+;; bcf STATUS,RP0
+;; incfsz EEADR,f ; increment flash address
+;; goto write_flash_segment_next
+;; incf EEADRH,f
+;; write_flash_segment_next
+;; decfsz cnt,f
+;; goto write_flash_segment_loop
+;; bsf STATUS,RP0
+;; clrw ; check if a write error occured
+;; btfsc EECON1,WRERR
+;; movlw E_FLASH_WERR
+;; bcf STATUS,RP1
+;; bcf STATUS,RP0
+;; movwf combuff + .2 ; = E_OK
+;; movlw .1 ; bytes to send
+;; call send_answer
+ movlw E_NOT_IMPL
+ call ack_cmd
+ goto wait_new_cmd
diff --git a/bootloader/com-16f1847-uart.inc b/bootloader/com-16f1847-uart.inc
new file mode 100644
index 0000000..2db9eca
--- /dev/null
+++ b/bootloader/com-16f1847-uart.inc
@@ -0,0 +1,76 @@
+ ;;
+ ;; 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
+ movlb .3
+ movwf TXREG
+ xorwf csum,f
+ movlb .0
+ return
+
+ ;; ---- wait for byte to be received
+com_rx_byte
+ movlb .3
+ btfsc RCSTA,OERR
+ goto uart_rx_oe
+ movlb .0
+ btfss PIR1,RCIF
+ goto com_rx_byte
+ movlb .3
+ btfsc RCSTA,FERR
+ goto uart_rx_fe
+ movf RCREG,w
+ movlb .0
+ 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
+ movlb .1
+ movlw b'01110000' ; 8 MHz
+ movwf OSCCON
+
+ movlb .3
+ bcf ANSELB,ANSB1
+ movlw b'01001000' ; TX non-inverted, 16bit Baudrate, no auto baud detect
+ movwf BAUDCON
+ 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 SPBRGL
+ clrf SPBRGH
+ movlw b'10010000' ; enable Serial Port, 8bit, enable continues receive, disable address detection
+ movwf RCSTA
+ movlb .0