From bbbe1e2f316a8a53bbbd41e8d73cb6e4bdc4f9b4 Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Mon, 27 Feb 2023 17:11:03 +0100 Subject: [PATCH] fw: Move LED defines and function to own files Signed-off-by: Daniel Lublin --- hw/application_fpga/Makefile | 2 ++ hw/application_fpga/fw/tk1/Makefile | 2 +- hw/application_fpga/fw/tk1/assert.c | 1 - hw/application_fpga/fw/tk1/led.c | 21 +++++++++++++++++++++ hw/application_fpga/fw/tk1/led.h | 22 ++++++++++++++++++++++ hw/application_fpga/fw/tk1/lib.c | 2 +- hw/application_fpga/fw/tk1/main.c | 20 ++------------------ 7 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 hw/application_fpga/fw/tk1/led.c create mode 100644 hw/application_fpga/fw/tk1/led.h diff --git a/hw/application_fpga/Makefile b/hw/application_fpga/Makefile index bf0f9fd..ed36d34 100644 --- a/hw/application_fpga/Makefile +++ b/hw/application_fpga/Makefile @@ -74,6 +74,7 @@ FIRMWARE_DEPS = \ $(P)/fw/tk1/lib.h \ $(P)/fw/tk1/proto.h \ $(P)/fw/tk1/assert.h \ + $(P)/fw/tk1/led.h FIRMWARE_OBJS = \ $(P)/fw/tk1/main.o \ @@ -81,6 +82,7 @@ FIRMWARE_OBJS = \ $(P)/fw/tk1/proto.o \ $(P)/fw/tk1/lib.o \ $(P)/fw/tk1/assert.o \ + $(P)/fw/tk1/led.o \ $(P)/fw/tk1/blake2s/blake2s.o TESTFW_OBJS = \ diff --git a/hw/application_fpga/fw/tk1/Makefile b/hw/application_fpga/fw/tk1/Makefile index cec6315..68b8261 100644 --- a/hw/application_fpga/fw/tk1/Makefile +++ b/hw/application_fpga/fw/tk1/Makefile @@ -1,5 +1,5 @@ # Uses ../.clang-format -FMTFILES=main.c lib.h lib.c proto.h proto.c types.h assert.c assert.h +FMTFILES=main.c lib.h lib.c proto.h proto.c types.h assert.c assert.h led.c led.h .PHONY: fmt fmt: clang-format --dry-run --ferror-limit=0 $(FMTFILES) diff --git a/hw/application_fpga/fw/tk1/assert.c b/hw/application_fpga/fw/tk1/assert.c index 97a3a9a..b9036bd 100644 --- a/hw/application_fpga/fw/tk1/assert.c +++ b/hw/application_fpga/fw/tk1/assert.c @@ -20,6 +20,5 @@ void __assert_fail(const char *__assertion, const char *__file, htif_lf(); for (;;); - // Not reached } diff --git a/hw/application_fpga/fw/tk1/led.c b/hw/application_fpga/fw/tk1/led.c new file mode 100644 index 0000000..d205700 --- /dev/null +++ b/hw/application_fpga/fw/tk1/led.c @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2022, 2023 - Tillitis AB + * SPDX-License-Identifier: GPL-2.0-only + */ + +#include "led.h" +#include "../tk1_mem.h" +#include "types.h" + +void forever_redflash() +{ + static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED; + + int led_on = 0; + for (;;) { + *led = led_on ? LED_RED : 0; + for (volatile int i = 0; i < 800000; i++) { + } + led_on = !led_on; + } +} diff --git a/hw/application_fpga/fw/tk1/led.h b/hw/application_fpga/fw/tk1/led.h new file mode 100644 index 0000000..6d34818 --- /dev/null +++ b/hw/application_fpga/fw/tk1/led.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2022, 2023 - Tillitis AB + * SPDX-License-Identifier: GPL-2.0-only + */ + +#ifndef LED_H +#define LED_H + +#include "../tk1_mem.h" +#include "types.h" + +// clang-format off +static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED; +// clang-format on + +#define LED_RED (1 << TK1_MMIO_TK1_LED_R_BIT) +#define LED_GREEN (1 << TK1_MMIO_TK1_LED_G_BIT) +#define LED_BLUE (1 << TK1_MMIO_TK1_LED_B_BIT) +#define LED_WHITE (LED_RED | LED_GREEN | LED_BLUE) + +void forever_redflash(); +#endif diff --git a/hw/application_fpga/fw/tk1/lib.c b/hw/application_fpga/fw/tk1/lib.c index bea45ec..7db4421 100644 --- a/hw/application_fpga/fw/tk1/lib.c +++ b/hw/application_fpga/fw/tk1/lib.c @@ -4,8 +4,8 @@ */ #include "lib.h" -#include "types.h" #include "assert.h" +#include "types.h" #if NOCONSOLE void htif_putc(int ch) diff --git a/hw/application_fpga/fw/tk1/main.c b/hw/application_fpga/fw/tk1/main.c index 9d842fb..264c2b3 100644 --- a/hw/application_fpga/fw/tk1/main.c +++ b/hw/application_fpga/fw/tk1/main.c @@ -4,11 +4,12 @@ */ #include "../tk1_mem.h" +#include "assert.h" #include "blake2s/blake2s.h" +#include "led.h" #include "lib.h" #include "proto.h" #include "types.h" -#include "assert.h" // clang-format off static volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST; @@ -21,7 +22,6 @@ static volatile uint32_t *cdi = (volatile uint32_t *)TK1_MMIO_TK1_CD static volatile uint32_t *app_addr = (volatile uint32_t *)TK1_MMIO_TK1_APP_ADDR; static volatile uint32_t *app_size = (volatile uint32_t *)TK1_MMIO_TK1_APP_SIZE; static volatile uint8_t *fw_ram = (volatile uint8_t *)TK1_MMIO_FW_RAM_BASE; -static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED; static volatile uint32_t *fw_blake2s_addr = (volatile uint32_t *)TK1_MMIO_TK1_BLAKE2S; static volatile uint32_t *trng_status = (volatile uint32_t *)TK1_MMIO_TRNG_STATUS; static volatile uint32_t *trng_entropy = (volatile uint32_t *)TK1_MMIO_TRNG_ENTROPY; @@ -29,11 +29,6 @@ static volatile uint32_t *timer = (volatile uint32_t *)TK1_MMIO_TIMER_ static volatile uint32_t *timer_prescaler = (volatile uint32_t *)TK1_MMIO_TIMER_PRESCALER; static volatile uint32_t *timer_status = (volatile uint32_t *)TK1_MMIO_TIMER_STATUS; static volatile uint32_t *timer_ctrl = (volatile uint32_t *)TK1_MMIO_TIMER_CTRL; - -#define LED_RED (1 << TK1_MMIO_TK1_LED_R_BIT) -#define LED_GREEN (1 << TK1_MMIO_TK1_LED_G_BIT) -#define LED_BLUE (1 << TK1_MMIO_TK1_LED_B_BIT) -#define LED_WHITE (LED_RED | LED_GREEN | LED_BLUE) // clang-format on struct namever { @@ -141,17 +136,6 @@ static void compute_cdi(uint8_t digest[32], uint8_t use_uss, uint8_t uss[32]) wordcpy_s((void *)cdi, 8, (void *)local_cdi, 8); } -void forever_redflash() -{ - int led_on = 0; - for (;;) { - *led = led_on ? LED_RED : 0; - for (volatile int i = 0; i < 800000; i++) { - } - led_on = !led_on; - } -} - enum state { FW_STATE_INITIAL, FW_STATE_INIT_LOADING,