How fjpolo/ostang works
Main Components
• FPGA/SoC “OSTang Top” Module:
• Top-level hardware integration (likely represented by src/ostang_top.sv)
• It brings together the various hardware blocks.
• CPU Core:
• Responsible for running the baremetal firmware (firmware/firmware.c, firmware.elf).
• Firmware and Baremetal Environment:
• Contains makefiles, build scripts (buildall.bat, firmware/build.bat/sh) and binary outputs (firmware.bin, firmware.elf)
• Integrated FAT file system support (firmware/fatfs directories give diskio, ff.c, ff.h, etc.)
• Video and Audio Modules:
• HDMI interface modules under src/hdmi2 (HDMI transmitter, audio packets, serializers, etc.)
• PLL components for HDMI (e.g., gowin_pll_hdmi.v in both nano20k and primer25k directories)
• Input/Controller Interfaces:
• Multiple controller modules including NES, SNES, DualShock, and USB gamepad support (files under src/usb_gamepad, src/controller_ds2.sv, src/controller_snes.v)
• Additional legacy or specialized controllers (look for ostang_snescontroller.cst and related files).
• System I/O and Configuration:
• Modules under src/iosys (e.g., simpleuart, spi_master, textdisp) for peripheral management and system interfacing.
• Gowin DPB menu (configuration) components in src/iosys.
• Clock and PLL Blocks:
• Specific PLL configurations are given in the nano20k and primer25k directories – these set up clock domains for HDMI, OS controllers, and USB.
• Memory and Storage:
• There is mention of SDRAM (src/sdram_nes.v), as well as EEPROM and potential SD card access (spi_sd.c in firmware)
• FATFS integration in the firmware is likely used to manage file systems on SD cards or external flash.
• Additional Utility Components:
• Assets (graphics, fonts, and test patterns) for video display.
• UART modules (a debug interface), and USB HID host implementations (src/usb_hid_host.v, related ROM files).
• A central FPGA/SoC block (“OSTang Top”) that connects to the CPU core (picorv32) and the rest of the hardware IP blocks.
• Dedicated sub-blocks for HDMI/audio processing, each with inputs/outputs (data streams, clock signals) coming from the PLL modules.
• Control path from input devices (USB gamepad, legacy controllers, etc.) flowing into dedicated controller interface blocks feeding data into the main processing system.
• Memory interfaces (SDRAM controller, EEPROM access, SPI for SD card and SPI flash) that link to both the CPU and peripheral modules.
• Separate design flows/configurations available (nano20k versus primer25k) by optionally annotating multiple configuration blocks that feed precise clock and power domains into the system.
Important Architectural Patterns and Principles
• Modularity: The system is organized into clear, function-specific modules (video processing, input control, memory, I/O) which suggests a highly modular design to ease testing and integration.
• Separation of concerns: The firmware layer (baremetal C and assembly) is kept distinct from the Hardware RTL, which itself is broken into logical blocks (e.g., clocking, data processing, interface).
• Use of standard libraries: Incorporation of FATFS for filesystem support in the firmware and reuse of open-source cores like picorv32 indicates a lean, reusable architecture.
• Multiple target configurations: With directories for nano20k and primer25k, the design supports variations based on board or FPGA family (likely differing in resources or performance).