diff options
author | Gabe Black <gabeblack@google.com> | 2018-05-24 01:37:55 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-08-08 10:09:54 +0000 |
commit | 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f (patch) | |
tree | 7b6faaacb4574a555e561534aa4a8508c0624c32 /src/systemc/tests/systemc/misc/v1.0/dash0 | |
parent | 7235d3b5211d0ba8f528d930a4c1e7ad62eec51a (diff) | |
download | gem5-16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f.tar.xz |
systemc: Import tests from the Accellera systemc distribution.
Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6
Reviewed-on: https://gem5-review.googlesource.com/10845
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/tests/systemc/misc/v1.0/dash0')
-rw-r--r-- | src/systemc/tests/systemc/misc/v1.0/dash0/const.h | 62 | ||||
-rw-r--r-- | src/systemc/tests/systemc/misc/v1.0/dash0/dash0.f | 4 | ||||
-rw-r--r-- | src/systemc/tests/systemc/misc/v1.0/dash0/dist.cpp | 88 | ||||
-rw-r--r-- | src/systemc/tests/systemc/misc/v1.0/dash0/dist.h | 57 | ||||
-rw-r--r-- | src/systemc/tests/systemc/misc/v1.0/dash0/golden/dash0.log | 191 | ||||
-rw-r--r-- | src/systemc/tests/systemc/misc/v1.0/dash0/main.cpp | 112 | ||||
-rw-r--r-- | src/systemc/tests/systemc/misc/v1.0/dash0/pulse.cpp | 102 | ||||
-rw-r--r-- | src/systemc/tests/systemc/misc/v1.0/dash0/pulse.h | 63 | ||||
-rw-r--r-- | src/systemc/tests/systemc/misc/v1.0/dash0/speed.cpp | 92 | ||||
-rw-r--r-- | src/systemc/tests/systemc/misc/v1.0/dash0/speed.h | 71 |
10 files changed, 842 insertions, 0 deletions
diff --git a/src/systemc/tests/systemc/misc/v1.0/dash0/const.h b/src/systemc/tests/systemc/misc/v1.0/dash0/const.h new file mode 100644 index 000000000..233583047 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash0/const.h @@ -0,0 +1,62 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you 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. + + *****************************************************************************/ + +/***************************************************************************** + + const.h -- Constants for the dashboard controller. + + Original Author: Ali Dasdan, Synopsys, Inc. + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#ifndef CONST_H +#define CONST_H + +const int MAX_SPEED = 130; // Car speed in km/h. +const int MAX_ANGLE = 270; // Needle angle in the speedometer in degrees. + +const double DIST_BETWEEN_TWO_PULSES = 0.00066 / 2; // 1/2 of a tire in km. +const double DIST_INCR = 0.01; // One distance increment in km. + +// Two pulses are needed to compute speed. +const int NUM_PULSES_FOR_SPEED = 2; + +// DIST_INCR / DIST_BETWEEN_TWO_PULSES +const int NUM_PULSES_FOR_DIST_INCR = 61; + +const int SLOW_CLOCK_PERIOD0 = 10000; // in 10 x milliseconds. +const int FAST_CLOCK_PERIOD1 = 50; // in 10 x milliseconds. +const int ONE_HOUR = 36000000; // in 10 x milliseconds. +const int PERIODS_PER_HOUR = ONE_HOUR / FAST_CLOCK_PERIOD1; + +#define AWAIT(N) \ + for (register int i = 0; i < N; ++i) \ + wait(); + +#endif diff --git a/src/systemc/tests/systemc/misc/v1.0/dash0/dash0.f b/src/systemc/tests/systemc/misc/v1.0/dash0/dash0.f new file mode 100644 index 000000000..787379cf9 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash0/dash0.f @@ -0,0 +1,4 @@ +dash0/main.cpp +dash0/dist.cpp +dash0/pulse.cpp +dash0/speed.cpp diff --git a/src/systemc/tests/systemc/misc/v1.0/dash0/dist.cpp b/src/systemc/tests/systemc/misc/v1.0/dash0/dist.cpp new file mode 100644 index 000000000..8056060ba --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash0/dist.cpp @@ -0,0 +1,88 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you 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. + + *****************************************************************************/ + +/***************************************************************************** + + dist.cpp -- Implementation of the odometers. + + Original Author: Ali Dasdan, Synopsys, Inc. + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +// $Log: dist.cpp,v $ +// Revision 1.1.1.1 2006/12/15 20:26:24 acg +// systemc_tests-2.3 +// +// Revision 1.4 2006/01/24 21:05:51 acg +// Andy Goodrich: replacement of deprecated features with their non-deprecated +// counterparts. +// +// Revision 1.3 2006/01/19 00:48:10 acg +// Andy Goodrich: Changes for the fact signal write checking is enabled. +// +// Revision 1.2 2006/01/18 00:23:44 acg +// Change over from SC_NO_WRITE_CHECK to sc_write_check_enable() call. +// + +#define SC_NO_WRITE_CHECK +#include "systemc.h" +#include "const.h" +#include "dist.h" + +// Compute the total and partial distances travelled. +void +dist_mod::get_dist_proc() +{ + wait(); + + double total = 0.0; + double partial = 0.0; + + while (true) { + + // More than one pulse is needed for a distance increment. This + // function collects NUM_PULSES_FOR_DIST_INCR pulses for that + // purpose. + AWAIT(NUM_PULSES_FOR_DIST_INCR); + + // Increment the distances: + total = total + DIST_INCR; + partial = partial + DIST_INCR; + + cout << "Current total distance displayed = " + << total << " km @ " << sc_time_stamp() << endl; + cout << "Current partial distance displayed = " + << partial << " km @ " << sc_time_stamp() << endl; + + if (total >= 3 * DIST_INCR) + sc_stop(); + } +} + +// End of file diff --git a/src/systemc/tests/systemc/misc/v1.0/dash0/dist.h b/src/systemc/tests/systemc/misc/v1.0/dash0/dist.h new file mode 100644 index 000000000..9eb449ad7 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash0/dist.h @@ -0,0 +1,57 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you 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. + + *****************************************************************************/ + +/***************************************************************************** + + dist.h -- Definition of the odometers. + + Original Author: Ali Dasdan, Synopsys, Inc. + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#ifndef DIST_H +#define DIST_H + +SC_MODULE( dist_mod ) +{ + // Ports: + sc_in<bool> pulse; // Pulse coming ftom the pulse generator. + + // Compute the total and partial distances travelled. + void get_dist_proc(); + + SC_CTOR( dist_mod ) + { + SC_THREAD( get_dist_proc ); + sensitive << pulse.pos(); + } + +}; + +#endif diff --git a/src/systemc/tests/systemc/misc/v1.0/dash0/golden/dash0.log b/src/systemc/tests/systemc/misc/v1.0/dash0/golden/dash0.log new file mode 100644 index 000000000..e3c2c7c53 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash0/golden/dash0.log @@ -0,0 +1,191 @@ +SystemC Simulation +Current speed displayed = 79.2 km/h @ 100 ns +Current speedometer angle = 164.492 degrees @ 100 ns +Current speed displayed = 118.8 km/h @ 200 ns +Current speedometer angle = 246.738 degrees @ 200 ns +Current speed displayed = 118.8 km/h @ 300 ns +Current speedometer angle = 246.738 degrees @ 300 ns +Current speed displayed = 118.8 km/h @ 400 ns +Current speedometer angle = 246.738 degrees @ 400 ns +Current speed displayed = 118.8 km/h @ 500 ns +Current speedometer angle = 246.738 degrees @ 500 ns +Current speed displayed = 118.8 km/h @ 600 ns +Current speedometer angle = 246.738 degrees @ 600 ns +Current speed displayed = 118.8 km/h @ 700 ns +Current speedometer angle = 246.738 degrees @ 700 ns +Current speed displayed = 118.8 km/h @ 800 ns +Current speedometer angle = 246.738 degrees @ 800 ns +Current speed displayed = 118.8 km/h @ 900 ns +Current speedometer angle = 246.738 degrees @ 900 ns +Current speed displayed = 118.8 km/h @ 1 us +Current speedometer angle = 246.738 degrees @ 1 us +Current speed displayed = 118.8 km/h @ 1100 ns +Current speedometer angle = 246.738 degrees @ 1100 ns +Current speed displayed = 118.8 km/h @ 1200 ns +Current speedometer angle = 246.738 degrees @ 1200 ns +Current speed displayed = 118.8 km/h @ 1300 ns +Current speedometer angle = 246.738 degrees @ 1300 ns +Current speed displayed = 118.8 km/h @ 1400 ns +Current speedometer angle = 246.738 degrees @ 1400 ns +Current speed displayed = 118.8 km/h @ 1500 ns +Current speedometer angle = 246.738 degrees @ 1500 ns +Current speed displayed = 118.8 km/h @ 1600 ns +Current speedometer angle = 246.738 degrees @ 1600 ns +Current speed displayed = 118.8 km/h @ 1700 ns +Current speedometer angle = 246.738 degrees @ 1700 ns +Current speed displayed = 118.8 km/h @ 1800 ns +Current speedometer angle = 246.738 degrees @ 1800 ns +Current speed displayed = 118.8 km/h @ 1900 ns +Current speedometer angle = 246.738 degrees @ 1900 ns +Current speed displayed = 118.8 km/h @ 2 us +Current speedometer angle = 246.738 degrees @ 2 us +Current speed displayed = 118.8 km/h @ 2100 ns +Current speedometer angle = 246.738 degrees @ 2100 ns +Current speed displayed = 118.8 km/h @ 2200 ns +Current speedometer angle = 246.738 degrees @ 2200 ns +Current speed displayed = 118.8 km/h @ 2300 ns +Current speedometer angle = 246.738 degrees @ 2300 ns +Current speed displayed = 118.8 km/h @ 2400 ns +Current speedometer angle = 246.738 degrees @ 2400 ns +Current speed displayed = 118.8 km/h @ 2500 ns +Current speedometer angle = 246.738 degrees @ 2500 ns +Current speed displayed = 118.8 km/h @ 2600 ns +Current speedometer angle = 246.738 degrees @ 2600 ns +Current speed displayed = 118.8 km/h @ 2700 ns +Current speedometer angle = 246.738 degrees @ 2700 ns +Current speed displayed = 118.8 km/h @ 2800 ns +Current speedometer angle = 246.738 degrees @ 2800 ns +Current speed displayed = 118.8 km/h @ 2900 ns +Current speedometer angle = 246.738 degrees @ 2900 ns +Current speed displayed = 118.8 km/h @ 3 us +Current speedometer angle = 246.738 degrees @ 3 us +Current total distance displayed = 0.01 km @ 3050 ns +Current partial distance displayed = 0.01 km @ 3050 ns +Current speed displayed = 118.8 km/h @ 3100 ns +Current speedometer angle = 246.738 degrees @ 3100 ns +Current speed displayed = 118.8 km/h @ 3200 ns +Current speedometer angle = 246.738 degrees @ 3200 ns +Current speed displayed = 118.8 km/h @ 3300 ns +Current speedometer angle = 246.738 degrees @ 3300 ns +Current speed displayed = 118.8 km/h @ 3400 ns +Current speedometer angle = 246.738 degrees @ 3400 ns +Current speed displayed = 118.8 km/h @ 3500 ns +Current speedometer angle = 246.738 degrees @ 3500 ns +Current speed displayed = 118.8 km/h @ 3600 ns +Current speedometer angle = 246.738 degrees @ 3600 ns +Current speed displayed = 118.8 km/h @ 3700 ns +Current speedometer angle = 246.738 degrees @ 3700 ns +Current speed displayed = 118.8 km/h @ 3800 ns +Current speedometer angle = 246.738 degrees @ 3800 ns +Current speed displayed = 118.8 km/h @ 3900 ns +Current speedometer angle = 246.738 degrees @ 3900 ns +Current speed displayed = 118.8 km/h @ 4 us +Current speedometer angle = 246.738 degrees @ 4 us +Current speed displayed = 118.8 km/h @ 4100 ns +Current speedometer angle = 246.738 degrees @ 4100 ns +Current speed displayed = 118.8 km/h @ 4200 ns +Current speedometer angle = 246.738 degrees @ 4200 ns +Current speed displayed = 118.8 km/h @ 4300 ns +Current speedometer angle = 246.738 degrees @ 4300 ns +Current speed displayed = 118.8 km/h @ 4400 ns +Current speedometer angle = 246.738 degrees @ 4400 ns +Current speed displayed = 118.8 km/h @ 4500 ns +Current speedometer angle = 246.738 degrees @ 4500 ns +Current speed displayed = 118.8 km/h @ 4600 ns +Current speedometer angle = 246.738 degrees @ 4600 ns +Current speed displayed = 118.8 km/h @ 4700 ns +Current speedometer angle = 246.738 degrees @ 4700 ns +Current speed displayed = 118.8 km/h @ 4800 ns +Current speedometer angle = 246.738 degrees @ 4800 ns +Current speed displayed = 118.8 km/h @ 4900 ns +Current speedometer angle = 246.738 degrees @ 4900 ns +Current speed displayed = 118.8 km/h @ 5 us +Current speedometer angle = 246.738 degrees @ 5 us +Current speed displayed = 118.8 km/h @ 5100 ns +Current speedometer angle = 246.738 degrees @ 5100 ns +Current speed displayed = 118.8 km/h @ 5200 ns +Current speedometer angle = 246.738 degrees @ 5200 ns +Current speed displayed = 118.8 km/h @ 5300 ns +Current speedometer angle = 246.738 degrees @ 5300 ns +Current speed displayed = 118.8 km/h @ 5400 ns +Current speedometer angle = 246.738 degrees @ 5400 ns +Current speed displayed = 118.8 km/h @ 5500 ns +Current speedometer angle = 246.738 degrees @ 5500 ns +Current speed displayed = 118.8 km/h @ 5600 ns +Current speedometer angle = 246.738 degrees @ 5600 ns +Current speed displayed = 118.8 km/h @ 5700 ns +Current speedometer angle = 246.738 degrees @ 5700 ns +Current speed displayed = 118.8 km/h @ 5800 ns +Current speedometer angle = 246.738 degrees @ 5800 ns +Current speed displayed = 118.8 km/h @ 5900 ns +Current speedometer angle = 246.738 degrees @ 5900 ns +Current speed displayed = 118.8 km/h @ 6 us +Current speedometer angle = 246.738 degrees @ 6 us +Current speed displayed = 118.8 km/h @ 6100 ns +Current speedometer angle = 246.738 degrees @ 6100 ns +Current total distance displayed = 0.02 km @ 6100 ns +Current partial distance displayed = 0.02 km @ 6100 ns +Current speed displayed = 118.8 km/h @ 6200 ns +Current speedometer angle = 246.738 degrees @ 6200 ns +Current speed displayed = 118.8 km/h @ 6300 ns +Current speedometer angle = 246.738 degrees @ 6300 ns +Current speed displayed = 118.8 km/h @ 6400 ns +Current speedometer angle = 246.738 degrees @ 6400 ns +Current speed displayed = 118.8 km/h @ 6500 ns +Current speedometer angle = 246.738 degrees @ 6500 ns +Current speed displayed = 118.8 km/h @ 6600 ns +Current speedometer angle = 246.738 degrees @ 6600 ns +Current speed displayed = 118.8 km/h @ 6700 ns +Current speedometer angle = 246.738 degrees @ 6700 ns +Current speed displayed = 118.8 km/h @ 6800 ns +Current speedometer angle = 246.738 degrees @ 6800 ns +Current speed displayed = 118.8 km/h @ 6900 ns +Current speedometer angle = 246.738 degrees @ 6900 ns +Current speed displayed = 118.8 km/h @ 7 us +Current speedometer angle = 246.738 degrees @ 7 us +Current speed displayed = 118.8 km/h @ 7100 ns +Current speedometer angle = 246.738 degrees @ 7100 ns +Current speed displayed = 118.8 km/h @ 7200 ns +Current speedometer angle = 246.738 degrees @ 7200 ns +Current speed displayed = 118.8 km/h @ 7300 ns +Current speedometer angle = 246.738 degrees @ 7300 ns +Current speed displayed = 118.8 km/h @ 7400 ns +Current speedometer angle = 246.738 degrees @ 7400 ns +Current speed displayed = 118.8 km/h @ 7500 ns +Current speedometer angle = 246.738 degrees @ 7500 ns +Current speed displayed = 118.8 km/h @ 7600 ns +Current speedometer angle = 246.738 degrees @ 7600 ns +Current speed displayed = 118.8 km/h @ 7700 ns +Current speedometer angle = 246.738 degrees @ 7700 ns +Current speed displayed = 118.8 km/h @ 7800 ns +Current speedometer angle = 246.738 degrees @ 7800 ns +Current speed displayed = 118.8 km/h @ 7900 ns +Current speedometer angle = 246.738 degrees @ 7900 ns +Current speed displayed = 118.8 km/h @ 8 us +Current speedometer angle = 246.738 degrees @ 8 us +Current speed displayed = 118.8 km/h @ 8100 ns +Current speedometer angle = 246.738 degrees @ 8100 ns +Current speed displayed = 118.8 km/h @ 8200 ns +Current speedometer angle = 246.738 degrees @ 8200 ns +Current speed displayed = 118.8 km/h @ 8300 ns +Current speedometer angle = 246.738 degrees @ 8300 ns +Current speed displayed = 118.8 km/h @ 8400 ns +Current speedometer angle = 246.738 degrees @ 8400 ns +Current speed displayed = 118.8 km/h @ 8500 ns +Current speedometer angle = 246.738 degrees @ 8500 ns +Current speed displayed = 118.8 km/h @ 8600 ns +Current speedometer angle = 246.738 degrees @ 8600 ns +Current speed displayed = 118.8 km/h @ 8700 ns +Current speedometer angle = 246.738 degrees @ 8700 ns +Current speed displayed = 118.8 km/h @ 8800 ns +Current speedometer angle = 246.738 degrees @ 8800 ns +Current speed displayed = 118.8 km/h @ 8900 ns +Current speedometer angle = 246.738 degrees @ 8900 ns +Current speed displayed = 118.8 km/h @ 9 us +Current speedometer angle = 246.738 degrees @ 9 us +Current speed displayed = 118.8 km/h @ 9100 ns +Current speedometer angle = 246.738 degrees @ 9100 ns +Current total distance displayed = 0.03 km @ 9150 ns +Current partial distance displayed = 0.03 km @ 9150 ns + +Info: /OSCI/SystemC: Simulation stopped by user. diff --git a/src/systemc/tests/systemc/misc/v1.0/dash0/main.cpp b/src/systemc/tests/systemc/misc/v1.0/dash0/main.cpp new file mode 100644 index 000000000..f31ae8c8a --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash0/main.cpp @@ -0,0 +1,112 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you 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. + + *****************************************************************************/ + +/***************************************************************************** + + main.cpp -- Main function for the dashboard controller for a + car. This controller contains a speedometer, two odometers (total + and partial distance), a clock, and the pulse generator. The + pulses are generated by the sensors placed around one of the wheel + shafts. The rate of pulse generation is determined by the speed of + the car, which is constant at 120 km/h. The clock represents the + real time. The signals in this program are traced. The simulation + is stopped by the odometers module. + + purpose -- no environment module; multiple modules at one level; + single processes within each module; input, output and clock + ports; internal and external signals; asynchronous function and + thread processes; one clock; tracing. + + Original Author: Ali Dasdan, Synopsys, Inc. + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +// $Log: main.cpp,v $ +// Revision 1.2 2011/01/07 01:20:19 acg +// Andy Goodrich: update for new IEEE 1666. +// +// Revision 1.1.1.1 2006/12/15 20:26:24 acg +// systemc_tests-2.3 +// +// Revision 1.5 2006/01/24 21:05:51 acg +// Andy Goodrich: replacement of deprecated features with their non-deprecated +// counterparts. +// +// Revision 1.4 2006/01/20 00:43:24 acg +// Andy Goodrich: Changed over to use putenv() instead of setenv() to accommodate old versions of Solaris. +// +// Revision 1.3 2006/01/19 00:48:10 acg +// Andy Goodrich: Changes for the fact signal write checking is enabled. +// +// Revision 1.2 2006/01/18 00:23:44 acg +// Change over from SC_NO_WRITE_CHECK to sc_write_check_enable() call. +// + +#define SC_NO_WRITE_CHECK +#include "systemc.h" +#include "const.h" +#include "pulse.h" +#include "speed.h" +#include "dist.h" + +int +sc_main(int argc, char *argv[]) +{ + // Pulses for the speedometer and odometers, generated by the pulse + // generator. + sc_signal<bool> speed_pulses("speed_pulses"); + sc_signal<bool> dist_pulses("dist_pulses"); + // Clocks. + sc_clock clk1("fast_clk", FAST_CLOCK_PERIOD1, SC_NS, 0.5, 0.0, SC_NS, false); + + gen_pulse_mod gen_pulse("gen_pulse"); + gen_pulse(clk1, speed_pulses, dist_pulses); + + speed_mod speedometer("speedometer"); + speedometer(clk1, speed_pulses); + + dist_mod odometers("odometers"); + odometers(dist_pulses); + + // Tracing: + // Trace file creation. + sc_trace_file *tf = sc_create_vcd_trace_file("dash"); + // External signals. + sc_trace(tf, clk1, "fast_clk"); + sc_trace(tf, speed_pulses, "speed_pulses"); + sc_trace(tf, dist_pulses, "dist_pulses"); + // Internal signals. + sc_trace(tf, speedometer.elapsed_time, "elapsed_time"); + + sc_start(); + + return 0; +} + +// End of file diff --git a/src/systemc/tests/systemc/misc/v1.0/dash0/pulse.cpp b/src/systemc/tests/systemc/misc/v1.0/dash0/pulse.cpp new file mode 100644 index 000000000..db885b1e0 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash0/pulse.cpp @@ -0,0 +1,102 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you 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. + + *****************************************************************************/ + +/***************************************************************************** + + pulse.cpp -- Implementation of the pulse generator. + + Original Author: Ali Dasdan, Synopsys, Inc. + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +// $Log: pulse.cpp,v $ +// Revision 1.1.1.1 2006/12/15 20:26:24 acg +// systemc_tests-2.3 +// +// Revision 1.4 2006/01/24 21:05:51 acg +// Andy Goodrich: replacement of deprecated features with their non-deprecated +// counterparts. +// +// Revision 1.3 2006/01/19 00:48:10 acg +// Andy Goodrich: Changes for the fact signal write checking is enabled. +// +// Revision 1.2 2006/01/18 00:23:44 acg +// Change over from SC_NO_WRITE_CHECK to sc_write_check_enable() call. +// + +#define SC_NO_WRITE_CHECK +#include "systemc.h" +#include "const.h" +#include "pulse.h" + +// Find the pulse period to produce speed. +// This function also rounds the period to the nearest integer. +int +gen_pulse_mod::find_period(int speed) +{ + if (speed <= 0) + return 1; + + const double num = DIST_BETWEEN_TWO_PULSES * PERIODS_PER_HOUR / 2; + + double dp = num / speed; + int ip = int(dp); + + ip = ip + ((dp - ip) >= double(0.5) ? 1 : 0); + + return ip; +} + +// Generate pulses for speedometer and odometers. +void +gen_pulse_mod::gen_pulse_proc() +{ + wait(); + + speed_pulse = false; + dist_pulse = false; + int speed = 120; + + while (true) { + +#ifdef DEBUG + cout << "Pulses were generated @ " << sc_time_stamp() << endl; +#endif + + speed_pulse = true; + dist_pulse = true; + AWAIT(find_period(speed)); + + speed_pulse = false; + dist_pulse = false; + AWAIT(find_period(speed)); + } +} + +// End of file diff --git a/src/systemc/tests/systemc/misc/v1.0/dash0/pulse.h b/src/systemc/tests/systemc/misc/v1.0/dash0/pulse.h new file mode 100644 index 000000000..d11f80185 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash0/pulse.h @@ -0,0 +1,63 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you 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. + + *****************************************************************************/ + +/***************************************************************************** + + pulse.h -- Definition of the pulse generator. + + Original Author: Ali Dasdan, Synopsys, Inc. + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#ifndef PULSE_H +#define PULSE_H + +SC_MODULE( gen_pulse_mod ) +{ + // Ports: + sc_in_clk clk; // Clock for the pulse generator. + sc_out<bool> speed_pulse; // Pulses for the speedometer. + sc_out<bool> dist_pulse; // Pulses for the odometers. + + // Find the pulse period to produce speed. + int find_period(int speed); + + // Generate pulses for speedometer and odometers. + void gen_pulse_proc(); + + SC_CTOR( gen_pulse_mod ) + { + SC_THREAD( gen_pulse_proc ); + sensitive << clk; + } + +}; + +#endif + diff --git a/src/systemc/tests/systemc/misc/v1.0/dash0/speed.cpp b/src/systemc/tests/systemc/misc/v1.0/dash0/speed.cpp new file mode 100644 index 000000000..012a8428e --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash0/speed.cpp @@ -0,0 +1,92 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you 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. + + *****************************************************************************/ + +/***************************************************************************** + + speed.cpp -- Definition of the speedometer. + + Original Author: Ali Dasdan, Synopsys, Inc. + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +// $Log: speed.cpp,v $ +// Revision 1.1.1.1 2006/12/15 20:26:24 acg +// systemc_tests-2.3 +// +// Revision 1.4 2006/01/24 21:05:52 acg +// Andy Goodrich: replacement of deprecated features with their non-deprecated +// counterparts. +// +// Revision 1.3 2006/01/19 00:48:10 acg +// Andy Goodrich: Changes for the fact signal write checking is enabled. +// +// Revision 1.2 2006/01/18 00:23:44 acg +// Change over from SC_NO_WRITE_CHECK to sc_write_check_enable() call. +// + +#define SC_NO_WRITE_CHECK +#include "systemc.h" +#include "const.h" +#include "speed.h" + +// Find the elapsed_time between NUM_PULSES_FOR_SPEED pulses. +void speed_mod::find_time_proc() +{ + elapsed_time = elapsed_time + 1; +} + +// Compute speed. +void +speed_mod::read_speed_proc() +{ + wait(); + + double speed = 0.0; + + while (true) { + + // More than one pulse is needed to compute a distance and + // consequently, speed. This function collects NUM_PULSES_FOR_SPEED + // pulses for that purpose. + AWAIT(NUM_PULSES_FOR_SPEED); + + speed = DIST_BETWEEN_TWO_PULSES * PERIODS_PER_HOUR / elapsed_time; + + // Reset timer. + elapsed_time = 0; + + cout << "Current speed displayed = " + << speed << " km/h @ " << sc_time_stamp() << endl; + cout << "Current speedometer angle = " + << speed * MAX_ANGLE / MAX_SPEED + << " degrees @ " << sc_time_stamp() << endl; + } +} + +// End of file diff --git a/src/systemc/tests/systemc/misc/v1.0/dash0/speed.h b/src/systemc/tests/systemc/misc/v1.0/dash0/speed.h new file mode 100644 index 000000000..821b36c25 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash0/speed.h @@ -0,0 +1,71 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you 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. + + *****************************************************************************/ + +/***************************************************************************** + + speed.h -- Definition of the speedometer. + + Original Author: Ali Dasdan, Synopsys, Inc. + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#ifndef SPEED_H +#define SPEED_H + +SC_MODULE( speed_mod ) +{ + // Ports: + sc_in_clk clk; // Clock to measure the time, needed to compute the speed. + sc_in<bool> pulse; // Pulse coming from the pulse generator. + + // Internal signals: + sc_signal<int> elapsed_time; + + // Find the elapsed_time between NUM_PULSES_FOR_SPEED pulses. + void find_time_proc(); + + // Compute speed. + void read_speed_proc(); + + SC_CTOR( speed_mod ) + { + // Initialize time. + elapsed_time = 0; + + SC_METHOD( find_time_proc ); + sensitive << clk.pos(); + + SC_THREAD( read_speed_proc ); + sensitive << pulse.pos(); + } + +}; + +#endif + |