|
7 | 7 | import sys
|
8 | 8 | import tomli
|
9 | 9 | from pathlib import Path
|
| 10 | +from dataclasses import dataclass |
| 11 | + |
10 | 12 | from pydantic import ValidationError
|
11 | 13 |
|
| 14 | +from amaranth.lib.wiring import Signature |
| 15 | + |
12 | 16 | __version__ = importlib.metadata.version("chipflow_lib")
|
13 | 17 |
|
14 | 18 | class ChipFlowError(Exception):
|
@@ -64,3 +68,63 @@ def _parse_config_file(config_file):
|
64 | 68 |
|
65 | 69 | error_str = "\n".join(error_messages)
|
66 | 70 | raise ChipFlowError(f"Validation error in chipflow.toml:\n{error_str}")
|
| 71 | + |
| 72 | + |
| 73 | +def _wire_ulx3s_spi_flash(m: Module, platform: _ULX3SPlatform, port_name: str, flash: Interface) -> None: |
| 74 | + flash_port = platform.request("spi_flash", dir=dict(cs='-', copi='-', cipo='-', wp='-', hold='-')) |
| 75 | + # Flash clock requires a special primitive to access in ECP5 |
| 76 | + m.submodules.usrmclk = Instance( |
| 77 | + "USRMCLK", |
| 78 | + i_USRMCLKI=flash.clk.o, |
| 79 | + i_USRMCLKTS=ResetSignal(), # tristate in reset for programmer accesss |
| 80 | + a_keep=1, |
| 81 | + ) |
| 82 | + |
| 83 | + # Flash IO buffers |
| 84 | + m.submodules += Instance( |
| 85 | + "OBZ", |
| 86 | + o_O=flash_port.cs.io, |
| 87 | + i_I=flash.csn.o, |
| 88 | + i_T=ResetSignal(), |
| 89 | + ) |
| 90 | + |
| 91 | + # Connect flash data pins in order |
| 92 | + data_pins = ["copi", "cipo", "wp", "hold"] |
| 93 | + for i in range(4): |
| 94 | + m.submodules += Instance( |
| 95 | + "BB", |
| 96 | + io_B=getattr(flash_port, data_pins[i]).io, |
| 97 | + i_I=flash.d.o[i], |
| 98 | + i_T=~flash.d.oe[i], |
| 99 | + o_O=flash.d.i[i] |
| 100 | + ) |
| 101 | + |
| 102 | +PortName = str |
| 103 | +WiringFunc = Callable[[Module, Platform, PortName, Interface], None] |
| 104 | +""" |
| 105 | +A :py:WiringFunc declares a function that is used to wire an :py:`wiring.Interface` to a given named :py:`io.PortLike` on the given :py:`build.Platform` |
| 106 | +""" |
| 107 | + |
| 108 | +@dataclass |
| 109 | +class BoardPrimitive: |
| 110 | + interface_type: type[amaranth.Signature] |
| 111 | + wiring_func: WiringFunc |
| 112 | + |
| 113 | +@dataclass |
| 114 | +class BoardVariant: |
| 115 | +"Specification of an FPGA board" |
| 116 | + board_platform: type[Platform] |
| 117 | + "The :py:`type` of the :py:`build.Platform` to use for this board." |
| 118 | + reset_button: Optional[str] = None |
| 119 | + "Resource name to wire to reset" |
| 120 | + default_clock: Optional[str] = None |
| 121 | + "Default clock to use for this BoardVariant or BoardType" |
| 122 | + primitives: Optional[Dict[str, BoardPrimitive]] = None |
| 123 | + "A mapping of a Platform Resource name to the primitive that should be used to wire it up" |
| 124 | + |
| 125 | +@dataclass |
| 126 | +class BoardType: |
| 127 | + types: List[ |
| 128 | + |
| 129 | +SUPPORTED_BOARDS = { |
| 130 | + 'ULX3S' |
0 commit comments