Skip to content

Commit

Permalink
update RISC-V CPU example
Browse files Browse the repository at this point in the history
  • Loading branch information
WangXuan95 committed Feb 25, 2022
1 parent e4f2d68 commit dbd15f4
Show file tree
Hide file tree
Showing 21 changed files with 17,102 additions and 540 deletions.
630 changes: 415 additions & 215 deletions README.md

Large diffs are not rendered by default.

Binary file added readme_image/0.bluespec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme_image/18.rv32i_pipe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme_image/9.bit_coding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 1 addition & 39 deletions src/JpegEncoder/JpegEncoder.bsv
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ package JpegEncoder;
import Vector::*;
import DReg::*;
import BRAM::*;
import StmtFSM::*;

// user defined packages
import DoubleBuffer::*;
import PgmReader::*;


interface JpegEncoder;
Expand All @@ -19,6 +17,7 @@ interface JpegEncoder;
method Bit#(128) get;
endinterface


(* synthesize *)
(* always_ready="init" *)
module mkJpegEncoder (JpegEncoder);
Expand Down Expand Up @@ -323,41 +322,4 @@ endmodule



module mkTb ();
PgmReader pgm_reader <- mkPgmReader("img/in003.pgm");
JpegEncoder jpg_encoder <- mkJpegEncoder;

Reg#(File) jpg_file <- mkReg(InvalidFile);

mkAutoFSM( seq
action
let fp <- $fopen("out.jpg.txt", "w");
jpg_file <= fp;
endaction

action
int width = pgm_reader.image_width;
int height = pgm_reader.image_height;
if(width%8 != 0 || height%8 !=0) begin // 合法性检查, width 和 height 必须是 8 的倍数,否则 JpegEncoder 不支持
$error(" Error: image width or height is not multiple of 8");
$finish;
end
jpg_encoder.init( unpack(pack(width/8)[8:0]) , unpack(pack(height/8)[8:0]) );
endaction

while(pgm_reader.not_finish) action
let pixels <- pgm_reader.get_pixels;
jpg_encoder.put(pixels);
endaction

delay(10000);
endseq );

rule write_jpg_to_file;
$fwrite(jpg_file, "%032x", jpg_encoder.get);
endrule

endmodule


endpackage
50 changes: 50 additions & 0 deletions src/JpegEncoder/TbJpegEncoder.bsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright(c) 2022 https://github.com/WangXuan95

package TbJpegEncoder;

// standard BSV packages
import StmtFSM::*;

// user defined packages
import PgmReader::*;
import JpegEncoder::*;


module mkTb ();
PgmReader pgm_reader <- mkPgmReader("img/in003.pgm");
JpegEncoder jpg_encoder <- mkJpegEncoder;

Reg#(File) jpg_file <- mkReg(InvalidFile);

mkAutoFSM( seq
action
let fp <- $fopen("out.jpg.txt", "w");
jpg_file <= fp;
endaction

action
int width = pgm_reader.image_width;
int height = pgm_reader.image_height;
if(width%8 != 0 || height%8 !=0) begin // 合法性检查, width 和 height 必须是 8 的倍数,否则 JpegEncoder 不支持
$error(" Error: image width or height is not multiple of 8");
$finish;
end
jpg_encoder.init( unpack(pack(width/8)[8:0]) , unpack(pack(height/8)[8:0]) );
endaction

while(pgm_reader.not_finish) action
let pixels <- pgm_reader.get_pixels;
jpg_encoder.put(pixels);
endaction

delay(10000);
endseq );

rule write_jpg_to_file;
$fwrite(jpg_file, "%032x", jpg_encoder.get);
endrule

endmodule


endpackage
28 changes: 28 additions & 0 deletions src/Rv32iCPU/DFIFOF1.bsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright(c) 2022 https://github.com/WangXuan95

package DFIFOF1;

import FIFOF::*;


module mkDFIFOF1#(td default_value) (FIFOF#(td))
provisos (Bits#(td, sz));

FIFOF#(td) fifo <- mkUGFIFOF1;

method td first = fifo.notEmpty ? fifo.first : default_value;

method Action deq = fifo.deq;

method Action enq(td value) if(fifo.notFull) = fifo.enq(value);

method notEmpty = fifo.notEmpty;

method notFull = fifo.notFull;

method clear = fifo.clear;

endmodule


endpackage
Loading

0 comments on commit dbd15f4

Please sign in to comment.