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>
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>
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>
This broadcasts a command to clear the id for all nodes running
the bootloader, which should prevent ID collisions.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This is just to avoid confusion between RX_EOF and the command trailer.
Having both as 0x03 could potential lead to issues.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This method isn't necessary as the bootloader shouldnt need to discover
multiple node ids. Change the decoded node ID offset to 0x200 in an
effort to avoid collisions with nodes assigned by Klipper.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Bring in the latest changes from Klipper. The STM32F4 variants are
still unsupported at this time.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>