This commit is contained in:
Oliver Schmidt 2022-09-12 10:07:24 +02:00
parent 2d705b4267
commit 2d2bbc56f1
5 changed files with 114 additions and 54 deletions

View File

@ -25,3 +25,9 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
pico_multicore
hardware_pio
)
if(${PICO_BOARD} STREQUAL "pico_w")
target_link_libraries(${PROJECT_NAME} PRIVATE
pico_cyw43_arch_none
)
endif()

View File

@ -26,13 +26,45 @@ SOFTWARE.
#include "bus.pio.h"
#include "board.h"
extern const __attribute__((aligned(4))) uint8_t firmware[];
static bool __not_in_flash( "active") active;
static uint32_t __not_in_flash("command") command;
static uint32_t __not_in_flash("control") control;
volatile bool active;
static uint32_t command;
static uint32_t control;
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
}
for (uint gpio = gpio_data; gpio < gpio_data + size_data; gpio++) {
pio_gpio_init(pio0, gpio);
gpio_set_pulls(gpio, false, false); // floating
}
gpio_init(gpio_enbl);
gpio_set_pulls(gpio_enbl, false, false); // floating
uint offset;
offset = pio_add_program(pio0, &enbl_program);
enbl_program_init(offset);
offset = pio_add_program(pio0, &write_program);
write_program_init(offset);
offset = pio_add_program(pio0, &read_program);
read_program_init(offset);
active = false;
command = 0;
control = 0;
void __not_in_flash_func(board)() {
while (true) {
uint32_t enbl = pio_sm_get_blocking(pio0, sm_enbl);
uint32_t addr = enbl & 0x0FFF;
@ -40,10 +72,6 @@ void __not_in_flash_func(board)() {
uint32_t strb = enbl & 0x0800; // IOSTRB
uint32_t read = enbl & 0x1000; // R/W
if (addr == 0x0FFF) {
active = false;
}
if (read) {
if (!io) { // DEVSEL
switch (addr & 0xF) {
@ -86,8 +114,8 @@ void __not_in_flash_func(board)() {
if (io && !strb) {
active = true;
} else if (addr == 0x0FFF) {
active = false;
}
gpio_put(gpio_led, active);
}
}

34
pipico/board.h Normal file
View File

@ -0,0 +1,34 @@
/*
MIT License
Copyright (c) 2022 Oliver Schmidt (https://a2retro.de/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _BOARD_H
#define _BOARD_H
extern volatile bool active;
void board(void);
#endif

View File

@ -31,10 +31,9 @@ SOFTWARE.
.define public gpio_addr 2 // 12 pins
.define public gpio_rw 14
.define public gpio_data 15 // 8 pins
.define public gpio_led 25
.define public gpio_enbl 26 // DEVSEL | IOSEL | IOSTRB
.define public gpio_irq 27
.define public gpio_rdy 28
.define public gpio_res 28
.define public size_addr 13 // incl. R/W
.define public size_data 8
@ -74,9 +73,9 @@ idle:
in pins, size_addr // shift A0-A11 + R/W into ISR
jmp pin idle // jump to idle if R/W is high
jmp pin idle // jump to 'idle' if R/W is high
irq irq_write // Set 'write' IRQ
irq irq_write // set 'write' IRQ
.wrap

View File

@ -28,10 +28,12 @@ SOFTWARE.
#include "pico/printf.h"
#include "pico/stdlib.h"
#include "pico/multicore.h"
#ifdef RASPBERRYPI_PICO_W
#include "pico/cyw43_arch.h"
#endif
#include "bus.pio.h"
void board();
#include "board.h"
#ifdef TRACE
void uart_printf(uart_inst_t *uart, const char *format, ...) {
@ -47,7 +49,25 @@ void uart_printf(uart_inst_t *uart, const char *format, ...) {
}
#endif
int main() {
void res_callback(uint gpio, uint32_t events) {
}
void main(void) {
multicore_launch_core1(board);
#ifdef RASPBERRYPI_PICO_W
cyw43_arch_init();
#else
gpio_init(PICO_DEFAULT_LED_PIN);
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);
@ -58,41 +78,6 @@ int main() {
gpio_set_function(1, GPIO_FUNC_UART);
#endif
for (uint gpio = gpio_addr; gpio < gpio_addr + size_addr; gpio++) {
gpio_init(gpio);
gpio_set_pulls(gpio, false, false); // floating
}
for (uint gpio = gpio_data; gpio < gpio_data + size_data; gpio++) {
pio_gpio_init(pio0, gpio);
gpio_set_pulls(gpio, false, false); // floating
}
gpio_init(gpio_enbl);
gpio_set_pulls(gpio_enbl, false, false); // floating
gpio_init(gpio_irq);
gpio_pull_up(gpio_irq);
gpio_init(gpio_rdy);
gpio_pull_up(gpio_rdy);
gpio_init(gpio_led);
gpio_set_dir(gpio_led, GPIO_OUT);
uint offset;
offset = pio_add_program(pio0, &enbl_program);
enbl_program_init(offset);
offset = pio_add_program(pio0, &write_program);
write_program_init(offset);
offset = pio_add_program(pio0, &read_program);
read_program_init(offset);
multicore_launch_core1(board);
while (true) {
if (multicore_fifo_rvalid()) {
uint32_t data = multicore_fifo_pop_blocking();
@ -111,7 +96,15 @@ int main() {
#endif
}
}
}
return 0;
#ifdef RASPBERRYPI_PICO_W
static bool last_active;
if (active != last_active) {
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, active);
last_active = active;
}
#else
gpio_put(PICO_DEFAULT_LED_PIN, active);
#endif
}
}