From d83d659284a2fa43e19b0312e945fe79fdb55164 Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Tue, 29 Apr 2025 20:32:55 +0200 Subject: [PATCH] fw: Remove use of timer in flash operations Since we want to keep the user of the timer to the device apps, remove the use of the timer for implementing a delay when writing to flash. Let's try without any delay what so ever, just busylooping the query to the chip. --- hw/application_fpga/fw/tk1/flash.c | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/hw/application_fpga/fw/tk1/flash.c b/hw/application_fpga/fw/tk1/flash.c index ed58671..68b344c 100644 --- a/hw/application_fpga/fw/tk1/flash.c +++ b/hw/application_fpga/fw/tk1/flash.c @@ -10,36 +10,12 @@ #include "flash.h" #include "spi.h" -// clang-format off -static volatile uint32_t *timer = (volatile uint32_t *)TK1_MMIO_TIMER_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; -// clang-format on - -// CPU clock frequency in Hz -#define CPUFREQ 24000000 #define PAGE_SIZE 256 static bool flash_is_busy(void); static void flash_wait_busy(void); static void flash_write_enable(void); -static void delay(int timeout_ms) -{ - // Tick once every centisecond - *timer_prescaler = CPUFREQ / 100; - *timer = timeout_ms / 10; - - *timer_ctrl |= (1 << TK1_MMIO_TIMER_CTRL_START_BIT); - - while (*timer_status != 0) { - } - - // Stop timer - *timer_ctrl |= (1 << TK1_MMIO_TIMER_CTRL_STOP_BIT); -} - static bool flash_is_busy(void) { uint8_t tx_buf = READ_STATUS_REG_1; @@ -58,9 +34,8 @@ static bool flash_is_busy(void) // Blocking until !busy static void flash_wait_busy(void) { - while (flash_is_busy()) { - delay(10); - } + while (flash_is_busy()) + ; } static void flash_write_enable(void)