-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4f2d68
commit dbd15f4
Showing
21 changed files
with
17,102 additions
and
540 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.