/* -*- c++ -*-
 *
 * SOCLIB_LGPL_HEADER_BEGIN
 * 
 * This file is part of SoCLib, GNU LGPLv2.1.
 * 
 * SoCLib is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; version 2.1 of the License.
 * 
 * SoCLib is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with SoCLib; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA
 * 
 * SOCLIB_LGPL_HEADER_END
 *
 * Copyright (c) Telecom ParisTech, Comelec 
 *         Jeremie Brunel <jeremie.brunel@telecom-paristech.fr>, 2014
 *
 */
#ifndef SOCLIB_CABA_SHUTDOWN
#define SOCLIB_CABA_SHUTDOWN

#include <systemc>
#include "vci_target_fsm.h"
#include "caba_base_module.h"
#include "mapping_table.h"

namespace soclib {
namespace caba {

using namespace sc_core;

template<typename vci_param>
class VciShutdown
	: public BaseModule
{

protected:
	SC_HAS_PROCESS(VciShutdown);

public:
    sc_in<bool> p_resetn;
    sc_in<bool> p_clk;
    VciTarget<vci_param> p_vci;
    VciTargetFsm<vci_param, true> m_vci_fsm;
    
    VciShutdown(
        sc_module_name insname, const IntTab &index,const MappingTable &mt)
        : BaseModule(insname),
          p_resetn("resetn"),
          p_clk("clk"),
          p_vci("vci"),
          m_vci_fsm(p_vci, mt.getSegmentList(index))
    {
        m_vci_fsm.on_read_write(on_read, on_write);

        SC_METHOD(transition)
            sensitive << p_clk.pos();

        SC_METHOD(genMoore)
            sensitive << p_clk.neg();
    }

    ~VciShutdown()
    {

    }

private:
    bool on_write(size_t seg, typename vci_param::addr_t addr, typename vci_param::addr_t data, int be)
    {
        sc_stop();
        return true;
    }
    bool on_read( size_t seg, typename vci_param::addr_t addr, typename vci_param::addr_t &data )
    {
        return true;
    }
    void transition()
    {
        if (!p_resetn)
        {
            m_vci_fsm.reset();
        }

        m_vci_fsm.transition();
    }
    void genMoore()
    {
        m_vci_fsm.genMoore();
    }

};

}}

#endif 

// Local Variables:
// tab-width: 4
// c-basic-offset: 4
// c-file-offsets:((innamespace . 0)(inline-open . 0))
// indent-tabs-mode: nil
// End:

// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4

