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