Move command handlers from canboot_main.c to flashcmd.c. Move startup
code to sched.c. Rename remaining bootloader entry code to new
bootentry.c file.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
There is no need for a custom check_blink_time() function as this can
be done from a new led_blink_task().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Move the low-level command parsing and encoding code from
canboot_main.c to a new command.c file.
Standardize the parameters and naming for command handlers. Rename
send_ack() to console_send_ack() and rework parameters to be similar
to command handlers.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add the sched.c code and associated DECL_INIT(), DECL_TASK() macros so
that it is easier to import low-level Klipper code into the CanBoot
repo.
These additional code wrappers do not increase the overall binary size
as gcc does a good job of inlining the wrappers and removing unused
code during the compile process.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
There is a severe corner case where two mcus could potentially be
assigned the same canbus_id and thus flash commands could go to the
wrong mcu. Add a get_canbus_id command to attempt to prevent this.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Wrap defines with expressions in parenthesis.
MAX_OBUF_SIZE is in bytes - divide by 4 for number of words.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
All commands are now framed, where the payload must
always be included within a frame. A 16-bit CRC is postfixed
to each frame for validation. The protocol is now as follows:
<16-bit header><8-bit command><8-bit payload length in words><payload><16-bit trailer><16-bit CRC>
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The latest Klipper main Makefile has bugfixes for proper rebuilding on
a change during "make menuconfig".
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It's a good idea to reset the cpu before starting the main application
code. However it is difficult to reliably reset the cpu in software.
This changes the software to actually do a cpu hardware reset prior to
launching the main application - after each bootup the code checks to
see if the application should be started before entering the main
bootloader code. This helps ensure the application code is started in
a "pristine" cpu state.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The bootloader is only called after a reset - it doesn't need to worry
about another bootloader launching it. This reduces the code size by
a small amount.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Build size is likely more important than CPU performance for a
bootloader. So, instruct gcc to optimize for size by default.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use Klipper's nodeid to canbus_id scheme (canbus_id = nodeid * 2 +
0x100). Instead, use a nodeid offset of 128 to avoid collisions with
Klipper.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>