main.cpp revision 12855
12568SN/A/*****************************************************************************
22568SN/A
32568SN/A  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
42568SN/A  more contributor license agreements.  See the NOTICE file distributed
52568SN/A  with this work for additional information regarding copyright ownership.
62568SN/A  Accellera licenses this file to you under the Apache License, Version 2.0
72568SN/A  (the "License"); you may not use this file except in compliance with the
82568SN/A  License.  You may obtain a copy of the License at
92568SN/A
102568SN/A    http://www.apache.org/licenses/LICENSE-2.0
112568SN/A
122568SN/A  Unless required by applicable law or agreed to in writing, software
132568SN/A  distributed under the License is distributed on an "AS IS" BASIS,
142568SN/A  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
152568SN/A  implied.  See the License for the specific language governing
162568SN/A  permissions and limitations under the License.
172568SN/A
182568SN/A *****************************************************************************/
192568SN/A
202568SN/A/*****************************************************************************
212568SN/A
222568SN/A  main.cpp -- Main function for the dashboard controller for a
232568SN/A           car. This controller contains a speedometer, two odometers (total
242568SN/A           and partial distance), the driver of the car, clocks, and the
252568SN/A           pulse generator. The pulses are generated by the sensors placed
262568SN/A           around one of the wheel shafts. The rate of pulse generation is
272568SN/A           determined by the speed of the car. The driver can start the car,
282665Ssaidi@eecs.umich.edu           set its speed, reset the partial distance odometer, and stop the
292665Ssaidi@eecs.umich.edu           car (which means he will stop the simulation). One of the clocks
302665Ssaidi@eecs.umich.edu           is slow and the other is fast. The fast clock represents the real
312568SN/A           time. The slow clock is used to control the actions of the
322568SN/A           driver. The signals in this program are traced.
332568SN/A
342982Sstever@eecs.umich.edu           purpose (in terms of changes to dash7's purpose) -- Positional
352982Sstever@eecs.umich.edu           connection method for binding the ports of modules. Example: Let m
362568SN/A           be a module with ports p1 and p2. Let m_ptr be a pointer to m, and
372568SN/A           let p1_arg and p2_arg be the ports that we want to bind to p1 and
382643Sstever@eecs.umich.edu           p2 of m. Then, we can do the binding in one of the following:
392568SN/A
402568SN/A           m(p1_arg, p2_arg);  or (*m_ptr)(p1_arg, p2_arg);
412568SN/A           m.p1(p1_arg); m.p2.bind(p2_arg); or
422568SN/A           m_ptr->p1(p1_arg); m->p2.bind(p2_arg);
432568SN/A
442643Sstever@eecs.umich.edu           The output of this program is identical to that of dash6 and dash7.
452643Sstever@eecs.umich.edu
464435Ssaidi@eecs.umich.edu  Original Author: Ali Dasdan, Synopsys, Inc.
474435Ssaidi@eecs.umich.edu
482643Sstever@eecs.umich.edu *****************************************************************************/
494435Ssaidi@eecs.umich.edu
504435Ssaidi@eecs.umich.edu/*****************************************************************************
514435Ssaidi@eecs.umich.edu
522643Sstever@eecs.umich.edu  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
532643Sstever@eecs.umich.edu  changes you are making here.
542643Sstever@eecs.umich.edu
554435Ssaidi@eecs.umich.edu      Name, Affiliation, Date:
564435Ssaidi@eecs.umich.edu  Description of Modification:
574435Ssaidi@eecs.umich.edu
584435Ssaidi@eecs.umich.edu *****************************************************************************/
594435Ssaidi@eecs.umich.edu
604435Ssaidi@eecs.umich.edu// $Log: main.cpp,v $
614435Ssaidi@eecs.umich.edu// Revision 1.2  2011/01/07 01:20:20  acg
622643Sstever@eecs.umich.edu//  Andy Goodrich: update for new IEEE 1666.
634432Ssaidi@eecs.umich.edu//
644432Ssaidi@eecs.umich.edu// Revision 1.1.1.1  2006/12/15 20:26:24  acg
652643Sstever@eecs.umich.edu// systemc_tests-2.3
662643Sstever@eecs.umich.edu//
672643Sstever@eecs.umich.edu// Revision 1.5  2006/01/24 21:05:58  acg
682738Sstever@eecs.umich.edu//  Andy Goodrich: replacement of deprecated features with their non-deprecated
692643Sstever@eecs.umich.edu//  counterparts.
702643Sstever@eecs.umich.edu//
712643Sstever@eecs.umich.edu// Revision 1.4  2006/01/20 00:43:24  acg
722643Sstever@eecs.umich.edu// Andy Goodrich: Changed over to use putenv() instead of setenv() to accommodate old versions of Solaris.
732643Sstever@eecs.umich.edu//
742643Sstever@eecs.umich.edu// Revision 1.3  2006/01/19 00:48:20  acg
752643Sstever@eecs.umich.edu// Andy Goodrich: Changes for the fact signal write checking is enabled.
762643Sstever@eecs.umich.edu//
772643Sstever@eecs.umich.edu// Revision 1.2  2006/01/18 00:23:51  acg
782643Sstever@eecs.umich.edu// Change over from SC_NO_WRITE_CHECK to sc_write_check_enable() call.
792643Sstever@eecs.umich.edu//
802643Sstever@eecs.umich.edu
812643Sstever@eecs.umich.edu#define SC_NO_WRITE_CHECK
822643Sstever@eecs.umich.edu#include "systemc.h"
832643Sstever@eecs.umich.edu#include "const.h"
842643Sstever@eecs.umich.edu#include "driver.h"
852568SN/A#include "pulse.h"
862568SN/A#include "speed.h"
872568SN/A#include "dist.h"
882568SN/A
892643Sstever@eecs.umich.eduint
904432Ssaidi@eecs.umich.edusc_main(int argc, char *argv[])
914432Ssaidi@eecs.umich.edu{
924432Ssaidi@eecs.umich.edu  // Pulses for the speedometer and odometers, generated by the pulse
934432Ssaidi@eecs.umich.edu  // generator.
942568SN/A  sc_signal<bool> speed_pulses("speed_pulses");
952568SN/A  sc_signal<bool> dist_pulses("dist_pulses");
964433Ssaidi@eecs.umich.edu  // Signals for the driver's actions.
974435Ssaidi@eecs.umich.edu  sc_signal<bool> reset("reset");
984433Ssaidi@eecs.umich.edu  sc_signal<int>  speed("speed");
994435Ssaidi@eecs.umich.edu  sc_signal<bool> start("start");
1004435Ssaidi@eecs.umich.edu
1014435Ssaidi@eecs.umich.edu  // Signals observed by the driver.
1024435Ssaidi@eecs.umich.edu  sc_signal<double> disp_speed("disp_speed");
1034435Ssaidi@eecs.umich.edu  sc_signal<double> disp_angle("disp_angle");
1044435Ssaidi@eecs.umich.edu  sc_signal<double> disp_total_dist("disp_total_dist");
1054435Ssaidi@eecs.umich.edu  sc_signal<double> disp_partial_dist("disp_partial_dist");
1064435Ssaidi@eecs.umich.edu
1074435Ssaidi@eecs.umich.edu  // Clocks.
1084433Ssaidi@eecs.umich.edu  sc_clock clk0("slow_clk", SLOW_CLOCK_PERIOD0, SC_NS, 0.5, 0.0, SC_NS, true);
1092568SN/A  sc_clock clk1("fast_clk", FAST_CLOCK_PERIOD1, SC_NS, 0.5, 0.0, SC_NS, false);
1102643Sstever@eecs.umich.edu
1112568SN/A  driver_mod driver("driver");
1122568SN/A  driver(clk0, disp_speed, disp_angle, disp_total_dist,
1133349Sbinkertn@umich.edu         disp_partial_dist, reset, speed, start);
1142568SN/A
1154433Ssaidi@eecs.umich.edu  gen_pulse_mod gen_pulse("gen_pulse");
1164433Ssaidi@eecs.umich.edu  gen_pulse(clk1, start, speed, speed_pulses, dist_pulses);
1174433Ssaidi@eecs.umich.edu
1184433Ssaidi@eecs.umich.edu  speed_mod speedometer("speedometer");
1194433Ssaidi@eecs.umich.edu  speedometer(clk1, start, speed_pulses, disp_speed, disp_angle);
1203662Srdreslin@umich.edu
1212643Sstever@eecs.umich.edu  dist_mod odometers("odometers");
1224435Ssaidi@eecs.umich.edu  odometers.pulse(dist_pulses);
1234433Ssaidi@eecs.umich.edu  odometers.reset(reset);
1244433Ssaidi@eecs.umich.edu  odometers.start.bind(start);
1254433Ssaidi@eecs.umich.edu  odometers.total(disp_total_dist);
1263662Srdreslin@umich.edu  odometers.partial.bind(disp_partial_dist);
1274433Ssaidi@eecs.umich.edu
1284433Ssaidi@eecs.umich.edu  // Initialize signals:
1294435Ssaidi@eecs.umich.edu  start = false;
1304433Ssaidi@eecs.umich.edu
1314433Ssaidi@eecs.umich.edu  // Tracing:
1324433Ssaidi@eecs.umich.edu  // Trace file creation.
1334433Ssaidi@eecs.umich.edu  sc_trace_file *tf = sc_create_vcd_trace_file("dash");
1344433Ssaidi@eecs.umich.edu  // External signals.
1354433Ssaidi@eecs.umich.edu  sc_trace(tf, clk0, "slow_clk");
1364433Ssaidi@eecs.umich.edu  sc_trace(tf, clk1, "fast_clk");
1374433Ssaidi@eecs.umich.edu  sc_trace(tf, speed_pulses, "speed_pulses");
1384433Ssaidi@eecs.umich.edu  sc_trace(tf, dist_pulses, "dist_pulses");
1394433Ssaidi@eecs.umich.edu  sc_trace(tf, reset, "reset");
1404433Ssaidi@eecs.umich.edu  sc_trace(tf, start, "start");
1414433Ssaidi@eecs.umich.edu  sc_trace(tf, speed, "speed");
1424433Ssaidi@eecs.umich.edu  sc_trace(tf, disp_speed, "disp_speed");
1432657Ssaidi@eecs.umich.edu  sc_trace(tf, disp_angle, "disp_angle");
1442657Ssaidi@eecs.umich.edu  sc_trace(tf, disp_total_dist, "disp_total_dist");
1454433Ssaidi@eecs.umich.edu  sc_trace(tf, disp_partial_dist, "disp_partial_dist");
1464433Ssaidi@eecs.umich.edu  // Internal signals.
1474433Ssaidi@eecs.umich.edu  sc_trace(tf, speedometer.elapsed_time, "elapsed_time");
1484433Ssaidi@eecs.umich.edu  sc_trace(tf, speedometer.read_mod->raw_speed, "raw_speed");
1494433Ssaidi@eecs.umich.edu  sc_trace(tf, speedometer.filtered_speed, "filtered_speed");
1504433Ssaidi@eecs.umich.edu  sc_trace(tf, odometers.ok_for_incr, "ok_for_incr");
1512657Ssaidi@eecs.umich.edu  sc_trace(tf, odometers.total_dist, "total_dist");
1524433Ssaidi@eecs.umich.edu  sc_trace(tf, odometers.partial_dist, "partial_dist");
1534435Ssaidi@eecs.umich.edu
1544433Ssaidi@eecs.umich.edu  disp_speed = 0.0;
1554435Ssaidi@eecs.umich.edu  disp_angle = 0.0;
1564435Ssaidi@eecs.umich.edu  disp_total_dist = 0.0;
1574433Ssaidi@eecs.umich.edu  disp_partial_dist = 0.0;
1584435Ssaidi@eecs.umich.edu
1594433Ssaidi@eecs.umich.edu  sc_start();
1604435Ssaidi@eecs.umich.edu
1614435Ssaidi@eecs.umich.edu  return 0;
1624433Ssaidi@eecs.umich.edu}
1634435Ssaidi@eecs.umich.edu
1644435Ssaidi@eecs.umich.edu// End of file
1654435Ssaidi@eecs.umich.edu