├── .gitignore ├── src ├── pin_order.cfg ├── cells.v └── config.tcl ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ └── bug_report.md └── workflows │ ├── doc_header.md │ ├── doc_preview.md │ ├── docs.yaml │ └── gds.yaml ├── README.md ├── info.yaml ├── configure.py └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | .vscode 4 | *.vcd 5 | -------------------------------------------------------------------------------- /src/pin_order.cfg: -------------------------------------------------------------------------------- 1 | #N 2 | 3 | #S 4 | 5 | #E 6 | 7 | #W 8 | io_in.* 9 | io_out.* 10 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | custom: ['https://zerotoasiccourse.com'] 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: mattvenn 7 | 8 | --- 9 | 10 | **Link to your wokwi project** 11 | 12 | Please put a link to your wokwi project here. 13 | -------------------------------------------------------------------------------- /.github/workflows/doc_header.md: -------------------------------------------------------------------------------- 1 | --- 2 | documentclass: scrartcl 3 | geometry: margin=2cm 4 | fontsize: 14pt 5 | mainfont: Latin Modern Sans 6 | header-includes: 7 | - \hypersetup{colorlinks=false, 8 | allbordercolors={0 0 0}, 9 | pdfborderstyle={/S/U/W 1}} 10 | --- 11 | 12 | -------------------------------------------------------------------------------- /.github/workflows/doc_preview.md: -------------------------------------------------------------------------------- 1 | ## {title} 2 | 3 | {picture_link} 4 | 5 | * Author: {author} 6 | * Description: {description} 7 | * [Extra docs]({doc_link}) 8 | * Clock: {clock_hz} Hz 9 | * External hardware: {external_hw} 10 | 11 | ### How it works 12 | 13 | {how_it_works} 14 | 15 | ### How to test 16 | 17 | {how_to_test} 18 | 19 | ### IO 20 | 21 | | # | Input | Output | 22 | |---|--------------|--------------| 23 | | 0 | {inputs[0]} | {outputs[0]} | 24 | | 1 | {inputs[1]} | {outputs[1]} | 25 | | 2 | {inputs[2]} | {outputs[2]} | 26 | | 3 | {inputs[3]} | {outputs[3]} | 27 | | 4 | {inputs[4]} | {outputs[4]} | 28 | | 5 | {inputs[5]} | {outputs[5]} | 29 | | 6 | {inputs[6]} | {outputs[6]} | 30 | | 7 | {inputs[7]} | {outputs[7]} | 31 | -------------------------------------------------------------------------------- /.github/workflows/docs.yaml: -------------------------------------------------------------------------------- 1 | name: docs 2 | # either manually started, or on a schedule 3 | on: [ push, workflow_dispatch ] 4 | permissions: 5 | contents: write 6 | pages: write 7 | id-token: write 8 | jobs: 9 | docs: 10 | # ubuntu 11 | runs-on: ubuntu-latest 12 | steps: 13 | # need the repo checked out 14 | - name: checkout repo 15 | uses: actions/checkout@v3 16 | 17 | # need python 18 | - name: setup python 19 | uses: actions/setup-python@v4 20 | with: 21 | python-version: '3.10' 22 | - run: pip install requests PyYAML 23 | 24 | # fetch the Verilog from Wokwi API 25 | - name: fetch Verilog and build config 26 | run: ./configure.py --check-docs 27 | 28 | # pandoc deps 29 | - name: Pandoc deps 30 | run: | 31 | sudo apt-get update -y 32 | sudo apt-get install -y pandoc texlive-xetex 33 | 34 | # fetch the Verilog from Wokwi API 35 | - name: build datasheet 36 | run: ./configure.py --build-pdf 37 | 38 | # make an artifact 39 | - name: upload artifact 40 | uses: actions/upload-artifact@v3 41 | with: 42 | name: docs 43 | path: info.yaml 44 | 45 | # archive the PDF 46 | - name: Archive PDF 47 | uses: actions/upload-artifact@v3 48 | with: 49 | name: PDF 50 | path: datasheet.pdf 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](../../workflows/gds/badge.svg) ![](../../workflows/docs/badge.svg) 2 | 3 | # What is Tiny Tapeout? 4 | 5 | TinyTapeout is an educational project that aims to make it easier and cheaper than ever to get your digital designs manufactured on a real chip! 6 | 7 | Go to https://tinytapeout.com for instructions! 8 | 9 | ## How to change the Wokwi project 10 | 11 | Edit the [info.yaml](info.yaml) and change the wokwi_id to match your project. 12 | 13 | ## How to enable the GitHub actions to build the ASIC files 14 | 15 | Please see the instructions for: 16 | 17 | * [Enabling GitHub Actions](https://tinytapeout.com/faq/#when-i-commit-my-change-the-gds-action-isnt-running) 18 | * [Enabling GitHub Pages](https://tinytapeout.com/faq/#my-github-action-is-failing-on-the-pages-part) 19 | 20 | ## How does it work? 21 | 22 | When you edit the info.yaml to choose a different ID, the [GitHub Action](.github/workflows/gds.yaml) will fetch the digital netlist of your design from Wokwi. 23 | 24 | After that, the action uses the open source ASIC tool called [OpenLane](https://www.zerotoasiccourse.com/terminology/openlane/) to build the files needed to fabricate an ASIC. 25 | 26 | ## Resources 27 | 28 | * [FAQ](https://tinytapeout.com/faq/) 29 | * [Digital design lessons](https://tinytapeout.com/digital_design/) 30 | * [Join the community](https://discord.gg/rPK2nSjxy8) 31 | 32 | ## What next? 33 | 34 | * Share your GDS on Twitter, tag it [#tinytapeout](https://twitter.com/hashtag/tinytapeout?src=hashtag_click) and [link me](https://twitter.com/matthewvenn)! 35 | -------------------------------------------------------------------------------- /src/cells.v: -------------------------------------------------------------------------------- 1 | /* 2 | This file provides the mapping from the Wokwi modules to Verilog HDL 3 | 4 | It's only needed for Wokwi designs 5 | 6 | */ 7 | `define default_netname none 8 | 9 | module buffer_cell ( 10 | input wire in, 11 | output wire out 12 | ); 13 | assign out = in; 14 | endmodule 15 | 16 | module and_cell ( 17 | input wire a, 18 | input wire b, 19 | output wire out 20 | ); 21 | 22 | assign out = a & b; 23 | endmodule 24 | 25 | module or_cell ( 26 | input wire a, 27 | input wire b, 28 | output wire out 29 | ); 30 | 31 | assign out = a | b; 32 | endmodule 33 | 34 | module xor_cell ( 35 | input wire a, 36 | input wire b, 37 | output wire out 38 | ); 39 | 40 | assign out = a ^ b; 41 | endmodule 42 | 43 | module nand_cell ( 44 | input wire a, 45 | input wire b, 46 | output wire out 47 | ); 48 | 49 | assign out = !(a&b); 50 | endmodule 51 | 52 | module not_cell ( 53 | input wire in, 54 | output wire out 55 | ); 56 | 57 | assign out = !in; 58 | endmodule 59 | 60 | module mux_cell ( 61 | input wire a, 62 | input wire b, 63 | input wire sel, 64 | output wire out 65 | ); 66 | 67 | assign out = sel ? b : a; 68 | endmodule 69 | 70 | module dff_cell ( 71 | input wire clk, 72 | input wire d, 73 | output reg q, 74 | output wire notq 75 | ); 76 | 77 | assign notq = !q; 78 | always @(posedge clk) 79 | q <= d; 80 | 81 | endmodule 82 | 83 | module dffsr_cell ( 84 | input wire clk, 85 | input wire d, 86 | input wire s, 87 | input wire r, 88 | output reg q, 89 | output wire notq 90 | ); 91 | 92 | assign notq = !q; 93 | 94 | always @(posedge clk or posedge s or posedge r) begin 95 | if (r) 96 | q <= 0; 97 | else if (s) 98 | q <= 1; 99 | else 100 | q <= d; 101 | end 102 | endmodule 103 | -------------------------------------------------------------------------------- /src/config.tcl: -------------------------------------------------------------------------------- 1 | # PLEASE DO NOT EDIT THIS FILE! 2 | # The only thing you can change is the PL_BASIC_PLACEMENT line 3 | # If you get stuck with this config, please open an issue or get in touch via the discord. 4 | 5 | # User config 6 | set script_dir [file dirname [file normalize [info script]]] 7 | 8 | # read some user config that is written by the setup.py program. 9 | # - the name of the module is defined 10 | # - the list of source files 11 | source $::env(DESIGN_DIR)/user_config.tcl 12 | 13 | # save some time 14 | set ::env(RUN_KLAYOUT_XOR) 0 15 | set ::env(RUN_KLAYOUT_DRC) 0 16 | 17 | # don't put clock buffers on the outputs 18 | set ::env(PL_RESIZER_BUFFER_OUTPUT_PORTS) 0 19 | 20 | # allow use of specific sky130 cells 21 | set ::env(SYNTH_READ_BLACKBOX_LIB) 1 22 | 23 | # put all the pins on the left 24 | set ::env(FP_PIN_ORDER_CFG) $::env(DESIGN_DIR)/pin_order.cfg 25 | 26 | # reduce wasted space 27 | set ::env(TOP_MARGIN_MULT) 2 28 | set ::env(BOTTOM_MARGIN_MULT) 2 29 | 30 | # absolute die size 31 | set ::env(FP_SIZING) absolute 32 | set ::env(DIE_AREA) "0 0 150 170" 33 | set ::env(FP_CORE_UTIL) 55 34 | 35 | # comment this if your design has more than a few hundred cells 36 | set ::env(PL_BASIC_PLACEMENT) {1} 37 | 38 | set ::env(FP_IO_HLENGTH) 2 39 | set ::env(FP_IO_VLENGTH) 2 40 | 41 | # use alternative efabless decap cells to solve LI density issue 42 | set ::env(DECAP_CELL) "\ 43 | sky130_fd_sc_hd__decap_3 \ 44 | sky130_fd_sc_hd__decap_4 \ 45 | sky130_fd_sc_hd__decap_6 \ 46 | sky130_fd_sc_hd__decap_8 \ 47 | sky130_ef_sc_hd__decap_12" 48 | 49 | # clock 50 | set ::env(CLOCK_TREE_SYNTH) 1 51 | # period is in ns, so 20000ns == 50kHz 52 | set ::env(CLOCK_PERIOD) "20000" 53 | set ::env(CLOCK_PORT) {io_in[0]} 54 | 55 | # hold/slack margin 56 | # set ::env(PL_RESIZER_HOLD_SLACK_MARGIN) 0.8 57 | # set ::env(GLB_RESIZER_HOLD_SLACK_MARGIN) 0.8 58 | 59 | # don't use power rings or met5 60 | set ::env(DESIGN_IS_CORE) 0 61 | set ::env(RT_MAX_LAYER) {met4} 62 | 63 | # connect to first digital rails 64 | set ::env(VDD_NETS) [list {vccd1}] 65 | set ::env(GND_NETS) [list {vssd1}] 66 | -------------------------------------------------------------------------------- /info.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # TinyTapeout project information 3 | project: 4 | wokwi_id: 0 # If using wokwi, set this to your project's ID 5 | # source_files: # If using an HDL, set wokwi_id as 0 and uncomment and list your source files here. Source files must be in ./src 6 | # - counter.v 7 | # - decoder.v 8 | # top_module: "seven_segment_seconds" # put the name of your top module here, make it unique by prepending your github username 9 | 10 | # keep a track of the submission yaml 11 | yaml_version: 2.1 12 | 13 | # As everyone will have access to all designs, try to make it easy for someone new to your design to know what 14 | # it does and how to operate it. 15 | # 16 | # Here is an example: https://github.com/mattvenn/tinytapeout_m_segments/blob/main/info.yaml 17 | # 18 | # This info will be automatically collected and used to make a datasheet for the chip. 19 | documentation: 20 | author: "" # Your name 21 | discord: "" # Your discord handle - make sure to include the # part as well 22 | title: "" # Project title 23 | description: "" # Short description of what your project does 24 | how_it_works: "" # Longer description of how the project works 25 | how_to_test: "" # Instructions on how someone could test your project, include things like what buttons do what and how to set the clock if needed 26 | external_hw: "" # Describe any external hardware needed 27 | language: "wokwi" # other examples include Verilog, Amaranth, VHDL, etc 28 | doc_link: "" # URL to longer form documentation, eg the README.md in your repository 29 | clock_hz: 0 # Clock frequency in Hz (if required) we are expecting max clock frequency to be ~6khz. Provided on input 0. 30 | picture: "" # relative path to a picture in your repository 31 | inputs: # a description of what the inputs do 32 | - clock 33 | - reset 34 | - none 35 | - none 36 | - none 37 | - none 38 | - none 39 | - none 40 | outputs: 41 | - segment a # a description of what the outputs do 42 | - segment b 43 | - segment c 44 | - segment d 45 | - segment e 46 | - segment f 47 | - segment g 48 | - none 49 | 50 | -------------------------------------------------------------------------------- /.github/workflows/gds.yaml: -------------------------------------------------------------------------------- 1 | name: gds 2 | # either manually started, or on a schedule 3 | on: [ push, workflow_dispatch ] 4 | permissions: 5 | contents: write 6 | pages: write 7 | id-token: write 8 | jobs: 9 | gds: 10 | env: 11 | OPENLANE_IMAGE_NAME: efabless/openlane:2022.07.02_01.38.08 12 | OPENLANE_ROOT: /home/runner/openlane 13 | PDK_ROOT: /home/runner/pdk 14 | PDK: sky130B 15 | 16 | # ubuntu 17 | runs-on: ubuntu-latest 18 | steps: 19 | # need the repo checked out 20 | - name: checkout repo 21 | uses: actions/checkout@v3 22 | with: 23 | submodules: recursive 24 | 25 | # build PDK and fetch OpenLane 26 | 27 | - name: pdk & caravel 28 | run: | 29 | cd $HOME 30 | git clone https://github.com/efabless/caravel_user_project.git -b mpw-7a 31 | cd caravel_user_project 32 | make setup 33 | 34 | # need python 35 | - name: setup python 36 | uses: actions/setup-python@v4 37 | with: 38 | python-version: '3.10' 39 | - run: pip install requests PyYAML 40 | 41 | # fetch the Verilog from Wokwi API 42 | - name: fetch Verilog and build config 43 | run: ./configure.py --create-user-config 44 | 45 | # run OpenLane to build the GDS 46 | - name: make GDS 47 | run: > 48 | docker run --rm 49 | -v $OPENLANE_ROOT:/openlane 50 | -v $PDK_ROOT:$PDK_ROOT 51 | -v $(pwd):/work 52 | -e PDK_ROOT=$PDK_ROOT 53 | -u $(id -u $USER):$(id -g $USER) 54 | $OPENLANE_IMAGE_NAME 55 | /bin/bash -c "./flow.tcl -verbose 2 -overwrite -design /work/src -run_path /work/runs -tag wokwi" 56 | 57 | # for debugging, show all the files 58 | - name: show files 59 | run: find runs/wokwi/ 60 | 61 | # print some routing stats 62 | - name: add summary 63 | run: ./configure.py --get-stats >> $GITHUB_STEP_SUMMARY 64 | 65 | # print some cell stats 66 | - name: cell usage summary 67 | run: | 68 | git clone https://github.com/TinyTapeout/sssummarizer 69 | sssummarizer/sssummarizer.py --gl runs/wokwi/results/final/verilog/gl/*.v --print-category >> $GITHUB_STEP_SUMMARY 70 | 71 | - name: populate src cache 72 | uses: actions/cache@v3 73 | with: 74 | path: src 75 | key: ${{ runner.os }}-src-${{ github.run_id }} 76 | 77 | - name: populate runs cache 78 | uses: actions/cache@v3 79 | with: 80 | path: runs 81 | key: ${{ runner.os }}-runs-${{ github.run_id }} 82 | 83 | png: 84 | needs: gds 85 | runs-on: ubuntu-latest 86 | steps: 87 | - name: checkout repo 88 | uses: actions/checkout@v3 89 | 90 | - name: setup python 91 | uses: actions/setup-python@v4 92 | with: 93 | python-version: '3.10' 94 | 95 | - name: restore runs cache 96 | uses: actions/cache@v3 97 | with: 98 | path: runs 99 | key: ${{ runner.os }}-runs-${{ github.run_id }} 100 | 101 | - name: create svg 102 | run: | 103 | python -m pip install gdstk 104 | python << EOF 105 | import gdstk 106 | import pathlib 107 | 108 | gds = sorted(pathlib.Path('runs').glob('wokwi/results/final/gds/*.gds')) 109 | library = gdstk.read_gds(gds[-1]) 110 | top_cells = library.top_level() 111 | top_cells[0].write_svg('gds_render.svg') 112 | EOF 113 | 114 | - name: convert to png 115 | run: | 116 | python -m pip install cairosvg 117 | python << EOF 118 | import cairosvg 119 | cairosvg.svg2png(url='gds_render.svg', write_to='gds_render.png') 120 | EOF 121 | 122 | - name: populate png cache 123 | uses: actions/cache@v3 124 | with: 125 | path: 'gds_render.png' 126 | key: ${{ runner.os }}-png-${{ github.run_id }} 127 | 128 | viewer: 129 | needs: gds 130 | runs-on: ubuntu-latest 131 | steps: 132 | - name: checkout GDS2glTF repo 133 | uses: actions/checkout@v3 134 | with: 135 | repository: mbalestrini/GDS2glTF 136 | 137 | - name: setup python 138 | uses: actions/setup-python@v4 139 | with: 140 | python-version: '3.10' 141 | 142 | - name: restore runs cache 143 | uses: actions/cache@v3 144 | with: 145 | path: runs 146 | key: ${{ runner.os }}-runs-${{ github.run_id }} 147 | 148 | - name: gds2gltf 149 | run: | 150 | python -m pip install numpy gdspy triangle pygltflib 151 | cp runs/wokwi/results/final/gds/*.gds tinytapeout.gds 152 | python3 gds2gltf.py tinytapeout.gds 153 | 154 | - name: populate viewer cache 155 | uses: actions/cache@v3 156 | with: 157 | path: 'tinytapeout.gds.gltf' 158 | key: ${{ runner.os }}-viewer-${{ github.run_id }} 159 | 160 | artifact: 161 | needs: 162 | - gds 163 | runs-on: ubuntu-latest 164 | steps: 165 | - name: restore src cache 166 | uses: actions/cache@v3 167 | with: 168 | path: src 169 | key: ${{ runner.os }}-src-${{ github.run_id }} 170 | 171 | - name: restore runs cache 172 | uses: actions/cache@v3 173 | with: 174 | path: runs 175 | key: ${{ runner.os }}-runs-${{ github.run_id }} 176 | 177 | - name: upload artifact 178 | uses: actions/upload-artifact@v3 179 | with: 180 | # path depends on the tag and the module name 181 | name: GDS 182 | path: | 183 | src/* 184 | runs/wokwi/results/final/* 185 | runs/wokwi/reports/metrics.csv 186 | runs/wokwi/reports/synthesis/1-synthesis.AREA 0.stat.rpt 187 | 188 | pages: 189 | needs: 190 | - png 191 | - viewer 192 | environment: 193 | name: github-pages 194 | url: ${{ steps.deployment.outputs.page_url }} 195 | outputs: 196 | page_url: ${{ steps.deployment.outputs.page_url }} 197 | runs-on: ubuntu-latest 198 | steps: 199 | - name: restore png cache 200 | uses: actions/cache@v3 201 | with: 202 | path: 'gds_render.png' 203 | key: ${{ runner.os }}-png-${{ github.run_id }} 204 | - name: restore viewer cache 205 | uses: actions/cache@v3 206 | with: 207 | path: 'tinytapeout.gds.gltf' 208 | key: ${{ runner.os }}-viewer-${{ github.run_id }} 209 | - name: generate redirect to viewer 210 | run: | 211 | cat << EOF >> index.html 212 | 213 | 214 | 215 | 216 | 217 | 218 | Redirecting to GDS Viewer... 219 | 220 | 221 | 224 | 225 | 226 | EOF 227 | - name: Setup Pages 228 | uses: actions/configure-pages@v2 229 | - name: Upload artifact 230 | uses: actions/upload-pages-artifact@v1 231 | with: 232 | path: '.' 233 | - name: Deploy to GitHub Pages 234 | id: deployment 235 | uses: actions/deploy-pages@v1.2.2 236 | 237 | preview: 238 | needs: pages 239 | runs-on: ubuntu-latest 240 | steps: 241 | - name: add gds preview 242 | run: | 243 | PAGE_URL=${{ needs.pages.outputs.page_url }} 244 | PAGE_URL=$(echo "$PAGE_URL" | sed -e 's/\/$//') 245 | cat << EOF >> $GITHUB_STEP_SUMMARY 246 | # layout 247 | ![png]($PAGE_URL/gds_render.png) 248 | # viewer 249 | [open preview](https://gds-viewer.tinytapeout.com/?model=$PAGE_URL/tinytapeout.gds.gltf) 250 | EOF 251 | -------------------------------------------------------------------------------- /configure.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import requests 3 | import argparse 4 | import os 5 | import yaml 6 | import logging 7 | import sys 8 | import csv 9 | import re 10 | import subprocess 11 | 12 | 13 | def load_yaml(yaml_file): 14 | with open(yaml_file, "r") as stream: 15 | return (yaml.safe_load(stream)) 16 | 17 | 18 | def write_user_config(module_name, sources): 19 | filename = 'user_config.tcl' 20 | with open(os.path.join('src', filename), 'w') as fh: 21 | fh.write("set ::env(DESIGN_NAME) {}\n".format(module_name)) 22 | fh.write('set ::env(VERILOG_FILES) "\\\n') 23 | for line, source in enumerate(sources): 24 | fh.write(" $::env(DESIGN_DIR)/" + source) 25 | if line != len(sources) - 1: 26 | fh.write(' \\\n') 27 | fh.write('"\n') 28 | 29 | 30 | def fetch_file(url, filename): 31 | logging.info("trying to download {}".format(url)) 32 | r = requests.get(url) 33 | if r.status_code != 200: 34 | logging.warning("couldn't download {}".format(url)) 35 | exit(1) 36 | 37 | with open(filename, 'wb') as fh: 38 | logging.info("written to {}".format(filename)) 39 | fh.write(r.content) 40 | 41 | 42 | def get_project_source(yaml): 43 | # wokwi_id must be an int or 0 44 | try: 45 | wokwi_id = int(yaml['project']['wokwi_id']) 46 | except ValueError: 47 | logging.error("wokwi id must be an integer") 48 | exit(1) 49 | 50 | # it's a wokwi project 51 | if wokwi_id != 0: 52 | url = "https://wokwi.com/api/projects/{}/verilog".format(wokwi_id) 53 | src_file = "user_module_{}.v".format(wokwi_id) 54 | fetch_file(url, os.path.join("src", src_file)) 55 | 56 | # also fetch the wokwi diagram 57 | url = "https://wokwi.com/api/projects/{}/diagram.json".format(wokwi_id) 58 | diagram_file = "wokwi_diagram.json" 59 | fetch_file(url, os.path.join("src", diagram_file)) 60 | 61 | return [src_file, 'cells.v'] 62 | 63 | # else it's HDL, so check source files 64 | else: 65 | if 'source_files' not in yaml['project']: 66 | logging.error("source files must be provided if wokwi_id is set to 0") 67 | exit(1) 68 | 69 | source_files = yaml['project']['source_files'] 70 | if source_files is None: 71 | logging.error("must be more than 1 source file") 72 | exit(1) 73 | 74 | if len(source_files) == 0: 75 | logging.error("must be more than 1 source file") 76 | exit(1) 77 | 78 | if 'top_module' not in yaml['project']: 79 | logging.error("must provide a top module name") 80 | exit(1) 81 | 82 | for filename in source_files: 83 | if not os.path.exists(os.path.join('src', filename)): 84 | logging.error(f"{filename} doesn't exist in the repo") 85 | exit(1) 86 | 87 | return source_files 88 | 89 | 90 | # documentation 91 | def check_docs(yaml): 92 | for key in ['author', 'title', 'description', 'how_it_works', 'how_to_test', 'language']: 93 | if key not in yaml['documentation']: 94 | logging.error("missing key {} in documentation".format(key)) 95 | exit(1) 96 | if yaml['documentation'][key] == "": 97 | logging.error("missing value for {} in documentation".format(key)) 98 | exit(1) 99 | 100 | # if provided, check discord handle is valid 101 | if len(yaml['documentation']['discord']): 102 | parts = yaml['documentation']['discord'].split('#') 103 | if len(parts) != 2 or len(parts[0]) == 0 or not re.match('^[0-9]{4}$', parts[1]): 104 | logging.error('Invalid format for discord username') 105 | exit(1) 106 | 107 | 108 | def build_pdf(yaml_data): 109 | with open(".github/workflows/doc_header.md") as fh: 110 | doc_header = fh.read() 111 | with open(".github/workflows/doc_preview.md") as fh: 112 | doc_template = fh.read() 113 | 114 | with open('datasheet.md', 'w') as fh: 115 | fh.write(doc_header) 116 | # handle pictures 117 | yaml_data['picture_link'] = '' 118 | if yaml_data['picture']: 119 | # skip SVG for now, not supported by pandoc 120 | picture_name = yaml_data['picture'] 121 | if 'svg' not in picture_name: 122 | yaml_data['picture_link'] = '![picture]({})'.format(picture_name) 123 | else: 124 | logging.warning("svg not supported") 125 | 126 | # now build the doc & print it 127 | try: 128 | doc = doc_template.format(**yaml_data) 129 | fh.write(doc) 130 | fh.write("\n\pagebreak\n") 131 | except IndexError: 132 | logging.warning("missing pins in info.yaml, skipping") 133 | 134 | pdf_cmd = 'pandoc --pdf-engine=xelatex -i datasheet.md -o datasheet.pdf' 135 | logging.info(pdf_cmd) 136 | p = subprocess.run(pdf_cmd, shell=True) 137 | if p.returncode != 0: 138 | logging.error("pdf command failed") 139 | 140 | 141 | def get_top_module(yaml): 142 | wokwi_id = int(yaml['project']['wokwi_id']) 143 | if wokwi_id != 0: 144 | return "user_module_{}".format(wokwi_id) 145 | else: 146 | return yaml['project']['top_module'] 147 | 148 | 149 | def get_stats(): 150 | with open('runs/wokwi/reports/metrics.csv') as f: 151 | report = list(csv.DictReader(f))[0] 152 | 153 | print('# Routing stats') 154 | print() 155 | print('| Utilisation | Wire length (um) |') 156 | print('|-------------|------------------|') 157 | print('| {} | {} |'.format(report['OpenDP_Util'], report['wire_length'])) 158 | 159 | 160 | if __name__ == '__main__': 161 | parser = argparse.ArgumentParser(description="TT setup") 162 | 163 | parser.add_argument('--check-docs', help="check the documentation part of the yaml", action="store_const", const=True) 164 | parser.add_argument('--build-pdf', help="build a single page PDF", action="store_const", const=True) 165 | parser.add_argument('--get-stats', help="print some stats from the run", action="store_const", const=True) 166 | parser.add_argument('--create-user-config', help="create the user_config.tcl file with top module and source files", action="store_const", const=True) 167 | parser.add_argument('--debug', help="debug logging", action="store_const", dest="loglevel", const=logging.DEBUG, default=logging.INFO) 168 | parser.add_argument('--yaml', help="yaml file to load", default='info.yaml') 169 | 170 | args = parser.parse_args() 171 | # setup log 172 | log_format = logging.Formatter('%(asctime)s - %(module)-10s - %(levelname)-8s - %(message)s') 173 | # configure the client logging 174 | log = logging.getLogger('') 175 | # has to be set to debug as is the root logger 176 | log.setLevel(args.loglevel) 177 | 178 | # create console handler and set level to info 179 | ch = logging.StreamHandler(sys.stdout) 180 | # create formatter for console 181 | ch.setFormatter(log_format) 182 | log.addHandler(ch) 183 | 184 | if args.get_stats: 185 | get_stats() 186 | 187 | elif args.check_docs: 188 | logging.info("checking docs") 189 | config = load_yaml(args.yaml) 190 | check_docs(config) 191 | 192 | elif args.build_pdf: 193 | logging.info("building pdf") 194 | config = load_yaml(args.yaml) 195 | build_pdf(config['documentation']) 196 | 197 | elif args.create_user_config: 198 | logging.info("creating include file") 199 | config = load_yaml(args.yaml) 200 | source_files = get_project_source(config) 201 | top_module = get_top_module(config) 202 | if top_module == 'top': 203 | logging.error("top module cannot be called top - prepend your repo name to make it unique") 204 | exit(1) 205 | write_user_config(top_module, source_files) 206 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------