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 dash8's purpose (in terms of changes to dash7's purpose) -- 35 Positional connection method for binding the ports of modules. 36 Example: Let m be a module with ports p1 and p2. Let m_ptr be a 37 pointer to m, and let p1_arg and p2_arg be the ports that we want 38 to bind to p1 and p2 of m. Then, we can do the binding in one of 39 the following: 40 41 m(p1_arg, p2_arg); or (*m_ptr)(p1_arg, p2_arg); 42 43 m.p1(p1_arg); m.p2.bind(p2_arg); or 44 m_ptr->p1(p1_arg); m->p2.bind(p2_arg); 45 46 The output of this program is identical to that of dash[6-8]. 47 48 purpose (in terms of changes to dash8's purpose) -- the use of 49 module and process declaration macros, defined in systemc.h. 50 51 Original Author: Ali Dasdan, Synopsys, Inc. 52 53 *****************************************************************************/ 54 55/***************************************************************************** 56 57 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 58 changes you are making here. 59 60 Name, Affiliation, Date: 61 Description of Modification: 62 63 *****************************************************************************/ 64 65// $Log: main.cpp,v $ 66// Revision 1.2 2011/01/07 01:20:20 acg 67// Andy Goodrich: update for new IEEE 1666. 68// 69// Revision 1.1.1.1 2006/12/15 20:26:24 acg 70// systemc_tests-2.3 71// 72// Revision 1.5 2006/01/24 21:05:59 acg 73// Andy Goodrich: replacement of deprecated features with their non-deprecated 74// counterparts. 75// 76// Revision 1.4 2006/01/20 00:43:24 acg 77// Andy Goodrich: Changed over to use putenv() instead of setenv() to accommodate old versions of Solaris. 78// 79// Revision 1.3 2006/01/19 00:48:20 acg 80// Andy Goodrich: Changes for the fact signal write checking is enabled. 81// 82// Revision 1.2 2006/01/18 00:23:51 acg 83// Change over from SC_NO_WRITE_CHECK to sc_write_check_enable() call. 84// 85 86#define SC_NO_WRITE_CHECK 87#include "systemc.h" 88#include "const.h" 89#include "driver.h" 90#include "pulse.h" 91#include "speed.h" 92#include "dist.h" 93 94int 95sc_main(int argc, char *argv[]) 96{ 97 // Pulses for the speedometer and odometers, generated by the pulse 98 // generator. 99 sc_signal<bool> speed_pulses("speed_pulses"); 100 sc_signal<bool> dist_pulses("dist_pulses"); 101 // Signals for the driver's actions. 102 sc_signal<bool> reset("reset"); 103 sc_signal<int> speed("speed"); 104 sc_signal<bool> start("start"); 105 106 // Signals observed by the driver. 107 sc_signal<double> disp_speed("disp_speed"); 108 sc_signal<double> disp_angle("disp_angle"); 109 sc_signal<double> disp_total_dist("disp_total_dist"); 110 sc_signal<double> disp_partial_dist("disp_partial_dist"); 111 112 // Clocks. 113 sc_clock clk0("slow_clk", SLOW_CLOCK_PERIOD0, SC_NS, 0.5, 0.0, SC_NS, true); 114 sc_clock clk1("fast_clk", FAST_CLOCK_PERIOD1, SC_NS, 0.5, 0.0, SC_NS, false); 115 116 driver_mod driver("driver"); 117 driver(clk0, disp_speed, disp_angle, disp_total_dist, 118 disp_partial_dist, reset, speed, start); 119 120 gen_pulse_mod gen_pulse("gen_pulse"); 121 gen_pulse(clk1, start, speed, speed_pulses, dist_pulses); 122 123 speed_mod speedometer("speedometer"); 124 speedometer(clk1, start, speed_pulses, disp_speed, disp_angle); 125 126 dist_mod odometers("odometers"); 127 odometers.pulse(dist_pulses); 128 odometers.reset(reset); 129 odometers.start.bind(start); 130 odometers.total(disp_total_dist); 131 odometers.partial.bind(disp_partial_dist); 132 133 // Initialize signals: 134 start = false; 135 136 // Tracing: 137 // Trace file creation. 138 sc_trace_file *tf = sc_create_vcd_trace_file("dash"); 139 // External signals. 140 sc_trace(tf, clk0, "slow_clk"); 141 sc_trace(tf, clk1, "fast_clk"); 142 sc_trace(tf, speed_pulses, "speed_pulses"); 143 sc_trace(tf, dist_pulses, "dist_pulses"); 144 sc_trace(tf, reset, "reset"); 145 sc_trace(tf, start, "start"); 146 sc_trace(tf, speed, "speed"); 147 sc_trace(tf, disp_speed, "disp_speed"); 148 sc_trace(tf, disp_angle, "disp_angle"); 149 sc_trace(tf, disp_total_dist, "disp_total_dist"); 150 sc_trace(tf, disp_partial_dist, "disp_partial_dist"); 151 // Internal signals. 152 sc_trace(tf, speedometer.elapsed_time, "elapsed_time"); 153 sc_trace(tf, speedometer.read_mod->raw_speed, "raw_speed"); 154 sc_trace(tf, speedometer.filtered_speed, "filtered_speed"); 155 sc_trace(tf, odometers.ok_for_incr, "ok_for_incr"); 156 sc_trace(tf, odometers.total_dist, "total_dist"); 157 sc_trace(tf, odometers.partial_dist, "partial_dist"); 158 159 disp_speed = 0.0; 160 disp_angle = 0.0; 161 disp_total_dist = 0.0; 162 disp_partial_dist = 0.0; 163 164 sc_start(); 165 166 return 0; 167} 168 169// End of file 170