mirror of
https://github.com/MCKero6423/uv-k5-v3-emulator.git
synced 2026-10-02 03:15:36 +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.
51 lines
1.6 KiB
C
51 lines
1.6 KiB
C
/* Recorder for observable firmware output.
|
|
*
|
|
* Deliberately records low-level intent (carrier on/off with a timestamp, the
|
|
* decoded character stream, debug text) rather than a summarised "a dit
|
|
* happened". Stage B swaps the stubs for real peripheral models but keeps these
|
|
* scenarios, so the assertions have to sit at a level both can produce.
|
|
*/
|
|
|
|
#ifndef SIM_RECORD_H
|
|
#define SIM_RECORD_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
typedef enum {
|
|
SIM_EV_CARRIER_ON,
|
|
SIM_EV_CARRIER_OFF,
|
|
SIM_EV_CHAR, // a character was decoded into the TX display / macro
|
|
} SIM_EventKind_t;
|
|
|
|
typedef struct {
|
|
SIM_EventKind_t kind;
|
|
uint32_t at_ms;
|
|
char ch; // valid for SIM_EV_CHAR
|
|
} SIM_Event_t;
|
|
|
|
void SIM_RecordReset(void);
|
|
|
|
void SIM_RecordCarrier(bool on);
|
|
void SIM_RecordChar(char ch);
|
|
void SIM_RecordDebug(const char *text, unsigned int size);
|
|
|
|
// Decoded characters in order, NUL-terminated. This is the main assertion
|
|
// surface: feed a paddle timeline, expect "CQ".
|
|
const char *SIM_RecordedText(void);
|
|
|
|
// Element durations in milliseconds, derived from carrier on/off pairs. Lets a
|
|
// test check the dit/dah ratio and inter-element spacing rather than only the
|
|
// resulting text.
|
|
unsigned int SIM_RecordedElementCount(void);
|
|
uint32_t SIM_RecordedElementMs(unsigned int index);
|
|
uint32_t SIM_RecordedGapMs(unsigned int index);
|
|
|
|
unsigned int SIM_RecordedEventCount(void);
|
|
const SIM_Event_t *SIM_RecordedEvent(unsigned int index);
|
|
|
|
// Enables echoing events and debug text to stderr as they happen.
|
|
void SIM_RecordSetVerbose(bool verbose);
|
|
|
|
#endif
|