main.cpp 6.7 KB
Newer Older
饶先宏's avatar
饶先宏 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36


/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
**   this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
**   this list of conditions and the following disclaimer in the documentation
**   and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
**   derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "stdlib.h"
#include "stdio.h"
#include "string.h"
37
#include "time.h"
饶先宏's avatar
饶先宏 已提交
38 39 40 41 42
#include "object.h"
#include "bignumber.h"
#include "hdl4secell.h"
#include "hdl4sesim.h"
#include "hdl4sevcdfile.h"
43
#include "terris.h"
饶先宏's avatar
饶先宏 已提交
44
#include "systemc.h"
饶先宏's avatar
饶先宏 已提交
45 46 47 48 49 50 51 52

IHDL4SESimulator** sim;
IHDL4SEUnit** topmodule; 
IHDL4SEUnit** gui;
unsigned long long clocks = 0;

static int running = 1;

饶先宏's avatar
饶先宏 已提交
53
#define VCDOUTPUT 1
饶先宏's avatar
饶先宏 已提交
54

饶先宏's avatar
饶先宏 已提交
55 56
extern "C" {
	int StopRunning()
饶先宏's avatar
饶先宏 已提交
57 58 59 60 61
{
	running = 0;
	return 0;
}

饶先宏's avatar
饶先宏 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

	IHDL4SEUnit** hdl4seCreate_main(IHDL4SEModule** parent, const char* instanceparam, const char* name);
	extern int (*A_u_t_o_registor_terrisctrl)();
	extern int (*A_u_t_o_registor_terrisctrl1)();
	extern int (*A_u_t_o_registor_terris_flushtodisp)();
	extern int (*A_u_t_o_registor_terris_blockwrite)();
	extern int (*A_u_t_o_registor_terris_canblocksetto)();
	extern int (*A_u_t_o_registor_terris_checkline)();
	extern int (*A_u_t_o_registor_terris_init)();
	extern int (*A_u_t_o_registor_terris_copylines)();
	extern int (*A_u_t_o_registor_terris_copylines)();
	extern int (*A_u_t_o_registor_terrisdevice)();
}

SC_MODULE(half_adder) {
	sc_in <bool>a, b;
	sc_out <bool> sum, carry;
	void prc_half_adder();

	SC_CTOR(half_adder) {
		SC_METHOD(prc_half_adder);
		sensitive << a << b;
	}
};

/*
struct signed_adder : ::sc_core::sc_module {
	sc_in <sc_int <4> >arb, tbe;
	sc_out <sc_int<5> > sum;
	void prc_signed_adder();

	typedef signed_adder SC_CURRENT_USER_MODULE;
	signed_adder(::sc_core::sc_module_name) {
		::sc_core::sc_process_handle prc_signed_adder_handle =
		sc_core::sc_get_curr_simcontext()->create_method_process(
		"prc_signed_adder",  false, SC_MAKE_FUNC_PTR( SC_CURRENT_USER_MODULE, prc_signed_adder ),
		this, 0 );
		sensitive << prc_signed_adder_handle;
		sensitive_pos << prc_signed_adder_handle;
		sensitive_neg << prc_signed_adder_handle;
		sensitive << arb << tbe;
	}
};
*/

void half_adder::prc_half_adder() {
	sum = a.read() ^ b.read();
	carry = a.read() & b.read();
	int aa = a.read();
	int bb = b.read();
	int ss = sum.read();
	int cc = carry.read();
	int dd = a.read();
}


饶先宏's avatar
饶先宏 已提交
118 119 120 121 122

int main(int argc, char* argv[])
{
	int i;
	int width;
123
	int resetwidth;
饶先宏's avatar
饶先宏 已提交
124 125
	int count, unitcount;
	IHDL4SEUnit** sim_unit;
饶先宏's avatar
饶先宏 已提交
126
	IHDL4SEWaveOutput** vcdfile;
127
	srand((unsigned int)time(NULL));
128
	resetwidth = 10 + rand() % 50;
饶先宏's avatar
饶先宏 已提交
129

饶先宏's avatar
饶先宏 已提交
130
	
131
	A_u_t_o_registor_terrisctrl();
饶先宏's avatar
饶先宏 已提交
132
	A_u_t_o_registor_terrisctrl1();
133 134 135 136 137 138
	A_u_t_o_registor_terris_flushtodisp();
	A_u_t_o_registor_terris_blockwrite();
	A_u_t_o_registor_terris_canblocksetto();
	A_u_t_o_registor_terris_checkline();
	A_u_t_o_registor_terris_init();
	A_u_t_o_registor_terris_copylines();
139
	A_u_t_o_registor_terrisdevice();
饶先宏's avatar
饶先宏 已提交
140
	sim = hdl4sesimCreateSimulator();
141
	topmodule = hdl4seCreate_main(NULL, "", "top");
饶先宏's avatar
饶先宏 已提交
142 143 144
	objectCall1(sim, SetTopModule, topmodule);
	objectCall1(sim, SetReset, 0);
	unitcount = 0;
饶先宏's avatar
饶先宏 已提交
145 146


饶先宏's avatar
饶先宏 已提交
147
	objectQueryInterface(sim, IID_HDL4SEUNIT, (void**) &sim_unit);
饶先宏's avatar
饶先宏 已提交
148
	objectPrintInfo(stdout, NULL);
饶先宏's avatar
饶先宏 已提交
149
#if VCDOUTPUT
150
	vcdfile = hdl4sesimCreateVCDFile("terris.vcd"); 
151 152 153 154
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl", "bWriteAddr");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl", "bWriteData");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/bCtrlState", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/wCtrlStateComplete", "out");
饶先宏's avatar
饶先宏 已提交
155 156
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/bCurBlockPos", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_curblock", "out");
157
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_nextblock", "out");
饶先宏's avatar
饶先宏 已提交
158 159
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_curposx", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_curposy", "out");
饶先宏's avatar
饶先宏 已提交
160 161 162
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_tick", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_speed", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/cur_key", "out");
163 164 165 166
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/outputx", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_curposx", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/outputy", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_curposy", "out");
饶先宏's avatar
饶先宏 已提交
167
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_testid", "out");
168 169 170 171 172
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/bResult", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_testx", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_testy", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_curposx", "out");
	objectCall2(vcdfile, AddSignal, "/top/terrisctrl/ctrl/wireout_curposy", "out");
173

174
	objectCall1(vcdfile, SetTopModule, topmodule);
饶先宏's avatar
饶先宏 已提交
175
	objectCall0(vcdfile, StartRecord);
饶先宏's avatar
饶先宏 已提交
176
#endif
饶先宏's avatar
饶先宏 已提交
177
	sc_get_curr_simcontext()->initialize();
饶先宏's avatar
饶先宏 已提交
178
	do {
饶先宏's avatar
饶先宏 已提交
179
		sc_time halfcycle(5, SC_NS);
饶先宏's avatar
饶先宏 已提交
180
		objectCall0(sim_unit, ClkTick);
饶先宏's avatar
饶先宏 已提交
181
#if VCDOUTPUT
饶先宏's avatar
饶先宏 已提交
182
		objectCall1(vcdfile, ClkTick, clocks);
饶先宏's avatar
饶先宏 已提交
183
#endif
饶先宏's avatar
饶先宏 已提交
184
		sc_get_curr_simcontext()->cycle(halfcycle);
饶先宏's avatar
饶先宏 已提交
185
		objectCall0(sim_unit, Setup);
饶先宏's avatar
饶先宏 已提交
186
		sc_get_curr_simcontext()->cycle(halfcycle);
饶先宏's avatar
饶先宏 已提交
187
		clocks++;
188
		if (clocks == resetwidth)
饶先宏's avatar
饶先宏 已提交
189 190
			objectCall1(sim, SetReset, 1);
	} while (running);
饶先宏's avatar
饶先宏 已提交
191
#if VCDOUTPUT
饶先宏's avatar
饶先宏 已提交
192 193
	objectCall0(vcdfile, StopRecord);
	objectRelease(vcdfile);
饶先宏's avatar
饶先宏 已提交
194
#endif
饶先宏's avatar
饶先宏 已提交
195 196
	return 0;
}