mirror of
https://github.com/polpo/picogus.git
synced 2026-10-25 21:40:16 +00:00
Merge branch 'ne2000'
This commit is contained in:
commit
0f5bdc380d
16 files changed
+1713
-27
No files matched your search
@@ -5,9 +5,10 @@ jobs:
|
||||
runs-on: ubuntu-22.04
|
||||
env:
|
||||
BUILD_TYPE: "Release"
|
||||
PICOSDK_VER: "1.5.1"
|
||||
PICOEXTRA_VER: "sdk-1.5.1"
|
||||
PICOSDK_VER: "2.0.0"
|
||||
PICOEXTRA_VER: "sdk-2.0.0"
|
||||
# The Pico-SDK will listen to these environment vars
|
||||
PICOTOOL_FETCH_FROM_GIT_PATH: ${{github.workspace}}/pico/picotool
|
||||
PICO_SDK_PATH: ${{github.workspace}}/pico/pico-sdk
|
||||
PICO_EXTRAS_PATH: ${{github.workspace}}/pico/pico-extras
|
||||
OUTPUT_DIR: ${{github.workspace}}/binaries
|
||||
@@ -20,7 +21,7 @@ jobs:
|
||||
- name: Install Arm GNU Toolchain (arm-none-eabi-gcc)
|
||||
uses: carlosperate/arm-none-eabi-gcc-action@v1
|
||||
with:
|
||||
release: '13.2.Rel1'
|
||||
release: '13.3.Rel1'
|
||||
|
||||
# Since we reference stable versions of Pico-SDK and pico-extras, we can cache their downloads.
|
||||
# If this were to reference changing branches (like "master"), this caching step must be removed!!!
|
||||
@@ -49,18 +50,27 @@ jobs:
|
||||
- name: Create Build Environment
|
||||
run: cmake -E make_directory ${{github.workspace}}/build
|
||||
|
||||
- name: Patch Pico SDK to allow LTO
|
||||
run: sed -i 's/WRAPPER_FUNC(x) __wrap_/WRAPPER_FUNC(x) __attribute__((used)) __wrap_/' ${{env.PICO_SDK_PATH}}/src/rp2_common/pico_platform/include/pico/platform.h
|
||||
# - name: Patch Pico SDK to allow LTO
|
||||
# run: sed -i 's/WRAPPER_FUNC(x) __wrap_/WRAPPER_FUNC(x) __attribute__((used)) __wrap_/' ${{env.PICO_SDK_PATH}}/src/rp2_common/pico_platform_compiler/include/pico/platform/compiler.h
|
||||
|
||||
- name: Build Mega Firmware
|
||||
shell: bash
|
||||
working-directory: ${{github.workspace}}/build
|
||||
run: |
|
||||
mkdir -p $OUTPUT_DIR
|
||||
cmake $GITHUB_WORKSPACE/sw -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPROJECT_TYPE="MULTIFW" -DUSE_LTO=1
|
||||
cmake $GITHUB_WORKSPACE/sw -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPROJECT_TYPE="MULTIFW" #-DUSE_LTO=1
|
||||
cmake --build . --config $BUILD_TYPE --parallel $(nproc)
|
||||
cp picogus.uf2 $OUTPUT_DIR/picogus.uf2
|
||||
|
||||
- name: Build NE2000 Firmware
|
||||
shell: bash
|
||||
working-directory: ${{github.workspace}}/build
|
||||
run: |
|
||||
mkdir -p $OUTPUT_DIR
|
||||
cmake $GITHUB_WORKSPACE/sw -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPROJECT_TYPE="NE2K" -DPICO_BOARD=picow_fast #-DUSE_LTO=1
|
||||
cmake --build . --config $BUILD_TYPE --parallel $(nproc)
|
||||
cp pg-ne2k.uf2 $OUTPUT_DIR/pg-ne2k.uf2
|
||||
|
||||
# will generate PicoGUS Firmwares.zip as downloadable artifact with all .uf2 files
|
||||
- name: Upload All Firmwares
|
||||
uses: actions/upload-artifact@v4
|
||||
|
||||
+12
-3
@@ -26,10 +26,11 @@ typedef enum {
|
||||
TANDY_MODE = 4,
|
||||
CMS_MODE = 5,
|
||||
SB_MODE = 6,
|
||||
USB_MODE = 7
|
||||
USB_MODE = 7,
|
||||
NE2000_MODE = 8
|
||||
} card_mode_t;
|
||||
|
||||
static const char *modenames[8] = {
|
||||
static const char *modenames[9] = {
|
||||
"INVALID",
|
||||
"GUS",
|
||||
"ADLIB",
|
||||
@@ -37,7 +38,8 @@ static const char *modenames[8] = {
|
||||
"TANDY",
|
||||
"CMS",
|
||||
"SB",
|
||||
"USB"
|
||||
"USB",
|
||||
"NE2000"
|
||||
};
|
||||
|
||||
#define MODE_MAGIC 0x00 // Magic string
|
||||
@@ -62,6 +64,13 @@ static const char *modenames[8] = {
|
||||
#define MODE_MOUSEPROTO 0x41 // Mouse protocol
|
||||
#define MODE_MOUSERATE 0x42 // Mouse report rate
|
||||
#define MODE_MOUSESEN 0x43 // Mouse sensitivity
|
||||
#define MODE_NE2KPORT 0x50 // NE2000 Base port
|
||||
#define MODE_WIFISSID 0x51 // NE2000 SSID
|
||||
#define MODE_WIFIPASS 0x52 // NE2000 password
|
||||
#define MODE_WIFIAPPLY 0x53 // NE2000 password
|
||||
#define MODE_WIFISTAT 0x54 // NE2000 wifi status
|
||||
#define MODE_WIFISCAN 0x55 // NE2000 wifi scan
|
||||
|
||||
#define MODE_DEFAULTS 0xE0 // Select reset to defaults register
|
||||
#define MODE_SAVE 0xE1 // Select save settings register
|
||||
#define MODE_REBOOT 0xE2 // Select reboot register
|
||||
|
||||
+95
-2
@@ -10,7 +10,7 @@
|
||||
#include "../common/picogus.h"
|
||||
|
||||
static void banner(void) {
|
||||
printf("PicoGUSinit v3.1.0 (c) 2024 Ian Scott - licensed under the GNU GPL v2\n");
|
||||
printf("PicoGUSinit v3.2.0 (c) 2024 Ian Scott - licensed under the GNU GPL v2\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,15 @@ static void usage(char *argv0, card_mode_t mode, bool print_all) {
|
||||
printf(" (increase for smoother cursor movement, decrease for lower CPU load)\n");
|
||||
printf(" /mousesen n - set mouse sensitivity (256 - 100%, 128 - 50%, 512 - 200%)\n");
|
||||
}
|
||||
if (mode == NE2000_MODE || print_all) {
|
||||
// "................................................................................\n"
|
||||
printf("NE2000/WiFi settings:\n");
|
||||
printf(" /ne2kport x - set the base port of the NE2000. Default: 300\n");
|
||||
printf(" /wifissid abc - set the WiFi SSID to abc\n");
|
||||
printf(" /wifipass xyz - set the WiFi WPA/WPA2 password/key to xyz\n");
|
||||
printf(" /wifinopass - unset the WiFi password to connect to an open access point\n");
|
||||
printf(" /wifistatus - print current WiFi status\n");
|
||||
}
|
||||
}
|
||||
|
||||
static const char* mouse_protocol_str[] = {
|
||||
@@ -349,6 +358,43 @@ static int write_firmware(const char* fw_filename) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void wifi_printStatus(void)
|
||||
{
|
||||
outp(CONTROL_PORT, 0xCC); // Knock on the door...
|
||||
outp(CONTROL_PORT, MODE_WIFISTAT); // Select WiFi status mode
|
||||
outp(DATA_PORT_HIGH, 0); // Write to start getting the status
|
||||
|
||||
printf("WiFi status: ");
|
||||
uint16_t try = 0;
|
||||
char c;
|
||||
while (c = inp(DATA_PORT_HIGH)) {
|
||||
if (c == 255) {
|
||||
if (++try == 10000) {
|
||||
printf("Error getting WiFI status\n");
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static void send_string(uint8_t mode, char* str, int16_t max_len)
|
||||
{
|
||||
outp(CONTROL_PORT, 0xCC); // Knock on the door...
|
||||
outp(CONTROL_PORT, mode);
|
||||
char chr;
|
||||
for (int i = 0; i < max_len; ++i) {
|
||||
if (str[i] == 0) { // End of string
|
||||
break;
|
||||
}
|
||||
outp(DATA_PORT_HIGH, str[i]);
|
||||
}
|
||||
outp(DATA_PORT_HIGH, 0);
|
||||
}
|
||||
|
||||
#define process_bool_opt(option) \
|
||||
if (i + 1 >= argc) { \
|
||||
usage(argv[0], mode, false); \
|
||||
@@ -378,6 +424,9 @@ int main(int argc, char* argv[]) {
|
||||
uint8_t enable_joystick = 0;
|
||||
uint8_t wtvol;
|
||||
char fw_filename[256] = {0};
|
||||
char wifi_ssid[33] = {0};
|
||||
char wifi_pass[64] = {0};
|
||||
bool nopass = false;
|
||||
card_mode_t mode;
|
||||
char mode_name[8] = {0};
|
||||
int fw_num = 8;
|
||||
@@ -389,7 +438,7 @@ int main(int argc, char* argv[]) {
|
||||
outp(CONTROL_PORT, MODE_MAGIC); // Select magic string register
|
||||
if (inp(DATA_PORT_HIGH) != 0xDD) {
|
||||
err_pigus();
|
||||
return 99;
|
||||
//return 99;
|
||||
};
|
||||
printf("PicoGUS detected: ");
|
||||
print_firmware_string();
|
||||
@@ -409,6 +458,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
return write_firmware(fw_filename);
|
||||
}
|
||||
printf("arg: %s\n", argv[i]);
|
||||
++i;
|
||||
}
|
||||
|
||||
@@ -603,6 +653,38 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
outp(CONTROL_PORT, MODE_MOUSERATE);
|
||||
outp(DATA_PORT_HIGH, tmp_uint8);
|
||||
// NE2000/WiFi options /////////////////////////////////////////////////////////////////
|
||||
} else if (stricmp(argv[i], "/ne2kport") == 0) {
|
||||
process_port_opt(tmp_uint16);
|
||||
outp(CONTROL_PORT, MODE_NE2KPORT); // Select NE2000 port register
|
||||
outpw(DATA_PORT_LOW, tmp_uint16); // Write port
|
||||
} else if (stricmp(argv[i], "/wifistatus") == 0) {
|
||||
wifi_printStatus();
|
||||
} else if (stricmp(argv[i], "/wifissid") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
usage(argv[0], mode, false);
|
||||
return 255;
|
||||
}
|
||||
e = sscanf(argv[++i], "%32s", wifi_ssid);
|
||||
if (e != 1) {
|
||||
usage(argv[0], mode, false);
|
||||
return 4;
|
||||
}
|
||||
send_string(MODE_WIFISSID, wifi_ssid, 32);
|
||||
} else if (stricmp(argv[i], "/wifipass") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
usage(argv[0], mode, false);
|
||||
return 255;
|
||||
}
|
||||
e = sscanf(argv[++i], "%63s", wifi_pass);
|
||||
if (e != 1) {
|
||||
usage(argv[0], mode, false);
|
||||
return 4;
|
||||
}
|
||||
send_string(MODE_WIFIPASS, wifi_pass, 63);
|
||||
} else if (stricmp(argv[i], "/wifinopass") == 0) {
|
||||
nopass = true;
|
||||
send_string(MODE_WIFIPASS, "", 1);
|
||||
} else {
|
||||
printf("Unknown option: %s\n", argv[i]);
|
||||
usage(argv[0], mode, false);
|
||||
@@ -627,6 +709,11 @@ int main(int argc, char* argv[]) {
|
||||
return reboot_to_firmware(fw_num, permanent);
|
||||
}
|
||||
|
||||
if (wifi_ssid[0] || wifi_pass[0] || nopass) {
|
||||
outp(CONTROL_PORT, MODE_WIFIAPPLY);
|
||||
outp(DATA_PORT_HIGH, 0);
|
||||
}
|
||||
|
||||
outp(CONTROL_PORT, MODE_HWTYPE); // Select hardware type register
|
||||
board_type_t board_type = inp(DATA_PORT_HIGH);
|
||||
if (board_type == PICO_BASED) {
|
||||
@@ -733,6 +820,12 @@ int main(int argc, char* argv[]) {
|
||||
printf("(AdLib port disabled)\n");
|
||||
}
|
||||
break;
|
||||
case NE2000_MODE:
|
||||
outp(CONTROL_PORT, MODE_NE2KPORT); // Select port register
|
||||
tmp_uint16 = inpw(DATA_PORT_LOW); // Get port
|
||||
printf("Running in NE2000 mode on port %x\n", tmp_uint16);
|
||||
wifi_printStatus();
|
||||
break;
|
||||
default:
|
||||
printf("Running in unknown mode (maybe upgrade pgusinit?)\n");
|
||||
break;
|
||||
|
||||
+35
-5
@@ -2,6 +2,12 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR})
|
||||
if(NOT PICO_BOARD)
|
||||
set(PICO_BOARD "picogus2")
|
||||
message("PICO_BOARD not set, defaulting to ${PROJECT_TYPE}")
|
||||
endif()
|
||||
set(PICO_COPY_TO_RAM 1)
|
||||
|
||||
# Initialise pico_sdk from installed location
|
||||
# (note this can come from environment, CMake cache etc)
|
||||
@@ -22,10 +28,6 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
include(pico_extras_import.cmake)
|
||||
|
||||
set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR})
|
||||
set(PICO_BOARD picogus2)
|
||||
set(PICO_COPY_TO_RAM 1)
|
||||
|
||||
# Tell the Pico SDK to use our local tinyusb instead of the one included in the SDK
|
||||
# This is needed to support tusb_xinput
|
||||
set(PICO_TINYUSB_PATH ${CMAKE_CURRENT_LIST_DIR}/tinyusb)
|
||||
@@ -176,7 +178,7 @@ endfunction()
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tusb_xinput)
|
||||
add_subdirectory(rp2040-psram)
|
||||
add_subdirectory(opl)
|
||||
|
||||
add_subdirectory(ne2000)
|
||||
|
||||
################################################################################
|
||||
# Build GUS firmware
|
||||
@@ -311,6 +313,31 @@ function(build_usb TARGET_NAME MULTIFW)
|
||||
endfunction()
|
||||
|
||||
|
||||
function(build_ne2k TARGET_NAME MULTIFW)
|
||||
config_target(${TARGET_NAME} ${MULTIFW})
|
||||
pico_set_program_name(${TARGET_NAME} "picogus-ne2k")
|
||||
# set(USB_JOYSTICK FALSE)
|
||||
# set(PICO_BOARD PICO_W) # For now, until USB Dongle
|
||||
# set(PICO_BOARD picow-fast)
|
||||
#set(PICO_CYW43_SUPPORTED "1")
|
||||
#pico_register_common_scope_var(PICO_CYW43_SUPPORTED)
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE
|
||||
NE2000=1
|
||||
PICOW=1
|
||||
# CYW43_RESOURCE_ATTRIBUTE="__in_flash()"
|
||||
CYW43_CONFIG_FILE="cyw43_firmware.h"
|
||||
CYW43_PIO_CLOCK_DIV_INT=3
|
||||
)
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
ne2000play.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
${TARGET_NAME}
|
||||
ne2000
|
||||
)
|
||||
endfunction()
|
||||
|
||||
|
||||
################################################################################
|
||||
# Build "multifw" - all firmwares in one UF2
|
||||
if(PROJECT_TYPE STREQUAL "MULTIFW")
|
||||
@@ -436,6 +463,9 @@ elseif(PROJECT_TYPE STREQUAL "CMS")
|
||||
elseif(PROJECT_TYPE STREQUAL "USB")
|
||||
set(FW_TARGET pg-usb)
|
||||
build_usb(pg-usb FALSE)
|
||||
elseif(PROJECT_TYPE STREQUAL "NE2K")
|
||||
set(FW_TARGET pg-ne2k)
|
||||
build_ne2k(pg-ne2k FALSE)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "flash_settings.h"
|
||||
#include "hardware/flash.h"
|
||||
#include "hardware/sync.h"
|
||||
#include "hardware/clocks.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/flash.h"
|
||||
|
||||
@@ -44,6 +45,13 @@ static const Settings defaultSettings = {
|
||||
.protocol = 0,
|
||||
.reportRate = 60,
|
||||
.sensitivity = 0x100
|
||||
},
|
||||
.NE2K = {
|
||||
.basePort = 0x300,
|
||||
},
|
||||
.WiFi = {
|
||||
.ssid = {0},
|
||||
.password = {0}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+8
-1
@@ -8,7 +8,7 @@ extern "C" {
|
||||
#include <stdbool.h>
|
||||
|
||||
#define SETTINGS_MAGIC 0x70677573 // "pgus" in ascii
|
||||
#define SETTINGS_VERSION 1
|
||||
#define SETTINGS_VERSION 2
|
||||
|
||||
// Settings struct has generous padding for future settings by aligning to 4 bytes
|
||||
typedef struct Settings {
|
||||
@@ -49,6 +49,13 @@ typedef struct Settings {
|
||||
uint8_t reportRate;
|
||||
int16_t sensitivity;
|
||||
} Mouse;
|
||||
struct {
|
||||
uint16_t basePort;
|
||||
} NE2K;
|
||||
struct {
|
||||
char ssid[33];
|
||||
char password[64];
|
||||
} WiFi;
|
||||
} Settings;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
add_library(ne2000 INTERFACE)
|
||||
|
||||
# if(NOT PICO_BOARD STREQUAL "PICO_W")
|
||||
# message(FATAL_ERROR "NE2000 Requires Pico W")
|
||||
# endif()
|
||||
|
||||
|
||||
|
||||
target_include_directories(ne2000 INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/ne2000
|
||||
)
|
||||
|
||||
target_sources(ne2000 INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/ne2000.c
|
||||
)
|
||||
|
||||
target_link_libraries(ne2000 INTERFACE
|
||||
pico_cyw43_arch_none
|
||||
# pico_cyw43_arch_poll
|
||||
)
|
||||
# target_compile_definitions(pico_cyw43_arch_poll_headers INTERFACE
|
||||
# CYW43_LWIP=0
|
||||
# )
|
||||
# target_compile_definitions(ne2000 INTERFACE
|
||||
# CYW43_LWIP=0
|
||||
# )
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
#include <cyw43_configport.h>
|
||||
#define CYW43_RESOURCE_ATTRIBUTE __in_flash()
|
||||
+1119
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,193 @@
|
||||
typedef struct wifi_infos_t {
|
||||
uint8_t cyw43_mac[6];
|
||||
char WIFI_SSID[33];
|
||||
char WIFI_KEY[63];
|
||||
} wifi_infos_t;
|
||||
extern wifi_infos_t PG_Wifi_info;
|
||||
|
||||
extern uint8_t PG_EnableWifi(void);
|
||||
extern uint8_t PG_NE2000_Read(uint8_t Addr);
|
||||
extern void PG_Wifi_GetStatus(void);
|
||||
extern char PG_Wifi_ReadStatusStr(void);
|
||||
extern void PG_Wifi_Connect(const char* ssid, const char* pass);
|
||||
extern void PG_Wifi_Reconnect(void);
|
||||
extern void PG_NE2000_Write(uint8_t Addr,uint8_t Data);
|
||||
extern void ne2000_initiate_send();
|
||||
#define FIFO_NE2K_SEND 0x88
|
||||
#define FIFO_WIFI_STATUS 0x89
|
||||
|
||||
typedef enum { NE2000_NE2000, NE2000_RTL8029AS } ne2000_type;
|
||||
|
||||
#define NETBLOCKING 0 // we won't block our pcap
|
||||
|
||||
//#define NE2000_DEBUG
|
||||
|
||||
#define BX_RESET_HARDWARE 0
|
||||
#define BX_RESET_SOFTWARE 1
|
||||
|
||||
// Never completely fill the ne2k ring so that we never
|
||||
// hit the unclear completely full buffer condition.
|
||||
#define BX_NE2K_NEVER_FULL_RING (1)
|
||||
|
||||
#define BX_NE2K_MEMSIZ (32 * 1024) // I had set this to 128 during testing?
|
||||
#define BX_NE2K_MEMSTART (16 * 1024)
|
||||
#define BX_NE2K_MEMEND (BX_NE2K_MEMSTART + BX_NE2K_MEMSIZ)
|
||||
|
||||
typedef struct ne2000_t {
|
||||
//
|
||||
// ne2k register state
|
||||
|
||||
//
|
||||
// Page 0
|
||||
//
|
||||
// Command Register - 00h read/write
|
||||
struct CR_t {
|
||||
int stop; // STP - Software Reset command
|
||||
int start; // START - start the NIC
|
||||
int tx_packet; // TXP - initiate packet transmission
|
||||
uint8_t rdma_cmd; // RD0,RD1,RD2 - Remote DMA command
|
||||
uint8_t pgsel; // PS0,PS1 - Page select
|
||||
} CR;
|
||||
// Interrupt Status Register - 07h read/write
|
||||
struct ISR_t {
|
||||
int pkt_rx; // PRX - packet received with no errors
|
||||
int pkt_tx; // PTX - packet transmitted with no errors
|
||||
int rx_err; // RXE - packet received with 1 or more errors
|
||||
int tx_err; // TXE - packet tx'd " " " " "
|
||||
int overwrite; // OVW - rx buffer resources exhausted
|
||||
int cnt_oflow; // CNT - network tally counter MSB's set
|
||||
int rdma_done; // RDC - remote DMA complete
|
||||
int reset; // RST - reset status
|
||||
} ISR;
|
||||
// Interrupt Mask Register - 0fh write
|
||||
struct IMR_t {
|
||||
int rx_inte; // PRXE - packet rx interrupt enable
|
||||
int tx_inte; // PTXE - packet tx interrput enable
|
||||
int rxerr_inte; // RXEE - rx error interrupt enable
|
||||
int txerr_inte; // TXEE - tx error interrupt enable
|
||||
int overw_inte; // OVWE - overwrite warn int enable
|
||||
int cofl_inte; // CNTE - counter o'flow int enable
|
||||
int rdma_inte; // RDCE - remote DMA complete int enable
|
||||
int reserved; // D7 - reserved
|
||||
} IMR;
|
||||
// Data Configuration Register - 0eh write
|
||||
struct DCR_t {
|
||||
int wdsize; // WTS - 8/16-bit select
|
||||
int endian; // BOS - byte-order select
|
||||
int longaddr; // LAS - long-address select
|
||||
int loop; // LS - loopback select
|
||||
int auto_rx; // AR - auto-remove rx packets with remote DMA
|
||||
uint8_t fifo_size; // FT0,FT1 - fifo threshold
|
||||
} DCR;
|
||||
// Transmit Configuration Register - 0dh write
|
||||
struct TCR_t {
|
||||
int crc_disable; // CRC - inhibit tx CRC
|
||||
uint8_t loop_cntl; // LB0,LB1 - loopback control
|
||||
int ext_stoptx; // ATD - allow tx disable by external mcast
|
||||
int coll_prio; // OFST - backoff algorithm select
|
||||
uint8_t reserved; // D5,D6,D7 - reserved
|
||||
} TCR;
|
||||
// Transmit Status Register - 04h read
|
||||
struct TSR_t {
|
||||
int tx_ok; // PTX - tx complete without error
|
||||
int reserved; // D1 - reserved
|
||||
int collided; // COL - tx collided >= 1 times
|
||||
int aborted; // ABT - aborted due to excessive collisions
|
||||
int no_carrier; // CRS - carrier-sense lost
|
||||
int fifo_ur; // FU - FIFO underrun
|
||||
int cd_hbeat; // CDH - no tx cd-heartbeat from transceiver
|
||||
int ow_coll; // OWC - out-of-window collision
|
||||
} TSR;
|
||||
// Receive Configuration Register - 0ch write
|
||||
struct RCR_t {
|
||||
int errors_ok; // SEP - accept pkts with rx errors
|
||||
int runts_ok; // AR - accept < 64-byte runts
|
||||
int broadcast; // AB - accept eth broadcast address
|
||||
int multicast; // AM - check mcast hash array
|
||||
int promisc; // PRO - accept all packets
|
||||
int monitor; // MON - check pkts, but don't rx
|
||||
uint8_t reserved; // D6,D7 - reserved
|
||||
} RCR;
|
||||
// Receive Status Register - 0ch read
|
||||
struct RSR_t {
|
||||
int rx_ok; // PRX - rx complete without error
|
||||
int bad_crc; // CRC - Bad CRC detected
|
||||
int bad_falign; // FAE - frame alignment error
|
||||
int fifo_or; // FO - FIFO overrun
|
||||
int rx_missed; // MPA - missed packet error
|
||||
int rx_mbit; // PHY - unicast or mcast/bcast address match
|
||||
int rx_disabled; // DIS - set when in monitor mode
|
||||
int deferred; // DFR - collision active
|
||||
} RSR;
|
||||
|
||||
uint16_t local_dma; // 01,02h read ; current local DMA addr
|
||||
uint8_t page_start; // 01h write ; page start register
|
||||
uint8_t page_stop; // 02h write ; page stop register
|
||||
uint8_t bound_ptr; // 03h read/write ; boundary pointer
|
||||
uint8_t tx_page_start; // 04h write ; transmit page start register
|
||||
uint8_t num_coll; // 05h read ; number-of-collisions register
|
||||
uint16_t tx_bytes; // 05,06h write ; transmit byte-count register
|
||||
uint8_t fifo; // 06h read ; FIFO
|
||||
uint16_t remote_dma; // 08,09h read ; current remote DMA addr
|
||||
uint16_t remote_start; // 08,09h write ; remote start address register
|
||||
uint16_t remote_bytes; // 0a,0bh write ; remote byte-count register
|
||||
uint8_t tallycnt_0; // 0dh read ; tally counter 0 (frame align errors)
|
||||
uint8_t tallycnt_1; // 0eh read ; tally counter 1 (CRC errors)
|
||||
uint8_t tallycnt_2; // 0fh read ; tally counter 2 (missed pkt errors)
|
||||
|
||||
//
|
||||
// Page 1
|
||||
//
|
||||
// Command Register 00h (repeated)
|
||||
//
|
||||
uint8_t physaddr[6]; // 01-06h read/write ; MAC address
|
||||
uint8_t curr_page; // 07h read/write ; current page register
|
||||
uint8_t mchash[8]; // 08-0fh read/write ; multicast hash array
|
||||
|
||||
//
|
||||
// Page 2 - diagnostic use only
|
||||
//
|
||||
// Command Register 00h (repeated)
|
||||
//
|
||||
// Page Start Register 01h read (repeated)
|
||||
// Page Stop Register 02h read (repeated)
|
||||
// Current Local DMA Address 01,02h write (repeated)
|
||||
// Transmit Page start address 04h read (repeated)
|
||||
// Receive Configuration Register 0ch read (repeated)
|
||||
// Transmit Configuration Register 0dh read (repeated)
|
||||
// Data Configuration Register 0eh read (repeated)
|
||||
// Interrupt Mask Register 0fh read (repeated)
|
||||
//
|
||||
uint8_t rempkt_ptr; // 03h read/write ; remote next-packet pointer
|
||||
uint8_t localpkt_ptr; // 05h read/write ; local next-packet pointer
|
||||
uint16_t address_cnt; // 06,07h read/write ; address counter
|
||||
|
||||
//
|
||||
// Page 3 - should never be modified.
|
||||
//
|
||||
|
||||
// Novell ASIC state
|
||||
uint8_t macaddr[32]; // ASIC ROM'd MAC address, even bytes
|
||||
uint8_t mem[BX_NE2K_MEMSIZ]; // on-chip packet memory
|
||||
|
||||
// ne2k internal state
|
||||
uint32_t base_address;
|
||||
int base_irq;
|
||||
int tx_timer_index;
|
||||
int tx_timer_active;
|
||||
uint8_t pending_tx;
|
||||
|
||||
ne2000_type type;
|
||||
|
||||
/*PCI stuff*/
|
||||
int is_pci;
|
||||
int card;
|
||||
uint32_t base_addr;
|
||||
uint8_t pci_command;
|
||||
uint8_t int_line;
|
||||
|
||||
/*RTL8029AS registers*/
|
||||
uint8_t config0, config2, config3;
|
||||
uint8_t _9346cr;
|
||||
} ne2000_t;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#if PICO_ON_DEVICE
|
||||
|
||||
#include "hardware/clocks.h"
|
||||
#include "hardware/structs/clocks.h"
|
||||
#include "hardware/timer.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "pico/flash.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/cyw43_arch.h"
|
||||
|
||||
extern "C" {
|
||||
#include "ne2000/ne2000.h"
|
||||
}
|
||||
|
||||
#include "flash_settings.h"
|
||||
extern Settings settings;
|
||||
|
||||
extern uint LED_PIN;
|
||||
|
||||
void play_ne2000() {
|
||||
//flash_safe_execute_core_init();
|
||||
puts("starting core 1 ne2000");
|
||||
PG_EnableWifi();
|
||||
PG_Wifi_Connect(settings.WiFi.ssid, settings.WiFi.password);
|
||||
|
||||
static bool flag = false;
|
||||
while(1) {
|
||||
if (multicore_fifo_rvalid()) {
|
||||
switch(multicore_fifo_pop_blocking()) {
|
||||
case FIFO_NE2K_SEND:
|
||||
ne2000_initiate_send();
|
||||
break;
|
||||
case FIFO_WIFI_STATUS:
|
||||
PG_Wifi_GetStatus();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* cyw43_arch_poll(); */
|
||||
/*
|
||||
if (((time_us_32() >> 21) & 0x1) == 0x1) {
|
||||
if (flag == false) {
|
||||
PG_Wifi_Reconnect();
|
||||
flag = true;
|
||||
}
|
||||
} else {
|
||||
flag = false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -26,14 +26,14 @@ if (NOT PICO_EXTRAS_PATH)
|
||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_EXTRAS_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
endif ()
|
||||
FetchContent_Declare(
|
||||
PICO_EXTRAS
|
||||
pico_extras
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-extras
|
||||
GIT_TAG master
|
||||
)
|
||||
if (NOT PICO_EXTRAS)
|
||||
message("Downloading PICO EXTRAS")
|
||||
FetchContent_Populate(PICO_EXTRAS)
|
||||
set(PICO_EXTRAS_PATH ${PICO_EXTRAS_SOURCE_DIR})
|
||||
if (NOT pico_extras)
|
||||
message("Downloading Raspberry Pi Pico Extras")
|
||||
FetchContent_Populate(pico_extras)
|
||||
set(PICO_EXTRAS_PATH ${pico_extras_SOURCE_DIR})
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
else ()
|
||||
@@ -59,4 +59,4 @@ endif ()
|
||||
|
||||
set(PICO_EXTRAS_PATH ${PICO_EXTRAS_PATH} CACHE PATH "Path to the PICO EXTRAS" FORCE)
|
||||
|
||||
add_subdirectory(${PICO_EXTRAS_PATH} pico_extras)
|
||||
add_subdirectory(${PICO_EXTRAS_PATH} pico_extras)
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <hardware/flash.h>
|
||||
#include "hardware/clocks.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
|
||||
@@ -18,9 +18,20 @@ if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_P
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
|
||||
endif ()
|
||||
|
||||
if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
|
||||
set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
|
||||
message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
|
||||
endif()
|
||||
|
||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
||||
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
||||
set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")
|
||||
|
||||
if (NOT PICO_SDK_PATH)
|
||||
if (PICO_SDK_FETCH_FROM_GIT)
|
||||
@@ -34,14 +45,14 @@ if (NOT PICO_SDK_PATH)
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG master
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
GIT_SUBMODULES_RECURSE FALSE
|
||||
)
|
||||
else ()
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG master
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
)
|
||||
endif ()
|
||||
|
||||
|
||||
+95
-2
@@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "hardware/adc.h"
|
||||
@@ -88,6 +89,15 @@ static uint8_t cms_detect = 0xFF;
|
||||
cms_buffer_t cms_buffer = { {0}, 0, 0 };
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef NE2000
|
||||
extern "C" {
|
||||
#include "ne2000/ne2000.h"
|
||||
}
|
||||
void play_ne2000(void);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USB_JOYSTICK
|
||||
#include "usb_hid/joy.h"
|
||||
extern "C" joystate_struct_t joystate_struct;
|
||||
@@ -102,11 +112,12 @@ uint8_t joystate_bin;
|
||||
void play_usb(void);
|
||||
#endif
|
||||
|
||||
|
||||
// PicoGUS control and data ports
|
||||
static bool control_active = false;
|
||||
static uint8_t sel_reg = 0;
|
||||
static uint16_t cur_data = 0;
|
||||
static uint32_t cur_read = 0;
|
||||
static uint32_t cur_write = 0;
|
||||
static bool queueSaveSettings = false;
|
||||
static bool queueReboot = false;
|
||||
|
||||
@@ -161,6 +172,21 @@ __force_inline void select_picogus(uint8_t value) {
|
||||
case MODE_MOUSERATE:
|
||||
case MODE_MOUSESEN:
|
||||
break;
|
||||
case MODE_NE2KPORT:
|
||||
basePort_low = 0;
|
||||
break;
|
||||
case MODE_WIFISSID:
|
||||
memset(settings.WiFi.ssid, 0, sizeof(settings.WiFi.ssid));
|
||||
cur_write = 0;
|
||||
break;
|
||||
case MODE_WIFIPASS:
|
||||
memset(settings.WiFi.password, 0, sizeof(settings.WiFi.password));
|
||||
cur_write = 0;
|
||||
break;
|
||||
case MODE_WIFIAPPLY:
|
||||
case MODE_WIFISTAT:
|
||||
case MODE_WIFISCAN:
|
||||
break;
|
||||
case MODE_SAVE: // Select save settings register
|
||||
case MODE_REBOOT: // Select reboot register
|
||||
case MODE_DEFAULTS: // Select reset to defaults register
|
||||
@@ -283,6 +309,29 @@ __force_inline void write_picogus_high(uint8_t value) {
|
||||
sermouse_set_sensitivity(settings.Mouse.sensitivity);
|
||||
#endif
|
||||
break;
|
||||
case MODE_NE2KPORT: // NE2000 Base port
|
||||
settings.NE2K.basePort = (value && basePort_low) ? ((value << 8) | (basePort_low & 0xFF)) : 0xFFFF;
|
||||
break;
|
||||
case MODE_WIFISSID:
|
||||
settings.WiFi.ssid[cur_write++] = value;
|
||||
break;
|
||||
case MODE_WIFIPASS:
|
||||
settings.WiFi.password[cur_write++] = value;
|
||||
/* printf("%s\n", settings.WiFi.password); */
|
||||
break;
|
||||
case MODE_WIFIAPPLY:
|
||||
printf("Applying wifi settings: %s %s\n", settings.WiFi.ssid, settings.WiFi.password);
|
||||
#ifdef PICOW
|
||||
PG_Wifi_Connect(settings.WiFi.ssid, settings.WiFi.password);
|
||||
#endif
|
||||
break;
|
||||
case MODE_WIFISTAT:
|
||||
#ifdef PICOW
|
||||
multicore_fifo_push_blocking(FIFO_WIFI_STATUS);
|
||||
#endif
|
||||
break;
|
||||
case MODE_WIFISCAN:
|
||||
break;
|
||||
// For multifw
|
||||
case MODE_BOOTMODE:
|
||||
settings.startupMode = value;
|
||||
@@ -324,6 +373,8 @@ __force_inline uint8_t read_picogus_low(void) {
|
||||
return settings.Mouse.basePort == 0xFFFF ? 0 : (settings.Mouse.basePort & 0xFF);
|
||||
case MODE_MOUSESEN: // USB Mouse Sensitivity (8.8 fixedpoint)
|
||||
return settings.Mouse.sensitivity & 0xFF;
|
||||
case MODE_NE2KPORT: // USB Mouse port (0 - disabled)
|
||||
return settings.NE2K.basePort == 0xFFFF ? 0 : (settings.NE2K.basePort & 0xFF);
|
||||
default:
|
||||
return 0x0;
|
||||
}
|
||||
@@ -380,6 +431,25 @@ __force_inline uint8_t read_picogus_high(void) {
|
||||
return settings.Mouse.reportRate;
|
||||
case MODE_MOUSESEN: // USB Mouse Sensitivity (8.8 fixedpoint)
|
||||
return settings.Mouse.sensitivity >> 8;
|
||||
case MODE_NE2KPORT: // NE2000 Base port
|
||||
return settings.NE2K.basePort == 0xFFFF ? 0 : (settings.NE2K.basePort >> 8);
|
||||
/*
|
||||
case MODE_WIFISSID:
|
||||
break;
|
||||
case MODE_WIFIPASS:
|
||||
break;
|
||||
*/
|
||||
case MODE_WIFISTAT:
|
||||
#ifdef PICOW
|
||||
return PG_Wifi_ReadStatusStr();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
break;
|
||||
/*
|
||||
case MODE_WIFISCAN:
|
||||
return PG_Wifi_ReadScanStr();
|
||||
*/
|
||||
case MODE_HWTYPE: // Hardware version
|
||||
return BOARD_TYPE;
|
||||
case MODE_FLASH:
|
||||
@@ -406,6 +476,8 @@ void processSettings(void) {
|
||||
settings.startupMode = MPU_MODE;
|
||||
#elif defined(USB_ONLY)
|
||||
settings.startupMode = USB_MODE;
|
||||
#elif defined(NE2000)
|
||||
settings.startupMode = NE2000_MODE;
|
||||
#else
|
||||
settings.startupMode = INVALID_MODE;
|
||||
#endif
|
||||
@@ -557,6 +629,12 @@ __force_inline void handle_iow(void) {
|
||||
uartemu_write(port & 7, iow_read & 0xFF);
|
||||
} else // if follows down below
|
||||
#endif // USB_MOUSE
|
||||
#ifdef NE2000
|
||||
if((port & ~0x1F) == settings.NE2K.basePort) {
|
||||
pio_sm_put(pio0, IOW_PIO_SM, IO_WAIT);
|
||||
PG_NE2000_Write(port & 0x1f, iow_read & 0xFF);
|
||||
} else // if follows down below
|
||||
#endif
|
||||
// PicoGUS control
|
||||
if (port == CONTROL_PORT) {
|
||||
pio_sm_put(pio0, IOW_PIO_SM, IO_WAIT);
|
||||
@@ -680,6 +758,13 @@ __force_inline void handle_ior(void) {
|
||||
pio_sm_put(pio0, IOR_PIO_SM, IOR_SET_VALUE | MPU401_ReadStatus());
|
||||
} else // if follows down below
|
||||
#endif
|
||||
#ifdef NE2000
|
||||
if((port & ~0x1F) == settings.NE2K.basePort) {
|
||||
pio_sm_put(pio0, IOR_PIO_SM, IO_WAIT);
|
||||
pio_sm_put(pio0, IOR_PIO_SM, IOR_SET_VALUE | PG_NE2000_Read(port & 0x1f));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef USB_JOYSTICK
|
||||
if (port == settings.Joy.basePort) {
|
||||
pio_sm_put(pio0, IOR_PIO_SM, IO_WAIT);
|
||||
@@ -747,7 +832,7 @@ void ior_isr(void) {
|
||||
|
||||
void err_blink(void) {
|
||||
for (;;) {
|
||||
gpio_xor_mask(LED_PIN);
|
||||
//gpio_xor_mask(LED_PIN);//need to abscrat led functions out to handle chipdown vs picow
|
||||
busy_wait_ms(100);
|
||||
}
|
||||
}
|
||||
@@ -949,6 +1034,14 @@ int main()
|
||||
multicore_launch_core1(&play_cms);
|
||||
#endif // SOUND_CMS
|
||||
|
||||
#ifdef NE2000
|
||||
extern void PIC_ActivateIRQ(void);
|
||||
extern void PIC_DeActivateIRQ(void);
|
||||
|
||||
puts("Creating NE2000");
|
||||
multicore_launch_core1(&play_ne2000);
|
||||
#endif
|
||||
|
||||
#ifdef USB_JOYSTICK
|
||||
// Init joystick as centered with no buttons pressed
|
||||
joystate_struct = {127, 127, 127, 127, 0xf};
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Board config file for overclocked Pico W
|
||||
|
||||
// The below lines aren't just comments - they're directives to the Pico SDK cmake system
|
||||
// pico_cmake_set PICO_PLATFORM = rp2040
|
||||
// pico_cmake_set PICO_CYW43_SUPPORTED = 1
|
||||
|
||||
#ifndef _BOARDS_PICOW_FAST_H
|
||||
#define _BOARDS_PICOW_FAST_H
|
||||
|
||||
// Allow extra time for xosc to start.
|
||||
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
|
||||
|
||||
// Slower flash to assist restarts when flashing on the fly
|
||||
#define PICO_FLASH_SPI_CLKDIV 4
|
||||
|
||||
#include "boards/pico_w.h"
|
||||
#endif
|
||||
Reference in new issue
Block a user