diff --git a/Makefile b/Makefile index f44a0fb..0b25106 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ test: sw: - + rm ./tb/sw/build/* -f riscv64-unknown-elf-gcc -Os -ggdb -march=rv32i -mabi=ilp32 -Wall -mcmodel=medany -mexplicit-relocs -mcmodel=medany -mexplicit-relocs \ -I ./tb/sw/ -I ./tb/sw/src \ @@ -120,6 +120,8 @@ sw: riscv64-unknown-elf-objcopy -O verilog ./tb/sw/build/slvTest.elf ./tb/sw/build/slvTest.verilog sed -i 's/@800/@000/g' ./tb/sw/build/slvTest.verilog + python3 ./tb/sw/bin_to_hex.py + fst: gtkwave ./tb/build/wave.fst & diff --git a/tb/sw/bin_to_hex.py b/tb/sw/bin_to_hex.py new file mode 100644 index 0000000..6a711d7 --- /dev/null +++ b/tb/sw/bin_to_hex.py @@ -0,0 +1,24 @@ +def bin_to_hex_file(bin_file, hex_file, address_depth=1024, data_width=32): + # 打开二进制文件和输出的Hex文件 + with open(bin_file, 'rb') as bf, open(hex_file, 'w') as hf: + # 写入文件头 + hf.write("#File_format=Hex\n") + hf.write(f"#Address_depth={address_depth}\n") + hf.write(f"#Data_width={data_width}\n") + + # 读取二进制文件内容 + data = bf.read() + + # 将二进制内容按每4字节分割并转换为十六进制字符串 + for i in range(address_depth): + if i * 4 < len(data): + # 提取4字节数据并转为32位的十六进制字符串 + value = int.from_bytes(data[i*4:(i+1)*4], byteorder='little') + hf.write(f"{value:08X}\n") + else: + # 如果数据不够,填充0 + hf.write("00000000\n") + +# 运行脚本 +bin_to_hex_file("./tb/sw/build/slvTest.bin", "./tb/sw/build/slvTest.mi") +bin_to_hex_file("./tb/sw/build/mstTest.bin", "./tb/sw/build/mstTest.mi") \ No newline at end of file diff --git a/tb/sw/src/MstMain.c b/tb/sw/src/MstMain.c index 5014b9b..063e846 100644 --- a/tb/sw/src/MstMain.c +++ b/tb/sw/src/MstMain.c @@ -44,6 +44,8 @@ void main() uint32_t isLast; + uint32_t led = 0; + while(1){ *cdr_softReset = 1; //复位脉冲 @@ -53,11 +55,19 @@ void main() "1:\n" "rdcycle ra\n" "srli ra, ra, 12\n" - //"srli ra, ra, 26\n" + // "srli ra, ra, 26\n" "andi ra, ra, 0x1\n" "beqz ra, 1b\n" ); + if( led ){ + *WriteGpio = 0xFFFFFFFF; + led = 0; + } else{ + *WriteGpio = 0x0; + led = 1; + } + //发送下行包头 *cdr_txLen = 520; //总长520 diff --git a/tb/sw/src/SlvMain.c b/tb/sw/src/SlvMain.c index 5044ddf..3749f90 100644 --- a/tb/sw/src/SlvMain.c +++ b/tb/sw/src/SlvMain.c @@ -48,6 +48,7 @@ void main() *cdr_softReset = 1; //复位脉冲 isLast = *ReadIsLast; *cdr_direct = 0; + *WriteGpio = 0xaaaa; asm volatile ( "1:\n"