blob: d1796a4ddfba305a3930176267e557bec59b03da [file] [log] [blame]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
5from enum import Enum
6
7
8class 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 Contributors802543a2019-08-31 12:12:56 +010014 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 Kim837c7962020-04-30 12:15:49 -070022# Edges = List[Edge]
23# Clocks = List[str] # If length is more than one, should be exactly two
lowRISC Contributors802543a2019-08-31 12:12:56 +010024
25# [UpstreamClock, DownstreamClock]
26
27
28class NodeType(Enum):
29 HOST = 1
30 DEVICE = 2
31 ASYNC_FIFO = 3
32 SOCKET_1N = 4
33 SOCKET_M1 = 5
34
35
36class 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 Chen09d859b2019-11-08 14:01:12 -080043 clocks = [] # Clocks # clock domains of the node
44 resets = [] # Resets # resets of the node
lowRISC Contributors802543a2019-08-31 12:12:56 +010045 # 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 Kim837c7962020-04-30 12:15:49 -070050 # address_from = 0 #: int
51 # address_to = 0 #: int
Eunchan Kimc7452942019-12-19 17:04:37 -080052 addr_range = []
lowRISC Contributors802543a2019-08-31 12:12:56 +010053
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 Chen61e25e82019-09-13 14:04:10 -070058 # 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 Contributors802543a2019-08-31 12:12:56 +010062 pipeline = False
63
Timothy Chen61e25e82019-09-13 14:04:10 -070064 # FIFO passtru option. default True
65 pipeline_byp = True
66
Timothy Chen09d859b2019-11-08 14:01:12 -080067 def __init__(self, name, node_type, clock, reset):
lowRISC Contributors802543a2019-08-31 12:12:56 +010068 self.name = name
69 self.node_type = node_type
70 self.clocks = [clock]
Timothy Chen09d859b2019-11-08 14:01:12 -080071 self.resets = [reset]
lowRISC Contributors802543a2019-08-31 12:12:56 +010072 self.us = []
73 self.ds = []
Eunchan Kimc7452942019-12-19 17:04:37 -080074 self.addr_range = []
Rupert Swarbricka5e687f2021-03-01 11:51:41 +000075
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('.', '__')