main.cpp revision 12855:588919e0e4aa
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 main.cpp -- Main function for the dashboard controller for a 23 car. This controller contains a speedometer, two odometers (total 24 and partial distance), the driver of the car, clocks, and the 25 pulse generator. The pulses are generated by the sensors placed 26 around one of the wheel shafts. The rate of pulse generation is 27 determined by the speed of the car. The driver can start the car, 28 set its speed, reset the partial distance odometer, and stop the 29 car (which means he will stop the simulation). One of the clocks 30 is slow and the other is fast. The fast clock represents the real 31 time. The slow clock is used to control the actions of the 32 driver. The signals in this program are traced. 33 34 purpose (in terms of changes to dash7's purpose) -- Positional 35 connection method for binding the ports of modules. Example: Let m 36 be a module with ports p1 and p2. Let m_ptr be a pointer to m, and 37 let p1_arg and p2_arg be the ports that we want to bind to p1 and 38 p2 of m. Then, we can do the binding in one of the following: 39 40 m(p1_arg, p2_arg); or (*m_ptr)(p1_arg, p2_arg); 41 m.p1(p1_arg); m.p2.bind(p2_arg); or 42 m_ptr->p1(p1_arg); m->p2.bind(p2_arg); 43 44 The output of this program is identical to that of dash6 and dash7. 45 46 Original Author: Ali Dasdan, Synopsys, Inc. 47 48 *****************************************************************************/ 49 50/***************************************************************************** 51 52 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 53 changes you are making here. 54 55 Name, Affiliation, Date: 56 Description of Modification: 57 58 *****************************************************************************/ 59 60// $Log: main.cpp,v $ 61// Revision 1.2 2011/01/07 01:20:20 acg 62// Andy Goodrich: update for new IEEE 1666. 63// 64// Revision 1.1.1.1 2006/12/15 20:26:24 acg 65// systemc_tests-2.3 66// 67// Revision 1.5 2006/01/24 21:05:58 acg 68// Andy Goodrich: replacement of deprecated features with their non-deprecated 69// counterparts. 70// 71// Revision 1.4 2006/01/20 00:43:24 acg 72// Andy Goodrich: Changed over to use putenv() instead of setenv() to accommodate old versions of Solaris. 73// 74// Revision 1.3 2006/01/19 00:48:20 acg 75// Andy Goodrich: Changes for the fact signal write checking is enabled. 76// 77// Revision 1.2 2006/01/18 00:23:51 acg 78// Change over from SC_NO_WRITE_CHECK to sc_write_check_enable() call. 79// 80 81#define SC_NO_WRITE_CHECK 82#include "systemc.h" 83#include "const.h" 84#include "driver.h" 85#include "pulse.h" 86#include "speed.h" 87#include "dist.h" 88 89int 90sc_main(int argc, char *argv[]) 91{ 92 // Pulses for the speedometer and odometers, generated by the pulse 93 // generator. 94 sc_signal<bool> speed_pulses("speed_pulses"); 95 sc_signal<bool> dist_pulses("dist_pulses"); 96 // Signals for the driver's actions. 97 sc_signal<bool> reset("reset"); 98 sc_signal<int> speed("speed"); 99 sc_signal<bool> start("start"); 100 101 // Signals observed by the driver. 102 sc_signal<double> disp_speed("disp_speed"); 103 sc_signal<double> disp_angle("disp_angle"); 104 sc_signal<double> disp_total_dist("disp_total_dist"); 105 sc_signal<double> disp_partial_dist("disp_partial_dist"); 106 107 // Clocks. 108 sc_clock clk0("slow_clk", SLOW_CLOCK_PERIOD0, SC_NS, 0.5, 0.0, SC_NS, true); 109 sc_clock clk1("fast_clk", FAST_CLOCK_PERIOD1, SC_NS, 0.5, 0.0, SC_NS, false); 110 111 driver_mod driver("driver"); 112 driver(clk0, disp_speed, disp_angle, disp_total_dist, 113 disp_partial_dist, reset, speed, start); 114 115 gen_pulse_mod gen_pulse("gen_pulse"); 116 gen_pulse(clk1, start, speed, speed_pulses, dist_pulses); 117 118 speed_mod speedometer("speedometer"); 119 speedometer(clk1, start, speed_pulses, disp_speed, disp_angle); 120 121 dist_mod odometers("odometers"); 122 odometers.pulse(dist_pulses); 123 odometers.reset(reset); 124 odometers.start.bind(start); 125 odometers.total(disp_total_dist); 126 odometers.partial.bind(disp_partial_dist); 127 128 // Initialize signals: 129 start = false; 130 131 // Tracing: 132 // Trace file creation. 133 sc_trace_file *tf = sc_create_vcd_trace_file("dash"); 134 // External signals. 135 sc_trace(tf, clk0, "slow_clk"); 136 sc_trace(tf, clk1, "fast_clk"); 137 sc_trace(tf, speed_pulses, "speed_pulses"); 138 sc_trace(tf, dist_pulses, "dist_pulses"); 139 sc_trace(tf, reset, "reset"); 140 sc_trace(tf, start, "start"); 141 sc_trace(tf, speed, "speed"); 142 sc_trace(tf, disp_speed, "disp_speed"); 143 sc_trace(tf, disp_angle, "disp_angle"); 144 sc_trace(tf, disp_total_dist, "disp_total_dist"); 145 sc_trace(tf, disp_partial_dist, "disp_partial_dist"); 146 // Internal signals. 147 sc_trace(tf, speedometer.elapsed_time, "elapsed_time"); 148 sc_trace(tf, speedometer.read_mod->raw_speed, "raw_speed"); 149 sc_trace(tf, speedometer.filtered_speed, "filtered_speed"); 150 sc_trace(tf, odometers.ok_for_incr, "ok_for_incr"); 151 sc_trace(tf, odometers.total_dist, "total_dist"); 152 sc_trace(tf, odometers.partial_dist, "partial_dist"); 153 154 disp_speed = 0.0; 155 disp_angle = 0.0; 156 disp_total_dist = 0.0; 157 disp_partial_dist = 0.0; 158 159 sc_start(); 160 161 return 0; 162} 163 164// End of file 165