From db39faa988cf306fbf8f915fe1c8f1119989b0b1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 4 Jul 2013 23:01:44 +0000 Subject: moved to binary command codes git-svn-id: https://svn.spreadspace.org/pic/trunk@37 a09c6847-51d9-44de-8ef2-e725cf50f3c7 --- bootloader/bootloader.asm | 86 ++++++++++++----------------------------------- downloader/downloader.py | 18 +++++----- downloader/proto.txt | 74 ++++++++++++++++++++-------------------- 3 files changed, 68 insertions(+), 110 deletions(-) diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm index 02b9105..bbf88b8 100644 --- a/bootloader/bootloader.asm +++ b/bootloader/bootloader.asm @@ -54,42 +54,26 @@ E_ADDR_PROHIB EQU .6 E_VALUE_OOB EQU .7 ;; CMD codes -CCMD_IDENTIFY EQU 'i' -CMD_IDENTIFY EQU .0 +CMD_INVALID EQU .0 -CCMD_BOOT EQU 'b' -CMD_BOOT EQU .1 +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 -CCMD_RESET EQU 'r' -CMD_RESET EQU .2 - -CCMD_R_FLASH EQU 'f' -CMD_R_FLASH EQU .3 - -CCMD_W_FLASH EQU 'F' -CMD_W_FLASH EQU .4 - -CCMD_R_EEPROM EQU 'e' -CMD_R_EEPROM EQU .5 - -CCMD_W_EEPROM EQU 'E' -CMD_W_EEPROM EQU .6 - -CCMD_R_CONFIG EQU 'c' -CMD_R_CONFIG EQU .7 - -CCMD_W_CONFIG EQU 'C' -CMD_W_CONFIG EQU .8 - -CMD_INVALID EQU H'FF' +CMD_MAX EQU .9 ;; Variables combuff EQU H'0020' combuff_end EQU H'006F' -current_cmd EQU H'0070' -current_cmdlen EQU H'0071' -csum EQU H'0072' +current_cmdlen EQU H'0070' +csum EQU H'0071' flags EQU H'007D' weep EQU .0 @@ -135,38 +119,12 @@ send_answer_next call uart_tx_byte return -translate_cmd_codes - xorlw CCMD_IDENTIFY - btfsc STATUS,Z - retlw CMD_IDENTIFY - xorlw CCMD_BOOT ^ CCMD_IDENTIFY - btfsc STATUS,Z - retlw CMD_BOOT - xorlw CCMD_RESET ^ CCMD_BOOT - btfsc STATUS,Z - retlw CMD_RESET - xorlw CCMD_R_FLASH ^ CCMD_RESET - btfsc STATUS,Z - retlw CMD_R_FLASH - xorlw CCMD_W_FLASH ^ CCMD_R_FLASH - btfsc STATUS,Z - retlw CMD_W_FLASH - xorlw CCMD_R_EEPROM ^ CCMD_W_FLASH - btfsc STATUS,Z - retlw CMD_R_EEPROM - 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 +check_cmd_code retlw CMD_INVALID get_cmdlen addwf PCL,f + retlw .0 ; invalid retlw .1 ; identify: retlw .1 ; boot: retlw .1 ; reset: @@ -220,8 +178,7 @@ boot wait_new_cmd movlw combuff movwf FSR - movlw CMD_INVALID - movwf current_cmd + clrf combuff clrf current_cmdlen clrf flags @@ -255,12 +212,10 @@ uart_rx_fe ; recover from framing error goto wait_new_cmd new_cmd ; got new command code - call translate_cmd_codes - movwf current_cmd - xorlw CMD_INVALID + call check_cmd_code + movf combuff,w btfsc STATUS,Z goto invalid_cmd - movf current_cmd,w ; initializing cmdlen call get_cmdlen movwf current_cmdlen goto wait_cmd @@ -275,8 +230,9 @@ invalid_cmd ; received command code is not known 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 + movf combuff,w ; dispatch commands addwf PCL,f + nop goto cmd_identify goto cmd_boot goto cmd_reset @@ -292,7 +248,7 @@ exec_cmd ; command is correct and complete ;; ** identify ******* cmd_identify clrf csum - movlw CCMD_IDENTIFY + movf combuff,w call uart_tx_byte movlw E_OK diff --git a/downloader/downloader.py b/downloader/downloader.py index 3a66f3b..b332271 100755 --- a/downloader/downloader.py +++ b/downloader/downloader.py @@ -160,7 +160,7 @@ def exec_command(dev, cmd, answer): ### Commands def identify(dev): - data = exec_command(dev, 'i', ' (in this case will always be 'i') + 1 | (in this case will always be 1) answer: - 'i' | | version | name | devid | fss | mess | supported | + 1 | | version | name | devid | fss | mess | supported | version: 2bytes, protocol version @@ -53,7 +55,7 @@ identify: devid: 2bytes, device id of the PIC - The downlaoder may use this id to check if it talks to the right bootloader + The downlaoder may use this id to check if it talks to the right bootloader fss: 1byte, flash segment size @@ -87,10 +89,10 @@ boot: ~~~~~ command: - 'b' | (in this case will always be 'b') + 2 | (in this case will always be 2) answer: - 'b' | | + 2 | | This instucts the bootloader to boot to the user application directly (no reset) @@ -99,10 +101,10 @@ reset: ~~~~~~ command: - 'r' | (in this case will always be 'r') + 3 | (in this case will always be 3) answer: - 'r' | | + 3 | | The device performs a reboot. If the boot condition (i.e.: port pin) is not met this instructs the device to boot to the user application. @@ -112,10 +114,10 @@ read flash: ~~~~~~~~~~~ command: - 'f' | addr | + 4 | addr | answer: - 'f' | | data | + 4 | | data | The bootloader reads words from flash address and returns it as . @@ -125,10 +127,10 @@ write flash: ~~~~~~~~~~~~ command: - 'F' | addr | data | + 5 | addr | data | answer: - 'F' | | + 5 | | The bootloader writes (which has to contain exactly words) to address inside the flash. @@ -138,10 +140,10 @@ read eeprom: ~~~~~~~~~~~~ command: - 'e' | addr | len | + 6 | addr | len | answer: - 'e' | | data | + 6 | | data | The bootloader reads bytes from eeprom at address and returns it as . len is 2bytes long. @@ -151,10 +153,10 @@ write eeprom: ~~~~~~~~~~~~~ command: - 'E' | addr | len | data | + 7 | addr | len | data | answer: - 'E' | | + 7 | | The bootloader writes (which has to contain exactly bytes) to address inside the eeprom. len is 2bytes long and the value must not exceed bytes. @@ -163,24 +165,24 @@ write eeprom: read config: ~~~~~~~~~~~~ - command: - 'c' | nr | + command: + 8 | nr | - answer: - 'c' | | word | + answer: + 8 | | word | - The bootloader reads and returns the configuration word number . is one - byte long. + The bootloader reads and returns the configuration word number . is one + byte long. write config: ~~~~~~~~~~~~~ - command: - 'C' | nr | word | + command: + 9 | nr | word | - answer: - 'C' | | + answer: + 9 | | - The bootloader writes onto configuration word number . is one - byte long + The bootloader writes onto configuration word number . is one + byte long. -- cgit v1.2.3