From 21c763f54ffa104d065cc7155d3de9dbeb2020d2 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Wed, 15 May 2024 21:54:11 +0800 Subject: [PATCH] change simulate --- Demosaic/sim/transform/raw_cut.py | 4 +-- FIFO/rptr_empty.v | 2 +- FIFO/wptr_full.v | 2 +- Merge/chanels_to_RGB.v | 3 ++- isp.v | 2 +- sim/Makefile | 8 +++--- sim/sc_main.cpp | 41 ++++++++++++++++++++----------- 7 files changed, 37 insertions(+), 25 deletions(-) diff --git a/Demosaic/sim/transform/raw_cut.py b/Demosaic/sim/transform/raw_cut.py index a0ed293..2cf7443 100644 --- a/Demosaic/sim/transform/raw_cut.py +++ b/Demosaic/sim/transform/raw_cut.py @@ -1,8 +1,8 @@ import imageio import numpy as np -cut_width = 512 -cut_height = 256 +cut_width = 1936 +cut_height = 1088 if __name__ == '__main__': # txt = open('./test.dat', 'w') diff --git a/FIFO/rptr_empty.v b/FIFO/rptr_empty.v index 17269c5..90bde33 100644 --- a/FIFO/rptr_empty.v +++ b/FIFO/rptr_empty.v @@ -37,7 +37,7 @@ module rptr_empty // Memory read-address pointer (okay to use binary to address memory) assign raddr = rbin[ADDRSIZE-1:0]; - assign rbinnext = rbin + (rinc & ~rempty); + assign rbinnext = rbin + {{(ADDRSIZE - 1){1'b0}},(rinc & ~rempty)}; assign rgraynext = (rbinnext >> 1) ^ rbinnext; assign rgraynextm1 = ((rbinnext + 1'b1) >> 1) ^ (rbinnext + 1'b1); diff --git a/FIFO/wptr_full.v b/FIFO/wptr_full.v index 3c8258c..f067d6b 100644 --- a/FIFO/wptr_full.v +++ b/FIFO/wptr_full.v @@ -35,7 +35,7 @@ module wptr_full // Memory write-address pointer (okay to use binary to address memory) assign waddr = wbin[ADDRSIZE-1:0]; - assign wbinnext = wbin + (winc & ~wfull); + assign wbinnext = wbin + {{(ADDRSIZE - 1){1'b0}}, (winc & ~wfull) }; assign wgraynext = (wbinnext >> 1) ^ wbinnext; assign wgraynextp1 = ((wbinnext + 1'b1) >> 1) ^ (wbinnext + 1'b1); diff --git a/Merge/chanels_to_RGB.v b/Merge/chanels_to_RGB.v index 8d8f537..335daf1 100644 --- a/Merge/chanels_to_RGB.v +++ b/Merge/chanels_to_RGB.v @@ -49,7 +49,8 @@ module chanels_to_RGB #( async_fifo #( .DSIZE(3 * OUT_DEPTH), - .ASIZE(128), + .ASIZE(4), + .FALLTHROUGH("False") ) RGB_FIFO ( .wclk(clk), .rclk(clk), diff --git a/isp.v b/isp.v index 3150728..41f87a2 100644 --- a/isp.v +++ b/isp.v @@ -58,7 +58,7 @@ module isp #( .clk(clk), .reset(reset), .in_en(rgb_en), - .data_in({im_red, im_green, im_red}), + .data_in({im_red, im_green, im_blue}), .data_que(scale_in_que), .out_en(scale_in_en), diff --git a/sim/Makefile b/sim/Makefile index a1a3948..70a48c7 100644 --- a/sim/Makefile +++ b/sim/Makefile @@ -90,10 +90,10 @@ run: @mkdir -p logs obj_dir/V$(TOP_MODULE) +trace - @echo - @echo "-- COVERAGE ----------------" - @rm -rf logs/annotated - $(VERILATOR_COVERAGE) --annotate logs/annotated logs/coverage.dat + # @echo + # @echo "-- COVERAGE ----------------" + # @rm -rf logs/annotated + # $(VERILATOR_COVERAGE) --annotate logs/annotated logs/coverage.dat @echo @echo "-- DONE --------------------" diff --git a/sim/sc_main.cpp b/sim/sc_main.cpp index f550002..9174ad6 100644 --- a/sim/sc_main.cpp +++ b/sim/sc_main.cpp @@ -37,9 +37,11 @@ SC_MODULE (TB_ISP) { sc_in im_en; sc_in im_data; - uint16_t image[IM_HEIGHT][IM_WIDTH]; - uint32_t out[IM_SIZE] = {0}; - uint32_t out_head = 0; + // uint16_t image[IM_HEIGHT][IM_WIDTH]; + // uint32_t out[IM_HEIGHT][IM_WIDTH]; + // uint32_t out_head = 0; + unique_ptr image = make_unique(IM_SIZE); + unique_ptr out = make_unique(IM_SIZE); SC_CTOR (TB_ISP) { SC_CTHREAD(send_Data, clk.pos()); @@ -55,13 +57,13 @@ SC_MODULE (TB_ISP) { if (data_que.read() && pos_y < IM_HEIGHT - 2) { data_en.write(1); - printf("x=%3d, y=%3d, data=0x%04x\t", pos_x, pos_y, image[pos_y + 0][pos_x]); - printf("x=%3d, y=%3d, data=0x%04x\t", pos_x, pos_y, image[pos_y + 1][pos_x]); - printf("x=%3d, y=%3d, data=0x%04x\n", pos_x, pos_y, image[pos_y + 2][pos_x]); + printf("x=%3d, y=%3d, data=0x%04x\t", pos_x, pos_y, image[( pos_y + 0 ) * IM_WIDTH + pos_x]); + printf("x=%3d, y=%3d, data=0x%04x\t", pos_x, pos_y, image[( pos_y + 1 ) * IM_WIDTH + pos_x]); + printf("x=%3d, y=%3d, data=0x%04x\n", pos_x, pos_y, image[( pos_y + 2 ) * IM_WIDTH + pos_x]); - data_out[0].write(image[pos_y + 0][pos_x]); - data_out[1].write(image[pos_y + 1][pos_x]); - data_out[2].write(image[pos_y + 2][pos_x]); + data_out[0].write(image[( pos_y + 0 ) * IM_WIDTH + pos_x]); + data_out[1].write(image[( pos_y + 1 ) * IM_WIDTH + pos_x]); + data_out[2].write(image[( pos_y + 2 ) * IM_WIDTH + pos_x]); if (pos_x++ >= IM_WIDTH) { pos_x = 0; @@ -77,10 +79,16 @@ SC_MODULE (TB_ISP) { } void read_Data(void) { + uint16_t pos_x = 0, pos_y = 0; while (true) { if (im_en.read()) { - out[out_head++] = im_data.read(); + out[pos_y * IM_WIDTH + pos_x] = im_data.read(); + + if (pos_x++ >= IM_WIDTH) { + pos_x = 0; + pos_y++; + } } wait(); @@ -89,6 +97,7 @@ SC_MODULE (TB_ISP) { }; int sc_main(int argc, char* argv[]) { + cout << "Get into sc_main" << endl; // Open image ifstream in_image; ofstream out_image; @@ -102,15 +111,17 @@ int sc_main(int argc, char* argv[]) { } // Read image - uint8_t buf[IM_SIZE * 2] = {0}; - in_image.read((char*)buf, IM_SIZE * 2); + // uint8_t buf[IM_SIZE * 2] = {0}; + auto buf = make_unique(2 * IM_SIZE); + in_image.read((char*)buf.get(), IM_SIZE * 2); in_image.close(); // Reshape data - uint16_t image[IM_HEIGHT][IM_WIDTH] = {0}; + // uint16_t image[IM_HEIGHT][IM_WIDTH] = {0}; + auto image = make_unique(IM_SIZE); uint32_t i = 0; for (int y = 0; y < IM_HEIGHT; y++) { for (int x = 0; x < IM_WIDTH; x++) { - image[y][x] = (uint16_t)buf[i] + ((uint16_t)buf[i + 1] << 8); + image[y * IM_WIDTH + x] = (uint16_t)buf[i] + ((uint16_t)buf[i + 1] << 8); i++; } } @@ -180,7 +191,7 @@ int sc_main(int argc, char* argv[]) { tb_isp.im_clk(out_clk); tb_isp.im_en(out_en); tb_isp.im_data(data_out); - memcpy(tb_isp.image, image, sizeof(image)); + tb_isp.image = move(image); // You must do one evaluation before enabling waves, in order to allow // SystemC to interconnect everything for testing.