Skip to content

Instantly share code, notes, and snippets.

@davidlenfesty
Created January 9, 2023 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidlenfesty/1d301f2769c8f2ba77098e50ded77e11 to your computer and use it in GitHub Desktop.
Save davidlenfesty/1d301f2769c8f2ba77098e50ded77e11 to your computer and use it in GitHub Desktop.
LiteX Wishbone Slave
from migen import *
from pathlib import Path
class LedGpio(Module):
def __init__(self, platform, led: Signal):
source = Path(__file__).parent / "led_gpio.v"
platform.add_source(source)
self.adr = Signal(32)
self.dat_w = Signal(32)
self.dat_r = Signal(32)
self.sel = Signal(4)
self.cyc = Signal()
self.stb = Signal()
self.ack = Signal()
self.we = Signal()
self.cti = Signal(3)
self.bte = Signal(2)
self.err = Signal()
# Needs to be added in self.specials
self.specials += Instance("led_gpio",
p_DATA_WIDTH=32,
p_ADR_WIDTH=32,
p_SEL_WIDTH=4,
i_clk=ClockSignal(),
i_rst=ResetSignal(),
i_adr=self.adr,
i_dat_w=self.dat_w,
o_dat_r=self.dat_r,
i_sel=self.sel,
i_cyc=self.cyc,
i_stb=self.stb,
o_ack=self.ack,
i_we=self.we,
i_cti=self.cti,
i_bte=self.bte,
o_err=self.err,
o_led=led
)
class BaseSoC(SoCCore):
def __init__(self, **kwargs):
# boilerplate from colorlight i5 goes here
# LED blinky thing
wb_interface = wishbone.Interface()
led = platform.request("user_led_n")
self.submodules.led = led = led_gpio.LedGpio(platform, led)
wb_interface.connect_to_pads(led, mode="slave")
self.add_memory_region("led_gpio", 0x8F000000, 0x1000, type="dawda")
self.add_wb_slave(0x8F000000, wb_interface, 0x1000)
# vague attempt based on colorlight i5 target, didn't suspect it would make much of a difference
#region = SoCRegion(origin=0x8F000000, size=0x1000, cached=False)
#self.bus.add_slave(name="led_gpio", slave=wb_interface, region=region)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment