summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/misc/v1.0/dash5/main.cpp
blob: af9623388c0cda799a33ad41fbdca35cccec5967 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*****************************************************************************

  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
  more contributor license agreements.  See the NOTICE file distributed
  with this work for additional information regarding copyright ownership.
  Accellera licenses this file to you under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with the
  License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  implied.  See the License for the specific language governing
  permissions and limitations under the License.

 *****************************************************************************/

/*****************************************************************************
 
  main.cpp -- Main function for the dashboard controller for a
           car. This controller contains a speedometer, two odometers (total
           and partial distance), the driver of the car, clocks, and the
           pulse generator. The pulses are generated by the sensors placed
           around one of the wheel shafts. The rate of pulse generation is
           determined by the speed of the car. The driver can start the car,
           set its speed, reset the partial distance odometer, and stop the
           car (which means he will stop the simulation). One of the clocks
           is slow and the other is fast. The fast clock represents the real
           time. The slow clock is used to control the actions of the
           driver. The signals in this program are traced.

           purpose (in terms of changes to dash4's purpose) -- synchronous
           processes.
 
  Original Author: Ali Dasdan, Synopsys, Inc.
 
 *****************************************************************************/

/*****************************************************************************

  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
  changes you are making here.

      Name, Affiliation, Date:
  Description of Modification:

 *****************************************************************************/

// $Log: main.cpp,v $
// Revision 1.2  2011/01/07 01:20:20  acg
//  Andy Goodrich: update for new IEEE 1666.
//
// Revision 1.1.1.1  2006/12/15 20:26:24  acg
// systemc_tests-2.3
//
// Revision 1.5  2006/01/24 21:05:56  acg
//  Andy Goodrich: replacement of deprecated features with their non-deprecated
//  counterparts.
//
// Revision 1.4  2006/01/20 00:43:24  acg
// Andy Goodrich: Changed over to use putenv() instead of setenv() to accommodate old versions of Solaris.
//
// Revision 1.3  2006/01/19 00:48:20  acg
// Andy Goodrich: Changes for the fact signal write checking is enabled.
//
// Revision 1.2  2006/01/18 00:23:51  acg
// Change over from SC_NO_WRITE_CHECK to sc_write_check_enable() call.
//

#define SC_NO_WRITE_CHECK
#include "systemc.h"
#include "const.h"
#include "driver.h"
#include "pulse.h"
#include "speed.h"
#include "dist.h"

int
sc_main(int argc, char *argv[])
{
  // Pulses for the speedometer and odometers, generated by the pulse
  // generator.
  sc_signal<bool> speed_pulses("speed_pulses");
  sc_signal<bool> dist_pulses("dist_pulses");
  // Signals for the driver's actions.
  sc_signal<bool> reset("reset");
  sc_signal<int>  speed("speed");
  sc_signal<bool> start("start");

  // Signals observed by the driver.
  sc_signal<double> disp_speed("disp_speed");
  sc_signal<double> disp_angle("disp_angle");
  sc_signal<double> disp_total_dist("disp_total_dist");
  sc_signal<double> disp_partial_dist("disp_partial_dist");

  // Clocks.
  sc_clock clk0("slow_clk", SLOW_CLOCK_PERIOD0, SC_NS, 0.5, 0.0, SC_NS, true);
  sc_clock clk1("fast_clk", FAST_CLOCK_PERIOD1, SC_NS, 0.5, 0.0, SC_NS, false);

  driver_mod driver("driver");
  driver(clk0, disp_speed, disp_angle, disp_total_dist, disp_partial_dist, 
      reset, speed, start);

  gen_pulse_mod gen_pulse("gen_pulse");
  gen_pulse(clk1, start, speed, speed_pulses, dist_pulses);

  speed_mod speedometer("speedometer");
  speedometer(clk1, start, speed_pulses, disp_speed, disp_angle);

  dist_mod odometers("odometers");
  odometers(dist_pulses, reset, start, disp_total_dist, disp_partial_dist);

  // Initialize signals:
  start = false;

  // Tracing:
  // Trace file creation.
  sc_trace_file *tf = sc_create_vcd_trace_file("dash");
  // External signals.
  sc_trace(tf, clk0, "slow_clk");
  sc_trace(tf, clk1, "fast_clk");
  sc_trace(tf, speed_pulses, "speed_pulses");
  sc_trace(tf, dist_pulses, "dist_pulses");
  sc_trace(tf, reset, "reset");
  sc_trace(tf, start, "start");
  sc_trace(tf, speed, "speed");
  sc_trace(tf, disp_speed, "disp_speed");
  sc_trace(tf, disp_angle, "disp_angle");
  sc_trace(tf, disp_total_dist, "disp_total_dist");
  sc_trace(tf, disp_partial_dist, "disp_partial_dist");
  // Internal signals.
  sc_trace(tf, speedometer.elapsed_time, "elapsed_time");
  sc_trace(tf, speedometer.read_mod->raw_speed, "raw_speed");
  sc_trace(tf, speedometer.filtered_speed, "filtered_speed");
  sc_trace(tf, odometers.ok_for_incr, "ok_for_incr");
  sc_trace(tf, odometers.total_dist, "total_dist");
  sc_trace(tf, odometers.partial_dist, "partial_dist");

  disp_speed = 0.0;
  disp_angle = 0.0;
  disp_total_dist = 0.0;
  disp_partial_dist = 0.0;

  sc_start();

  return 0;
}

// End of file