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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
-- EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*-
-- vim: tabstop=2:shiftwidth=2:noexpandtab
-- kate: tab-width 2; replace-tabs off; indent-width 2;
--
-- =============================================================================
-- Authors: Patrick Lehmann
-- Thomas B. Preusser
--
-- Package: Simulation constants, functions and utilities.
--
-- Description:
-- ------------------------------------
-- TODO
--
-- License:
-- =============================================================================
-- Copyright 2007-2016 Technische Universitaet Dresden - Germany
-- Chair for VLSI-Design, Diagnostics and Architecture
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- =============================================================================
use STD.TextIO.all;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
library PoC;
use PoC.utils.all;
use PoC.strings.all;
use PoC.vectors.all;
use PoC.physical.all;
use PoC.sim_types.all;
package sim_protected is
-- Simulation Task and Status Management
-- ===========================================================================
type T_SIM_STATUS is protected
-- Initializer and Finalizer
procedure initialize;
procedure finalize;
-- Assertions
procedure fail(Message : STRING := "");
procedure assertion(Condition : BOOLEAN; Message : STRING := "");
procedure writeMessage(Message : STRING);
procedure writeReport;
-- Process Management
-- impure function registerProcess(Name : STRING; InstanceName : STRING) return T_SIM_PROCESS_ID;
impure function registerProcess(Name : STRING) return T_SIM_PROCESS_ID;
procedure deactivateProcess(procID : T_SIM_PROCESS_ID);
-- Test Management
impure function createTest(Name : STRING) return T_SIM_TEST_ID;
-- Run Management
procedure stopAllClocks;
impure function isStopped return BOOLEAN;
end protected;
end package;
package body sim_protected is
-- Simulation process and Status Management
-- ===========================================================================
type T_SIM_STATUS is protected body
-- status
variable IsInitialized : BOOLEAN := FALSE;
variable IsFinalized : BOOLEAN := FALSE;
-- Internal state variable to log a failure condition for final reporting.
-- Once de-asserted, this variable will never return to a value of true.
variable Passed : BOOLEAN := TRUE;
variable AssertCount : NATURAL := 0;
variable FailedAssertCount : NATURAL := 0;
-- Clock Management
variable MainClockEnable : BOOLEAN := TRUE;
-- Process Management
variable ProcessCount : NATURAL := 0;
variable ActiveProcessCount : NATURAL := 0;
variable Processes : T_SIM_PROCESS_VECTOR(T_SIM_PROCESS_ID);
-- Test Management
variable TestCount : NATURAL := 0;
variable Tests : T_SIM_TEST_VECTOR(T_SIM_TEST_ID);
-- Initializer
procedure initialize is
begin
IsInitialized := TRUE;
end procedure;
procedure finalize is
begin
if (IsFinalized = FALSE) then
if (ActiveProcessCount = 0) then
writeReport;
IsFinalized := TRUE;
end if;
end if;
end procedure;
procedure fail(Message : STRING := "") is
begin
if (Message'length > 0) then
report Message severity ERROR;
end if;
Passed := FALSE;
end procedure;
procedure assertion(condition : BOOLEAN; Message : STRING := "") is
begin
AssertCount := AssertCount + 1;
if (condition = FALSE) then
fail(Message);
FailedAssertCount := FailedAssertCount + 1;
end if;
end procedure;
procedure writeMessage(Message : STRING) is
variable LineBuffer : LINE;
begin
write(LineBuffer, Message);
writeline(output, LineBuffer);
end procedure;
procedure writeReport is
variable LineBuffer : LINE;
begin
write(LineBuffer, (CR & STRING'("========================================")));
write(LineBuffer, (CR & STRING'("POC TESTBENCH REPORT")));
write(LineBuffer, (CR & STRING'("========================================")));
write(LineBuffer, (CR & STRING'("Assertions ") & INTEGER'image(AssertCount)));
write(LineBuffer, (CR & STRING'(" failed ") & INTEGER'image(FailedAssertCount)));
write(LineBuffer, (CR & STRING'("Processes ") & INTEGER'image(ProcessCount)));
write(LineBuffer, (CR & STRING'(" active ") & INTEGER'image(ActiveProcessCount)));
for i in 0 to ProcessCount - 1 loop
if (Processes(i).Status = SIM_PROCESS_STATUS_ACTIVE) then
write(LineBuffer, (CR & STRING'(" ") & str_trim(Processes(i).Name)));
end if;
end loop;
write(LineBuffer, (CR & STRING'("Tests ") & INTEGER'image(TestCount)));
for i in 0 to TestCount - 1 loop
write(LineBuffer, (CR & STRING'(" ") & str_ralign(INTEGER'image(i), log10ceil(T_SIM_TEST_ID'high)) & ": " & str_trim(Tests(i).Name)));
end loop;
write(LineBuffer, (CR & STRING'("========================================")));
if (AssertCount = 0) then
write(LineBuffer, (CR & STRING'("SIMULATION RESULT = NO ASSERTS")));
elsif (Passed = TRUE) then
write(LineBuffer, (CR & STRING'("SIMULATION RESULT = PASSED")));
else
write(LineBuffer, (CR & STRING'("SIMULATION RESULT = FAILED")));
end if;
write(LineBuffer, (CR & STRING'("========================================")));
writeline(output, LineBuffer);
end procedure;
-- impure function registerProcess(Name : STRING; InstanceName : STRING) return T_SIM_PROCESS_ID is
impure function registerProcess(Name : STRING) return T_SIM_PROCESS_ID is
variable Proc : T_SIM_PROCESS;
begin
Proc.ID := ProcessCount;
Proc.Name := resize(Name, T_SIM_PROCESS_NAME'length);
-- Proc.InstanceName := resize(InstanceName, T_SIM_PROCESS_INSTNAME'length);
Proc.Status := SIM_PROCESS_STATUS_ACTIVE;
Processes(Proc.ID) := Proc;
ProcessCount := ProcessCount + 1;
ActiveProcessCount := ActiveProcessCount + 1;
return Proc.ID;
end function;
procedure deactivateProcess(ProcID : T_SIM_PROCESS_ID) is
variable hasActiveProcesses : BOOLEAN := FALSE;
begin
if (ProcID < ProcessCount) then
if (Processes(ProcID).Status = SIM_PROCESS_STATUS_ACTIVE) then
Processes(ProcID).Status := SIM_PROCESS_STATUS_ENDED;
ActiveProcessCount := ActiveProcessCount - 1;
end if;
end if;
if (ActiveProcessCount = 0) then
stopAllClocks;
end if;
end procedure;
impure function createTest(Name : STRING) return T_SIM_TEST_ID is
variable Test : T_SIM_TEST;
begin
Test.ID := TestCount;
Test.Name := resize(Name, T_SIM_TEST_NAME'length);
Test.Status := SIM_TEST_STATUS_ACTIVE;
Tests(Test.ID) := Test;
TestCount := TestCount + 1;
return Test.ID;
end function;
procedure stopAllClocks is
begin
MainClockEnable := FALSE;
end procedure;
impure function isStopped return BOOLEAN is
begin
return not MainClockEnable;
end function;
end protected body;
end package body;
|