#include "linebuffer_2.h"
#include "AESL_pkg.h"

using namespace std;

namespace ap_rtl {

const sc_logic linebuffer_2::ap_const_logic_0 = sc_dt::Log_0;
const sc_logic linebuffer_2::ap_const_logic_1 = sc_dt::Log_1;
const bool linebuffer_2::ap_const_boolean_1 = true;
const sc_lv<128> linebuffer_2::ap_const_lv128_lc_1 = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";

linebuffer_2::linebuffer_2(sc_module_name name) : sc_module(name), mVcdFile(0) {
    call_1_U0 = new call_1("call_1_U0");
    call_1_U0->in_stream_V_value_V_dout(in_stream_V_value_V_dout);
    call_1_U0->in_stream_V_value_V_empty_n(in_stream_V_value_V_empty_n);
    call_1_U0->in_stream_V_value_V_read(call_1_U0_in_stream_V_value_V_read);
    call_1_U0->out_stream_V_value_V_din(call_1_U0_out_stream_V_value_V_din);
    call_1_U0->out_stream_V_value_V_full_n(out_stream_V_value_V_full_n);
    call_1_U0->out_stream_V_value_V_write(call_1_U0_out_stream_V_value_V_write);
    call_1_U0->ap_clk(ap_clk);
    call_1_U0->ap_rst(ap_rst);
    call_1_U0->ap_done(call_1_U0_ap_done);
    call_1_U0->ap_start(call_1_U0_ap_start);
    call_1_U0->ap_ready(call_1_U0_ap_ready);
    call_1_U0->ap_idle(call_1_U0_ap_idle);
    call_1_U0->ap_continue(call_1_U0_ap_continue);

    SC_METHOD(thread_ap_clk_no_reset_);
    dont_initialize();
    sensitive << ( ap_clk.pos() );

    SC_METHOD(thread_ap_done);
    sensitive << ( call_1_U0_ap_done );

    SC_METHOD(thread_ap_idle);
    sensitive << ( call_1_U0_ap_idle );

    SC_METHOD(thread_ap_ready);
    sensitive << ( internal_ap_ready );

    SC_METHOD(thread_ap_sync_continue);
    sensitive << ( ap_continue );

    SC_METHOD(thread_ap_sync_done);
    sensitive << ( call_1_U0_ap_done );

    SC_METHOD(thread_ap_sync_ready);
    sensitive << ( call_1_U0_ap_ready );

    SC_METHOD(thread_call_1_U0_ap_continue);
    sensitive << ( ap_continue );

    SC_METHOD(thread_call_1_U0_ap_start);
    sensitive << ( real_start );
    sensitive << ( ap_rst );

    SC_METHOD(thread_call_1_U0_start_full_n);

    SC_METHOD(thread_call_1_U0_start_write);

    SC_METHOD(thread_in_stream_V_value_V_read);
    sensitive << ( call_1_U0_in_stream_V_value_V_read );

    SC_METHOD(thread_internal_ap_ready);
    sensitive << ( ap_sync_ready );

    SC_METHOD(thread_out_stream_V_value_V_din);
    sensitive << ( call_1_U0_out_stream_V_value_V_din );

    SC_METHOD(thread_out_stream_V_value_V_write);
    sensitive << ( call_1_U0_out_stream_V_value_V_write );

    SC_METHOD(thread_real_start);
    sensitive << ( ap_start );
    sensitive << ( real_start_status_reg );

    SC_METHOD(thread_start_out);
    sensitive << ( real_start );

    SC_METHOD(thread_start_write);
    sensitive << ( ap_start );
    sensitive << ( start_control_reg );

    real_start_status_reg = SC_LOGIC_0;
    start_once_reg = SC_LOGIC_0;
    start_control_reg = SC_LOGIC_0;
    static int apTFileNum = 0;
    stringstream apTFilenSS;
    apTFilenSS << "linebuffer_2_sc_trace_" << apTFileNum ++;
    string apTFn = apTFilenSS.str();
    mVcdFile = sc_create_vcd_trace_file(apTFn.c_str());
    mVcdFile->set_time_unit(1, SC_PS);
    if (1) {
#ifdef __HLS_TRACE_LEVEL_PORT_HIER__
    sc_trace(mVcdFile, ap_start, "(port)ap_start");
    sc_trace(mVcdFile, start_full_n, "(port)start_full_n");
    sc_trace(mVcdFile, ap_ready, "(port)ap_ready");
    sc_trace(mVcdFile, start_out, "(port)start_out");
    sc_trace(mVcdFile, start_write, "(port)start_write");
    sc_trace(mVcdFile, in_stream_V_value_V_dout, "(port)in_stream_V_value_V_dout");
    sc_trace(mVcdFile, in_stream_V_value_V_empty_n, "(port)in_stream_V_value_V_empty_n");
    sc_trace(mVcdFile, in_stream_V_value_V_read, "(port)in_stream_V_value_V_read");
    sc_trace(mVcdFile, out_stream_V_value_V_din, "(port)out_stream_V_value_V_din");
    sc_trace(mVcdFile, out_stream_V_value_V_full_n, "(port)out_stream_V_value_V_full_n");
    sc_trace(mVcdFile, out_stream_V_value_V_write, "(port)out_stream_V_value_V_write");
    sc_trace(mVcdFile, ap_clk, "(port)ap_clk");
    sc_trace(mVcdFile, ap_rst, "(port)ap_rst");
    sc_trace(mVcdFile, ap_done, "(port)ap_done");
    sc_trace(mVcdFile, ap_idle, "(port)ap_idle");
    sc_trace(mVcdFile, ap_continue, "(port)ap_continue");
#endif
#ifdef __HLS_TRACE_LEVEL_INT__
    sc_trace(mVcdFile, real_start, "real_start");
    sc_trace(mVcdFile, real_start_status_reg, "real_start_status_reg");
    sc_trace(mVcdFile, internal_ap_ready, "internal_ap_ready");
    sc_trace(mVcdFile, start_once_reg, "start_once_reg");
    sc_trace(mVcdFile, start_control_reg, "start_control_reg");
    sc_trace(mVcdFile, call_1_U0_in_stream_V_value_V_read, "call_1_U0_in_stream_V_value_V_read");
    sc_trace(mVcdFile, call_1_U0_out_stream_V_value_V_din, "call_1_U0_out_stream_V_value_V_din");
    sc_trace(mVcdFile, call_1_U0_out_stream_V_value_V_write, "call_1_U0_out_stream_V_value_V_write");
    sc_trace(mVcdFile, call_1_U0_ap_done, "call_1_U0_ap_done");
    sc_trace(mVcdFile, call_1_U0_ap_start, "call_1_U0_ap_start");
    sc_trace(mVcdFile, call_1_U0_ap_ready, "call_1_U0_ap_ready");
    sc_trace(mVcdFile, call_1_U0_ap_idle, "call_1_U0_ap_idle");
    sc_trace(mVcdFile, call_1_U0_ap_continue, "call_1_U0_ap_continue");
    sc_trace(mVcdFile, ap_sync_continue, "ap_sync_continue");
    sc_trace(mVcdFile, ap_sync_done, "ap_sync_done");
    sc_trace(mVcdFile, ap_sync_ready, "ap_sync_ready");
    sc_trace(mVcdFile, call_1_U0_start_full_n, "call_1_U0_start_full_n");
    sc_trace(mVcdFile, call_1_U0_start_write, "call_1_U0_start_write");
#endif

    }
}

linebuffer_2::~linebuffer_2() {
    if (mVcdFile) 
        sc_close_vcd_trace_file(mVcdFile);

    delete call_1_U0;
}

void linebuffer_2::thread_ap_clk_no_reset_() {
    if ( ap_rst.read() == ap_const_logic_1) {
        real_start_status_reg = ap_const_logic_0;
    } else {
        if (esl_seteq<1,1,1>(start_full_n.read(), ap_const_logic_1)) {
            real_start_status_reg = ap_const_logic_0;
        } else if ((esl_seteq<1,1,1>(start_full_n.read(), ap_const_logic_0) && 
                    esl_seteq<1,1,1>(internal_ap_ready.read(), ap_const_logic_1))) {
            real_start_status_reg = ap_const_logic_1;
        }
    }
    if ( ap_rst.read() == ap_const_logic_1) {
        start_control_reg = ap_const_logic_0;
    } else {
        if ((esl_seteq<1,1,1>(real_start.read(), ap_const_logic_1) && 
             (esl_seteq<1,1,1>(internal_ap_ready.read(), ap_const_logic_1) || 
              esl_seteq<1,1,1>(ap_const_logic_0, start_once_reg.read())))) {
            start_control_reg = ap_const_logic_1;
        } else if (esl_seteq<1,1,1>(ap_const_logic_1, start_control_reg.read())) {
            start_control_reg = ap_const_logic_0;
        }
    }
    if ( ap_rst.read() == ap_const_logic_1) {
        start_once_reg = ap_const_logic_0;
    } else {
        if (esl_seteq<1,1,1>(real_start.read(), ap_const_logic_1)) {
            start_once_reg = ap_const_logic_1;
        } else if (esl_seteq<1,1,1>(ap_start.read(), ap_const_logic_0)) {
            start_once_reg = ap_const_logic_0;
        }
    }
}

void linebuffer_2::thread_ap_done() {
    ap_done = call_1_U0_ap_done.read();
}

void linebuffer_2::thread_ap_idle() {
    ap_idle = call_1_U0_ap_idle.read();
}

void linebuffer_2::thread_ap_ready() {
    ap_ready = internal_ap_ready.read();
}

void linebuffer_2::thread_ap_sync_continue() {
    ap_sync_continue = ap_continue.read();
}

void linebuffer_2::thread_ap_sync_done() {
    ap_sync_done = call_1_U0_ap_done.read();
}

void linebuffer_2::thread_ap_sync_ready() {
    ap_sync_ready = call_1_U0_ap_ready.read();
}

void linebuffer_2::thread_call_1_U0_ap_continue() {
    call_1_U0_ap_continue = ap_continue.read();
}

void linebuffer_2::thread_call_1_U0_ap_start() {
    if ( ap_rst.read() == ap_const_logic_1) {
        call_1_U0_ap_start = ap_const_logic_0;
    } else {
        call_1_U0_ap_start = real_start.read();
    }
}

void linebuffer_2::thread_call_1_U0_start_full_n() {
    call_1_U0_start_full_n = ap_const_logic_0;
}

void linebuffer_2::thread_call_1_U0_start_write() {
    call_1_U0_start_write = ap_const_logic_0;
}

void linebuffer_2::thread_in_stream_V_value_V_read() {
    in_stream_V_value_V_read = call_1_U0_in_stream_V_value_V_read.read();
}

void linebuffer_2::thread_internal_ap_ready() {
    internal_ap_ready = ap_sync_ready.read();
}

void linebuffer_2::thread_out_stream_V_value_V_din() {
    out_stream_V_value_V_din = call_1_U0_out_stream_V_value_V_din.read();
}

void linebuffer_2::thread_out_stream_V_value_V_write() {
    out_stream_V_value_V_write = call_1_U0_out_stream_V_value_V_write.read();
}

void linebuffer_2::thread_real_start() {
    if (esl_seteq<1,1,1>(real_start_status_reg.read(), ap_const_logic_1)) {
        real_start = ap_const_logic_0;
    } else {
        real_start = ap_start.read();
    }
}

void linebuffer_2::thread_start_out() {
    start_out = real_start.read();
}

void linebuffer_2::thread_start_write() {
    start_write = (ap_start.read() & start_control_reg.read());
}

}
// ==============================================================
// RTL generated by Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC
// Version: 2017.2
// Copyright (C) 1986-2017 Xilinx, Inc. All Rights Reserved.
// 
// ===========================================================

#include "linebuffer_2.h"
#include "AESL_pkg.h"

using namespace std;

namespace ap_rtl {

const sc_logic linebuffer_2::ap_const_logic_0 = sc_dt::Log_0;
const sc_logic linebuffer_2::ap_const_logic_1 = sc_dt::Log_1;
const bool linebuffer_2::ap_const_boolean_1 = true;
const sc_lv<128> linebuffer_2::ap_const_lv128_lc_1 = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";

linebuffer_2::linebuffer_2(sc_module_name name) : sc_module(name), mVcdFile(0) {
    call_1_U0 = new call_1("call_1_U0");
    call_1_U0->in_stream_V_value_V_dout(in_stream_V_value_V_dout);
    call_1_U0->in_stream_V_value_V_empty_n(in_stream_V_value_V_empty_n);
    call_1_U0->in_stream_V_value_V_read(call_1_U0_in_stream_V_value_V_read);
    call_1_U0->out_stream_V_value_V_din(call_1_U0_out_stream_V_value_V_din);
    call_1_U0->out_stream_V_value_V_full_n(out_stream_V_value_V_full_n);
    call_1_U0->out_stream_V_value_V_write(call_1_U0_out_stream_V_value_V_write);
    call_1_U0->ap_clk(ap_clk);
    call_1_U0->ap_rst(ap_rst);
    call_1_U0->ap_done(call_1_U0_ap_done);
    call_1_U0->ap_start(call_1_U0_ap_start);
    call_1_U0->ap_ready(call_1_U0_ap_ready);
    call_1_U0->ap_idle(call_1_U0_ap_idle);
    call_1_U0->ap_continue(call_1_U0_ap_continue);

    SC_METHOD(thread_ap_clk_no_reset_);
    dont_initialize();
    sensitive << ( ap_clk.pos() );

    SC_METHOD(thread_ap_done);
    sensitive << ( call_1_U0_ap_done );

    SC_METHOD(thread_ap_idle);
    sensitive << ( call_1_U0_ap_idle );

    SC_METHOD(thread_ap_ready);
    sensitive << ( internal_ap_ready );

    SC_METHOD(thread_ap_sync_continue);
    sensitive << ( ap_continue );

    SC_METHOD(thread_ap_sync_done);
    sensitive << ( call_1_U0_ap_done );

    SC_METHOD(thread_ap_sync_ready);
    sensitive << ( call_1_U0_ap_ready );

    SC_METHOD(thread_call_1_U0_ap_continue);
    sensitive << ( ap_continue );

    SC_METHOD(thread_call_1_U0_ap_start);
    sensitive << ( real_start );
    sensitive << ( ap_rst );

    SC_METHOD(thread_call_1_U0_start_full_n);

    SC_METHOD(thread_call_1_U0_start_write);

    SC_METHOD(thread_in_stream_V_value_V_read);
    sensitive << ( call_1_U0_in_stream_V_value_V_read );

    SC_METHOD(thread_internal_ap_ready);
    sensitive << ( ap_sync_ready );

    SC_METHOD(thread_out_stream_V_value_V_din);
    sensitive << ( call_1_U0_out_stream_V_value_V_din );

    SC_METHOD(thread_out_stream_V_value_V_write);
    sensitive << ( call_1_U0_out_stream_V_value_V_write );

    SC_METHOD(thread_real_start);
    sensitive << ( ap_start );
    sensitive << ( real_start_status_reg );

    SC_METHOD(thread_start_out);
    sensitive << ( real_start );

    SC_METHOD(thread_start_write);
    sensitive << ( ap_start );
    sensitive << ( start_control_reg );

    real_start_status_reg = SC_LOGIC_0;
    start_once_reg = SC_LOGIC_0;
    start_control_reg = SC_LOGIC_0;
    static int apTFileNum = 0;
    stringstream apTFilenSS;
    apTFilenSS << "linebuffer_2_sc_trace_" << apTFileNum ++;
    string apTFn = apTFilenSS.str();
    mVcdFile = sc_create_vcd_trace_file(apTFn.c_str());
    mVcdFile->set_time_unit(1, SC_PS);
    if (1) {
#ifdef __HLS_TRACE_LEVEL_PORT_HIER__
    sc_trace(mVcdFile, ap_start, "(port)ap_start");
    sc_trace(mVcdFile, start_full_n, "(port)start_full_n");
    sc_trace(mVcdFile, ap_ready, "(port)ap_ready");
    sc_trace(mVcdFile, start_out, "(port)start_out");
    sc_trace(mVcdFile, start_write, "(port)start_write");
    sc_trace(mVcdFile, in_stream_V_value_V_dout, "(port)in_stream_V_value_V_dout");
    sc_trace(mVcdFile, in_stream_V_value_V_empty_n, "(port)in_stream_V_value_V_empty_n");
    sc_trace(mVcdFile, in_stream_V_value_V_read, "(port)in_stream_V_value_V_read");
    sc_trace(mVcdFile, out_stream_V_value_V_din, "(port)out_stream_V_value_V_din");
    sc_trace(mVcdFile, out_stream_V_value_V_full_n, "(port)out_stream_V_value_V_full_n");
    sc_trace(mVcdFile, out_stream_V_value_V_write, "(port)out_stream_V_value_V_write");
    sc_trace(mVcdFile, ap_clk, "(port)ap_clk");
    sc_trace(mVcdFile, ap_rst, "(port)ap_rst");
    sc_trace(mVcdFile, ap_done, "(port)ap_done");
    sc_trace(mVcdFile, ap_idle, "(port)ap_idle");
    sc_trace(mVcdFile, ap_continue, "(port)ap_continue");
#endif
#ifdef __HLS_TRACE_LEVEL_INT__
    sc_trace(mVcdFile, real_start, "real_start");
    sc_trace(mVcdFile, real_start_status_reg, "real_start_status_reg");
    sc_trace(mVcdFile, internal_ap_ready, "internal_ap_ready");
    sc_trace(mVcdFile, start_once_reg, "start_once_reg");
    sc_trace(mVcdFile, start_control_reg, "start_control_reg");
    sc_trace(mVcdFile, call_1_U0_in_stream_V_value_V_read, "call_1_U0_in_stream_V_value_V_read");
    sc_trace(mVcdFile, call_1_U0_out_stream_V_value_V_din, "call_1_U0_out_stream_V_value_V_din");
    sc_trace(mVcdFile, call_1_U0_out_stream_V_value_V_write, "call_1_U0_out_stream_V_value_V_write");
    sc_trace(mVcdFile, call_1_U0_ap_done, "call_1_U0_ap_done");
    sc_trace(mVcdFile, call_1_U0_ap_start, "call_1_U0_ap_start");
    sc_trace(mVcdFile, call_1_U0_ap_ready, "call_1_U0_ap_ready");
    sc_trace(mVcdFile, call_1_U0_ap_idle, "call_1_U0_ap_idle");
    sc_trace(mVcdFile, call_1_U0_ap_continue, "call_1_U0_ap_continue");
    sc_trace(mVcdFile, ap_sync_continue, "ap_sync_continue");
    sc_trace(mVcdFile, ap_sync_done, "ap_sync_done");
    sc_trace(mVcdFile, ap_sync_ready, "ap_sync_ready");
    sc_trace(mVcdFile, call_1_U0_start_full_n, "call_1_U0_start_full_n");
    sc_trace(mVcdFile, call_1_U0_start_write, "call_1_U0_start_write");
#endif

    }
}

linebuffer_2::~linebuffer_2() {
    if (mVcdFile) 
        sc_close_vcd_trace_file(mVcdFile);

    delete call_1_U0;
}

void linebuffer_2::thread_ap_clk_no_reset_() {
    if ( ap_rst.read() == ap_const_logic_1) {
        real_start_status_reg = ap_const_logic_0;
    } else {
        if (esl_seteq<1,1,1>(start_full_n.read(), ap_const_logic_1)) {
            real_start_status_reg = ap_const_logic_0;
        } else if ((esl_seteq<1,1,1>(start_full_n.read(), ap_const_logic_0) && 
                    esl_seteq<1,1,1>(internal_ap_ready.read(), ap_const_logic_1))) {
            real_start_status_reg = ap_const_logic_1;
        }
    }
    if ( ap_rst.read() == ap_const_logic_1) {
        start_control_reg = ap_const_logic_0;
    } else {
        if ((esl_seteq<1,1,1>(real_start.read(), ap_const_logic_1) && 
             (esl_seteq<1,1,1>(internal_ap_ready.read(), ap_const_logic_1) || 
              esl_seteq<1,1,1>(ap_const_logic_0, start_once_reg.read())))) {
            start_control_reg = ap_const_logic_1;
        } else if (esl_seteq<1,1,1>(ap_const_logic_1, start_control_reg.read())) {
            start_control_reg = ap_const_logic_0;
        }
    }
    if ( ap_rst.read() == ap_const_logic_1) {
        start_once_reg = ap_const_logic_0;
    } else {
        if (esl_seteq<1,1,1>(real_start.read(), ap_const_logic_1)) {
            start_once_reg = ap_const_logic_1;
        } else if (esl_seteq<1,1,1>(ap_start.read(), ap_const_logic_0)) {
            start_once_reg = ap_const_logic_0;
        }
    }
}

void linebuffer_2::thread_ap_done() {
    ap_done = call_1_U0_ap_done.read();
}

void linebuffer_2::thread_ap_idle() {
    ap_idle = call_1_U0_ap_idle.read();
}

void linebuffer_2::thread_ap_ready() {
    ap_ready = internal_ap_ready.read();
}

void linebuffer_2::thread_ap_sync_continue() {
    ap_sync_continue = ap_continue.read();
}

void linebuffer_2::thread_ap_sync_done() {
    ap_sync_done = call_1_U0_ap_done.read();
}

void linebuffer_2::thread_ap_sync_ready() {
    ap_sync_ready = call_1_U0_ap_ready.read();
}

void linebuffer_2::thread_call_1_U0_ap_continue() {
    call_1_U0_ap_continue = ap_continue.read();
}

void linebuffer_2::thread_call_1_U0_ap_start() {
    if ( ap_rst.read() == ap_const_logic_1) {
        call_1_U0_ap_start = ap_const_logic_0;
    } else {
        call_1_U0_ap_start = real_start.read();
    }
}

void linebuffer_2::thread_call_1_U0_start_full_n() {
    call_1_U0_start_full_n = ap_const_logic_0;
}

void linebuffer_2::thread_call_1_U0_start_write() {
    call_1_U0_start_write = ap_const_logic_0;
}

void linebuffer_2::thread_in_stream_V_value_V_read() {
    in_stream_V_value_V_read = call_1_U0_in_stream_V_value_V_read.read();
}

void linebuffer_2::thread_internal_ap_ready() {
    internal_ap_ready = ap_sync_ready.read();
}

void linebuffer_2::thread_out_stream_V_value_V_din() {
    out_stream_V_value_V_din = call_1_U0_out_stream_V_value_V_din.read();
}

void linebuffer_2::thread_out_stream_V_value_V_write() {
    out_stream_V_value_V_write = call_1_U0_out_stream_V_value_V_write.read();
}

void linebuffer_2::thread_real_start() {
    if (esl_seteq<1,1,1>(real_start_status_reg.read(), ap_const_logic_1)) {
        real_start = ap_const_logic_0;
    } else {
        real_start = ap_start.read();
    }
}

void linebuffer_2::thread_start_out() {
    start_out = real_start.read();
}

void linebuffer_2::thread_start_write() {
    start_write = (ap_start.read() & start_control_reg.read());
}

}

