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