Article #400

既に発行済みのブログであっても適宜修正・追加することがあります。
We may make changes and additions to blogs already published.
posted by sakurai on May 12, 2021 #400

前稿の疑似コードをBSVに変換します。作成したBSVプログラムを以下に示します。

Tb.bsv

import StmtFSM::*;
import mkUart::*;
import RegFile::*;

typedef Bit#(16) Addr_t;
typedef Bit#(4) Data_t;
typedef Bit#(8) Byte;

(* synthesize *)
module mkTb();
      RegFile#(Addr_t, Data_t) rom <- mkRegFileLoad("data.hex", 0, 65535);
      Reg#(Addr_t) address <- mkReg(0);
      Reg#(Data_t) data <- mkReg(0);
      Reg#(Byte) byteData <- mkReg(0);
      Reg#(int) x <- mkReg(0);
      Reg#(int) y <- mkReg(0);
      Reg#(Data_t) checksum <- mkReg(0);
      Uart_ifc uart <- mkUart();

      function Stmt nibbleOut(Data_t nibble);
            return (seq
                  byteData <= extend(nibble) + (nibble >= 10) ? (- 10 + 8'h61) : 8'h30;
                  uart.load(byteData);
                  // $write("%c", byteData);
            endseq);
      endfunction: nibbleOut

      Stmt test = seq
            for (y <= 0; y <= 255; y <= y + 1) seq
                  checksum <= 0;
                  for (x <= 0; x <= 255; x <= x + 1) seq
                        data <= rom.sub(address);
                        address <= address + 1;
                        checksum <= checksum + extend(data);
                        nibbleOut(data);
                  endseq
                  nibbleOut(truncate(checksum >> 4));
                  nibbleOut(truncate(checksum));
                  uart.load(8'h0a); // LF
                  // $display("");
            endseq
            await(uart.done());
            $finish;
      endseq;

      mkAutoFSM(test);
endmodule

左矢前のブログ 次のブログ右矢

Leave a Comment

Your email address will not be published.

You may use Markdown syntax. If you include an ad such as http://, it will be invalidated by our AI system.

Please enter the numbers as they are shown in the image above.