mirror of
https://github.com/andreili/katapult.git
synced 2025-08-23 19:34:06 +02:00
led: Move led code to new led.c file
Move the led c code from the buildcommands.py to a new led.c file. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
5279c33ea0
commit
807c1ef0bd
9
Makefile
9
Makefile
@ -53,13 +53,6 @@ Q=@
|
||||
MAKEFLAGS += --no-print-directory
|
||||
endif
|
||||
|
||||
# Status LED def for buildcommands.py
|
||||
ifdef CONFIG_STATUS_LED_PIN
|
||||
LED_OPT= -l $(CONFIG_STATUS_LED_PIN)
|
||||
else
|
||||
LED_OPT=
|
||||
endif
|
||||
|
||||
# Include board specific makefile
|
||||
include src/Makefile
|
||||
-include src/$(patsubst "%",%,$(CONFIG_BOARD_DIRECTORY))/Makefile
|
||||
@ -87,7 +80,7 @@ $(OUT)%.o.ctr: $(OUT)%.o
|
||||
$(OUT)compile_time_request.o: $(patsubst %.c, $(OUT)src/%.o.ctr,$(src-y)) ./scripts/buildcommands.py
|
||||
@echo " Building $@"
|
||||
$(Q)cat $(patsubst %.c, $(OUT)src/%.o.ctr,$(src-y)) | tr -s '\0' '\n' > $(OUT)compile_time_request.txt
|
||||
$(Q)$(PYTHON) ./scripts/buildcommands.py $(LED_OPT) $(OUT)compile_time_request.txt $(OUT)compile_time_request.c
|
||||
$(Q)$(PYTHON) ./scripts/buildcommands.py $(OUT)compile_time_request.txt $(OUT)compile_time_request.c
|
||||
$(Q)$(CC) $(CFLAGS) -c $(OUT)compile_time_request.c -o $@
|
||||
|
||||
################ Auto generation of "board/" include file link
|
||||
|
@ -11,8 +11,6 @@ FILEHEADER = """
|
||||
|
||||
#include <stdint.h>
|
||||
#include "compiler.h"
|
||||
#include "board/misc.h"
|
||||
#include "board/gpio.h"
|
||||
"""
|
||||
|
||||
def error(msg):
|
||||
@ -155,59 +153,32 @@ Handlers.append(Handle_arm_irq())
|
||||
|
||||
class HandleStatusLED:
|
||||
def __init__(self):
|
||||
self.ctr_dispatch = {}
|
||||
self.pin = None
|
||||
self.ctr_dispatch = { 'DECL_LED_PIN': self.decl_led_pin }
|
||||
def decl_led_pin(self, req):
|
||||
pin = req.split(None, 1)[1].strip()
|
||||
if pin.startswith('"') and pin.endswith('"'):
|
||||
pin = pin[1:-1].strip()
|
||||
self.pin = pin
|
||||
def generate_code(self, options):
|
||||
pin = options.led_pin
|
||||
if not pin:
|
||||
led_def = led_init = led_toggle = led_on = led_off = ""
|
||||
else:
|
||||
led_def = "static struct gpio_out led;"
|
||||
led_init = "led = gpio_out_setup(%d, %d);"
|
||||
led_toggle = "gpio_out_toggle(led);"
|
||||
led_write = "gpio_out_write(led, %d);"
|
||||
write_on = 1
|
||||
led_gpio = led_gpio_high = 0
|
||||
pin = self.pin
|
||||
if pin:
|
||||
led_gpio_high = 1
|
||||
if pin[0] == "!":
|
||||
write_on = 0
|
||||
pin = pin[1:].upper()
|
||||
led_gpio_high = 0
|
||||
pin = pin[1:].strip()
|
||||
avail_pins = HandlerEnumerations.get_available_pins()
|
||||
reserved_pins = HandlerConstants.get_reserved_pins()
|
||||
pin_num = avail_pins.get(pin)
|
||||
if pin_num is None:
|
||||
led_gpio = avail_pins.get(pin)
|
||||
if led_gpio is None:
|
||||
error("Pin %s is not available for this build" % pin)
|
||||
if pin in reserved_pins:
|
||||
error("Pin %s is reserved by an active MCU peripheral" % pin)
|
||||
led_init = led_init % (pin_num, write_on)
|
||||
led_on = led_write % (write_on)
|
||||
led_off = led_write % (int(not write_on))
|
||||
fmt = """
|
||||
|
||||
%s
|
||||
|
||||
void __always_inline
|
||||
led_init(void)
|
||||
{
|
||||
%s
|
||||
}
|
||||
|
||||
void __always_inline
|
||||
led_toggle(void)
|
||||
{
|
||||
%s
|
||||
}
|
||||
|
||||
void __always_inline
|
||||
led_on(void)
|
||||
{
|
||||
%s
|
||||
}
|
||||
|
||||
void __always_inline
|
||||
led_off(void)
|
||||
{
|
||||
%s
|
||||
}
|
||||
uint32_t led_gpio = %d, led_gpio_high = %d; // "%s"
|
||||
"""
|
||||
return fmt % (led_def, led_init, led_toggle, led_on, led_off)
|
||||
return fmt % (led_gpio, led_gpio_high, self.pin)
|
||||
|
||||
|
||||
Handlers.append(HandleStatusLED())
|
||||
@ -219,8 +190,6 @@ Handlers.append(HandleStatusLED())
|
||||
def main():
|
||||
usage = "%prog [options] <cmd section file> <output.c>"
|
||||
opts = optparse.OptionParser(usage)
|
||||
opts.add_option("-l", "--ledpin", dest="led_pin", default="",
|
||||
help="LED Status Pin")
|
||||
opts.add_option("-v", action="store_true", dest="verbose",
|
||||
help="enable debug messages")
|
||||
options, args = opts.parse_args()
|
||||
|
@ -1,3 +1,3 @@
|
||||
# Main code build rules
|
||||
|
||||
src-y += canboot_main.c
|
||||
src-y += canboot_main.c led.c
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "board/canbus.h" // canbus_send
|
||||
#include "board/flash.h" // write_page
|
||||
#include "canboot_main.h" // canboot_main
|
||||
#include "led.h" // check_blink_time
|
||||
|
||||
|
||||
#define COMMAND_SIZE 8
|
||||
@ -38,7 +39,6 @@ static uint8_t cmd_buf[CMD_BUF_SIZE];
|
||||
static uint8_t cmd_pos = 0;
|
||||
static uint16_t page_count = 0;
|
||||
static uint16_t page_pos = 0;
|
||||
static uint32_t last_blink_time = 0;
|
||||
static uint16_t cmd_arg = 0;
|
||||
enum { CMD_PENDING, RX_BLOCK, RX_DONE, TX_BLOCK, COMPLETE };
|
||||
static uint8_t current_state = CMD_PENDING;
|
||||
@ -149,17 +149,6 @@ process_page(void) {
|
||||
send_ack(ACK_BLOCK_RX, cmd_arg);
|
||||
}
|
||||
|
||||
static void
|
||||
check_blink_time(uint32_t usec)
|
||||
{
|
||||
uint32_t curtime = timer_read_time();
|
||||
uint32_t endtime = last_blink_time + timer_from_us(usec);
|
||||
if (timer_is_before(endtime, curtime)) {
|
||||
led_toggle();
|
||||
last_blink_time = timer_read_time();
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
process_state(void)
|
||||
{
|
||||
@ -238,16 +227,7 @@ static void
|
||||
enter_bootloader(void)
|
||||
{
|
||||
can_init();
|
||||
|
||||
// TODO: this is temporary. It lets us know
|
||||
// that the bootloader has been entered. We can
|
||||
// also toggle this as a means to visualize transfers.
|
||||
// We will want to set it up in the menuconfig
|
||||
led_init();
|
||||
// The short delay is simply to ensure that the Debug Timer is
|
||||
// enabled
|
||||
udelay(10);
|
||||
last_blink_time = timer_read_time();
|
||||
|
||||
for (;;) {
|
||||
canbus_rx_task();
|
||||
|
@ -18,10 +18,4 @@ uint8_t timer_is_before(uint32_t time1, uint32_t time2);
|
||||
uint32_t timer_read_time(void);
|
||||
void udelay(uint32_t usecs);
|
||||
|
||||
// Led Commands (generated by buildcommands.py)
|
||||
void led_init();
|
||||
void led_toggle();
|
||||
void led_on();
|
||||
void led_off();
|
||||
|
||||
#endif // misc.h
|
||||
|
39
src/led.c
Normal file
39
src/led.c
Normal file
@ -0,0 +1,39 @@
|
||||
// LED status updates
|
||||
//
|
||||
// Copyright (C) 2021 Eric Callahan <arksine.code@gmail.com>
|
||||
//
|
||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
|
||||
#include "autoconf.h" // CONFIG_ENABLE_LED
|
||||
#include "board/gpio.h" // gpio_out_setup
|
||||
#include "board/misc.h" // timer_read_time
|
||||
#include "ctr.h" // DECL_CTR
|
||||
#include "led.h" // check_blink_time
|
||||
|
||||
DECL_CTR("DECL_LED_PIN " __stringify(CONFIG_STATUS_LED_PIN));
|
||||
extern uint32_t led_gpio, led_gpio_high; // Generated by buildcommands.py
|
||||
|
||||
static struct gpio_out led;
|
||||
static uint32_t last_blink_time;
|
||||
|
||||
void
|
||||
led_init(void)
|
||||
{
|
||||
if (!CONFIG_ENABLE_LED)
|
||||
return;
|
||||
led = gpio_out_setup(led_gpio, led_gpio_high);
|
||||
last_blink_time = timer_read_time();
|
||||
}
|
||||
|
||||
void
|
||||
check_blink_time(uint32_t usec)
|
||||
{
|
||||
if (!CONFIG_ENABLE_LED)
|
||||
return;
|
||||
uint32_t curtime = timer_read_time();
|
||||
uint32_t endtime = last_blink_time + timer_from_us(usec);
|
||||
if (timer_is_before(endtime, curtime)) {
|
||||
gpio_out_toggle(led);
|
||||
last_blink_time = timer_read_time();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user