mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 21:04:32 +01:00
Stability (users' random "FELUCCA/JIANT CRASH" screens since the dual-core 0.6.x builds): - MENU > SYSTEM > CPU 2 CORES / 1 CORE and CPU CLOCK 360 / 320 MHZ (settings byte favorites.factory[15][17], editor ids 23, 24), from the next start. A crash or a watchdog hang while both cores ran, or the second core given up (misread / no answer / fault), turns 2 CORES off for good (was: until power-off) and says "2 CORES OFF AFTER A CRASH - MENU > SYSTEM > CPU" / "CORE 2 FAILED: 1 CORE"; ABOUT: CORES 1 (AFTER A CRASH). - 320 MHz: curist's fm1-clk320-probe switch (MIT, hal/fm1_clk320.h, unchanged; LICENSES/MIT-fm1-clk320.txt), at boot before the scan, core 1, audio and USB; a reset during it: no failed boot, no retry until power-off. - Crash screen: version, the faulting core and how many ran, a short code (cpu_safe.c crash_code) and the five numbers labelled (VEC PC EMU DBG RETS, same order as every older screen). The last crash (or watchdog hang) is logged as 32 characters in the settings record (SLICE's retired favourites row 13): MENU > ABOUT > LAST CRASH, the editor's settings backup, console `crash`. tools/crash_decode.py maps a photo's numbers to functions (ELF). - Fixed race: every flash erase/write/read turns XIP off with IRQs off; the 48 kHz USB resampler job (0.8.9) runs on core 1 past the audio ISR, so a core-1 fault then would fetch the vectors from a disabled flash. irq_save now parks core 1 first (fm1_mc_park, FL_PARK hook). - One core: the load governor's budget at 55 % (was 65 %) so peaks have room without core 1. - MENU > AUDIO > LOAD (was SYSTEM's; a bottom tile holds 7 rows), RAMTEXT 1 KiB larger (from the pool's spare). Crackle since 0.9.10 (owner's unit: 0.9.9 clean, 0.9.10/0.9.11 up to 94 % load on every output, host counts equal): - 0.9.9 -> 0.9.10 changed no sound code and left the RAM code byte for byte, but the +6 KB of new drawings came before the engines in the image: every engine render (flash/XIP, shared cache) moved +6178 B (analog +9414) while the effects, master and ISR stayed put. Now everything an interrupt reaches (347 functions, 244 tables) is placed first in name order (build.py audio_sections, app.ld .text.a.* / .rodata.a.*): UI changes can no longer move it (verified: this commit's +2.3 KB of UI moved the renders by 48 B, sound-side edits). Same size. - TIMER5's USB refill (0.9.10, every 10 kHz tick, also nested in the render): no SIE poll for 0.6 ms after a packet is queued (it cannot have left yet): ~4 polls a ms instead of ~10. tests/target_budget.py watches ep4_tx / ep4_fill. Image 578540 B (+2348 over 0.9.11). ./build.sh && tests/run_tests.sh: ALL HOST TESTS PASSED (new tests/cpu_safe_test.c; settings, ui, editor tests extended). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
192 lines
6.5 KiB
C
192 lines
6.5 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only
|
|
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
|
|
/* FM-1 system HAL: P33 access, watchdog, reset reason, reboot / UBOOT entry
|
|
* No vendor code; call with interrupts off
|
|
* (no IRQs are enabled yet, so nothing else touches P33).
|
|
*
|
|
* fm1_reset_reason() snapshot P3_RST_SRC / RST_SRC (call first thing)
|
|
* fm1_wdt_arm(t) reset-mode watchdog, t = 0xA 1 s .. 0xF 32 s
|
|
* fm1_wdt_feed() in the main loop
|
|
* fm1_reboot() chip reset through P33 (P3_PR_PWR bit 4)
|
|
* fm1_enter_uboot() "usb_update_mode" at 0x01C7FD80 + chip reset
|
|
* fm1_enter_update(p) 112-byte UPDATA_PARM record at 0x01C7FD88 + core reset
|
|
* (the SPL then runs the staged update loader)
|
|
* fm1_core_reset() PWR_CON core reset
|
|
* fm1_updata_parm_clear() zero the record (CRC 0: ignored on a warm reset)
|
|
* fm1_mailbox_clear() zero 0x01C7FD80..0x01C7FDFF (boot info, mailbox) at cold start
|
|
* fm1_mem_readable(a, n) / fm1_peek8(a) debug reads of RAM / XIP only
|
|
*/
|
|
#pragma once
|
|
#include <stdint.h>
|
|
#include "fm1_cc.h"
|
|
|
|
#define FM1_P33_CON (*(volatile uint32_t *)0x13E08u)
|
|
#define FM1_P33_DAT (*(volatile uint32_t *)0x13E0Cu)
|
|
#define FM1_RST_SRC (*(volatile uint32_t *)0x100C0u)
|
|
#define FM1_BOOT_STATE ((volatile uint8_t *)0x01C7FD80u)
|
|
#define FM1_PWR_CON (*(volatile uint32_t *)0x10000u)
|
|
#define FM1_UPDATA_PARM ((volatile uint8_t *)0x01C7FD88u)
|
|
#define FM1_UPDATA_PARM_LEN 112u
|
|
|
|
static uint32_t fm1_p33_timeouts;
|
|
|
|
static uint8_t fm1__p33_xfer(uint8_t b)
|
|
{
|
|
uint32_t n = 100000u;
|
|
FM1_P33_DAT = b;
|
|
FM1_P33_CON |= 1u << 4;
|
|
(void)FM1_P33_CON; /* stands in for csync */
|
|
while (FM1_P33_CON & (1u << 1))
|
|
if (--n == 0) {
|
|
fm1_p33_timeouts++;
|
|
break;
|
|
}
|
|
return (uint8_t)FM1_P33_DAT;
|
|
}
|
|
|
|
static void fm1__p33_cs(uint32_t a)
|
|
{
|
|
if (a & 0x8000u) {
|
|
FM1_P33_CON |= (1u << 0) | (1u << 8); /* RTC domain */
|
|
} else {
|
|
FM1_P33_CON &= ~(1u << 8);
|
|
FM1_P33_CON |= 1u << 0;
|
|
}
|
|
}
|
|
|
|
static void fm1__p33_op(uint32_t op, uint32_t a, uint8_t d) /* 0 wr, 1 or, 2 and, 3 xor */
|
|
{
|
|
fm1__p33_cs(a);
|
|
fm1__p33_xfer((uint8_t)((op << 5) | ((a >> 8) & 3u)));
|
|
fm1__p33_xfer((uint8_t)a);
|
|
fm1__p33_xfer(d);
|
|
FM1_P33_CON &= ~((1u << 0) | (1u << 8));
|
|
}
|
|
|
|
static uint8_t fm1_p33_read(uint32_t a)
|
|
{
|
|
uint8_t v;
|
|
fm1__p33_cs(a);
|
|
fm1__p33_xfer((uint8_t)(0x80u | ((a >> 8) & 3u)));
|
|
fm1__p33_xfer((uint8_t)a);
|
|
v = fm1__p33_xfer(0x5E);
|
|
FM1_P33_CON &= ~((1u << 0) | (1u << 8));
|
|
return v;
|
|
}
|
|
static void fm1_p33_write(uint32_t a, uint8_t d) { fm1__p33_op(0, a, d); }
|
|
static void fm1_p33_or(uint32_t a, uint8_t d) { fm1__p33_op(1, a, d); }
|
|
static void fm1_p33_and(uint32_t a, uint8_t d) { fm1__p33_op(2, a, d); }
|
|
|
|
/* ------------------------------------------------------------ watchdog --- */
|
|
#define FM1_P3_WDT_CON 0x80u
|
|
#define FM1_P3_VLD_KEEP 0x17u
|
|
#define FM1_P3_RST_SRC 0x12u
|
|
#define FM1_P3_PR_PWR 0xA0u
|
|
|
|
static void fm1_wdt_arm(uint8_t t)
|
|
{
|
|
fm1_p33_write(FM1_P3_WDT_CON, 0);
|
|
fm1_p33_and(FM1_P3_VLD_KEEP, (uint8_t)~0x40u); /* WDT_EXPT_EN = 0: plain reset */
|
|
fm1_p33_write(FM1_P3_WDT_CON, (uint8_t)((t & 0x0Fu) | 0x40u)); /* timeout, reset mode, clear */
|
|
fm1_p33_or(FM1_P3_WDT_CON, 0x10); /* enable */
|
|
}
|
|
static void fm1_wdt_feed(void) { fm1_p33_or(FM1_P3_WDT_CON, 0x40); }
|
|
static void fm1_wdt_stop(void) { fm1_p33_write(FM1_P3_WDT_CON, 0); }
|
|
|
|
/* ---------------------------------------------------- reset and reboot --- */
|
|
static struct {
|
|
uint8_t p3_rst; /* bit0 power-on, 1 VDDIO low, 2 WDT, 3 VCM, 4 long press, 5 1.2 V, 6 soft (P33) */
|
|
uint32_t rst_src; /* bit5 soft (PWR_CON) */
|
|
uint8_t wdt_con; /* as found at boot */
|
|
} fm1_boot;
|
|
|
|
static void fm1_reset_reason(void)
|
|
{
|
|
fm1_boot.p3_rst = fm1_p33_read(FM1_P3_RST_SRC);
|
|
fm1_boot.rst_src = FM1_RST_SRC;
|
|
fm1_boot.wdt_con = fm1_p33_read(FM1_P3_WDT_CON);
|
|
}
|
|
|
|
/* (JIANT 0.6.71) hold the second core (C1_CON 0x1EEE004: bit 1 holds it, bit 3 lets it run; the SDK's, as Melodee and
|
|
* fm1-x0x have it): before every reset and update, and first thing at boot, so it never runs over RAM being cleared
|
|
* or handed back to the boot loader. Harmless when it is not running */
|
|
static inline void fm1_core1_stop(void)
|
|
{
|
|
*(volatile uint32_t *)0x1EEE004u |= 2u;
|
|
*(volatile uint32_t *)0x1EEE004u &= ~8u;
|
|
__asm__ volatile("csync" ::: "memory");
|
|
}
|
|
|
|
/* (JIANT 0.9.12) the core clock is JieLi's 320 MHz (PLL2's multiplier 240, field + 2; the boot stage's 360: 270):
|
|
* MENU > ABOUT. hal/fm1_clk320.h switches it */
|
|
static inline int fm1_clk_320(void) { return ((*(volatile uint32_t *)0x119ACu) & 0xFFFu) == 238u; }
|
|
|
|
static void fm1_reboot(void)
|
|
{
|
|
__asm__ volatile("cli");
|
|
fm1_core1_stop();
|
|
fm1_p33_or(FM1_P3_PR_PWR, 0x10);
|
|
for (;;)
|
|
;
|
|
}
|
|
|
|
static void fm1_enter_uboot(void)
|
|
{
|
|
static const char k[16] = "usb_update_mode";
|
|
uint32_t i;
|
|
__asm__ volatile("cli");
|
|
fm1_core1_stop();
|
|
/* CPU0 write limits (fm1_guard.h) may cover the mailbox: drop them all */
|
|
if (!(*(volatile uint32_t *)0x1EEE240u & 1u))
|
|
*(volatile uint32_t *)0x1EEE240u = 0xE7u;
|
|
*(volatile uint32_t *)0x1EEE348u = 0;
|
|
for (i = 0; i < 16u; i++)
|
|
FM1_BOOT_STATE[i] = (uint8_t)k[i];
|
|
fm1_p33_or(FM1_P3_PR_PWR, 0x10);
|
|
for (;;)
|
|
;
|
|
}
|
|
|
|
FM1_INLINE void fm1_core_reset(void)
|
|
{
|
|
__asm__ volatile("cli" ::: "memory");
|
|
fm1_core1_stop();
|
|
FM1_PWR_CON |= 0x10u;
|
|
for (;;)
|
|
;
|
|
}
|
|
|
|
FM1_INLINE void fm1_enter_update(const uint8_t *parm)
|
|
{
|
|
uint32_t i;
|
|
__asm__ volatile("cli");
|
|
if (!(*(volatile uint32_t *)0x1EEE240u & 1u)) /* drop CPU0 write limits, as fm1_enter_uboot */
|
|
*(volatile uint32_t *)0x1EEE240u = 0xE7u;
|
|
*(volatile uint32_t *)0x1EEE348u = 0;
|
|
for (i = 0; i < FM1_UPDATA_PARM_LEN; i++)
|
|
FM1_UPDATA_PARM[i] = parm[i];
|
|
fm1_core_reset();
|
|
}
|
|
|
|
FM1_INLINE void fm1_updata_parm_clear(void)
|
|
{
|
|
uint32_t i;
|
|
for (i = 0; i < FM1_UPDATA_PARM_LEN; i++)
|
|
FM1_UPDATA_PARM[i] = 0;
|
|
}
|
|
|
|
FM1_INLINE void fm1_mailbox_clear(void) /* before fm1_guard_enable (it write-protects the top) */
|
|
{
|
|
uint32_t *s;
|
|
for (s = (uint32_t *)0x01C7FD80u; s < (uint32_t *)0x01C7FE00u; s++)
|
|
*s = 0;
|
|
}
|
|
|
|
/* RAM and the XIP window only: SFR reads can have side effects */
|
|
static int fm1_mem_readable(uint32_t a, uint32_t n)
|
|
{
|
|
return (a >= 0x01C00000u && a + n <= 0x01C80000u && a + n >= a) ||
|
|
(a >= 0x02000000u && a + n <= 0x02100000u && a + n >= a);
|
|
}
|
|
FM1_INLINE uint8_t fm1_peek8(uint32_t a) { return *(const volatile uint8_t *)a; }
|