From 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 24 May 2018 01:37:55 -0700 Subject: systemc: Import tests from the Accellera systemc distribution. Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6 Reviewed-on: https://gem5-review.googlesource.com/10845 Reviewed-by: Giacomo Travaglini Maintainer: Gabe Black --- src/systemc/tests/systemc/misc/v1.0/dash7/const.h | 62 ++++++++ src/systemc/tests/systemc/misc/v1.0/dash7/dash7.f | 5 + src/systemc/tests/systemc/misc/v1.0/dash7/dist.cpp | 134 ++++++++++++++++ src/systemc/tests/systemc/misc/v1.0/dash7/dist.h | 177 +++++++++++++++++++++ .../tests/systemc/misc/v1.0/dash7/driver.cpp | 124 +++++++++++++++ src/systemc/tests/systemc/misc/v1.0/dash7/driver.h | 69 ++++++++ .../tests/systemc/misc/v1.0/dash7/golden/dash7.log | 35 ++++ src/systemc/tests/systemc/misc/v1.0/dash7/main.cpp | 157 ++++++++++++++++++ .../tests/systemc/misc/v1.0/dash7/pulse.cpp | 101 ++++++++++++ src/systemc/tests/systemc/misc/v1.0/dash7/pulse.h | 63 ++++++++ .../tests/systemc/misc/v1.0/dash7/speed.cpp | 111 +++++++++++++ src/systemc/tests/systemc/misc/v1.0/dash7/speed.h | 148 +++++++++++++++++ 12 files changed, 1186 insertions(+) create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/const.h create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/dash7.f create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/dist.cpp create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/dist.h create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/driver.cpp create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/driver.h create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/golden/dash7.log create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/main.cpp create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/pulse.cpp create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/pulse.h create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/speed.cpp create mode 100644 src/systemc/tests/systemc/misc/v1.0/dash7/speed.h (limited to 'src/systemc/tests/systemc/misc/v1.0/dash7') diff --git a/src/systemc/tests/systemc/misc/v1.0/dash7/const.h b/src/systemc/tests/systemc/misc/v1.0/dash7/const.h new file mode 100644 index 000000000..9bc1ed3bf --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/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/dash7/dash7.f b/src/systemc/tests/systemc/misc/v1.0/dash7/dash7.f new file mode 100644 index 000000000..319d6fb4f --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/dash7.f @@ -0,0 +1,5 @@ +dash7/driver.cpp +dash7/dist.cpp +dash7/main.cpp +dash7/pulse.cpp +dash7/speed.cpp diff --git a/src/systemc/tests/systemc/misc/v1.0/dash7/dist.cpp b/src/systemc/tests/systemc/misc/v1.0/dash7/dist.cpp new file mode 100644 index 000000000..7080a461f --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/dist.cpp @@ -0,0 +1,134 @@ +/***************************************************************************** + + 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.3 2006/01/19 00:48:20 acg +// Andy Goodrich: Changes for the fact signal write checking is enabled. +// +// Revision 1.2 2006/01/18 00:23:51 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" + +bool dist_compute_mod::prev_reset; +double dist_compute_mod::total_compute_dist; +double dist_compute_mod::partial_compute_dist; + +// Get the pulses for one distance increment. +void +dist_read_mod::get_dist_proc() +{ + wait(); + + bool ok = false; + + 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); + + if (start) + ok = !ok; + else + ok = false; + + ok_for_incr = ok; + } +} + +// Compute total distance. +void +dist_compute_mod::compute_total_proc() +{ + if (start) + total_compute_dist += 1.0; + else + total_compute_dist = 0.0; + + total_dist = total_compute_dist; +} + +// Compute partial distance. +void +dist_compute_mod::compute_partial_proc() +{ + if (start) { + + // Implement reset.event(): + if (prev_reset != (bool) reset) + partial_compute_dist = 0.0; + else + partial_compute_dist += 1.0; + + prev_reset = reset; + + } + else + partial_compute_dist = 0.0; + + partial_dist = partial_compute_dist; +} + +// LCD display driver. +void +dist_lcd_mod::lcd_driver_proc() +{ + if (start) { + + if (total_dist.event()) + total = total_dist * DIST_INCR; + + if (partial_dist.event()) + partial = partial_dist * DIST_INCR; + + } + else { + total = 0.0; + partial = 0.0; + } +} + +// End of file diff --git a/src/systemc/tests/systemc/misc/v1.0/dash7/dist.h b/src/systemc/tests/systemc/misc/v1.0/dash7/dist.h new file mode 100644 index 000000000..0285b557e --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/dist.h @@ -0,0 +1,177 @@ +/***************************************************************************** + + 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_read_mod ) +{ + // Input ports: + sc_in pulse; // Pulse coming from the pulse generator. + sc_in start; // Becomes true if the car's started. + + // Output ports: + sc_out ok_for_incr; + + // Get the pulses for one distance increment. + void get_dist_proc(); + + SC_CTOR( dist_read_mod ) + { + SC_THREAD( get_dist_proc ); + sensitive << pulse.pos(); + } +}; + +SC_MODULE( dist_compute_mod ) +{ + // Input ports: + sc_in reset; // Reset the partial distance odometer if true. + sc_in start; // Becomes true if the car's started. + sc_in ok_for_incr; + + // Output ports: + sc_out total_dist; + sc_out partial_dist; + + // Internal variables: + static bool prev_reset; + static double total_compute_dist; + static double partial_compute_dist; + + // Compute total and partial distances. + void compute_total_proc(); + void compute_partial_proc(); + + SC_CTOR( dist_compute_mod ) + { + SC_METHOD( compute_total_proc ); + sensitive << ok_for_incr; + + SC_METHOD( compute_partial_proc ); + sensitive << ok_for_incr; + + prev_reset = false; + total_compute_dist = 0.0; + partial_compute_dist = 0.0; + } +}; + +SC_MODULE( dist_lcd_mod ) +{ + // Input ports: + sc_in start; // Becomes true if the car's started. + sc_in total_dist; + sc_in partial_dist; + + // Output ports: + sc_out total; // Total distance. + sc_out partial; // Partial distance. + + // LCD display driver. + void lcd_driver_proc(); + + SC_CTOR( dist_lcd_mod ) + { + SC_METHOD( lcd_driver_proc ); + sensitive << total_dist << partial_dist; + } +}; + +SC_MODULE( dist_mod ) +{ + // Ports: + sc_in pulse; // Pulse coming ftom the pulse generator. + sc_in reset; // Reset the partial distance odometer if true. + sc_in start; // Becomes true if the car's started. + + // Output ports: + sc_out total; // Total distance. + sc_out partial; // Partial distance. + + // Internal signals: + sc_signal ok_for_incr; + sc_signal total_dist; + sc_signal partial_dist; + + // Internal models: + dist_read_mod *read_mod; + dist_compute_mod *compute_mod; + dist_lcd_mod *lcd_mod; + + SC_CTOR( dist_mod ) + { + read_mod = new dist_read_mod("read_mod"); + compute_mod = new dist_compute_mod("compute_mod"); + lcd_mod = new dist_lcd_mod("lcd_mod"); + + // read_mod->pulse.bind(pulse); + // read_mod->start.bind(start); + // read_mod->ok_for_incr.bind(ok_for_incr); + read_mod->pulse(pulse); + read_mod->start(start); + read_mod->ok_for_incr(ok_for_incr); + + // compute_mod->reset.bind(reset); + // compute_mod->start.bind(start); + // compute_mod->ok_for_incr.bind(ok_for_incr); + // compute_mod->total_dist.bind(total_dist); + // compute_mod->partial_dist.bind(partial_dist); + compute_mod->reset(reset); + compute_mod->start(start); + compute_mod->ok_for_incr(ok_for_incr); + compute_mod->total_dist(total_dist); + compute_mod->partial_dist(partial_dist); + + // lcd_mod->start.bind(start); + // lcd_mod->total_dist.bind(total_dist); + // lcd_mod->partial_dist.bind(partial_dist); + // lcd_mod->total.bind(total); + // lcd_mod->partial.bind(partial); + lcd_mod->start.bind(start); + lcd_mod->total_dist.bind(total_dist); + lcd_mod->partial_dist(partial_dist); + lcd_mod->total(total); + lcd_mod->partial.bind(partial); + + ok_for_incr = false; + total_dist = 0.0; + partial_dist = 0.0; + } +}; + +#endif diff --git a/src/systemc/tests/systemc/misc/v1.0/dash7/driver.cpp b/src/systemc/tests/systemc/misc/v1.0/dash7/driver.cpp new file mode 100644 index 000000000..6c085b77d --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/driver.cpp @@ -0,0 +1,124 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + driver.cpp -- Implementation of the driver. + + 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: driver.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:57 acg +// Andy Goodrich: replacement of deprecated features with their non-deprecated +// counterparts. +// +// Revision 1.3 2006/01/19 00:48:20 acg +// Andy Goodrich: Changes for the fact signal write checking is enabled. +// +// Revision 1.2 2006/01/18 00:23:51 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 "driver.h" + +// Driver's output actions. +void +driver_mod::driver_out_proc() +{ + // while (true) { + cout << "Driver is up @ " << sc_time_stamp() << endl; + + // Car is at rest. + speed_set = 0; + reset = false; + start = false; + wait(); + + cout << "Driver started the car @ " << sc_time_stamp() << endl; + cout << "Driver set the speed to 40 km/h @ " << sc_time_stamp() << endl; + start = true; + speed_set = 40; + wait(); + + cout << "Driver set the speed to 120 km/h @ " << sc_time_stamp() << endl; + speed_set = 120; + wait(); + + cout << "Driver reset the partial distance odometer @ " + << sc_time_stamp() << endl; + cout << "Driver set the speed to 60 km/h @ " << sc_time_stamp() << endl; + reset = true; + speed_set = 60; + wait(); + + cout << "Driver set the speed to 40 km/h @ " << sc_time_stamp() << endl; + speed_set = 40; + wait(); + + cout << "Driver stopped the car @ " << sc_time_stamp() << endl; + wait(); + + sc_stop(); + // } +} + +// Driver's input actions. +void +driver_mod::driver_in_proc() +{ + if (speed.event()) { + cout << "Current speed displayed = " + << speed << " km/h @ " << sc_time_stamp() << endl; + } + + if (angle.event()) { + cout << "Current speedometer angle = " << angle + << " degrees @ " << sc_time_stamp() << endl; + } + + if (total.event()) { + cout << "Current total distance displayed = " + << total << " km @ " << sc_time_stamp() << endl; + } + + if (partial.event()) { + cout << "Current partial distance displayed = " + << partial << " km @ " << sc_time_stamp() << endl; + } +} + +// End of file diff --git a/src/systemc/tests/systemc/misc/v1.0/dash7/driver.h b/src/systemc/tests/systemc/misc/v1.0/dash7/driver.h new file mode 100644 index 000000000..795fa63b5 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/driver.h @@ -0,0 +1,69 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + driver.h -- Definition of the driver. + + 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 DRIVER_H +#define DRIVER_H + +SC_MODULE( driver_mod ) +{ + // Input ports: + sc_in_clk clk; // Clock for the actions of the driver. + sc_in speed; + sc_in angle; + sc_in total; + sc_in partial; + + // Output ports: + sc_out reset; // Set if the driver wants to reset the partial + // distance odometer. + sc_out speed_set; // Speed of the car as set by the driver. + sc_out start; // Set if the driver starts the car. + + // Driver's actions. + void driver_out_proc(); + void driver_in_proc(); + + SC_CTOR( driver_mod ) + { + SC_CTHREAD( driver_out_proc, clk.pos() ); + + SC_METHOD( driver_in_proc ); + sensitive << speed << angle << total << partial; + } +}; + +#endif diff --git a/src/systemc/tests/systemc/misc/v1.0/dash7/golden/dash7.log b/src/systemc/tests/systemc/misc/v1.0/dash7/golden/dash7.log new file mode 100644 index 000000000..8668a2d8a --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/golden/dash7.log @@ -0,0 +1,35 @@ +SystemC Simulation +Driver is up @ 0 s +Driver started the car @ 10 us +Driver set the speed to 40 km/h @ 10 us +Current speed displayed = 18.2769 km/h @ 10625 ns +Current speedometer angle = 37.9598 degrees @ 10625 ns +Current speed displayed = 19.8 km/h @ 11225 ns +Current speedometer angle = 41.1231 degrees @ 11225 ns +Driver set the speed to 120 km/h @ 20 us +Current speed displayed = 26.4 km/h @ 20075 ns +Current speedometer angle = 54.8308 degrees @ 20075 ns +Current speed displayed = 59.4 km/h @ 20275 ns +Current speedometer angle = 123.369 degrees @ 20275 ns +Current total distance displayed = 0.01 km @ 22775 ns +Current partial distance displayed = 0.01 km @ 22775 ns +Current total distance displayed = 0.02 km @ 28875 ns +Current partial distance displayed = 0.02 km @ 28875 ns +Driver reset the partial distance odometer @ 30 us +Driver set the speed to 60 km/h @ 30 us +Current speed displayed = 39.6 km/h @ 30175 ns +Current speedometer angle = 82.2462 degrees @ 30175 ns +Current speed displayed = 29.7 km/h @ 30575 ns +Current speedometer angle = 61.6846 degrees @ 30575 ns +Current total distance displayed = 0.03 km @ 39975 ns +Current partial distance displayed = 0 km @ 39975 ns +Driver set the speed to 40 km/h @ 40 us +Current speed displayed = 23.76 km/h @ 40275 ns +Current speedometer angle = 49.3477 degrees @ 40275 ns +Current speed displayed = 19.8 km/h @ 40875 ns +Current speedometer angle = 41.1231 degrees @ 40875 ns +Driver stopped the car @ 50 us +Current total distance displayed = 0.04 km @ 58275 ns +Current partial distance displayed = 0.01 km @ 58275 ns + +Info: /OSCI/SystemC: Simulation stopped by user. diff --git a/src/systemc/tests/systemc/misc/v1.0/dash7/main.cpp b/src/systemc/tests/systemc/misc/v1.0/dash7/main.cpp new file mode 100644 index 000000000..fd1b45ba0 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/main.cpp @@ -0,0 +1,157 @@ +/***************************************************************************** + + 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), the driver of the car, clocks, 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. The driver can start the car, + set its speed, reset the partial distance odometer, and stop the + car (which means he will stop the simulation). One of the clocks + is slow and the other is fast. The fast clock represents the real + time. The slow clock is used to control the actions of the + driver. The signals in this program are traced. + + purpose (in terms of changes to dash6's purpose) -- named port + binding mixed with bind(). Example: let m1 and m2 be two modules, + and p1 and p2 be their ports. Let m2 contain m1. Let's bind these + ports. In dashX with X <= 6, the binding is done in m2's + constructor as m1->p1.bind(p2). In this test, the binding is named + in that the binding is done in m2's constructor as m1->p1(p2). + + The output of this program is identical to that of dash6. + + 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:20 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:58 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:20 acg +// Andy Goodrich: Changes for the fact signal write checking is enabled. +// +// Revision 1.2 2006/01/18 00:23:51 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 "driver.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 speed_pulses("speed_pulses"); + sc_signal dist_pulses("dist_pulses"); + // Signals for the driver's actions. + sc_signal reset("reset"); + sc_signal speed("speed"); + sc_signal start("start"); + + // Signals observed by the driver. + sc_signal disp_speed("disp_speed"); + sc_signal disp_angle("disp_angle"); + sc_signal disp_total_dist("disp_total_dist"); + sc_signal disp_partial_dist("disp_partial_dist"); + + // Clocks. + sc_clock clk0("slow_clk", SLOW_CLOCK_PERIOD0, SC_NS, 0.5, 0.0, SC_NS, true); + sc_clock clk1("fast_clk", FAST_CLOCK_PERIOD1, SC_NS, 0.5, 0.0, SC_NS, false); + + driver_mod driver("driver"); + driver(clk0, disp_speed, disp_angle, disp_total_dist, disp_partial_dist, + reset, speed, start); + + gen_pulse_mod gen_pulse("gen_pulse"); + gen_pulse(clk1, start, speed, speed_pulses, dist_pulses); + + speed_mod speedometer("speedometer"); + speedometer(clk1, start, speed_pulses, disp_speed, disp_angle); + + dist_mod odometers("odometers"); + odometers(dist_pulses, reset, start, disp_total_dist, disp_partial_dist); + + // Initialize signals: + start = false; + + // Tracing: + // Trace file creation. + sc_trace_file *tf = sc_create_vcd_trace_file("dash"); + // External signals. + sc_trace(tf, clk0, "slow_clk"); + sc_trace(tf, clk1, "fast_clk"); + sc_trace(tf, speed_pulses, "speed_pulses"); + sc_trace(tf, dist_pulses, "dist_pulses"); + sc_trace(tf, reset, "reset"); + sc_trace(tf, start, "start"); + sc_trace(tf, speed, "speed"); + sc_trace(tf, disp_speed, "disp_speed"); + sc_trace(tf, disp_angle, "disp_angle"); + sc_trace(tf, disp_total_dist, "disp_total_dist"); + sc_trace(tf, disp_partial_dist, "disp_partial_dist"); + // Internal signals. + sc_trace(tf, speedometer.elapsed_time, "elapsed_time"); + sc_trace(tf, speedometer.read_mod->raw_speed, "raw_speed"); + sc_trace(tf, speedometer.filtered_speed, "filtered_speed"); + sc_trace(tf, odometers.ok_for_incr, "ok_for_incr"); + sc_trace(tf, odometers.total_dist, "total_dist"); + sc_trace(tf, odometers.partial_dist, "partial_dist"); + + disp_speed = 0.0; + disp_angle = 0.0; + disp_total_dist = 0.0; + disp_partial_dist = 0.0; + + sc_start(); + + return 0; +} + +// End of file diff --git a/src/systemc/tests/systemc/misc/v1.0/dash7/pulse.cpp b/src/systemc/tests/systemc/misc/v1.0/dash7/pulse.cpp new file mode 100644 index 000000000..c2b5031f2 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/pulse.cpp @@ -0,0 +1,101 @@ +/***************************************************************************** + + 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.3 2006/01/19 00:48:20 acg +// Andy Goodrich: Changes for the fact signal write checking is enabled. +// +// Revision 1.2 2006/01/18 00:23:51 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() +{ + speed_pulse = false; + dist_pulse = false; + + // Wait until the car is started. + + do { wait(); } while (start != true); + + /* + do { + wait(); + } while (start == false); + */ + + while (true) { + + 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/dash7/pulse.h b/src/systemc/tests/systemc/misc/v1.0/dash7/pulse.h new file mode 100644 index 000000000..b1206d185 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/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_in start; // Becomes true if the car's started. + sc_in speed; // Speed of the car set by the driver. + sc_out speed_pulse; // Pulses for the speedometer. + sc_out 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_CTHREAD( gen_pulse_proc, clk.pos() ); + } +}; + +#endif + diff --git a/src/systemc/tests/systemc/misc/v1.0/dash7/speed.cpp b/src/systemc/tests/systemc/misc/v1.0/dash7/speed.cpp new file mode 100644 index 000000000..10e29ce12 --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/speed.cpp @@ -0,0 +1,111 @@ +/***************************************************************************** + + 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.3 2006/01/19 00:48:20 acg +// Andy Goodrich: Changes for the fact signal write checking is enabled. +// +// Revision 1.2 2006/01/18 00:23:51 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() +{ + if (start) + elapsed_time = elapsed_time + 1; + else + elapsed_time = 0; +} + +// Compute speed. +void +speed_read_mod::read_speed_proc() +{ + wait(); + + 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); + + if (start) + raw_speed = DIST_BETWEEN_TWO_PULSES * PERIODS_PER_HOUR / elapsed_time; + else + raw_speed = 0.0; + + // Reset timer. + elapsed_time = 0; + } +} + +// Filter speed. +void +speed_read_mod::filter_speed_proc() +{ + if (start) + filtered_speed = raw_speed; + else + filtered_speed = 0.0; +} + +// Compute needle angle and drive the speedometer. +void +speed_pwm_mod::pwm_driver_proc() +{ + if (start) { + speed = filtered_speed; + angle = filtered_speed * MAX_ANGLE / MAX_SPEED; + } + else { + speed = 0.0; + angle = 0.0; + } +} + + +// End of file diff --git a/src/systemc/tests/systemc/misc/v1.0/dash7/speed.h b/src/systemc/tests/systemc/misc/v1.0/dash7/speed.h new file mode 100644 index 000000000..b56b3a17e --- /dev/null +++ b/src/systemc/tests/systemc/misc/v1.0/dash7/speed.h @@ -0,0 +1,148 @@ +/***************************************************************************** + + 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_read_mod ) +{ + // Input ports: + sc_in start; // Becomes true if the car's started. + sc_in pulse; // Pulse coming from the pulse generator. + + // Output ports: + sc_out filtered_speed; // Filtered speed. + + // Inout ports: + sc_inout elapsed_time; + + // Internal signals: + sc_signal raw_speed; + + // Compute speed. + void read_speed_proc(); + + // Filter speed. + void filter_speed_proc(); + + SC_CTOR( speed_read_mod ) + { + SC_THREAD( read_speed_proc ); + sensitive << pulse.pos(); + + SC_METHOD( filter_speed_proc ); + sensitive << raw_speed; + + raw_speed = 0.0; + } +}; + +SC_MODULE( speed_pwm_mod ) +{ + // Input ports: + sc_in start; // Becomes true if the car's started. + sc_in filtered_speed; + + // Output ports: + sc_out speed; // Displayed speed. + sc_out angle; // Displayed angle. + + // Compute needle angle and drive the speedometer. + void pwm_driver_proc(); + + SC_CTOR( speed_pwm_mod ) + { + SC_METHOD( pwm_driver_proc ); + sensitive << filtered_speed; + } +}; + +SC_MODULE( speed_mod ) +{ + // Input ports: + sc_in_clk clk; // Clock to measure the time, needed to compute the speed. + sc_in start; // Becomes true if the car's started. + sc_in pulse; // Pulse coming from the pulse generator. + + // Output ports: + sc_out speed; // Displayed speed. + sc_out angle; // Displayed angle. + + // Internal signals: + sc_signal elapsed_time; + sc_signal filtered_speed; + + // Internal models: + speed_read_mod *read_mod; + speed_pwm_mod *pwm_mod; + + // Find the elapsed_time between NUM_PULSES_FOR_SPEED pulses. + void find_time_proc(); + + SC_CTOR( speed_mod ) + { + SC_METHOD( find_time_proc ); + sensitive << clk.pos(); + + read_mod = new speed_read_mod("read_mod"); + pwm_mod = new speed_pwm_mod("pwm_mod"); + + // read_mod->start.bind(start); + // read_mod->pulse.bind(pulse); + // read_mod->elapsed_time.bind(elapsed_time); + // read_mod->filtered_speed.bind(filtered_speed); + read_mod->start(start); + read_mod->pulse(pulse); + read_mod->elapsed_time(elapsed_time); + read_mod->filtered_speed(filtered_speed); + + // pwm_mod->start.bind(start); + // pwm_mod->filtered_speed.bind(filtered_speed); + // pwm_mod->speed.bind(speed); + // pwm_mod->angle.bind(angle); + pwm_mod->start(start); + pwm_mod->filtered_speed.bind(filtered_speed); + pwm_mod->speed.bind(speed); + pwm_mod->angle(angle); + + elapsed_time = 0; + filtered_speed = 0.0; + } +}; + +#endif + -- cgit v1.2.3