Files
fmini-1/firmware/hal/fm1_time.h
T
ClaudeandКирилл Сапфиров c8d571bd22 Felucca 1.6.1
MENU > LARGE keeps one size per knob (#251): each knob shows all its
values in the size its longest value fits, so a value no longer jumps
between sizes while it is turned. No new fonts.

Updates check the package's size on the device: the update entry and the
update loader take only a package whose firmware area is exactly the
FM-1's. Another device's package is refused before anything is erased
(the update screen shows FAILED -15; the loader answers -14).

Second core (beta, PR #247): MENU > SYSTEM > 2ND CORE, OFF by default.
ON (BETA) applies from the next power-on: the second core renders some
of the four parts of each block, bit for bit the one-core sound. A unit
whose second core misreads goes on with one core and sets it back to
OFF. FELUCCA_CPU2=0 builds none of it. Start, mailbox and guards from
X0X (with Melodee's dual-core findings), the split and hardening after
Jangada.

Felucca-Engines: ANALOG, LOFI, TRIO, WHEEL and NOISE, the engine
interface, the shared DSP helpers and their table generator move to
https://github.com/hugelton/Felucca-Engines under the MIT licence,
included as the git submodule firmware/engines. The firmware stays
GPL-3.0-only; clone with --recurse-submodules. The sound is unchanged
(the same golden renders); the engines' own tests run with Felucca's.

Co-authored-by: Кирилл Сапфиров <gospodindilly@gmail.com>
2026-10-17 19:04:28 -03:00

49 lines
1.6 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
/* FM-1 time base: TIMER4 free-running from the 24 MHz crystal.
* Measured on hardware: under mask-ROM UBOOT the crystal runs and TIMER4 counts
* 24 MHz, matching the host's measurement of the same interval to 0.3 %.
* TIMER4 is not used by the ROM or the SPL. No interrupts, no ROM calls.
*
* JL_TIMER4 = 0x10800: CON [1:0]=1 run, [3:2]=2 OSC source, [7:4]=0 /1,
* bit14 = clear pending; CNT +4; PRD +8 (32-bit, set to 0xFFFFFFFF).
* The counter wraps every 178.9 s; use differences (unsigned arithmetic).
*/
#pragma once
#include <stdint.h>
#define FM1_T4_CON (*(volatile uint32_t *)0x10800u)
#define FM1_T4_CNT (*(volatile uint32_t *)0x10804u)
#define FM1_T4_PRD (*(volatile uint32_t *)0x10808u)
#define FM1_TICKS_PER_US 24u
/* Start TIMER4 unless it already runs, so time stays continuous across
* RAM-run jumps. */
static inline void fm1_time_init(void)
{
if ((FM1_T4_CON & 0xFu) == ((2u << 2) | 1u))
return;
FM1_T4_CON = 0;
FM1_T4_PRD = 0xFFFFFFFFu;
FM1_T4_CNT = 0;
FM1_T4_CON = (2u << 2) | 1u | (1u << 14);
}
static inline uint32_t fm1_ticks(void) { return FM1_T4_CNT; }
/* Microseconds, wrapping every ~178.9 s. */
static inline uint32_t fm1_micros(void) { return FM1_T4_CNT / FM1_TICKS_PER_US; }
static inline void fm1_delay_us(uint32_t us)
{
uint32_t start = FM1_T4_CNT, span = us * FM1_TICKS_PER_US;
while ((uint32_t)(FM1_T4_CNT - start) < span)
;
}
static inline void fm1_delay_ms(uint32_t ms)
{
while (ms--)
fm1_delay_us(1000u);
}