SystemC-Components-Test/examples/simple_system/simple_system.cpp

88 lines
2.4 KiB
C++
Raw Normal View History

2017-09-18 12:18:55 +02:00
////////////////////////////////////////////////////////////////////////////////
// Copyright 2017 eyck@minres.com
2017-09-25 22:00:46 +02:00
//
2017-09-18 12:18:55 +02:00
// Licensed 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
2017-09-25 22:00:46 +02:00
//
2017-09-18 12:18:55 +02:00
// http://www.apache.org/licenses/LICENSE-2.0
2017-09-25 22:00:46 +02:00
//
2017-09-18 12:18:55 +02:00
// 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.
////////////////////////////////////////////////////////////////////////////////
2017-09-18 07:30:54 +02:00
/*
* simplesystem.cpp
*
* Created on: 17.09.2017
2017-09-18 12:18:55 +02:00
* Author: eyck@minres.com
2017-09-18 07:30:54 +02:00
*/
#include "simple_system.h"
namespace sysc {
simple_system::simple_system(sc_core::sc_module_name nm)
: sc_core::sc_module(nm)
, NAMED(i_master)
, NAMED(i_router, 4, 1)
2017-09-18 07:30:54 +02:00
, NAMED(i_uart)
, NAMED(i_spi)
, NAMED(i_gpio)
, NAMED(i_plic)
2017-09-18 07:30:54 +02:00
, NAMED(s_clk)
, NAMED(s_rst)
2017-09-25 13:07:04 +02:00
, NAMED(s_global_interrupts, 256)
, NAMED(s_core_interrupt)
, NAMED(s_gpio, 32)
{
2017-09-25 22:00:46 +02:00
// todo: discuss naming conventions (s_<signal> vs. <port>_i/_o) --> covnert into _s
2017-09-25 13:07:04 +02:00
2017-09-25 22:00:46 +02:00
// bus connections
2017-09-18 07:30:54 +02:00
i_master.intor(i_router.target[0]);
2018-11-20 23:57:56 +01:00
i_router.bind_target(i_plic.socket, 0, "plic");
i_router.bind_target(i_uart.socket, 1, "uart");
i_router.bind_target(i_spi.socket, 2, "spi");
i_router.bind_target(i_gpio.socket, 3, "gpio");
// target address ranges
for (const auto &e : e300_plat_map)
i_router.add_target_range(e.name, e.start, e.size);
2017-09-25 13:07:04 +02:00
// clock/reset connections
2017-09-18 07:30:54 +02:00
i_uart.clk_i(s_clk);
i_spi.clk_i(s_clk);
i_gpio.clk_i(s_clk);
i_plic.clk_i(s_clk);
s_clk.write(10_ns);
i_uart.rst_i(s_rst);
i_spi.rst_i(s_rst);
i_gpio.rst_i(s_rst);
i_plic.rst_i(s_rst);
i_master.rst_i(s_rst);
2017-09-25 13:07:04 +02:00
// interrupt connections
i_plic.core_interrupt_o(s_core_interrupt);
i_plic.global_interrupts_i.bind(s_global_interrupts);
i_master.global_interrupts_o(s_global_interrupts);
i_master.core_interrupt_i(s_core_interrupt);
for(auto i=0U; i<s_gpio.size(); ++i){
s_gpio[i].in(i_gpio.pins_o[i]);
i_gpio.pins_i[i](s_gpio[i].out);
}
SC_THREAD(gen_reset);
2017-09-18 07:30:54 +02:00
}
void simple_system::gen_reset() {
2017-09-25 22:00:46 +02:00
s_rst = true;
wait(10_ns);
2017-09-25 22:00:46 +02:00
s_rst = false;
2017-09-18 07:30:54 +02:00
}
} /* namespace sysc */