speed.h 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  speed.h -- Definition of the speedometer.
23
24  Original Author: Ali Dasdan, Synopsys, Inc.
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38#ifndef SPEED_H
39#define SPEED_H
40
41SC_MODULE( speed_read_mod )
42{
43  // Input ports:
44  sc_in<bool> start; // Becomes true if the car's started.
45  sc_in<bool> pulse; // Pulse coming from the pulse generator.
46
47  // Output ports:
48  sc_out<double> filtered_speed; // Filtered speed.
49
50  // Inout ports:
51  sc_inout<int>  elapsed_time;
52
53  // Internal signals:
54  sc_signal<double> raw_speed;
55
56  // Compute speed.
57  void read_speed_proc();
58
59  // Filter speed.
60  void filter_speed_proc();
61
62  SC_CTOR( speed_read_mod )
63  {
64    SC_THREAD( read_speed_proc );
65    sensitive << pulse.pos();
66
67    SC_METHOD( filter_speed_proc );
68    sensitive << raw_speed;
69
70    raw_speed = 0.0;
71  }
72};
73
74SC_MODULE( speed_pwm_mod )
75{
76  // Input ports:
77  sc_in<bool> start; // Becomes true if the car's started.
78  sc_in<double> filtered_speed;
79
80  // Output ports:
81  sc_out<double> speed; // Displayed speed.
82  sc_out<double> angle; // Displayed angle.
83
84  // Compute needle angle and drive the speedometer.
85  void pwm_driver_proc();
86
87  SC_CTOR( speed_pwm_mod )
88  {
89    SC_METHOD( pwm_driver_proc );
90    sensitive << filtered_speed;
91  }
92};
93
94SC_MODULE( speed_mod )
95{
96  // Input ports:
97  sc_in_clk   clk; // Clock to measure the time, needed to compute the speed.
98  sc_in<bool> start; // Becomes true if the car's started.
99  sc_in<bool> pulse; // Pulse coming from the pulse generator.
100
101  // Output ports:
102  sc_out<double> speed; // Displayed speed.
103  sc_out<double> angle; // Displayed angle.
104
105  // Internal signals:
106  sc_signal<int>    elapsed_time;
107  sc_signal<double> filtered_speed;
108
109  // Internal models:
110  speed_read_mod *read_mod;
111  speed_pwm_mod  *pwm_mod;
112
113  // Find the elapsed_time between NUM_PULSES_FOR_SPEED pulses.
114  void find_time_proc();
115
116  SC_CTOR( speed_mod )
117  {
118    SC_METHOD( find_time_proc );
119    sensitive << clk.pos();
120
121    read_mod = new speed_read_mod("read_mod");
122    pwm_mod = new speed_pwm_mod("pwm_mod");
123
124    // read_mod->start.bind(start);
125    // read_mod->pulse.bind(pulse);
126    // read_mod->filtered_speed.bind(filtered_speed);
127    // read_mod->elapsed_time.bind(elapsed_time);
128
129    read_mod->start(start);
130    read_mod->pulse(pulse);
131    read_mod->filtered_speed(filtered_speed);
132    read_mod->elapsed_time(elapsed_time);
133
134    // (*read_mod)(start, pulse, filtered_speed, elapsed_time);
135
136    // pwm_mod->start.bind(start);
137    // pwm_mod->filtered_speed.bind(filtered_speed);
138    // pwm_mod->speed.bind(speed);
139    // pwm_mod->angle.bind(angle);
140
141    pwm_mod->start(start);
142    pwm_mod->filtered_speed(filtered_speed);
143    pwm_mod->speed(speed);
144    pwm_mod->angle(angle);
145
146    // *pwm_mod << start << filtered_speed << speed << angle;
147
148    elapsed_time = 0;
149    filtered_speed = 0.0;
150  }
151};
152
153#endif
154
155