OpenCores
URL https://opencores.org/ocsvn/lateq/lateq/trunk

Subversion Repositories lateq

[/] [lateq/] [trunk/] [hdl_various_types/] [src/] [lateqgen.py] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wzab
#!/usr/bin/python3
2
# This file was written by Wojciech M. Zabolotny (wzab@ise.pw.edu.pl)
3
# And is published under BSD license
4
import os
5
import sys
6
import string
7
 
8
""" Below we define the entity template, which will be later filled with generated data
9
"""
10
EntTemp="""
11
-------------------------------------------------------------------------------
12
-- Title      : Latency checker/equalizer for pipelined designs
13
-- Project    :
14
-------------------------------------------------------------------------------
15
-- This file is autmatically generated, please don't
16
-- edit it manually.
17
-- This file is generated by the tool written by Wojciech M. Zabolotny
18
-- ( wzab01<at>gmail.com )
19
-- This file is licensed under the BSD license
20
 
21
-- Libraries used
22
library  ieee;
23
use ieee.std_logic_1164.all;
24
 
25
use ieee.numeric_std.all;
26
library work;
27
${packages}
28
entity ${entity_name} is
29
  generic (
30
    LEQ_ID : string := "X"
31
    );
32
  port (
33
    -- groups of inputs and outputs automatically generated
34
${ports}
35
    -- system ports
36
    clk  : in  std_logic;
37
    rst_p  : in  std_logic
38
    );
39
end ${entity_name};
40
 
41
architecture beh of ${entity_name} is
42
  -- declarations
43
  -- definition of types and signals used in delay lines
44
${types_and_dels}
45
 
46
begin
47
  -- signal assignment and processes for delay lines
48
${delay_lines}
49
 
50
 ${delay_check}
51
 ${delay_equalize}
52
end beh;
53
 
54
"""
55
def type2init(tname):
56
    """ This function converts the type name into the name of its initialization
57
        constant. Of course it is the user responsibility to define the appropriate
58
        types and constants
59
    """
60
    tname = tname.upper()
61
    if tname[0:2] != "T_":
62
        raise(Exception("Wrong type name, should start with T_"))
63
    tname="C"+tname[1:]+"_INIT"
64
    return tname
65
 
66
if len(sys.argv)<4:
67
    appname=sys.argv[0]
68
    print(string.Template("""
69
Correct calling syntax:
70
${appname} entity_name output_file type_0 type_1 type_2
71
    """).substitute(locals()))
72
    sys.exit(0)
73
fout=open(sys.argv[2], "w")
74
ndef={}
75
ndef['entity_name']=sys.argv[1]
76
types = sys.argv[3:]
77
ndef['packages']="""
78
use work.lateq_pkg.all;
79
use work.ex1_pkg.all;
80
use work.lateq_read_pkg.all;
81
"""
82
# Generate ports definition
83
tdef=""
84
for i in range(0, len(types)):
85
    tdef += "   in"+str(i)+" : in "+types[i]+";\n"
86
    tdef += "   out"+str(i)+" : out "+types[i]+";\n"
87
ndef['ports'] = tdef
88
# Generate types and signals for delay lines
89
tdef=""
90
for i in range(0, len(types)):
91
    tdef += "   type TDEL"+str(i)+" is array (integer range <>) of "+types[i]+";\n"
92
    tdef += "   constant DLEN"+str(i)+" : integer := lateq_read_delays(LEQ_ID,"+str(i)+ ");\n"
93
    tdef += "   signal s_out"+str(i)+" : "+types[i]+";\n"
94
    tdef += "   signal del"+str(i)+" : TDEL"+str(i)+"(0 to DLEN"+str(i)+ ") := (others => "+type2init(types[i])+");\n"
95
ndef['types_and_dels'] = tdef
96
# Generate delay lines together with their processes
97
tdef=""
98
for i in range(0, len(types)):
99
    # Assign appropriate positions in the delay lines to input and output
100
    tdef += "   s_out"+str(i)+ "<= del"+str(i)+"(0);\n"
101
    # If necessary, generate the process, servicing the delay line
102
    tdef += "   gp"+str(i)+": if DLEN"+str(i)+" > 0 generate\n"
103
    tdef += "     pd"+str(i)+" : process(clk,rst_p) is\n"
104
    tdef += "     begin\n"
105
    tdef += "      if clk'event and clk='1' then\n"
106
    tdef += "         if rst_p='1' then\n"
107
    tdef += "            for i in 0 to DLEN"+str(i)+"-1 loop \n"
108
    tdef += "               del"+str(i)+"(i) <= "+type2init(types[i])+";\n"
109
    tdef += "            end loop;\n"
110
    tdef += "         else\n"
111
    tdef += "            del"+str(i)+"(DLEN"+str(i)+"-1) <= in"+str(i)+";\n"
112
    tdef += "            for i in 1 to DLEN"+str(i)+"-1 loop \n"
113
    tdef += "               del"+str(i)+"(i-1) <= del"+str(i)+"(i);\n"
114
    tdef += "            end loop;\n"
115
    tdef += "         end if;\n"
116
    tdef += "      end if;\n"
117
    tdef += "     end process pd"+str(i)+";\n"
118
    tdef += "   end generate gp"+str(i)+";\n"
119
    # Generate signal path for case when delay is 0
120
    tdef += "   gn"+str(i)+": if DLEN"+str(i)+" = 0 generate\n"
121
    tdef += "   del"+str(i)+"(0) <= in"+str(i)+";\n"
122
    tdef += "   end generate gn"+str(i)+";\n"
123
    tdef += "\n"
124
ndef['delay_lines'] = tdef
125
 
126
# Generate the delay checking and reporting part (only in simulation)
127
tdef=""
128
tdef += " --pragma translate off\n"
129
tdef += "  pc : process(clk,rst_p) is\n"
130
tdef += "     begin\n"
131
tdef += "      if clk'event and clk='1' then\n"
132
tdef += "         if rst_p='1' then\n"
133
tdef += "            null;\n"
134
tdef += "         else\n"
135
tdef += "           if C_LATEQ_MODE=0 then\n"
136
tdef += "              -- Analyzis mode, report delays\n"
137
for i in range(0,len(types)):
138
    tdef += "                lateq_report_delay(LEQ_ID,"+str(i)+",in"+str(i)+".lateq_mrk);\n"
139
tdef += "                lateq_report_end(LEQ_ID);\n"
140
tdef += "           elsif C_LATEQ_MODE=1 then\n"
141
tdef += "              -- Final verification mode, assert output latency equality\n"
142
for i in range(1,len(types)):
143
    tdef += "             if s_out0.lateq_mrk /= s_out"+str(i)+".lateq_mrk then\n"
144
    tdef += "               report LEQ_ID & \" inequal latencies: out0=\" & \n"
145
    tdef += "               lateq_mrk_to_str(s_out0.lateq_mrk) & \", out"+str(i)+"=\" &\n"
146
    tdef += "               lateq_mrk_to_str(s_out"+str(i)+".lateq_mrk) severity FAILURE;\n"
147
    tdef += "             end if;\n"
148
tdef += "           end if;\n"
149
tdef += "         end if;\n"
150
tdef += "      end if;\n"
151
tdef += "     end process pc;\n"
152
tdef += " --pragma translate on\n"
153
ndef['delay_check'] = tdef
154
 
155
# Generate the delay adjusting part
156
# Idea is to find the smallest time marker and to propagate it to all outputs.
157
tdef = ""
158
tdef += "     pu : process("
159
for i in range(0, len(types)):
160
    if i>0:
161
        tdef += ", "
162
    tdef += "s_out"+str(i)
163
tdef +=  ") is\n"
164
tdef += "--pragma translate off\n"
165
tdef += "       variable dmin : T_LATEQ_MRK;\n"
166
tdef += "--pragma translate on\n"
167
tdef += "     begin\n"
168
for i in range(0, len(types)):
169
    tdef += "   out"+str(i)+" <= s_out"+str(i)+";\n"
170
tdef += "--pragma translate off\n"
171
# Next part should be performed only for LATEQ_MODE=0
172
tdef += "     if C_LATEQ_MODE=0 then\n"
173
tdef += "       dmin := s_out0.lateq_mrk;\n"
174
for i in range(0, len(types)):
175
    tdef += "       if lateq_mrk_cmp(dmin,s_out"+str(i)+".lateq_mrk) > 0 then\n"
176
    tdef += "         dmin := s_out"+str(i)+".lateq_mrk;\n"
177
    tdef += "       end if;\n"
178
tdef += "-- now we have found the dmin, so set it in all outputs\n"
179
for i in range(0, len(types)):
180
    tdef += "   out"+str(i)+".lateq_mrk <= dmin;\n"
181
tdef += "       end if;\n"
182
tdef += "--pragma translate on\n"
183
tdef += "    end process pu;\n"
184
ndef['delay_equalize'] = tdef
185
 
186
tout=string.Template(EntTemp).substitute(ndef)
187
fout.write(tout)
188
fout.close()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.