fix naming

This commit is contained in:
Arthur Lu 2022-08-27 16:33:33 -07:00
parent 9281b984ae
commit e5684b4705

View File

@ -2,13 +2,13 @@
// testbench for programmable message decryption, space removal (Program #3)
// CSE141L
// runs program 2 (decrypt a message), but with corruption
module decrypt_depad_tb () ;
// DUT interface
module program3_tb () ;
// DUT interface
logic clk = 1'b0 , // advances simulation step-by-step
init = 1'b1 , // init (reset) command to DUT
start = 1'b1 ; // req (start program) command to DUT
wire done ; // done flag returned by DUT
// test bench parameters
// test bench parameters
logic[3:0] pre_length ; // space char. bytes before first char. in message
logic[7:0] message1[49] , // original raw message, in binary
msg_padded1[80], // original message, plus pre- and post-padding w/ ASCII spaces
@ -21,16 +21,16 @@ module decrypt_depad_tb () ;
// our original American Standard Code for Information Interchange message follows
// note in practice your design should be able to handle ANY ASCII string that is
// restricted to characters between space (0x20) and script f (0x9f) and shorter than
// 53 characters in length
// 53 characters in length
// *** No more than 24 leading space characters, including preamble. ***
// string str1 =
// string str1 =
// string str1 = "Mr. Watson, come here. I want to see you."; // sample program 1 input
// string str1 = " Knowledge comes, but wisdom lingers. "; // alternative inputs
// string str1 = " 01234546789abcdefghijklmnopqrstuvwxyz. "; // (make up your own,
// string str1 = " A joke is a very serious thing."; // as well)
string str1 = " Ajok "; //
// string str1 = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
// string str1 = "``@@```@@@````@@@@````@@@@@";
// string str1 = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
// string str1 = "``@@```@@@````@@@@````@@@@@";
// string str1 = " Knowledge comes, but wisdom lingers. "; //
// displayed encrypted string will go here:
@ -42,7 +42,7 @@ module decrypt_depad_tb () ;
logic[5:0] flipper; // corruptor -- bit flip
logic[79:0] flipped = 80'b0; // tracks which word got a bit flipped
// the 8 possible maximal-length feedback tap patterns from which to choose
assign LFSR_ptrn[0] = 7'h60; // 110_0000
assign LFSR_ptrn[0] = 7'h60; // 110_0000
assign LFSR_ptrn[1] = 7'h48; // 100_1000
assign LFSR_ptrn[2] = 7'h78;
assign LFSR_ptrn[3] = 7'h72;
@ -83,7 +83,7 @@ module decrypt_depad_tb () ;
// you may also pre-load desired constants, etc. into
// your data_mem here -- the upper addresses are reserved for your use
// dut.data_mem.DM[128]=8'hfe; //whatever constants you want
file_no = 1; // write to transcript
file_no = 1; // write to transcript
// file_no = $fopen("msg_decoder_out.txt"); // create your output file
#0ns strlen = str1.len; // length of string 1 (# characters between " ")
if(strlen>52) strlen = 52; // clip message at 52 characters
@ -95,9 +95,9 @@ module decrypt_depad_tb () ;
$fdisplay(file_no,"run encryption program; original message = ");
$fdisplay(file_no,"%s",str1); // print original message in transcript window
$fdisplay(file_no,"LFSR_ptrn = 0x%h, LFSR_init = 0x%h, pre_length: %d",lfsr_ptrn,LFSR_init,pre_length);
$fdisplay(file_no,"pt_no = %d",pt_no);
// will subtract 0x20 from each preamble and messge character to fit into 7 bits
$fdisplay(file_no,"pt_no = %d",pt_no);
// will subtract 0x20 from each preamble and messge character to fit into 7 bits
for(int j=0; j<80; j++) // pre-fill message_padded with ASCII space characters
msg_padded1[j] = 8'h20; //
for(int l=0; l<strlen; l++) // overwrite up to 49 of these spaces w/ message itself
@ -112,7 +112,7 @@ module decrypt_depad_tb () ;
msg_crypto1[i] = ((msg_padded1[i]-'h20) ^ lfsr1[i]);
msg_crypto1[i][7] = 0;//^msg_crypto1[i][6:0]; // prepend parity bit into MSB
$fdisplay(file_no,"i=%d, msg_pad=0x%h, lfsr=%b msg_crypt w/ parity = 0x%h",
i,msg_padded1[i],lfsr1[i],msg_crypto1[i]);
i,msg_padded1[i],lfsr1[i],msg_crypto1[i]);
//for display purposes only, add 8'h20 to avoid nonprintable characters
str_enc1[i] = string'(msg_crypto1[i][6:0]+'h20);
end
@ -134,9 +134,9 @@ module decrypt_depad_tb () ;
for(int m=0; m<24; m++) // load first 24 characters of encrypted message into data memory
dut.DM.core[m+64] = msg_crypto1[m];
for(int n=24; n<64; n++) begin // load subsequent, possibly corrupt, encrypted message into data memory
// set flipper = 8 or higher to disable bit corruption
// set flipper = 8 or higher to disable bit corruption
flipper = 8;//$random; // value between 0 and 63, inclusive
dut.DM.core[n+64] = msg_crypto1[n]^(1<<flipper);
dut.DM.core[n+64] = msg_crypto1[n]^(1<<flipper);
if(flipper<8) flipped[n]=1;
end
#20ns init = 1'b0; // suggestion: reset = 1 forces your program counter to 0