From ea6d56f413ba33c0663e74c22e2eaff9a6153335 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 11 Nov 2022 08:25:11 +0100 Subject: [PATCH] adds cci test setup, needs to becomne self-checking --- scc | 2 +- tests/CMakeLists.txt | 1 + tests/configuration/CMakeLists.txt | 5 + tests/configuration/initiator.h | 140 ++++++++++++++++++ tests/configuration/router.h | 175 ++++++++++++++++++++++ tests/configuration/sc_main.cpp | 86 +++++++++++ tests/configuration/target.h | 147 +++++++++++++++++++ tests/configuration/top_module.h | 224 +++++++++++++++++++++++++++++ 8 files changed, 779 insertions(+), 1 deletion(-) create mode 100644 tests/configuration/CMakeLists.txt create mode 100644 tests/configuration/initiator.h create mode 100644 tests/configuration/router.h create mode 100644 tests/configuration/sc_main.cpp create mode 100644 tests/configuration/target.h create mode 100644 tests/configuration/top_module.h diff --git a/scc b/scc index fc75958..b1b9ad0 160000 --- a/scc +++ b/scc @@ -1 +1 @@ -Subproject commit fc75958b72caa7bb93919515c92a5b0779fe06bd +Subproject commit b1b9ad050802cf38523a40b5845822f22d7af70e diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index eeee6f4..83bc841 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(io-redirector) add_subdirectory(ordered_semaphore) add_subdirectory(axi4_pin_level) +add_subdirectory(configuration) if(FULL_TEST_SUITE) add_subdirectory(sim_performance) endif() \ No newline at end of file diff --git a/tests/configuration/CMakeLists.txt b/tests/configuration/CMakeLists.txt new file mode 100644 index 0000000..7e1e069 --- /dev/null +++ b/tests/configuration/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable (cci-example + sc_main.cpp +) +target_link_libraries (cci-example LINK_PUBLIC scc-sysc) +add_test(NAME cci-example_test COMMAND cci-example) \ No newline at end of file diff --git a/tests/configuration/initiator.h b/tests/configuration/initiator.h new file mode 100644 index 0000000..589653e --- /dev/null +++ b/tests/configuration/initiator.h @@ -0,0 +1,140 @@ +/***************************************************************************** + + 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. + + ****************************************************************************/ + +/** + * @file initiator.h + * @brief initiator module implementation. + * This file declares and implements the functionality of the initiator. + * Few of the parameters of the initiator sc_module are configured by the + * router sc_module + * @author P V S Phaneendra, CircuitSutra Technologies + * Parvinder Pal Singh, CircuitSutra Technologies + * @date 29th April, 2011 (Friday) + */ + +#ifndef EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_INITIATOR_H_ +#define EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_INITIATOR_H_ + +#include +#include +#include +#include +#include + +/** + * @class initiator + * @brief The implementation of the initiator module with tlm2 socket for communication + * @return void + */ +SC_MODULE(initiator) { +public: + int data; + + tlm_utils::simple_initiator_socket initiator_socket; ///< Instance of TLM2 simple initiator socket + + /** + * @fn initiator + * @brief The class constructor + * @return void + */ + SC_CTOR(initiator) + : + data(0), initiator_socket("initiator_socket"), initiator_ID("initiator_ID", "initiator_default") { + SCCINFO(SCMOD) << "[" << initiator_ID.get_value() << " C_TOR] ------- [INITIATOR CONSTRUCTOR BEGINS HERE] --------"; + + // initiator's SC_THREAD declaration + SC_THREAD(run_initiator); + + } + + /** + * @fn void run_initiator(void) + * @brief Main function to send transactions + * @return void + */ + void run_initiator(void) { + tlm::tlm_generic_payload *trans = new tlm::tlm_generic_payload; + + int i = 0; + + static tlm::tlm_command cmds[8] = + { tlm::TLM_WRITE_COMMAND, tlm::TLM_READ_COMMAND, tlm::TLM_WRITE_COMMAND, tlm::TLM_READ_COMMAND, tlm::TLM_READ_COMMAND, + tlm::TLM_READ_COMMAND, tlm::TLM_WRITE_COMMAND, tlm::TLM_WRITE_COMMAND }; + while (1) { + tlm::tlm_command cmd = cmds[(i >> 2) % 8]; + //static_cast(cmd_dist(rng)); + + if (cmd == tlm::TLM_WRITE_COMMAND) data = 0xFF000000 | i; + + trans->set_command(cmd); + trans->set_address(i); + trans->set_data_ptr(reinterpret_cast(&data)); + trans->set_data_length(4); + trans->set_streaming_width(4); + trans->set_byte_enable_ptr(0); + trans->set_dmi_allowed(false); + trans->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); + sc_core::sc_time delay = sc_core::sc_time(0, sc_core::SC_NS); + + if (cmd == tlm::TLM_WRITE_COMMAND) { + SCCINFO(SCMOD) << "[Initiators Message]=>At address " << std::hex << i << " sending transaction with command = Write" + << ", data=" << std::hex << data << " at time " << sc_core::sc_time_stamp(); + } else { + SCCINFO(SCMOD) << "[Initiators Message]=>At address " << std::hex << i << " sending transaction with command= Read " + << " at time " << sc_core::sc_time_stamp(); + } + + initiator_socket->b_transport(*trans, delay); + + if (trans->is_response_error()) + SCCERR(SCMOD) << "TLM_2" << trans->get_response_string().c_str(); + + if (delay.to_double() != 0) wait(delay); + + if (cmd == tlm::TLM_WRITE_COMMAND) { + SCCINFO(SCMOD) << "[Initiators Message]=>At address " << std::hex << i << " received response of Write transaction " + << " at time " << sc_core::sc_time_stamp(); + } else { + SCCINFO(SCMOD) << "[Initiators Message]=>At address " << std::hex << i << " received response of Read transaction " + << " data " << data << " at time " << sc_core::sc_time_stamp(); + } + + SCCINFO(SCMOD) << "--------------------------------------------------------"; + + wait(5.0, sc_core::SC_NS); + + i = i + 4; + } + } + +private: + cci::cci_param initiator_ID; ///< Elab Time Param for assigning initiator ID (initialized by top_module) + /** + * @fn void end_of_elaboration() + * @brief end of elaboration function to lock structural param + * @return void + */ + void end_of_elaboration() { + initiator_ID.lock(); + } + +}; +// initiator + +#endif // EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_INITIATOR_H_ diff --git a/tests/configuration/router.h b/tests/configuration/router.h new file mode 100644 index 0000000..5c1cfea --- /dev/null +++ b/tests/configuration/router.h @@ -0,0 +1,175 @@ +/***************************************************************************** + + 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. + + ****************************************************************************/ + +/** + * @file router.h + * @brief Definition of the router module. + * This file declares and implements the functionality of the router. + * Few of the parameters of the target and initiator sc_module(s) are + * configured by the router sc_module + * @authors P V S Phaneendra, CircuitSutra Technologies + * @date 29th April, 2011 (Friday) + */ + +#ifndef EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_ROUTER_H_ +#define EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_ROUTER_H_ + +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + +#include +#include +#include +#include +#include + +#include +#include + +/** + * @class router + * @brief Thes module implements a router functionality + */ +SC_MODULE(router) { +public: + // Declare tlm multi-passthrough sockets for target and initiator modules + tlm_utils::multi_passthrough_target_socket Router_target; + tlm_utils::multi_passthrough_initiator_socket Router_initiator; + + /** + * @fn router + * @brief The class constructor + * @return void + */ + SC_CTOR(router) + : + Router_target("Router_target"), Router_initiator("Router_initiator"), r_initiators("r_initiators", 0), r_targets("r_targets", + 0), addr_limit("addr_max", 64), m_broker(cci::cci_get_broker()), addrSize(0) { + SCCINFO(SCMOD) << "[ROUTER C_TOR] ----- [ROUTER CONSTRUCTOR BEGINS HERE] ------"; + + // Register b_transport + Router_target.register_b_transport(this, &router::b_transport); + } + + /** + * @fn void before_end_of_elaboration(void) + * @brief The router table information is filled in during this function + * @return void + */ + void before_end_of_elaboration(void) { + SCCINFO(SCMOD) << "[ROUTER in beoe] : Number of initiator(s) : " << r_initiators.get_cci_value().to_json(); + SCCINFO(SCMOD) << "[ROUTER in beoe] : Number of target(s) : " << r_targets.get_value(); + SCCINFO(SCMOD) << "[ROUTER in beoe] : Maximum Addressable Limit of the router : " << addr_limit.get_value(); + + char targetName[10]; ///< Holds router table's fields' names + addrSize = (unsigned int) (addr_limit.get_value() / r_targets); + + // Printing the Router Table contents + SCCINFO(SCMOD) << "============= ROUTER TABLE INFORMATION =============="; + SCCINFO(SCMOD) << "-----------------------------------------------------"; + SCCINFO(SCMOD) << "| Target ID | Start Addr | End Addr | Base Addr |"; + SCCINFO(SCMOD) << "-----------------------------------------------------"; + + // Sets the contents of the routing table with (default) values + // calculated within 'beoe' phase + for (int i = 0; i < r_targets; i++) { + snprintf(targetName, sizeof(targetName), "r_index_%d", i); + r_target_index.push_back(new cci::cci_param(targetName, i)); + + snprintf(targetName, sizeof(targetName), "r_sa_%d", i); + r_addr_start.push_back(new cci::cci_param(targetName, (i * addrSize))); + + snprintf(targetName, sizeof(targetName), "r_ea_%d", i); + r_addr_end.push_back(new cci::cci_param(targetName, ((i + 1) * addrSize - 1))); + } + + for (int i = 0; i < r_targets; i++) { + snprintf(stringName, sizeof(stringName), "top_module_inst.target_%d.s_base_addr", i); + + base_handle = m_broker.get_param_handle(stringName); + if (!base_handle.is_valid()) { + sc_assert(!"target Base Address Handle returned is NULL"); + } + std::stringstream row_ss; + row_ss << "| " << std::setw(10) << r_target_index[i]->get_value() << " | " << std::setw(10) << std::hex << std::showbase + << r_addr_start[i]->get_value() << " | " << std::setw(10) << r_addr_end[i]->get_value() << " | " << std::setw(10) + << base_handle.get_cci_value().to_json() << " |"; + SCCINFO(SCMOD) << row_ss.str().c_str(); + SCCINFO(SCMOD) << "-----------------------------------------------------"; + } + } + + // Blocking transport implementation of the router + void b_transport(int i_, tlm::tlm_generic_payload &trans, sc_core::sc_time &delay) { + wait(delay); + + delay = sc_core::SC_ZERO_TIME; + + sc_dt::uint64 addr = trans.get_address(); + + if (addr >= static_cast(addr_limit.get_value())) { + trans.set_response_status(tlm::TLM_ADDRESS_ERROR_RESPONSE); + return; + } + + for (unsigned int i = 0; i < r_target_index.size(); i++) { + if ((addr >= (r_addr_start[i]->get_value())) && (addr <= (r_addr_end[i]->get_value()))) { + SCCINFO(SCMOD) << "[Router in 'b_transport' layer]"; + SCCINFO(SCMOD) << "Address = " << std::hex << addr; + SCCINFO(SCMOD) << "Index = " << (r_target_index[i])->get_value(); + SCCINFO(SCMOD) << "Start addres = " << std::hex << (r_addr_start[i]->get_value()); + SCCINFO(SCMOD) << "End Address = " << std::hex << (r_addr_end[i]->get_value()); + Router_initiator[(r_target_index[i])->get_value()]->b_transport(trans, delay); + break; + } + } + } + +private: + /// Demonstrates Model-to-Model Configuration (UC12) + /// Elaboration Time Parameters for setting up the model hierarcy; + cci::cci_param r_initiators; ///< initiator ID assigned by the top_module upon instantiation + cci::cci_param r_targets; ///< target ID assigned by the top_module upon instantiation + cci::cci_param addr_limit; ///< Router Addressing Range + cci::cci_broker_handle m_broker; ///< CCI configuration broker handle + + /// Router Table contents holding targets related information + std::vector*> r_target_index; ///< Router table target index + std::vector*> r_addr_start; ///< Router table start address + std::vector*> r_addr_end; ///< Router table end address + + cci::cci_param_handle base_handle; ///< CCI base parameter handle for target base address + + /** + * @fn void end_of_elaboration() + * @brief end of elaboration function to lock structural param + * @return void + */ + void end_of_elaboration() { + r_initiators.lock(); + r_targets.lock(); + } + + int addrSize; + char stringName[50]; +}; +// router + +#endif // EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_ROUTER_H_ diff --git a/tests/configuration/sc_main.cpp b/tests/configuration/sc_main.cpp new file mode 100644 index 0000000..9127202 --- /dev/null +++ b/tests/configuration/sc_main.cpp @@ -0,0 +1,86 @@ +/***************************************************************************** + + 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. + + ****************************************************************************/ + +#ifndef SC_INCLUDE_DYNAMIC_PROCESSES +#define SC_INCLUDE_DYNAMIC_PROCESSES +#endif + +/** + * @file main.cpp + * @brief Testbench file + * This file declares and implements the functionality of the target. + * Few of the parameters of the target sc_module are configured by the + * router sc_module. + * @author P V S Phaneendra, CircuitSutra Technologies + * @date 29th April, 2011 (Friday) + */ + +#include +#include +#include +#include "top_module.h" + +/** + * @fn int sc_main(int argc, char* argv[]) + * @brief The testbench for the hierarchical override of parameter values example + * @param argc The number of input arguments + * @param argv The list of input arguments + * @return An integer for the execution status + */ +int sc_main(int sc_argc, char *sc_argv[]) { + scc::init_logging(scc::log::INFO); + cci::cci_originator me = cci::cci_originator("sc_main"); + // Get handle to the default broker + cci::cci_broker_handle myGlobalBroker = cci::cci_get_global_broker(me); + myGlobalBroker.set_preset_cci_value("top_module_inst.**.log_level", cci::cci_value(3)); + SCCINFO("sc_main") << "[MAIN] : Setting preset value of the number of initiators to 2"; + // Set preset value to the number of initiator(s) (within top_module) + std::string initiatorHierarchicalName = "top_module_inst.number_of_initiators"; + myGlobalBroker.set_preset_cci_value(initiatorHierarchicalName, cci::cci_value(2)); + SCCINFO("sc_main") << "[MAIN] : Setting preset value of the number of initiators to 1"; + // The program considers only the last set preset value + myGlobalBroker.set_preset_cci_value(initiatorHierarchicalName, cci::cci_value(1)); + SCCINFO("sc_main") << "[MAIN] : Setting preset value of the number of targets to 4"; + // Set preset value to the number of target(s) (within top_module) + std::string targetHierarchicalName = "top_module_inst.number_of_targets"; + myGlobalBroker.set_preset_cci_value(targetHierarchicalName, cci::cci_value(4)); + // Set the maximum addressing limit for the router + myGlobalBroker.set_preset_cci_value("top_module_inst.RouterInstance.addr_max", cci::cci_value(1024)); + // Set and lock the Router Table presets values for target_1 + // These values have again been tried to set within the Top_MODULE + // @see top_module.h + SCCINFO("sc_main") << "[MAIN] : Set and lock Router Table target_1 contents"; + myGlobalBroker.set_preset_cci_value("top_module_inst.RouterInstance.r_index_1", cci::cci_value(1)); + myGlobalBroker.lock_preset_value("top_module_inst.RouterInstance.r_index_1"); + SCCINFO("sc_main") << "[MAIN] : Set and lock Router Table Start Address for target_1 to 128"; + myGlobalBroker.set_preset_cci_value("top_module_inst.RouterInstance.r_sa_1", cci::cci_value(128)); + myGlobalBroker.lock_preset_value("top_module_inst.RouterInstance.r_sa_1"); + SCCINFO("sc_main") << "[MAIN] : Set and lock Router Table End Address for target_1 to 255"; + myGlobalBroker.set_preset_cci_value("top_module_inst.RouterInstance.r_ea_1", cci::cci_value(255)); + myGlobalBroker.lock_preset_value("top_module_inst.RouterInstance.r_ea_1"); + SCCINFO("sc_main") << "[MAIN] : Instantiate top module after setting preset values to top_module, router and target parameters"; + // Instantiate TOP_MODULE responsible for creating the model hierarchy + top_module top_mod("top_module_inst"); + // Start the simulation + SCCINFO("sc_main") << "Begin Simulation."; + sc_core::sc_start(1140, sc_core::SC_NS); + SCCINFO("sc_main") << "End Simulation."; + + return EXIT_SUCCESS; +} // End of 'sc_main' diff --git a/tests/configuration/target.h b/tests/configuration/target.h new file mode 100644 index 0000000..d4b5315 --- /dev/null +++ b/tests/configuration/target.h @@ -0,0 +1,147 @@ +/***************************************************************************** + + 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. + + ****************************************************************************/ + +/** + * @file target.h + * @brief target module implementation. + * This file declares and implements the functionality of the target. + * Few of the parameters of the target sc_module are configured by the + * router sc_module + * @author P V S Phaneendra, CircuitSutra Technologies + * Parvinder Pal Singh, CircuitSutra Technologies + * @date 5th May, 2011 (Thursday) + */ + +#ifndef EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_TARGET_H_ +#define EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_TARGET_H_ + +#include +#include +#include +#include +#include + +/** + * @class target + * @brief This module implementas the functionality of a target IP + */ +SC_MODULE(target) { +public: + tlm_utils::simple_target_socket target_socket; + sc_core::sc_time read_latency, write_latency; + + SC_CTOR(target) + : + target_socket("target_socket"), target_ID("target_ID", "target_default"), s_base_addr("s_base_addr", 0), s_size("s_size", 256) { + SCCINFO(SCMOD) << "[" << target_ID.get_value() << " C_TOR] ------- [TARGET CONSTRUCTOR BEGINS HERE] --------"; + SCCINFO(SCMOD) << "[" << target_ID.get_value() << " C_TOR] : Base Address : " << s_base_addr.get_value(); + + // Register b_transport + target_socket.register_b_transport(this, &target::b_transport); + + write_latency = sc_core::sc_time(3, sc_core::SC_NS); + read_latency = sc_core::sc_time(5, sc_core::SC_NS); + + mem = new int[s_size.get_value()]; + + for (unsigned int i = 0; i < s_size.get_value(); i++) + mem[i] = 0xAABBCCDD | i; + + // target's SC_THREAD declaration + SC_THREAD(run_target); + } + + /** + * @fn void run_target(void) + * @brief The run thread of the modeul (does nothing) + * @return void + */ + void run_target(void) { + } + + /** + * @fn void b_transport(tlm::tlm_generic_payload& trans, sc_core::sc_time& delay) + * @brief Implementation of the blocking transport in the target + * @param trans The transaction being sent + * @param delay The annotated delay associated with the transaction + * @return void + */ + void b_transport(tlm::tlm_generic_payload &trans, sc_core::sc_time &delay) { + tlm::tlm_command cmd = trans.get_command(); + sc_dt::uint64 adr = trans.get_address() - s_base_addr.get_value(); + unsigned char *ptr = trans.get_data_ptr(); + unsigned int len = trans.get_data_length(); + unsigned char *byt = trans.get_byte_enable_ptr(); + unsigned int wid = trans.get_streaming_width(); + + SCCINFO(SCMOD) << "[TARGET] : adr ---- " << std::hex << adr; + SCCINFO(SCMOD) << "[TARGET] : base addr ---- " << std::hex << s_base_addr.get_value(); + + // Check for storage address overflow + if (adr > s_size.get_value()) { + trans.set_response_status(tlm::TLM_ADDRESS_ERROR_RESPONSE); + return; + } + + // Target unable to support byte enable attribute + if (byt) { + trans.set_response_status(tlm::TLM_BYTE_ENABLE_ERROR_RESPONSE); + return; + } + + // Target unable to support streaming width attribute + if (wid < len) { + trans.set_response_status(tlm::TLM_BURST_ERROR_RESPONSE); + return; + } + + if (cmd == tlm::TLM_READ_COMMAND) { + memcpy(ptr, &mem[adr], len); + delay = delay + read_latency; + } else + if (cmd == tlm::TLM_WRITE_COMMAND) { + memcpy(&mem[adr], ptr, len); + delay = delay + write_latency; + } + + trans.set_response_status(tlm::TLM_OK_RESPONSE); + } + +private: + cci::cci_param target_ID; ///< Elaboration Time Param for assigning target ID (initialized by top_module) + + cci::cci_param s_base_addr; ///< Mutable time param for setting target's base addr (initialized by router) + + cci::cci_param s_size; ///< Mutable time parameter for setting target's size (initialized by router); + + /** + * @fn void end_of_elaboration() + * @brief end of elaboration function to lock structural param + * @return void + */ + void end_of_elaboration() { + target_ID.lock(); + s_base_addr.lock(); + } + + int *mem; +}; +// target + +#endif // EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_TARGET_H_ diff --git a/tests/configuration/top_module.h b/tests/configuration/top_module.h new file mode 100644 index 0000000..0bd8cd6 --- /dev/null +++ b/tests/configuration/top_module.h @@ -0,0 +1,224 @@ +/***************************************************************************** + + 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. + + ****************************************************************************/ + +/** + * @file top_module.h + * @brief Implementation the TOP_MODULE. + * This header contains code related to the top module which decides + * the model hierarchy for example#9. + * @author P V S Phaneendra, CircuitSutra Technologies + * Girish Verma, CircuitSutra Technologies + * Parvinder Pal Singh, CircuitSutra Technologies + * @date 29th April, 2011 (Friday) + */ + +#ifndef EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_TOP_MODULE_H_ +#define EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_TOP_MODULE_H_ + +#include +#include +#include +#include +#include + +#include "router.h" +#include "initiator.h" +#include "target.h" + +/** + * @class top_module + * @brief This module instantiated a initiator, target, and router and binds them correctly for communication. + */ +SC_MODULE(top_module) { +public: + /** + * @fn top_module + * @brief The class constructor + */ + SC_CTOR(top_module) + : + n_initiators("number_of_initiators", 0), n_targets("number_of_targets", 0), m_broker(cci::cci_get_broker()) { + std::stringstream ss; + + SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] -- [TOP MODULE CONSTRUCTOR BEGINS HERE]"; + + SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Number of initiators : " << n_initiators.get_value(); + SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Number of targets : " << n_targets.get_value(); + + // Set and lock the number of initiators in Router Table + // to value passed from 'sc_main' + m_broker.set_preset_cci_value("top_module_inst.RouterInstance.r_initiators", n_initiators.get_cci_value()); + m_broker.lock_preset_value("top_module_inst.RouterInstance.r_initiators"); + + // Set and lock the number of targets in Router Table + // to value passed from 'sc_main' + m_broker.set_preset_cci_value("top_module_inst.RouterInstance.r_targets", n_targets.get_cci_value()); + m_broker.lock_preset_value("top_module_inst.RouterInstance.r_targets"); + + // Declaring and defining router module + char routerName[15] = "RouterInstance"; + SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Creating Router : " << routerName; + routerInstance = new router(routerName); + + // Top_Module begins construction of the model hierarchy from here + // ---------------------------------------------------------------- + + cci::cci_param_handle r_addr_limit_handle = m_broker.get_param_handle("top_module_inst.RouterInstance.addr_limit"); + if (r_addr_limit_handle.is_valid()) { + r_addr_max = atoi((r_addr_limit_handle.get_cci_value().to_json()).c_str()); + + SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Router's maximum addressable limit : " << r_addr_max; + } + + /// Creating instances of initiator(s) + for (int i = 0; i < n_initiators; i++) { + snprintf(initiatorName, sizeof(initiatorName), "initiator_%d", i); + SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Creating initiator : " << initiatorName; + + snprintf(stringMisc, sizeof(stringMisc), "%s.%s.initiator_ID", name(), initiatorName); + + snprintf(initiatorName, sizeof(initiatorName), "\"initiator_%d\"", i); + m_broker.set_preset_cci_value(stringMisc, cci::cci_value::from_json(initiatorName)); + snprintf(initiatorName, sizeof(initiatorName), "initiator_%d", i); + initiatorList.push_back(new initiator(initiatorName)); + + // Binding of initiator to Router + SCCINFO(SCMOD) << "[TOP MODULE C_TOR] : Binding Router_Initiator to " << initiatorName; + initiatorList[i]->initiator_socket.bind(routerInstance->Router_target); + } + + // Defining target size + targetSize = 128; + + // Creating instances of target(s) + for (int i = 0; i < n_targets; i++) { + snprintf(targetName, sizeof(targetName), "target_%d", i); + SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Creating target : " << targetName; + + snprintf(stringMisc, sizeof(stringMisc), "%s.%s.target_ID", name(), targetName); + snprintf(targetName, sizeof(targetName), "\"target_%d\"", i); + m_broker.set_preset_cci_value(stringMisc, cci::cci_value::from_json(targetName)); + snprintf(targetName, sizeof(targetName), "target_%d", i); + + // Set preset value for maximum target size(memory) + snprintf(stringMisc, sizeof(stringMisc), "%s.%s.s_size", name(), targetName); + ss.clear(); + ss.str(""); + ss << targetSize; + + m_broker.set_preset_cci_value(stringMisc, cci::cci_value::from_json(ss.str())); + targetList.push_back(new target(targetName)); + + // Binding Router to target + SCCINFO(SCMOD) << "[TOP MODULE C_TOR] : Binding Router_Initiator to " << targetName; + routerInstance->Router_initiator.bind(targetList[i]->target_socket); + } + + // Try re-setting locked values for Router Table contents + for (int i = 0; i < n_targets; i++) { + snprintf(targetName, sizeof(targetName), "%s.RouterInstance.r_index_%d", name(), i); + ss.clear(); + ss.str(""); + ss << i; + + try { + SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Re-setting fields of target_" << i; + m_broker.set_preset_cci_value(targetName, cci::cci_value::from_json(ss.str())); + } catch (sc_core::sc_report const &exception) { + SCCINFO(SCMOD) << "[ROUTER : Caught] : " << exception.what(); + } + + snprintf(targetName, sizeof(targetName), "%s.RouterInstance.r_sa_%d", name(), i); + ss.clear(); + ss.str(""); + ss << (i * targetSize); + + snprintf(targetBaseAddr, sizeof(targetBaseAddr), "%s.target_%d.s_base_addr", name(), i); + + cci::cci_param_untyped_handle h = m_broker.get_param_handle(targetBaseAddr); + h.set_cci_value(cci::cci_value::from_json(ss.str())); + + try { + SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Re-setting start addr of target_" << i; + m_broker.set_preset_cci_value(targetName, cci::cci_value::from_json(ss.str())); + } catch (sc_core::sc_report const &exception) { + SCCINFO(SCMOD) << "[ROUTER : Caught] : " << exception.what(); + } + + snprintf(targetName, sizeof(targetName), "%s.RouterInstance.r_ea_%d", name(), i); + ss.clear(); + ss.str(""); + ss << ((i + 1) * targetSize - 1); + + try { + SCCINFO(SCMOD) << "[TOP_MODULE C_TOR] : Re-setting end addr of target_" << i; + m_broker.set_preset_cci_value(targetName, cci::cci_value::from_json(ss.str())); + } catch (sc_core::sc_report const &exception) { + SCCINFO(SCMOD) << "[ROUTER : Caught] : " << exception.what(); + } + } + } + + /** + * @fn ~top_module() + * @brief The class destructor + * @return void + */ + ~top_module() { + if (!initiatorList.empty()) { + for (std::vector::iterator it = initiatorList.begin(); it != initiatorList.end(); ++it) { + delete (*it); + } + initiatorList.clear(); + } + + if (!targetList.empty()) { + for (std::vector::iterator it = targetList.begin(); it != targetList.end(); ++it) { + delete (*it); + } + targetList.clear(); + } + } + +private: + // Immutable type cci-parameters + cci::cci_param n_initiators; ///< Number of initiators to be instantiated + cci::cci_param n_targets; ///< Number of targets to be instantiated + + cci::cci_broker_handle m_broker; ///< Configuration broker handle + + router *routerInstance; ///< Declaration of a router pointer + + // STD::VECTORs for creating instances of initiator and target + std::vector initiatorList; ///< STD::VECTOR for initiators + std::vector targetList; ///< STD::VECTOR for targets + + char initiatorName[50]; ///< initiator_ID + char targetName[50]; ///< target_ID + char stringMisc[50]; ///< String to be used for misc things + char targetBaseAddr[50]; ///< The base address of the target + + int addrValue + { 0 }; ///< Address Value + int targetSize; ///< Maximum target Size (preset value) + int r_addr_max; ///< Maximum Router Table's memory range +}; +// top_module + +#endif // EXAMPLES_EX09_HIERARCHICAL_OVERRIDE_OF_PARAMETER_VALUES_TOP_MODULE_H_