From e0648c1048189fb32ec48cc8d1c124a5e0d8f402 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sun, 11 Sep 2022 23:15:27 +0200 Subject: [PATCH] Updated from https://github.com/a2retrosystems/A2retroNET At this point, nothing at all is done on an A2 reset. This can likely be improved. However, Apple2-IO-RPi doesn't seem to handle A2 reset exactly gracefully anyhow. In general, it seems desirable to introduce some simple framing protocol - like SLIP - that allows to recover from an A2 reset in the middle of an Apple2-IO-RPi command execution. Such a framing protocol would allow to introduce different frame types. One frame type could then be an A2 reset frame sent by the A2retroNET firmware. --- RaspberryPiPico/board.c | 18 +++++++----------- RaspberryPiPico/bus.pio | 2 +- RaspberryPiPico/main.c | 10 ++++++++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/RaspberryPiPico/board.c b/RaspberryPiPico/board.c index 953f29d..cf62246 100644 --- a/RaspberryPiPico/board.c +++ b/RaspberryPiPico/board.c @@ -32,9 +32,9 @@ SOFTWARE. extern const __attribute__((aligned(4))) uint8_t firmware[]; -static uint32_t __not_in_flash("page") page; +static uint32_t page; -void __not_in_flash_func(board)(void) { +void __time_critical_func(board)(void) { for (uint gpio = gpio_addr; gpio < gpio_addr + size_addr; gpio++) { gpio_init(gpio); gpio_set_pulls(gpio, false, false); // floating @@ -46,13 +46,7 @@ void __not_in_flash_func(board)(void) { } gpio_init(gpio_enbl); - gpio_pull_up(gpio_enbl); - - gpio_init(gpio_irq); - gpio_pull_up(gpio_irq); - - gpio_init(gpio_nmi); - gpio_pull_up(gpio_nmi); + gpio_set_pulls(gpio_enbl, false, false); // floating uint offset; @@ -65,6 +59,8 @@ void __not_in_flash_func(board)(void) { offset = pio_add_program(pio0, &read_program); read_program_init(offset); + page = 0; + while (true) { uint32_t enbl = pio_sm_get_blocking(pio0, sm_enbl); uint32_t addr = enbl & 0x0FFF; @@ -73,7 +69,7 @@ void __not_in_flash_func(board)(void) { uint32_t read = enbl & 0x1000; // R/W if (read) { - if (!io) { + if (!io) { // DEVSEL switch (addr & 0x7) { case 0x3: pio_sm_put(pio0, sm_read, !multicore_fifo_rvalid() << 7 | @@ -90,7 +86,7 @@ void __not_in_flash_func(board)(void) { } } else { uint32_t data = pio_sm_get_blocking(pio0, sm_write); - if (!io) { + if (!io) { // DEVSEL switch (addr & 0x7) { case 0x5: sio_hw->fifo_wr = data; diff --git a/RaspberryPiPico/bus.pio b/RaspberryPiPico/bus.pio index 9098e56..d708a8e 100644 --- a/RaspberryPiPico/bus.pio +++ b/RaspberryPiPico/bus.pio @@ -33,7 +33,7 @@ SOFTWARE. .define public gpio_data 15 // 8 pins .define public gpio_enbl 26 // DEVSEL | IOSEL | IOSTRB .define public gpio_irq 27 -.define public gpio_nmi 28 +.define public gpio_res 28 .define public size_addr 13 // incl. R/W .define public size_data 8 diff --git a/RaspberryPiPico/main.c b/RaspberryPiPico/main.c index df27a45..d0f8efc 100644 --- a/RaspberryPiPico/main.c +++ b/RaspberryPiPico/main.c @@ -32,6 +32,7 @@ SOFTWARE. #include "pico/cyw43_arch.h" #endif +#include "bus.pio.h" #include "board.h" #ifdef TRACE @@ -48,6 +49,9 @@ void uart_printf(uart_inst_t *uart, const char *format, ...) { } #endif +void res_callback(uint gpio, uint32_t events) { +} + void main(void) { multicore_launch_core1(board); @@ -58,6 +62,12 @@ void main(void) { gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); #endif + gpio_init(gpio_irq); + gpio_pull_up(gpio_irq); + + gpio_init(gpio_res); + gpio_set_irq_enabled_with_callback(gpio_res, GPIO_IRQ_EDGE_RISE, true, &res_callback); + stdio_init_all(); stdio_set_translate_crlf(&stdio_usb, false);