mirror of
https://github.com/andreili/katapult.git
synced 2025-08-24 03:44:06 +02:00
canboot_main: remove process_state() method
Commands are now executed after decoding, so there is no need to track any state other than complete. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
9762327ac3
commit
6199e9d107
@ -38,7 +38,7 @@
|
|||||||
#define CMD_TRAILER 0x9903
|
#define CMD_TRAILER 0x9903
|
||||||
|
|
||||||
#define WAIT_BLINK_TIME 1000000
|
#define WAIT_BLINK_TIME 1000000
|
||||||
#define XFER_BLINK_TIME 10000
|
#define XFER_BLINK_TIME 20000
|
||||||
|
|
||||||
#define REQUEST_SIG 0x5984E3FA6CA1589B // Random request sig
|
#define REQUEST_SIG 0x5984E3FA6CA1589B // Random request sig
|
||||||
|
|
||||||
@ -49,8 +49,8 @@ static uint8_t cmd_pos = 0;
|
|||||||
// Page Tracking
|
// Page Tracking
|
||||||
static uint16_t last_page_written = 0;
|
static uint16_t last_page_written = 0;
|
||||||
static uint8_t page_pending = 0;
|
static uint8_t page_pending = 0;
|
||||||
enum { CMD_PENDING, RX_BLOCK, RX_DONE, TX_BLOCK, COMPLETE };
|
static uint32_t blink_time = WAIT_BLINK_TIME;
|
||||||
static uint8_t current_state = CMD_PENDING;
|
static uint8_t complete = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
send_ack(uint8_t ack_type, uint32_t arg)
|
send_ack(uint8_t ack_type, uint32_t arg)
|
||||||
@ -116,23 +116,23 @@ process_command(uint8_t cmd, uint32_t* data, uint8_t data_len)
|
|||||||
send_ack(ACK_COMMAND, (cmd << 24) | CONFIG_BLOCK_SIZE);
|
send_ack(ACK_COMMAND, (cmd << 24) | CONFIG_BLOCK_SIZE);
|
||||||
break;
|
break;
|
||||||
case CMD_RX_BLOCK:
|
case CMD_RX_BLOCK:
|
||||||
current_state = RX_BLOCK;
|
blink_time = XFER_BLINK_TIME;
|
||||||
process_write_block(cmd, data, data_len);
|
process_write_block(cmd, data, data_len);
|
||||||
break;
|
break;
|
||||||
case CMD_RX_EOF:
|
case CMD_RX_EOF:
|
||||||
if (page_pending)
|
if (page_pending)
|
||||||
write_page(last_page_written + 1);
|
write_page(last_page_written + 1);
|
||||||
flash_complete();
|
flash_complete();
|
||||||
|
blink_time = WAIT_BLINK_TIME;
|
||||||
send_ack(ACK_COMMAND, (cmd << 24) | (last_page_written + 1));
|
send_ack(ACK_COMMAND, (cmd << 24) | (last_page_written + 1));
|
||||||
current_state = CMD_PENDING;
|
|
||||||
break;
|
break;
|
||||||
case CMD_REQ_BLOCK:
|
case CMD_REQ_BLOCK:
|
||||||
current_state = TX_BLOCK;
|
blink_time = XFER_BLINK_TIME;
|
||||||
process_read_block(cmd, data, data_len);
|
process_read_block(cmd, data, data_len);
|
||||||
break;
|
break;
|
||||||
case CMD_COMPLETE:
|
case CMD_COMPLETE:
|
||||||
send_ack(ACK_COMMAND, cmd << 24);
|
send_ack(ACK_COMMAND, cmd << 24);
|
||||||
current_state = COMPLETE;
|
complete = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Unknown command or gabage data, NACK it
|
// Unknown command or gabage data, NACK it
|
||||||
@ -208,20 +208,6 @@ canboot_process_rx(uint8_t *data, uint32_t len)
|
|||||||
decode_command();
|
decode_command();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
|
||||||
process_state(void)
|
|
||||||
{
|
|
||||||
switch (current_state) {
|
|
||||||
case CMD_PENDING:
|
|
||||||
check_blink_time(WAIT_BLINK_TIME);
|
|
||||||
break;
|
|
||||||
case RX_BLOCK:
|
|
||||||
case TX_BLOCK:
|
|
||||||
check_blink_time(XFER_BLINK_TIME);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint8_t
|
static inline uint8_t
|
||||||
check_application_code(void)
|
check_application_code(void)
|
||||||
{
|
{
|
||||||
@ -277,8 +263,8 @@ enter_bootloader(void)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
canbus_rx_task();
|
canbus_rx_task();
|
||||||
canbus_tx_task();
|
canbus_tx_task();
|
||||||
process_state();
|
check_blink_time(blink_time);
|
||||||
if (current_state == COMPLETE && canbus_tx_clear())
|
if (complete && canbus_tx_clear())
|
||||||
// wait until we are complete and the ack has returned
|
// wait until we are complete and the ack has returned
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user