summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-04 22:28:25 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-04 22:28:25 +0000
commit5b75aff608197bd4b229e89274988ebdfb522a80 (patch)
tree8e433e1d8bab8eec8d6d4f991f9250bb64db1ea8
parentcleanups (diff)
fixed issues with short answers
bootloader now has working stubs for all commands git-svn-id: https://svn.spreadspace.org/pic/trunk@36 a09c6847-51d9-44de-8ef2-e725cf50f3c7
-rw-r--r--bootloader/bootloader.asm106
-rwxr-xr-xdownloader/downloader.py43
-rw-r--r--downloader/proto.txt9
3 files changed, 99 insertions, 59 deletions
diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm
index 87ee0f6..02b9105 100644
--- a/bootloader/bootloader.asm
+++ b/bootloader/bootloader.asm
@@ -51,6 +51,7 @@ 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
CCMD_IDENTIFY EQU 'i'
@@ -83,13 +84,15 @@ CMD_W_CONFIG EQU .8
CMD_INVALID EQU H'FF'
;; Variables
-inbuff EQU H'0020'
-inbuff_end EQU H'006F'
+combuff EQU H'0020'
+combuff_end EQU H'006F'
current_cmd EQU H'0070'
current_cmdlen EQU H'0071'
csum EQU H'0072'
-ret EQU H'0073'
+
+flags EQU H'007D'
+weep EQU .0
cnt2 EQU H'007E'
cnt1 EQU H'007F'
@@ -116,13 +119,18 @@ uart_tx_byte
xorwf csum,f
return
-ack_cmd
- movwf ret
+send_answer
+ movwf cnt1
+ movlw combuff
+ movwf FSR
clrf csum
- movf inbuff,w
- call uart_tx_byte
- movf ret,w
+send_answer_next
+ movf INDF,w
call uart_tx_byte
+ incf FSR,f
+ decfsz cnt1,f
+ goto send_answer_next
+
movf csum,w
call uart_tx_byte
return
@@ -149,12 +157,12 @@ translate_cmd_codes
xorlw CCMD_W_EEPROM ^ CCMD_R_EEPROM
btfsc STATUS,Z
retlw CMD_W_EEPROM
- ;; xorlw CCMD_R_CONFIG ^ CCMD_W_EEPROM
- ;; btfsc STATUS,Z
- ;; retlw CMD_R_CONFIG
- ;; xorlw CCMD_W_CONFIG ^ CCMD_R_CONFIG
- ;; btfsc STATUS,Z
- ;; retlw CMD_W_CONFIG
+ xorlw CCMD_R_CONFIG ^ CCMD_W_EEPROM
+ btfsc STATUS,Z
+ retlw CMD_R_CONFIG
+ xorlw CCMD_W_CONFIG ^ CCMD_R_CONFIG
+ btfsc STATUS,Z
+ retlw CMD_W_CONFIG
retlw CMD_INVALID
get_cmdlen
@@ -166,8 +174,8 @@ get_cmdlen
retlw .3 + .2*FSS ; write flash: addr | data | <csum>
retlw .5 ; read eeprom: addr | len | <csum>
retlw .5 ; write eeprom: addr | len | data | <csum> (minimal)
- ;; retlw .2 ; read config: nr | <csum>
- ;; retlw .4 ; write config: nr | word | <csum>
+ retlw .2 ; read config: nr | <csum>
+ retlw .4 ; write config: nr | word | <csum>
get_name
addwf PCL,f
@@ -204,22 +212,18 @@ boot
movwf SPBRG
clrf SPBRGH
- bcf TRISD,0 ; DEBUG!!!!
-
;; bank 0
bcf STATUS,RP0
movlw b'10010000' ; enable Serial Port, 8bit, enable continues receive, disable address detection
movwf RCSTA
- bsf PORTD,0 ; DEBUG!!!!
- ;; INIT Finished
-
wait_new_cmd
- movlw inbuff
+ movlw combuff
movwf FSR
movlw CMD_INVALID
movwf current_cmd
clrf current_cmdlen
+ clrf flags
wait_cmd
btfsc PIR1,RCIF
@@ -263,10 +267,14 @@ new_cmd ; got new command code
invalid_cmd ; received command code is not known
movlw E_INV_CMD
- call ack_cmd
+ movwf combuff + .1
+ movlw .2
+ call send_answer
goto wait_new_cmd
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 current_cmd,w ; dispatch commands
addwf PCL,f
goto cmd_identify
@@ -276,8 +284,8 @@ exec_cmd ; command is correct and complete
goto cmd_w_flash
goto cmd_r_eeprom
goto cmd_w_eeprom
- ;; goto cmd_r_config
- ;; goto cmd_w_config
+ goto cmd_r_config
+ goto cmd_w_config
goto wait_new_cmd
;; ** Command Handlers ********************
@@ -329,13 +337,17 @@ cmd_identify_send_name
;; ** boot *******
cmd_boot
movlw E_OK
- call ack_cmd
+ movwf combuff + .1
+ movlw .2
+ call send_answer
goto USERVECT
;; ** reset *******
cmd_reset
movlw E_OK
- call ack_cmd
+ movwf combuff + .1
+ movlw .2
+ call send_answer
movlw b'00000001'
movwf WDTCON ; why does this not work?????
cmd_reset_wait
@@ -343,26 +355,56 @@ cmd_reset_wait
;; ** read flash *******
cmd_r_flash
+ ;; call read_flash_segment
+ movlw E_ADDR_INVALID
+ movwf combuff + .1
+ movlw .2
+ call send_answer
goto wait_new_cmd
;; ** write flash *******
cmd_w_flash
+ ;; call write_flash_segment
+ movlw E_ADDR_INVALID
+ movwf combuff + .1
+ movlw .2
+ call send_answer
goto wait_new_cmd
;; ** read eeprom *******
cmd_r_eeprom
+ ;; call read_eeprom
+ movlw E_ADDR_INVALID
+ movwf combuff + .1
+ movlw .2
+ call send_answer
goto wait_new_cmd
;; ** write eeprom *******
cmd_w_eeprom
- ;; depending on <len> the command may actually not be complete
+ btfss flags,weep
+ goto cmd_w_eeprom_len
+ ;; call write_eeprom
+ movlw E_ADDR_INVALID
+ movwf combuff + .1
+ movlw .2
+ call send_answer
goto wait_new_cmd
-;; cmd_r_config
-;; goto wait_new_cmd
+cmd_w_eeprom_len
+ movf combuff + .3,w
+ movwf current_cmdlen
+ bsf flags,weep
+ goto wait_cmd
-;; cmd_w_config
-;; goto wait_new_cmd
+ ;; ** not implemented commands *******
+cmd_r_config
+cmd_w_config
+ movlw E_NOT_IMPL
+ movwf combuff + .1
+ movlw .2
+ call send_answer
+ goto wait_new_cmd
;; -------------------------------------
;; dummy user code
diff --git a/downloader/downloader.py b/downloader/downloader.py
index 00b50a4..3a66f3b 100755
--- a/downloader/downloader.py
+++ b/downloader/downloader.py
@@ -89,7 +89,7 @@ def open_serial(device, baud):
9600: termios.B9600, 19200: termios.B19200, 38400: termios.B38400,
57600: termios.B57600, 115200: termios.B115200, 230400: termios.B230400 }
- baudreate = termios.B19200
+ baudreate = termios.B57600
try:
baudrate = baudrates[int(baud)]
except (KeyError, ValueError):
@@ -123,17 +123,15 @@ def exec_command(dev, cmd, answer):
return_codes = { 0: "OK", 1: "invalid command", 2: "bad checksum",
3: "not implemented", 4: "flash write error",
- 5: "address invalid", 6: "address prohibited" }
-
- answer = '<' + answer + 'B'
- answer_len = struct.calcsize(answer) + 2
+ 5: "address invalid", 6: "address prohibited",
+ 7: "value out of bounds" }
cstr = cmd + chr(calc_csum(cmd))
os.write(dev, cstr)
astr = b''
- while len(astr) < 2:
- astr += os.read(dev, 2 - len(astr))
+ while len(astr) < 3:
+ astr += os.read(dev, 3 - len(astr))
if astr[0] != cmd[0]:
print "ERROR: bootloader returned wrong command code"
@@ -149,6 +147,7 @@ def exec_command(dev, cmd, answer):
print "ERROR: bootloader returned %d: %s" % (ret, rstr)
sys.exit(4)
+ answer_len = struct.calcsize(answer) + len(astr)
while len(astr) < answer_len:
astr += os.read(dev, answer_len - len(astr))
@@ -161,7 +160,7 @@ def exec_command(dev, cmd, answer):
### Commands
def identify(dev):
- data = exec_command(dev, 'i', 'BB10sHBHH')
+ data = exec_command(dev, 'i', '<BB10sHBHH')
id = { 'ver_min': data[0], 'ver_maj': data[1], 'name': data[2], 'devid': data[3],
'fss': data[4], 'mess': data[5], 'supported': data[6] }
@@ -176,35 +175,35 @@ def identify(dev):
return id
def boot(dev):
- exec_command(dev, 'b', '')
+ exec_command(dev, 'b', '<')
def reset(dev, id):
- exec_command(dev, 'r', '')
+ exec_command(dev, 'r', '<')
def read_flash_segment(dev, id, addr):
cmd = struct.pack('<cH', 'f', addr)
- return exec_command(dev, cmd, '%dH' % id['fss'])
+ return exec_command(dev, cmd, '<%dH' % id['fss'])
def write_flash_segment(dev, id, addr, data):
cmd = struct.pack('<cH%dH' % id['fss'], 'F', addr, *data)
- return exec_command(dev, cmd, '')
+ return exec_command(dev, cmd, '<')
def read_eeprom(dev, id, addr, len):
cmd = struct.pack('<cHH', 'e', addr, len)
- return exec_command(dev, cmd, '%dH' % len)
+ return exec_command(dev, cmd, '<%dB' % len)
-def write_eeprom(dev, id, addr, len, data):
- cmd = struct.pack('<cHH%dH' % len, 'E', addr, len, *data)
- return exec_command(dev, cmd, '')
+def write_eeprom(dev, id, addr, data):
+ cmd = struct.pack('<cHH%dB' % len(data), 'E', addr, len(data), *data)
+ return exec_command(dev, cmd, '<')
def read_config(dev, id, nr):
cmd = struct.pack('<cB', 'c', nr)
- data = exec_command(dev, cmd, 'H')
+ data = exec_command(dev, cmd, '<H')
return data[0]
def write_config(dev, id, nr, word):
cmd = struct.pack('<cBH', 'C', nr, word)
- return exec_command(dev, cmd, '')
+ return exec_command(dev, cmd, '<')
### Main
@@ -227,11 +226,11 @@ Options:
-h, --help this help message.
-v, --version version info.
--device=N the serial port to use (default: /dev/ttyUSB0).
- --baud=N baudrate to use (default: 19200).
+ --baud=N baudrate to use (default: 57600).
'''
device = "/dev/ttyUSB0"
- baudrate = 19200
+ baudrate = 57600
try:
opts, args = getopt.getopt(sys.argv[1:], "hv",
@@ -264,5 +263,5 @@ Options:
codedata = load_hex(args[0])
id = identify(dev)
- for segment in create_flash_segments(codedata, id['fss']):
- print "%05X: %s" % (segment[0], ''.join('%04X'%i for i in segment[1]))
+ # for segment in create_flash_segments(codedata, id['fss']):
+ # print "%05X: %s" % (segment[0], ''.join('%04X'%i for i in segment[1]))
diff --git a/downloader/proto.txt b/downloader/proto.txt
index 5afe572..71b0774 100644
--- a/downloader/proto.txt
+++ b/downloader/proto.txt
@@ -31,7 +31,7 @@ The return codes have the following meaning:
4 | flash write error
5 | address invalid
6 | address prohibited
-
+ 5 | value out of bounds
identify:
~~~~~~~~~
@@ -63,10 +63,9 @@ identify:
mess:
2bytes, maximum eeprom segment size
- This represents the maximum number of eeprom bytes which may be written at
- once. Unlike <fss> value it is ok to write less than <mess> bytes. Also
- this only applies to eeprom writes, reading the eeprom is much faster and
- therefore not subject to this limitation.
+ This represents the maximum number of eeprom bytes which may be written or
+ read at once. Unlike <fss> value it is ok to write or read less than <mess>
+ bytes.
supported:
2bytes, a bitmap showing supported commands