lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | # Copyright lowRISC contributors. |
| 2 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | |
| 5 | from enum import Enum |
| 6 | |
| 7 | |
| 8 | class Edge: |
| 9 | """Edge class contains the connection from a node to a node. |
| 10 | |
| 11 | a Node can be a host port, output of async_fifo, port in a socket, |
| 12 | or a device port. |
| 13 | """ |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 14 | def __init__(self, us, ds): |
| 15 | self.us = us |
| 16 | self.ds = ds |
| 17 | |
| 18 | def __repr__(self): |
| 19 | return "U(%s) D(%s)" % (self.us.name, self.ds.name) |
| 20 | |
| 21 | |
Eunchan Kim | 837c796 | 2020-04-30 12:15:49 -0700 | [diff] [blame] | 22 | # Edges = List[Edge] |
| 23 | # Clocks = List[str] # If length is more than one, should be exactly two |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 24 | |
| 25 | # [UpstreamClock, DownstreamClock] |
| 26 | |
| 27 | |
| 28 | class NodeType(Enum): |
| 29 | HOST = 1 |
| 30 | DEVICE = 2 |
| 31 | ASYNC_FIFO = 3 |
| 32 | SOCKET_1N = 4 |
| 33 | SOCKET_M1 = 5 |
| 34 | |
| 35 | |
| 36 | class Node: |
| 37 | """Node class is a port that communicates from/to other Node or TL-UL |
| 38 | input/output. |
| 39 | """ |
| 40 | |
| 41 | name = "" # name: str |
| 42 | # node_type: NodeType |
Timothy Chen | 09d859b | 2019-11-08 14:01:12 -0800 | [diff] [blame] | 43 | clocks = [] # Clocks # clock domains of the node |
| 44 | resets = [] # Resets # resets of the node |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 45 | # e.g. async_fifo in : clk_core , out : clk_main |
| 46 | |
| 47 | # If NodeType is Socket out from 1:N then address steering is used |
| 48 | # But this value is also propagated up to a Host from multiple Devices |
| 49 | # Device Node should have address_from, address_to |
Eunchan Kim | 837c796 | 2020-04-30 12:15:49 -0700 | [diff] [blame] | 50 | # address_from = 0 #: int |
| 51 | # address_to = 0 #: int |
Eunchan Kim | c745294 | 2019-12-19 17:04:37 -0800 | [diff] [blame] | 52 | addr_range = [] |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 53 | |
| 54 | us = [] # Edges # Number of Ports depends on the NodeType |
| 55 | # 1 for Host, Device, 2 for Async FIFO, N for Sockets |
| 56 | ds = [] # Edges |
| 57 | |
Timothy Chen | 61e25e8 | 2019-09-13 14:04:10 -0700 | [diff] [blame] | 58 | # Req/Rsp FIFO. default False |
| 59 | # when False, FIFO fully passthrough, no storage element |
| 60 | # when True, FIFO present with default depth, "pipeline_byp" |
| 61 | # controls passthrough option |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 62 | pipeline = False |
| 63 | |
Timothy Chen | 61e25e8 | 2019-09-13 14:04:10 -0700 | [diff] [blame] | 64 | # FIFO passtru option. default True |
| 65 | pipeline_byp = True |
| 66 | |
Timothy Chen | 09d859b | 2019-11-08 14:01:12 -0800 | [diff] [blame] | 67 | def __init__(self, name, node_type, clock, reset): |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 68 | self.name = name |
| 69 | self.node_type = node_type |
| 70 | self.clocks = [clock] |
Timothy Chen | 09d859b | 2019-11-08 14:01:12 -0800 | [diff] [blame] | 71 | self.resets = [reset] |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 72 | self.us = [] |
| 73 | self.ds = [] |
Eunchan Kim | c745294 | 2019-12-19 17:04:37 -0800 | [diff] [blame] | 74 | self.addr_range = [] |
Rupert Swarbrick | a5e687f | 2021-03-01 11:51:41 +0000 | [diff] [blame] | 75 | |
| 76 | def esc_name(self) -> str: |
| 77 | '''Return an "escaped name" for this node |
| 78 | |
| 79 | This replaces '.' characters with '__'. Needed because the node name |
| 80 | might be of the form inst_name.if_name (which isn't a valid symbol name |
| 81 | in C or SystemVerilog) |
| 82 | |
| 83 | ''' |
| 84 | return self.name.replace('.', '__') |