fsm.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  fsm.cpp --
23
24  Original Author: Rocco Jonack, Synopsys, Inc., 1999-07-30
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
39#include "fsm.h"
40
41void fsm::entry(){
42
43  sc_biguint<4>   tmp1;
44  sc_biguint<4>   tmp2;
45  sc_biguint<4>   tmp3;
46  sc_unsigned     out_tmp2(12);
47  sc_unsigned     out_tmp3(12);
48
49  unsigned int tmpint;
50
51  // reset_loop
52  if (reset.read() == true) {
53    out_value1.write(0);
54    out_value2.write(0);
55    out_value3.write(0);
56    out_valid1.write(false);
57    out_valid2.write(false);
58    out_valid3.write(false);
59    wait();
60  } else wait();
61
62  //
63  // main loop
64  //
65  while(1) {
66    do { wait(); } while  (in_valid == false);
67
68    //reading inputs
69    tmp1 = in_value1.read();
70
71    //easy, just a bunch of different waits
72    out_valid1.write(true);
73    tmpint = tmp1.to_uint();
74    wait();
75    switch (tmpint) {
76    case 4 :
77      wait();
78      wait();
79      wait();
80      wait();
81      out_value1.write(3);
82      wait();
83      break;
84    case 3 :
85      out_value1.write(2);
86      wait();
87      wait();
88      wait();
89      break;
90    case 2 :
91      out_value1.write(1);
92      wait();
93      wait();
94      break;
95    default :
96      out_value1.write(tmp1);
97      wait();
98      break;
99    };
100    out_valid1.write(false);
101    wait();
102
103    //the first branch should be pushed out in latency due to long delay
104    tmp2 = in_value2.read();
105    out_valid2.write(true);
106    wait();
107    tmpint = tmp2.to_uint();
108    switch (tmpint) {
109    case 0 :
110    case 1 :
111    case 2 :
112    case 3 :
113      //long operation should extent latency
114      out_tmp2 = tmp2*tmp2*tmp2;
115      wait();
116      break;
117    case 4 :
118    case 5 :
119    case 6 :
120    case 7 :
121      //short operation should not extent latency
122      out_tmp2 = 4;
123      wait();
124      break;
125    case 8  :
126    case 9  :
127    case 10 :
128    case 11 :
129      //wait statements should extent latency
130      out_tmp2 = 1;
131      wait();
132      wait();
133      wait();
134      break;
135    };
136
137    out_value2.write( sc_biguint<4>( out_tmp2 ) );
138    out_valid2.write(false);
139    wait();
140
141    // and just another short case, maybe later to check unbalanched case
142    tmp3 = in_value3.read();
143    out_valid3.write(true);
144    wait();
145    tmpint = tmp3.to_uint();
146    switch (tmpint) {
147    case 0 :
148    case 1 :
149    case 2 :
150    case 3 :
151      //long operation should extent latency
152      out_tmp3 = tmp3*tmp3*tmp3;
153      wait();
154      break;
155    default :
156      //short operation should not extent latency
157      out_tmp3 = 4;
158      wait();
159      break;
160    };
161    out_value3.write( sc_biguint<4>( out_tmp3 ) );
162    wait();
163    out_valid3.write(false);
164  }
165}
166
167// EOF
168
169