gem5  v22.1.0.0
speed.h
Go to the documentation of this file.
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 
41 SC_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 
74 SC_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 
94 SC_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->elapsed_time.bind(elapsed_time);
127  read_mod->filtered_speed.bind(filtered_speed);
128 
129  pwm_mod->start.bind(start);
130  pwm_mod->filtered_speed.bind(filtered_speed);
131  pwm_mod->speed.bind(speed);
132  pwm_mod->angle.bind(angle);
133 
134  elapsed_time = 0;
135  filtered_speed = 0.0;
136  }
137 };
138 
139 #endif
140 
SC_MODULE(speed_mod)
Definition: speed.h:41
sc_in< bool > sc_in_clk
Definition: sc_clock.hh:116
#define SC_METHOD(name)
Definition: sc_module.hh:303
#define SC_THREAD(name)
Definition: sc_module.hh:313
#define SC_CTOR(name)
Definition: sc_module.hh:297

Generated on Wed Dec 21 2022 10:22:49 for gem5 by doxygen 1.9.1