From 85b1a65ea747e5ae10aeff248a2a658dfa9916fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Mon, 23 Oct 2017 21:33:08 +0200 Subject: [PATCH] Implement KbootCommand_Ping and set set left BOOTLOADER_TIMEOUT_MS back to 100 ms. --- left/build/kds/blhost-unix.sh | 17 +++++++++-------- right/src/slave_drivers/kboot_driver.c | 23 +++++++++++++++++++++++ right/src/slave_drivers/kboot_driver.h | 1 + right/src/slave_scheduler.c | 2 ++ right/src/slave_scheduler.h | 2 ++ shared/bootloader.h | 2 +- 6 files changed, 38 insertions(+), 9 deletions(-) diff --git a/left/build/kds/blhost-unix.sh b/left/build/kds/blhost-unix.sh index 34db54f..31d8618 100755 --- a/left/build/kds/blhost-unix.sh +++ b/left/build/kds/blhost-unix.sh @@ -35,7 +35,8 @@ case "$(uname -s)" in ;; esac -blhost="../../../lib/bootloader/bin/Tools/blhost/$blhost_path/blhost --usb 0x1d50,0x6121 --buspal i2c,0x10,100k" +blhost_usb="../../../lib/bootloader/bin/Tools/blhost/$blhost_path/blhost --usb 0x1d50,0x6121" +blhost_buspal="$blhost_usb --buspal i2c,0x10,100k" set -x # echo on @@ -44,12 +45,12 @@ set -x # echo on # npm install #fi +$usb_dir/send-kboot-command.js ping 0x10 $usb_dir/jump-to-slave-bootloader.js $usb_dir/reenumerate.js buspal -$blhost get-property 1 -$blhost flash-erase-all-unsecure -$blhost write-memory 0x0 "$firmware_image" -$blhost reset -sleep 4 -#$usb_dir/send-kboot-command.js reset 0x10 -#../../../lib/bootloader/bin/Tools/blhost/$blhost_path/blhost --usb 0x1d50,0x6121 reset +$blhost_buspal get-property 1 +$blhost_buspal flash-erase-all-unsecure +$blhost_buspal write-memory 0x0 "$firmware_image" +$blhost_usb reset +$usb_dir/reenumerate.js normalKeyboard +$usb_dir/send-kboot-command.js reset 0x10 diff --git a/right/src/slave_drivers/kboot_driver.c b/right/src/slave_drivers/kboot_driver.c index 275a659..f7f220a 100644 --- a/right/src/slave_drivers/kboot_driver.c +++ b/right/src/slave_drivers/kboot_driver.c @@ -5,6 +5,7 @@ kboot_driver_state_t KbootDriverState; static uint8_t rxBuffer[MAX_KBOOT_COMMAND_LENGTH]; +static uint8_t pingCommand[] = {0x5a, 0xa6}; static uint8_t resetCommand[] = {0x5a, 0xa4, 0x04, 0x00, 0x6f, 0x46, 0x0b, 0x00, 0x00, 0x00}; static uint8_t ackMessage[] = {0x5a, 0xa1}; @@ -30,6 +31,28 @@ status_t KbootSlaveDriver_Update(uint8_t kbootInstanceId) case KbootCommand_Idle: break; case KbootCommand_Ping: + switch (KbootDriverState.phase) { + case 0: + status = tx(pingCommand, sizeof(pingCommand)); + KbootDriverState.phase++; + break; + case 1: + KbootDriverState.status = Slaves[SlaveId_KbootDriver].previousStatus; + KbootDriverState.phase = KbootDriverState.status == kStatus_Success ? 2 : 0; + return kStatus_Uhk_NoTransfer; + case 2: + status = rx(10); + KbootDriverState.phase++; + break; + case 3: + KbootDriverState.status = Slaves[SlaveId_KbootDriver].previousStatus; + if (KbootDriverState.status == kStatus_Success) { + KbootDriverState.commandType = KbootCommand_Idle; + } else { + KbootDriverState.phase = 0; + return kStatus_Uhk_NoTransfer; + } + } break; case KbootCommand_Reset: switch (KbootDriverState.phase) { diff --git a/right/src/slave_drivers/kboot_driver.h b/right/src/slave_drivers/kboot_driver.h index 16bbf3a..707baca 100644 --- a/right/src/slave_drivers/kboot_driver.h +++ b/right/src/slave_drivers/kboot_driver.h @@ -25,6 +25,7 @@ kboot_command_t commandType; uint8_t i2cAddress; uint8_t phase; + uint32_t status; } kboot_driver_state_t; // Variables: diff --git a/right/src/slave_scheduler.c b/right/src/slave_scheduler.c index b25e9c4..7ebf081 100644 --- a/right/src/slave_scheduler.c +++ b/right/src/slave_scheduler.c @@ -57,6 +57,8 @@ static void slaveSchedulerCallback(I2C_Type *base, i2c_master_handle_t *handle, uhk_slave_t *previousSlave = Slaves + previousSlaveId; uhk_slave_t *currentSlave = Slaves + currentSlaveId; + previousSlave->previousStatus = previousStatus; + if (isFirstIteration) { bool wasPreviousSlaveConnected = previousSlave->isConnected; previousSlave->isConnected = previousStatus == kStatus_Success; diff --git a/right/src/slave_scheduler.h b/right/src/slave_scheduler.h index 80b8095..cbae515 100644 --- a/right/src/slave_scheduler.h +++ b/right/src/slave_scheduler.h @@ -13,6 +13,7 @@ SlaveId_RightAddon, SlaveId_RightLedDriver, SlaveId_LeftLedDriver, + SlaveId_KbootDriver, } slave_id_t; typedef void (slave_init_t)(uint8_t); @@ -25,6 +26,7 @@ slave_update_t *update; slave_disconnect_t *disconnect; bool isConnected; + status_t previousStatus; } uhk_slave_t; typedef enum { diff --git a/shared/bootloader.h b/shared/bootloader.h index fc1434e..62894a9 100644 --- a/shared/bootloader.h +++ b/shared/bootloader.h @@ -11,7 +11,7 @@ // Macros: #define BOOTLOADER_TAG 0x6766636B - #define BOOTLOADER_TIMEOUT_MS 3000 + #define BOOTLOADER_TIMEOUT_MS 100 #define CLOCK_FLAG_HIGH_SPEED_MODE 0x01 #define DEFINE_BOOTLOADER_CONFIG_AREA(address) \