From 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 24 May 2018 01:37:55 -0700 Subject: systemc: Import tests from the Accellera systemc distribution. Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6 Reviewed-on: https://gem5-review.googlesource.com/10845 Reviewed-by: Giacomo Travaglini Maintainer: Gabe Black --- .../systemc/misc/user_guide/chpt3.1/chpt3.1.f | 4 ++ .../systemc/misc/user_guide/chpt3.1/counter.cpp | 52 ++++++++++++++ .../systemc/misc/user_guide/chpt3.1/counter.h | 62 ++++++++++++++++ .../tests/systemc/misc/user_guide/chpt3.1/fsmr.cpp | 83 ++++++++++++++++++++++ .../tests/systemc/misc/user_guide/chpt3.1/fsmr.h | 76 ++++++++++++++++++++ .../misc/user_guide/chpt3.1/golden/chpt3.1.log | 12 ++++ .../tests/systemc/misc/user_guide/chpt3.1/main.cpp | 63 ++++++++++++++++ .../tests/systemc/misc/user_guide/chpt3.1/sg.cpp | 57 +++++++++++++++ .../tests/systemc/misc/user_guide/chpt3.1/sg.h | 64 +++++++++++++++++ .../tests/systemc/misc/user_guide/chpt3.1/testcase | 9 +++ 10 files changed, 482 insertions(+) create mode 100644 src/systemc/tests/systemc/misc/user_guide/chpt3.1/chpt3.1.f create mode 100644 src/systemc/tests/systemc/misc/user_guide/chpt3.1/counter.cpp create mode 100644 src/systemc/tests/systemc/misc/user_guide/chpt3.1/counter.h create mode 100644 src/systemc/tests/systemc/misc/user_guide/chpt3.1/fsmr.cpp create mode 100644 src/systemc/tests/systemc/misc/user_guide/chpt3.1/fsmr.h create mode 100644 src/systemc/tests/systemc/misc/user_guide/chpt3.1/golden/chpt3.1.log create mode 100644 src/systemc/tests/systemc/misc/user_guide/chpt3.1/main.cpp create mode 100644 src/systemc/tests/systemc/misc/user_guide/chpt3.1/sg.cpp create mode 100644 src/systemc/tests/systemc/misc/user_guide/chpt3.1/sg.h create mode 100644 src/systemc/tests/systemc/misc/user_guide/chpt3.1/testcase (limited to 'src/systemc/tests/systemc/misc/user_guide/chpt3.1') diff --git a/src/systemc/tests/systemc/misc/user_guide/chpt3.1/chpt3.1.f b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/chpt3.1.f new file mode 100644 index 000000000..e036afa06 --- /dev/null +++ b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/chpt3.1.f @@ -0,0 +1,4 @@ +chpt3.1/counter.cpp +chpt3.1/fsmr.cpp +chpt3.1/main.cpp +chpt3.1/sg.cpp diff --git a/src/systemc/tests/systemc/misc/user_guide/chpt3.1/counter.cpp b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/counter.cpp new file mode 100644 index 000000000..a5cf06e8f --- /dev/null +++ b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/counter.cpp @@ -0,0 +1,52 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + counter.cpp -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +/* File containing functionality of counter */ + +#include "counter.h" + +void counter::entry() +{ + int count; + + count = 0; + while (true) { // infinite loop + do { wait(); } while (found != true); + count = count + 1; + cout << "\nFound Count is " << count << endl; + } +} diff --git a/src/systemc/tests/systemc/misc/user_guide/chpt3.1/counter.h b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/counter.h new file mode 100644 index 000000000..400246f5f --- /dev/null +++ b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/counter.h @@ -0,0 +1,62 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + counter.h -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +/* Header file for the counter that counts number of strings found */ + +#include "systemc.h" + +SC_MODULE( counter ) +{ + SC_HAS_PROCESS( counter ); + + sc_in_clk clk; + + // The inputs + const sc_signal& found; + + // The constructor + counter(sc_module_name NAME, + sc_clock& POS_CLK, + const sc_signal& FOUND) + : found(FOUND) { + clk(POS_CLK); + SC_CTHREAD( entry, clk.pos() ); + } + + // The main functionality of the process + void entry(); +}; diff --git a/src/systemc/tests/systemc/misc/user_guide/chpt3.1/fsmr.cpp b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/fsmr.cpp new file mode 100644 index 000000000..d2fef570d --- /dev/null +++ b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/fsmr.cpp @@ -0,0 +1,83 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + fsmr.cpp -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +/* File containing functionality of the FSM recognizer */ + +#include "fsmr.h" + +void fsm_recognizer::entry() +{ + char c; + int state = 0; + bool out; + + while (true) { + do { wait(); } while (data_ready != true); + c = input_char.read(); + cout << c << flush; + + switch(state) { + case 0: + if (c == pattern[0]) state = 1; + else state = 0; + out = false; + break; + case 1: + if (c == pattern[1]) state = 2; + else state = 0; + out = false; + break; + case 2: + if (c == pattern[2]) state = 3; + else state = 0; + out = false; + break; + case 3: + if (c == pattern[3]) out = true; + else out = false; + state = 0; + break; + default: + cout << "Error: FSM in bad state." << endl; + break; + } + + found.write(out); + wait(); // for writing the found signal + found.write(false); // reset the found signal + } +} diff --git a/src/systemc/tests/systemc/misc/user_guide/chpt3.1/fsmr.h b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/fsmr.h new file mode 100644 index 000000000..237afcfae --- /dev/null +++ b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/fsmr.h @@ -0,0 +1,76 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + fsmr.h -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +/* Header file for FSM recognizer */ + +#include "systemc.h" + +SC_MODULE( fsm_recognizer ) +{ + SC_HAS_PROCESS( fsm_recognizer ); + + sc_in_clk clk; + + // The input signals + const sc_signal& input_char; // The input character + const sc_signal& data_ready; // The data ready signal + // The output signals + sc_signal& found; // The indicator that sequence found + + // The internal variables + char pattern[4]; // This string will hold the pattern to match against + + // The constructor + fsm_recognizer(sc_module_name NAME, + sc_clock& TICK, + const sc_signal& INPUT_CHAR, + const sc_signal& DATA_READY, + sc_signal& FOUND) + : input_char(INPUT_CHAR), data_ready(DATA_READY), + found(FOUND) { + clk(TICK); + SC_CTHREAD( entry, clk.pos() ); + found = 0; + pattern[0] = 'S'; + pattern[1] = 'c'; + pattern[2] = 'e'; + pattern[3] = 'n'; + } + + // The functionality of the process + void entry(); +}; diff --git a/src/systemc/tests/systemc/misc/user_guide/chpt3.1/golden/chpt3.1.log b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/golden/chpt3.1.log new file mode 100644 index 000000000..52e7c3766 --- /dev/null +++ b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/golden/chpt3.1.log @@ -0,0 +1,12 @@ +SystemC Simulation +Synopsys is delivering great value through Scen +Found Count is 1 +ic. I cannot wait to use Scen +Found Count is 2 +ic +Compiler and Scen +Found Count is 3 +ic Simulator. I am learning a lot about modeling using +Scen +Found Count is 4 +ic. diff --git a/src/systemc/tests/systemc/misc/user_guide/chpt3.1/main.cpp b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/main.cpp new file mode 100644 index 000000000..d432b7f42 --- /dev/null +++ b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/main.cpp @@ -0,0 +1,63 @@ +/***************************************************************************** + + 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 -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +/* Main routine - top level */ + +#include "counter.h" +#include "sg.h" +#include "fsmr.h" + +int sc_main(int ac, char *av[]) +{ + sc_signal handshake ("HS"); + sc_signal found; + sc_signal stream ("ST"); + + sc_clock clk("Clock", 20, SC_NS, 0.5, 0.0, SC_NS); + + counter cnt("COUNTER", clk, found); + fsm_recognizer fsm("Recog", clk, stream, handshake, found); + stimgen chargen("TESTB", clk, stream, handshake); + + int n; + if (ac == 2) n = atoi(av[1]); + else n = 6340; + sc_start(n, SC_NS); + cout << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/misc/user_guide/chpt3.1/sg.cpp b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/sg.cpp new file mode 100644 index 000000000..65edd73e6 --- /dev/null +++ b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/sg.cpp @@ -0,0 +1,57 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + sg.cpp -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +/* File containing functionality for the Stimulus Generator */ + +#include "sg.h" + +void stimgen::entry() +{ + char c; + FILE *file; + + file = fopen("./chpt3.1/testcase", "r"); + + while (true) { + fscanf(file, "%c", &c); + data_ready.write(true); + stream.write(c); + wait(); + data_ready.write(false); + wait(); + } +} diff --git a/src/systemc/tests/systemc/misc/user_guide/chpt3.1/sg.h b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/sg.h new file mode 100644 index 000000000..937c3169e --- /dev/null +++ b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/sg.h @@ -0,0 +1,64 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + sg.h -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +/* Header file for the stimulus generator */ + +#include "systemc.h" + +SC_MODULE( stimgen ) +{ + SC_HAS_PROCESS( stimgen ); + + sc_in_clk clk; + + // The output + sc_signal& stream; + sc_signal& data_ready; + + // The constructor + stimgen(sc_module_name NAME, + sc_clock& CLK, + sc_signal& STREAM, + sc_signal& DATA_READY) + : stream(STREAM), data_ready(DATA_READY) { + clk(CLK); + SC_CTHREAD( entry, clk.pos() ); + } + + // The functionality of the process + void entry(); +}; diff --git a/src/systemc/tests/systemc/misc/user_guide/chpt3.1/testcase b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/testcase new file mode 100644 index 000000000..3b56603ff --- /dev/null +++ b/src/systemc/tests/systemc/misc/user_guide/chpt3.1/testcase @@ -0,0 +1,9 @@ +Synopsys is delivering great value through Scenic. I cannot wait to use Scenic +Compiler and Scenic Simulator. I am learning a lot about modeling using +Scenic. + +This is a testcase for my first Scenic program. I have learnt modeling using +Scenic and would now like to check if I can really program in Scenic. There is +no doubt in my mind that Scenic is the best way to model hardware. The Scenic +Compiler will make a lot of things easy by implementing by refined Scenic +models. -- cgit v1.2.3