mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-07-22 06:39:18 -04:00
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.
This commit is contained in:
parent
4f4de4a07d
commit
d83d659284
1 changed files with 2 additions and 27 deletions
|
@ -10,36 +10,12 @@
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#include "spi.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
|
#define PAGE_SIZE 256
|
||||||
|
|
||||||
static bool flash_is_busy(void);
|
static bool flash_is_busy(void);
|
||||||
static void flash_wait_busy(void);
|
static void flash_wait_busy(void);
|
||||||
static void flash_write_enable(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)
|
static bool flash_is_busy(void)
|
||||||
{
|
{
|
||||||
uint8_t tx_buf = READ_STATUS_REG_1;
|
uint8_t tx_buf = READ_STATUS_REG_1;
|
||||||
|
@ -58,9 +34,8 @@ static bool flash_is_busy(void)
|
||||||
// Blocking until !busy
|
// Blocking until !busy
|
||||||
static void flash_wait_busy(void)
|
static void flash_wait_busy(void)
|
||||||
{
|
{
|
||||||
while (flash_is_busy()) {
|
while (flash_is_busy())
|
||||||
delay(10);
|
;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flash_write_enable(void)
|
static void flash_write_enable(void)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue