@@ -54,41 +54,41 @@ extern Config usbsid_config;
5454extern uint32_t clockcycles (void );
5555
5656/* PIO */
57- PIO raster_pio = pio1 ;
57+ const PIO raster_pio = pio1 ;
5858static uint sm_buffer , offset_buffer ;
59- bool buffer_sm_started = false;
60- bool buffer_sm_claimed = false;
59+ static bool buffer_sm_started = false;
60+ static bool buffer_sm_claimed = false;
6161
6262/* Arrival rate tracking */
6363#define ARRIVAL_HISTORY_SIZE 8
6464#define MULTISID_TIMEOUT_FRAMES 30 /* Reset to 1-SID after this many frames without SID2+ */
6565#define NOWRITES_TIMEOUT_FRAMES 100 /* Disable everything after this amount of frames */
6666
67- static bool still_receiving = false;
67+ static bool still_receiving = false; /* IRQ */
6868static uint32_t arrival_times [ARRIVAL_HISTORY_SIZE ];
6969volatile uint8_t arrival_index = 0 ;
7070volatile uint8_t arrival_count = 0 ;
7171volatile uint32_t calculated_rate = 0 ;
72- static uint16_t base_rate = 0 ; /* The rate from env message */
73- static uint8_t sid_count_estimate = 1 ; /* Estimated number of SIDs in tune */
74- volatile /* static */ uint8_t frames_since_nowrites = 0 ; /* Frames since last SID2/3/4 message */
75- static uint8_t frames_since_multisid = 0 ; /* Frames since last SID2/3/4 message */
72+ volatile static uint16_t base_rate = 0 ; /* The rate from env message */
73+ volatile static uint8_t sid_count_estimate = 1 ; /* Estimated number of SIDs in tune */
74+ volatile uint8_t frames_since_nowrites = 0 ; /* Frames since last SID2/3/4 message */
75+ volatile static uint8_t frames_since_multisid = 0 ; /* Frames since last SID2/3/4 message */
7676
7777/* IRQ */
78- int pio_irq ;
79- static int8_t buffer_irq ;
8078const int BUFFPIOIRQ = 2 ;
81- bool buffer_irq_started = false;
79+ volatile static int pio_irq = 0 ;
80+ volatile static int8_t buffer_irq = 0 ;
81+ volatile static bool buffer_irq_started = false;
8282volatile uint32_t irq_now_at = 0 ;
8383volatile uint32_t irq_end_at = 0 ;
8484volatile uint32_t irq_prev_at = 0 ;
8585
8686/* Ring buffer */
87- static const uint8_t ASID_FRAME_WRITES_MAX = 28 ;
8887static uint8_t ring_get (void );
8988static int ring_diff (void );
89+ static const uint8_t ASID_FRAME_WRITES_MAX = 28 ;
9090volatile uint16_t corrected_rate = 0 ;
91- uint8_t diff_size = (2 * (4 * ASID_FRAME_WRITES_MAX )); /* = 224 bytes | 112 bytes == 1 frame, was 64 bytes */
91+ const uint8_t diff_size = (2 * (4 * ASID_FRAME_WRITES_MAX )); /* = 224 bytes | 112 bytes == 1 frame, was 64 bytes */
9292typedef struct {
9393 uint16_t ring_read ;
9494 uint16_t ring_write ;
@@ -104,8 +104,6 @@ static const uint16_t RING_SIZE_MAX = (150 * 224); /* 33600 bytes - maximum s
104104static const uint16_t RING_SIZE_STEP = (20 * 224 ); /* 4480 bytes - grow/shrink increment */
105105volatile uint16_t ring_size = RING_SIZE_DEFAULT ; /* Current effective size */
106106static uint16_t ring_size_allocated = 0 ; /* Actual allocated size */
107- /* TODO: REMOVE ~ TEMPORARY */
108- volatile bool in_asid_irq = false;
109107
110108
111109/**
@@ -430,7 +428,6 @@ void reset_arrival_tracking(void)
430428 */
431429void __not_in_flash_func (buffer_irq_handler )(void )
432430{
433- in_asid_irq = true;
434431 irq_prev_at = irq_now_at ;
435432 irq_now_at = clockcycles ();
436433
@@ -478,7 +475,6 @@ void __not_in_flash_func(buffer_irq_handler)(void)
478475 frames_since_nowrites = 0 ;
479476 still_receiving = true;
480477 }
481- in_asid_irq = false;
482478
483479 /* Interrupt cleared at end of routine
484480 * if play becomes irregular, irq's might be
@@ -668,6 +664,9 @@ static uint8_t __not_in_flash_func(ring_get)(void)
668664 */
669665void asid_ring_init (void )
670666{
667+ /* Explicitely set sid_count_estimate to 1 at start for potential compiler zeroing issue */
668+ sid_count_estimate = 1 ;
669+
671670 if (!asid_ringbuffer .is_allocated ) {
672671 if (asid_ringbuffer .ringbuffer != NULL ) { free (asid_ringbuffer .ringbuffer ); }
673672 /* Allocate max size upfront - allows growth without reallocation */
0 commit comments