mirror of
https://github.com/andreili/katapult.git
synced 2025-08-23 19:34:06 +02:00
canboot_main: Rework "complete" handling
Convert the "complete" command to use a regular task instead of custom code in enter_bootloader(). Perform the reboot based on a timer so that it is not necessary to query the low-level code for ack transmission status. Use jump_to_application() instead of canbus_reboot() to start the user code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
21469fea3e
commit
09a500cf90
@ -7,7 +7,6 @@
|
||||
#include <string.h> // strlen
|
||||
#include "autoconf.h" // CONFIG_*
|
||||
#include "board/misc.h" // udelay
|
||||
#include "board/canbus.h" // canbus_send
|
||||
#include "board/flash.h" // flash_read_block
|
||||
#include "board/gpio.h" // gpio_in_setup
|
||||
#include "canboot_main.h" // canboot_main
|
||||
@ -18,7 +17,8 @@
|
||||
|
||||
#define REQUEST_SIG 0x5984E3FA6CA1589B // Random request sig
|
||||
|
||||
static uint8_t complete = 0;
|
||||
static uint8_t complete;
|
||||
static uint32_t complete_endtime;
|
||||
|
||||
void
|
||||
command_complete(uint32_t *data)
|
||||
@ -26,8 +26,17 @@ command_complete(uint32_t *data)
|
||||
uint32_t out[3];
|
||||
command_respond_ack(CMD_COMPLETE, out, ARRAY_SIZE(out));
|
||||
complete = 1;
|
||||
complete_endtime = timer_read_time() + timer_from_us(100000);
|
||||
}
|
||||
|
||||
void
|
||||
complete_task(void)
|
||||
{
|
||||
if (complete && timer_is_before(complete_endtime, timer_read_time()))
|
||||
jump_to_application();
|
||||
}
|
||||
DECL_TASK(complete_task);
|
||||
|
||||
void
|
||||
command_connect(uint32_t *data)
|
||||
{
|
||||
@ -93,16 +102,8 @@ enter_bootloader(void)
|
||||
{
|
||||
sched_run_init();
|
||||
|
||||
for (;;) {
|
||||
for (;;)
|
||||
sched_run_tasks();
|
||||
if (complete && canbus_tx_clear())
|
||||
// wait until we are complete and the ack has returned
|
||||
break;
|
||||
}
|
||||
|
||||
// Flash Complete, system reset
|
||||
udelay(100000);
|
||||
canbus_reboot();
|
||||
}
|
||||
|
||||
// Main loop of program
|
||||
|
@ -22,12 +22,6 @@ static uint8_t canbus_uuid[CANBUS_UUID_LEN];
|
||||
static struct task_wake canbus_tx_wake;
|
||||
static uint8_t transmit_buf[96], transmit_pos, transmit_max;
|
||||
|
||||
uint8_t
|
||||
canbus_tx_clear(void)
|
||||
{
|
||||
return transmit_pos >= transmit_max;
|
||||
}
|
||||
|
||||
void
|
||||
canbus_notify_tx(void)
|
||||
{
|
||||
|
@ -11,13 +11,11 @@
|
||||
int canbus_read(uint32_t *id, uint8_t *data);
|
||||
int canbus_send(uint32_t id, uint32_t len, uint8_t *data);
|
||||
void canbus_set_filter(uint32_t id);
|
||||
void canbus_reboot(void);
|
||||
|
||||
// canbus.c
|
||||
void canbus_notify_tx(void);
|
||||
void canbus_notify_rx(void);
|
||||
void canbus_process_data(uint32_t id, uint32_t len, uint8_t *data);
|
||||
void canbus_set_uuid(void *data);
|
||||
uint8_t canbus_tx_clear(void);
|
||||
|
||||
#endif // canbus.h
|
||||
|
@ -268,12 +268,6 @@ compute_btr(uint32_t pclock, uint32_t bitrate)
|
||||
return make_btr(sjw, time_seg1, time_seg2, brp);
|
||||
}
|
||||
|
||||
void
|
||||
canbus_reboot(void)
|
||||
{
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
void
|
||||
can_init(void)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user