mirror of
https://github.com/andreili/katapult.git
synced 2025-08-24 03:44:06 +02:00
led: Convert code to use a task
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>
This commit is contained in:
parent
38ef4860da
commit
b0291b3cdb
@ -1,3 +1,4 @@
|
|||||||
# Main code build rules
|
# Main code build rules
|
||||||
|
|
||||||
src-y += canboot_main.c sched.c command.c led.c
|
src-y += canboot_main.c sched.c command.c
|
||||||
|
src-$(CONFIG_ENABLE_LED) += led.c
|
||||||
|
@ -13,22 +13,24 @@
|
|||||||
#include "canboot_main.h" // canboot_main
|
#include "canboot_main.h" // canboot_main
|
||||||
#include "command.h" // command_respond_ack
|
#include "command.h" // command_respond_ack
|
||||||
#include "ctr.h" // DECL_CTR
|
#include "ctr.h" // DECL_CTR
|
||||||
#include "led.h" // check_blink_time
|
|
||||||
#include "byteorder.h" // cpu_to_le32
|
#include "byteorder.h" // cpu_to_le32
|
||||||
#include "sched.h" // sched_run_init
|
#include "sched.h" // sched_run_init
|
||||||
|
|
||||||
#define WAIT_BLINK_TIME 1000000
|
|
||||||
#define XFER_BLINK_TIME 20000
|
|
||||||
|
|
||||||
#define REQUEST_SIG 0x5984E3FA6CA1589B // Random request sig
|
#define REQUEST_SIG 0x5984E3FA6CA1589B // Random request sig
|
||||||
|
|
||||||
static uint8_t page_buffer[CONFIG_MAX_FLASH_PAGE_SIZE];
|
static uint8_t page_buffer[CONFIG_MAX_FLASH_PAGE_SIZE];
|
||||||
// Page Tracking
|
// Page Tracking
|
||||||
static uint32_t last_page_address = 0;
|
static uint32_t last_page_address = 0;
|
||||||
static uint8_t page_pending = 0;
|
static uint8_t page_pending = 0;
|
||||||
static uint32_t blink_time = WAIT_BLINK_TIME;
|
static uint8_t is_in_transfer;
|
||||||
static uint8_t complete = 0;
|
static uint8_t complete = 0;
|
||||||
|
|
||||||
|
int
|
||||||
|
flashcmd_is_in_transfer(void)
|
||||||
|
{
|
||||||
|
return is_in_transfer;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
write_page(uint32_t page_address)
|
write_page(uint32_t page_address)
|
||||||
{
|
{
|
||||||
@ -41,7 +43,7 @@ write_page(uint32_t page_address)
|
|||||||
void
|
void
|
||||||
command_read_block(uint32_t *data)
|
command_read_block(uint32_t *data)
|
||||||
{
|
{
|
||||||
blink_time = XFER_BLINK_TIME;
|
is_in_transfer = 1;
|
||||||
uint32_t block_address = le32_to_cpu(data[1]);
|
uint32_t block_address = le32_to_cpu(data[1]);
|
||||||
uint32_t out[CONFIG_BLOCK_SIZE / 4 + 2 + 2];
|
uint32_t out[CONFIG_BLOCK_SIZE / 4 + 2 + 2];
|
||||||
out[2] = cpu_to_le32(block_address);
|
out[2] = cpu_to_le32(block_address);
|
||||||
@ -52,7 +54,7 @@ command_read_block(uint32_t *data)
|
|||||||
void
|
void
|
||||||
command_write_block(uint32_t *data)
|
command_write_block(uint32_t *data)
|
||||||
{
|
{
|
||||||
blink_time = XFER_BLINK_TIME;
|
is_in_transfer = 1;
|
||||||
if (command_get_arg_count(data) != (CONFIG_BLOCK_SIZE / 4) + 1) {
|
if (command_get_arg_count(data) != (CONFIG_BLOCK_SIZE / 4) + 1) {
|
||||||
command_respond_command_error();
|
command_respond_command_error();
|
||||||
return;
|
return;
|
||||||
@ -76,7 +78,7 @@ command_write_block(uint32_t *data)
|
|||||||
void
|
void
|
||||||
command_eof(uint32_t *data)
|
command_eof(uint32_t *data)
|
||||||
{
|
{
|
||||||
blink_time = WAIT_BLINK_TIME;
|
is_in_transfer = 0;
|
||||||
uint32_t flash_page_size = flash_get_page_size();
|
uint32_t flash_page_size = flash_get_page_size();
|
||||||
if (page_pending) {
|
if (page_pending) {
|
||||||
write_page(last_page_address + flash_page_size);
|
write_page(last_page_address + flash_page_size);
|
||||||
@ -163,7 +165,6 @@ enter_bootloader(void)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
sched_run_tasks();
|
sched_run_tasks();
|
||||||
check_blink_time(blink_time);
|
|
||||||
if (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;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdint.h> // uint32_t
|
#include <stdint.h> // uint32_t
|
||||||
|
|
||||||
|
int flashcmd_is_in_transfer(void);
|
||||||
void canboot_main(void);
|
void canboot_main(void);
|
||||||
|
|
||||||
#endif // canboot_main.h
|
#endif // canboot_main.h
|
||||||
|
14
src/led.c
14
src/led.c
@ -7,10 +7,13 @@
|
|||||||
#include "autoconf.h" // CONFIG_ENABLE_LED
|
#include "autoconf.h" // CONFIG_ENABLE_LED
|
||||||
#include "board/gpio.h" // gpio_out_setup
|
#include "board/gpio.h" // gpio_out_setup
|
||||||
#include "board/misc.h" // timer_read_time
|
#include "board/misc.h" // timer_read_time
|
||||||
|
#include "canboot_main.h" // flashcmd_is_in_transfer
|
||||||
#include "ctr.h" // DECL_CTR
|
#include "ctr.h" // DECL_CTR
|
||||||
#include "led.h" // check_blink_time
|
|
||||||
#include "sched.h" // DECL_INIT
|
#include "sched.h" // DECL_INIT
|
||||||
|
|
||||||
|
#define WAIT_BLINK_TIME 1000000
|
||||||
|
#define XFER_BLINK_TIME 20000
|
||||||
|
|
||||||
DECL_CTR("DECL_LED_PIN " __stringify(CONFIG_STATUS_LED_PIN));
|
DECL_CTR("DECL_LED_PIN " __stringify(CONFIG_STATUS_LED_PIN));
|
||||||
extern uint32_t led_gpio, led_gpio_high; // Generated by buildcommands.py
|
extern uint32_t led_gpio, led_gpio_high; // Generated by buildcommands.py
|
||||||
|
|
||||||
@ -20,8 +23,6 @@ static uint32_t last_blink_time;
|
|||||||
void
|
void
|
||||||
led_init(void)
|
led_init(void)
|
||||||
{
|
{
|
||||||
if (!CONFIG_ENABLE_LED)
|
|
||||||
return;
|
|
||||||
led = gpio_out_setup(led_gpio, led_gpio_high);
|
led = gpio_out_setup(led_gpio, led_gpio_high);
|
||||||
// The short delay is simply to ensure that the Debug Timer is
|
// The short delay is simply to ensure that the Debug Timer is
|
||||||
// enabled
|
// enabled
|
||||||
@ -31,10 +32,10 @@ led_init(void)
|
|||||||
DECL_INIT(led_init);
|
DECL_INIT(led_init);
|
||||||
|
|
||||||
void
|
void
|
||||||
check_blink_time(uint32_t usec)
|
led_blink_task(void)
|
||||||
{
|
{
|
||||||
if (!CONFIG_ENABLE_LED)
|
int in_transfer = flashcmd_is_in_transfer();
|
||||||
return;
|
uint32_t usec = in_transfer ? XFER_BLINK_TIME : WAIT_BLINK_TIME;
|
||||||
uint32_t curtime = timer_read_time();
|
uint32_t curtime = timer_read_time();
|
||||||
uint32_t endtime = last_blink_time + timer_from_us(usec);
|
uint32_t endtime = last_blink_time + timer_from_us(usec);
|
||||||
if (timer_is_before(endtime, curtime)) {
|
if (timer_is_before(endtime, curtime)) {
|
||||||
@ -42,3 +43,4 @@ check_blink_time(uint32_t usec)
|
|||||||
last_blink_time = timer_read_time();
|
last_blink_time = timer_read_time();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DECL_TASK(led_blink_task);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user