mirror of
https://github.com/MCKero6423/uv-k5-v3-emulator.git
synced 2026-10-02 11:07:31 +00:00
Adds a QEMU machine for the Puya PY32F071 (Cortex-M0+) so Quansheng UV-K5 V3 firmware can run on a PC. The firmware boots to its main loop in about five seconds and the LCD contents are readable. Register layouts come from the vendor CMSIS header shipped with the firmware rather than guesswork. Modelled: RCC, GPIO, ADC, both SPI controllers, DMA1 and the PY25Q16 flash; everything else answers through a logging catch-all, which is how the next thing worth modelling gets identified. Seven things had to be right before it would boot, each found by watching where the firmware stopped: flash aliased at the application offset, clock ready bits, self-clearing ADC calibration, SPI transfer flags, DMA-driven flash reads, SysTick poll acceleration, and the bit-banged transceiver bus idling low. SysTick needs explanation. SYSTICK_DelayUs polls the counter and accumulates differences; under emulation a register read costs far more relative to guest time, so a measured 120 ms delay would have taken about 7.7 hours. Lowering the clock does not help because the bottleneck is loop iterations, not counter speed. Reporting a value that runs ahead of the real counter does, via a new poll-boost property on SysTick. Guest time therefore runs fast during delays: fine for exercising menus and control flow, wrong for judging signal timing. Also includes the host build of the CW timing chain (harness, stubs, shim, tests), which compiles app/cwkeyer.c and app/cwmacro.c unmodified against stub drivers with a virtual clock and scripted paddle input. Known gap: keypad rows reach the firmware's scan and KEYBOARD_Poll returns the right key code, but the UI does not react yet. Not modelled, and not intended to be: radio behaviour. The transceiver chip has no public datasheet, so keying envelopes and emissions need real hardware.
62 lines
1.5 KiB
Plaintext
62 lines
1.5 KiB
Plaintext
/*
|
|
* ARMv7M SysTick timer
|
|
*
|
|
* Copyright (c) 2006-2007 CodeSourcery.
|
|
* Written by Paul Brook
|
|
* Copyright (c) 2017 Linaro Ltd
|
|
* Written by Peter Maydell
|
|
*
|
|
* This code is licensed under the GPL (version 2 or later).
|
|
*/
|
|
|
|
#ifndef HW_TIMER_ARMV7M_SYSTICK_H
|
|
#define HW_TIMER_ARMV7M_SYSTICK_H
|
|
|
|
#include "hw/sysbus.h"
|
|
#include "qom/object.h"
|
|
#include "hw/ptimer.h"
|
|
#include "hw/clock.h"
|
|
|
|
#define TYPE_SYSTICK "armv7m_systick"
|
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(SysTickState, SYSTICK)
|
|
|
|
/*
|
|
* QEMU interface:
|
|
* + sysbus MMIO region 0 is the register interface (covering
|
|
* the registers which are mapped at address 0xE000E010)
|
|
* + sysbus IRQ 0 is the interrupt line to the NVIC
|
|
* + Clock input "refclk" is the external reference clock
|
|
* (used when SYST_CSR.CLKSOURCE == 0)
|
|
* + Clock input "cpuclk" is the main CPU clock
|
|
* (used when SYST_CSR.CLKSOURCE == 1)
|
|
*/
|
|
|
|
struct SysTickState {
|
|
/*< private >*/
|
|
SysBusDevice parent_obj;
|
|
/*< public >*/
|
|
|
|
uint32_t control;
|
|
uint32_t reload;
|
|
int64_t tick;
|
|
ptimer_state *ptimer;
|
|
MemoryRegion iomem;
|
|
qemu_irq irq;
|
|
Clock *refclk;
|
|
Clock *cpuclk;
|
|
|
|
/*
|
|
* Ticks to additionally advance on each read of the current-value register,
|
|
* so firmware busy-wait delay loops converge under emulation. Zero keeps
|
|
* exact hardware behaviour and is the default; only boards that need it
|
|
* set the "poll-boost" property.
|
|
*/
|
|
uint32_t poll_boost;
|
|
|
|
/* Running total added by poll_boost, applied to reported counter values. */
|
|
uint32_t poll_skew;
|
|
};
|
|
|
|
#endif
|