File: html_tilegrid.py

package info (click to toggle)
prjpeppercorn 1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,756 kB
  • sloc: python: 5,518; cpp: 2,634; makefile: 37; sh: 15
file content (105 lines) | stat: -rw-r--r-- 3,426 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python3
#
#  prjpeppercorn -- GateMate FPGAs Bitstream Documentation and Tools
#
#  Copyright (C) 2024  The Project Peppercorn Authors.
#
#  Permission to use, copy, modify, and/or distribute this software for any
#  purpose with or without fee is hereby granted, provided that the above
#  copyright notice and this permission notice appear in all copies.
#
#  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
#  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
#  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
#  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
#  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
#  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

import sys
import argparse
import chip
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):
    match ttype:
        case "CPE":
            colour = "#ACC8E6"
        case "SB_BIG":
            colour = "#9CC763"
        case "SB_SML":
            colour = "#F8EA56"
        case "GPIO":
            colour = "#B699D4"
        case "IM":
            colour = "#FFC51F"
        case "OM":
            colour = "#D19537"
        case "IOES":
            colour = "#6D6D6D"
        case "LES" | "RES" | "TES" | "BES":
            colour = "#FDD3D3"
        case "PLL":
            colour = "#FF7ABE"
        case "SERDES":
            colour = "#64FF65"
        case "CFG_CTRL":
            colour = "#999999"
        case _:
            colour = "#FFFFFF"
    return colour

def main(argv):
    args = parser.parse_args(argv[1:])
    ch = chip.get_device(args.device)

    max_row = ch.max_row()
    max_col = ch.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):
            for type in ch.get_tile_types(x,y):
                tiles[max_row-y][x+2].append((f"{x},{y}", type))

    f = args.outfile
    print(
        f"""<html>
            <head><title>{args.family} Tiles</title></head>
            <body>
            <h1>{args.device} Tilegrid</h1>
            <table style='font-size: 8pt; border: 2px solid black; text-align: center'>
        """, file=f)
    for trow in tiles:
        print("<tr>", file=f)
        row_max_height = 0
        for tloc in trow:
            row_max_height = max(row_max_height, len(tloc))
        row_height = max(90, 30 * row_max_height)
        for tloc in trow:
            print(f"<td style='border: 2px solid black; height: {row_height}px'>", file=f)
            for tile in tloc:
                print(f"<div style='height: {100 / len(tloc)}%; background-color: {get_colour(tile[1])}'><em>{tile[0]}</em><br/><strong>{tile[1]}</strong></div>", file=f)
            print("</td>", file=f)
        print("</tr>", file=f)
    print("</table></body></html>", file=f)


if __name__ == "__main__":
    main(sys.argv)