提交 8eb37b5b 编写于 作者: 饶先宏's avatar 饶先宏

202105250652

上级 85a95817
......@@ -49,6 +49,8 @@ IHDL4SEUnit** hdl4seCreateMain2(IHDL4SEModule** parent, char* instanceparam, cha
static int running = 1;
int StopRunning()
{
running = 0;
......@@ -70,24 +72,121 @@ static int hdl4se_print_all_signal(IHDL4SEDetector** detector, const char * path
return 0;
}
typedef struct s_signal_item {
const char* unitname;
const char* signalname;
IHDL4SEDetector** detector;
int index;
int width;
} signal_item;
signal_item signal_list[] = {
{"/simulator/digitled", "nwReset", NULL, 0, 0},
{"/simulator/digitled", "wWrite", NULL, 0, 0},
{"/simulator/digitled", "bWriteAddr", NULL, 0, 0},
{"/simulator/digitled", "bWriteData", NULL, 0, 0},
{"/simulator/digitled", "wRead", NULL, 0, 0},
{"/simulator/digitled", "bReadAddr", NULL, 0, 0},
{"/simulator/digitled", "bReadData", NULL, 0, 0},
};
#define signal_list_count (sizeof(signal_list) / sizeof(signal_list[0]))
static int hdl4se_init_signal_list(IHDL4SEDetector** detector, const char* pathname, int *pcount)
{
int i, j;
int count;
int width;
const char* name;
for (j = 0; j < signal_list_count; j++) {
if (strcmp(pathname, signal_list[j].unitname) == 0) {
count = objectCall0(detector, GetSignalCount);
for (i = 0; i < count; i++) {
objectCall3(detector, GetSignalInfo, i, &name, &width);
if (strcmp(name, signal_list[j].signalname) == 0) {
signal_list[j].detector = detector;
signal_list[j].index = i;
signal_list[j].width = width;
printf("sig: %s, unit=%s, index=%d, width=%d\n", name, pathname, i, width);
(*pcount)++;
}
}
}
}
return 0;
}
FILE* pSignalFile = NULL;
IBigNumber** signal_value = NULL;
static int hdl4se_print_signal_list_header()
{
int i;
fprintf(pSignalFile, "clocks");
for (i = 0; i < signal_list_count; i++) {
fprintf(pSignalFile, ",%s", signal_list[i].signalname);
}
fprintf(pSignalFile, "\n");
return 0;
}
static int hdl4se_print_signal_list_detector()
{
int i;
/*
我们可以设置记录条件,比如,看到bDataRead数据不为零才记录,
此时必然是由按键消息了
*/
{
unsigned int v;
objectCall2(signal_value, SetWidth, 32, 0);
objectCall2(signal_list[6].detector, GetSignalValue, signal_list[6].index, signal_value);
objectCall1(signal_value, GetInt, &v);
if (v != 4) /* 只有F3按下的时候才记录 */
return 0;
}
fprintf(pSignalFile, "%lld", clocks);
for (i = 0; i < signal_list_count; i++) {
unsigned int v;
objectCall2(signal_value, SetWidth, 32, 0);
objectCall2(signal_list[i].detector, GetSignalValue, signal_list[i].index, signal_value);
objectCall1(signal_value, GetInt, &v);
if (signal_list[i].width == 1) {
fprintf(pSignalFile, ",%d", v & 1);
}
else {
fprintf(pSignalFile, ",%08x", v);
}
}
fprintf(pSignalFile, "\n");
return 0;
}
int main(int argc, char* argv[])
{
int width;
int count;
sim = hdl4sesimCreateSimulator();
topmodule = hdl4seCreateMain(NULL, "", "main");
gui = guiCreate(0xf0000000, "digitled");
objectCall1(sim, SetTopModule, topmodule);
objectCall1(sim, AddDevice, gui);
objectCall1(sim, SetReset, 0);
width = 0;
hdl4sedetectorTraversal(sim, hdl4se_print_all_signal, "", &width);
printf("Total width=%d bits, %d word\n", width * 32, width);
count = 0;
pSignalFile = fopen("digitled.csv", "w");
signal_value = bigintegerCreate(32);
hdl4se_print_signal_list_header();
hdl4sedetectorTraversal(sim, hdl4se_init_signal_list, "", &count);
printf("want %d, inited %d\n", signal_list_count, count);
do {
objectCall0(sim, RunClockTick);
hdl4se_print_signal_list_detector();
clocks++;
if (clocks == 4)
objectCall1(sim, SetReset, 1);
} while (running);
objectRelease(signal_value);
fclose(pSignalFile);
return 0;
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册