diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..304f4c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +#python +__pycache__/ +*.pyc diff --git a/environment.sh b/environment.sh new file mode 100644 index 0000000..25448fe --- /dev/null +++ b/environment.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +SCRIPT_PATH=$(readlink -f "${BASH_SOURCE:-$0}") +SCRIPT_DIR=$(dirname "$SCRIPT_PATH") +PYTHONLIBS_DIR="${SCRIPT_DIR}/gatemate" +export PYTHONPATH="${PYTHONLIBS_DIR}:${PYTHONPATH}" diff --git a/gatemate/__init__.py b/gatemate/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gatemate/die.py b/gatemate/die.py new file mode 100644 index 0000000..b73f0fd --- /dev/null +++ b/gatemate/die.py @@ -0,0 +1,68 @@ +def max_row(): + return 131 + +def max_col(): + return 163 + +def is_sb_big(x,y): + if (x>=-1 and x<=162 and y>=-1 and y<=130): + if (x+1) % 2 == 1 and (y+1) % 2 == 1: + return False if (x+1) % 4 == (y+1) % 4 else True + if (x+1) % 2 == 0 and (y+1) % 2 == 0: + return False if (x+1) % 4 != (y+1) % 4 else True + return False + +def is_sb_sml(x,y): + if (x>=-1 and x<=162 and y>=-1 and y<=130): + if (x+1) % 2 == 1 and (y+1) % 2 == 1: + return True if (x+1) % 4 == (y+1) % 4 else False + if (x+1) % 2 == 0 and (y+1) % 2 == 0: + return True if (x+1) % 4 != (y+1) % 4 else False + return False + +def is_cpe(x,y): + return x>=1 and x<=160 and y>=1 and y<=128 + +def is_outmux(x,y): + return is_cpe(x,y) and (x+1) % 2 == (y+1) % 2 + +def is_edge_left(x,y): + return x==-2 and y>=1 and y<=130 + +def is_edge_right(x,y): + return x==max_col() and y>=1 and y<=128 + +def is_edge_bottom(x,y): + return y==-2 and x>=-1 and x<=162 + +def is_edge_top(x,y): + return y==max_row() and x>=1 and x<=162 + +def is_edge_io(x,y): + if (y==-2 and x>=5 and x<=40): # GPIO_S3 + return True + if (y==-2 and x>=57 and x<=92): # GPIO_S1 + return True + if (y==-2 and x>=101 and x<=136): # GPIO_S2 + return True + if (x==-2 and y>=25 and y<=60): # GPIO_W1 + return True + if (x==-2 and y>=69 and y<=104): # GPIO_W2 + return True + if (x==max_col() and y>=25 and y<=50): # GPIO_E1 + return True + if (x==max_col() and y>=69 and y<=104): # GPIO_E2 + return True + if (y==max_row() and x>=57 and x<=92): # GPIO_N1 + return True + if (y==max_row() and x>=101 and x<=136): # GPIO_N2 + return True + +def is_gpio(x,y): + if is_edge_io(x,y): + if (y==-2 or y==max_row()): + return x % 2==1 + if (x==-2 or x==max_col()): + return y % 2==1 + return False + diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/html_all.py b/tools/html_all.py new file mode 100644 index 0000000..697aa80 --- /dev/null +++ b/tools/html_all.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +import os, time +from os import path +from string import Template +import html_tilegrid +import shutil + +GM_DOCS_INDEX = """ + + +Project Peppercorn HTML Documentation + + +

Project Peppercorn HTML Documentation

+

Project Peppercorn is a project to document the GateMate bitstream and internal architecture.

+

This repository contains HTML documentation automatically generated from the +Project Peppercorn database. +Data generated includes tilemap data and bitstream data for many tile types. Click on any tile to see its bitstream +documentation. +

+
+$docs_toc +
+

Licensed under a very permissive CC0 1.0 Universal license.

+ + +""" + +def main(): + shutil.rmtree("work_html", ignore_errors=True) + os.mkdir("work_html") + commit_hash = "" #database.get_db_commit() + build_dt = time.strftime('%Y-%m-%d %H:%M:%S') + + docs_toc = "" + family = "CCGM1" + print("Family: " + family) + docs_toc += f"

{family.upper()} Family

" + docs_toc += "

Bitstream Documentation

" + docs_toc += "" + index_html = Template(GM_DOCS_INDEX).substitute( + datetime=build_dt, + commit=commit_hash, + docs_toc=docs_toc + ) + with open(path.join("work_html", "index.html"), 'w') as f: + f.write(index_html) +if __name__ == "__main__": + main() diff --git a/tools/html_tilegrid.py b/tools/html_tilegrid.py new file mode 100644 index 0000000..ca7bf03 --- /dev/null +++ b/tools/html_tilegrid.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +import sys +import argparse +import die + +parser = argparse.ArgumentParser(description=__doc__) +parser.add_argument('family', type=str, + help="FPGA family (e.g. CCGM1)") +parser.add_argument('device', type=str, + help="FPGA device (e.g. A1)") +parser.add_argument('outfile', type=argparse.FileType('w'), + help="output HTML file") + + +def get_colour(ttype): + colour = "#FFFFFF" + if ttype.startswith("SB_BIG"): + colour = "#73fc03" + elif ttype.startswith("SB_SML"): + colour = "#F0FC03" + elif ttype.startswith("GPIO"): + colour = "#88FFFF" + elif ttype.startswith("INMUX"): + colour = "#FF9040" + elif ttype.startswith("OUTMUX"): + colour = "#9040FF" + elif ttype.startswith("EDGE_IO"): + colour = "#6d6d6d" + elif ttype.startswith("EDGE_"): + colour = "#DDDDDD" + else: + colour = "#888888" + return colour + +def main(argv): + args = parser.parse_args(argv[1:]) + + max_row = die.max_row() + max_col = die.max_col() + tiles = [] + + for i in range(-2, max_row+1): + row = [] + for j in range(-2, max_col+1): + row.append([]) + tiles.append(row) + + for y in range(-2, max_row+1): + for x in range(-2, max_col+1): + if die.is_sb_big(x,y): + tiles[max_row-y][x+2].append((f"{x},{y}", "SB_BIG")) + if die.is_sb_sml(x,y): + tiles[max_row-y][x+2].append((f"{x},{y}", "SB_SML")) + if die.is_cpe(x,y): + tiles[max_row-y][x+2].append((f"{x},{y}", "CPE")) + tiles[max_row-y][x+2].append((f"{x},{y}", "INMUX")) + if die.is_outmux(x,y): + tiles[max_row-y][x+2].append((f"{x},{y}", "OUTMUX")) + if die.is_edge_left(x,y): + tiles[max_row-y][x+2].append((f"{x},{y}", "EDGE_L")) + if die.is_edge_right(x,y): + tiles[max_row-y][x+2].append((f"{x},{y}", "EDGE_R")) + if die.is_edge_bottom(x,y): + tiles[max_row-y][x+2].append((f"{x},{y}", "EDGE_B")) + if die.is_edge_top(x,y): + tiles[max_row-y][x+2].append((f"{x},{y}", "EDGE_T")) + + if die.is_gpio(x,y): + tiles[max_row-y][x+2].append((f"{x},{y}", "GPIO")) + if die.is_edge_io(x,y): + tiles[max_row-y][x+2].append((f"{x},{y}", "EDGE_IO")) + + f = args.outfile + print( + f""" + {args.family} Tiles + +

{args.device} Tilegrid

+ + """, file=f) + for trow in tiles: + print("", file=f) + row_max_height = 0 + for tloc in trow: + row_max_height = max(row_max_height, len(tloc)) + row_height = max(75, 30 * row_max_height) + for tloc in trow: + print(f"", file=f) + print("", file=f) + print("
", file=f) + for tile in tloc: + print(f"
{tile[0]}
{tile[1]}
", file=f) + print("
", file=f) + + +if __name__ == "__main__": + main(sys.argv)