visrealm / pico-56

The HBC-56 (65C02/TMS9918A/AY-3-8910 retro computer) fully emulated on a Raspberry Pi Pico
https://youtube.com/@TroySchrapel
MIT License
107 stars 10 forks source link

Hardware timers causes crash #10

Closed cbmeeks closed 1 day ago

cbmeeks commented 2 days ago

I'm quite sure I have misconfigured the timer example I was trying, but it seems if you try to use one, the video output just stops.

I was mostly curious if you have run into this.

// code in vga.c

bool repeating_timer_callback(struct repeating_timer *t) {
    return true;
}

static void vgaLoop() {

    struct repeating_timer timer;
    add_repeating_timer_ms(500, repeating_timer_callback, NULL, &timer);

    while (1) {
        uint32_t message = multicore_fifo_pop_blocking();
        if (message & 0x01) {
            vgaParams.scanlineFn(message & 0xfff, rgbDataBufferOdd);
        } else {
            vgaParams.scanlineFn(message & 0xfff, rgbDataBufferEven);
        }
    }
}
visrealm commented 1 day ago

I suspect the default alarm pool hardware timer IRQ handling is occurring on core 0. This is the same core which is handling the VGA DMA Interrupts (dmaIrqHandler()).

Note: add_repeating_timer_ms() is a wrapper for alarm_pool_add_repeating_timer_us() with alarm_pool_get_default() as the first argument.

You might need to manually create an alarm pool on core 1.

See

visrealm commented 1 day ago

Note: In the actual PICO-56 VGA code ( https://github.com/visrealm/pico-56/blob/main/src/devices/tms9918/vga/vga.c ) you can add a callback for the end of frame. If you've still having issues using the hardware timer, you could use this to accumulate time in 16.67ms increments. There is also an end of scanline callback which I use to update the PWM audio. So, the PICO-56 audio frequency is tied to the VGA HSYNC frequency (~31KHz).

cbmeeks commented 1 day ago

Ah, I didn't think about that. I know very little about the timers on the Pico but I will study that some more.

But now that you mention it, I like the idea of the "end of frame" better anyway. I needed a timer to flash a cursor but it makes more sense to just put a callback at the end of frame.

Thanks again for your help! I will try not to pester you with things like this. :-)

visrealm commented 1 day ago

I don't mind. No problem at all.