1 |
3 |
dinesha |
|
2 |
|
|
task reg_write;
|
3 |
|
|
input [15:0] addr;
|
4 |
|
|
input [31:0] data;
|
5 |
|
|
reg [7:0] read_data;
|
6 |
|
|
reg flag;
|
7 |
|
|
begin
|
8 |
|
|
fork
|
9 |
|
|
begin : loop_1
|
10 |
|
|
tb_top.tb_uart.write_char("w");
|
11 |
|
|
tb_top.tb_uart.write_char("m");
|
12 |
|
|
tb_top.tb_uart.write_char(" ");
|
13 |
|
|
tb_top.tb_uart.write_char(hex2char(addr[15:12]));
|
14 |
|
|
tb_top.tb_uart.write_char(hex2char(addr[11:8]));
|
15 |
|
|
tb_top.tb_uart.write_char(hex2char(addr[7:4]));
|
16 |
|
|
tb_top.tb_uart.write_char(hex2char(addr[3:0]));
|
17 |
|
|
tb_top.tb_uart.write_char(" ");
|
18 |
|
|
tb_top.tb_uart.write_char(hex2char(data[31:28]));
|
19 |
|
|
tb_top.tb_uart.write_char(hex2char(data[27:24]));
|
20 |
|
|
tb_top.tb_uart.write_char(hex2char(data[23:20]));
|
21 |
|
|
tb_top.tb_uart.write_char(hex2char(data[19:16]));
|
22 |
|
|
tb_top.tb_uart.write_char(hex2char(data[15:12]));
|
23 |
|
|
tb_top.tb_uart.write_char(hex2char(data[11:8]));
|
24 |
|
|
tb_top.tb_uart.write_char(hex2char(data[7:4]));
|
25 |
|
|
tb_top.tb_uart.write_char(hex2char(data[3:0]));
|
26 |
|
|
tb_top.tb_uart.write_char("\n");
|
27 |
|
|
end
|
28 |
|
|
begin : loop_2
|
29 |
|
|
// Wait for sucess command
|
30 |
|
|
flag = 0;
|
31 |
|
|
while(flag == 0)
|
32 |
|
|
begin
|
33 |
|
|
tb_top.tb_uart.read_char(read_data,flag);
|
34 |
|
|
//$write ("%c",read_data);
|
35 |
|
|
end
|
36 |
|
|
end
|
37 |
|
|
join
|
38 |
|
|
end
|
39 |
|
|
endtask
|
40 |
|
|
|
41 |
|
|
task reg_read;
|
42 |
|
|
input [15:0] addr;
|
43 |
|
|
output [31:0] data;
|
44 |
|
|
reg [7:0] read_data;
|
45 |
|
|
reg flag;
|
46 |
|
|
integer i;
|
47 |
|
|
begin
|
48 |
|
|
fork
|
49 |
|
|
begin : loop_1
|
50 |
|
|
tb_top.tb_uart.write_char("r");
|
51 |
|
|
tb_top.tb_uart.write_char("m");
|
52 |
|
|
tb_top.tb_uart.write_char(" ");
|
53 |
|
|
tb_top.tb_uart.write_char(hex2char(addr[15:12]));
|
54 |
|
|
tb_top.tb_uart.write_char(hex2char(addr[11:8]));
|
55 |
|
|
tb_top.tb_uart.write_char(hex2char(addr[7:4]));
|
56 |
|
|
tb_top.tb_uart.write_char(hex2char(addr[3:0]));
|
57 |
|
|
tb_top.tb_uart.write_char(" ");
|
58 |
|
|
tb_top.tb_uart.write_char("\n");
|
59 |
|
|
end
|
60 |
|
|
begin : loop_2
|
61 |
|
|
// Wait for sucess command
|
62 |
|
|
flag = 0;
|
63 |
|
|
i = 0;
|
64 |
|
|
while(flag == 0)
|
65 |
|
|
begin
|
66 |
|
|
tb_top.tb_uart.read_char(read_data,flag);
|
67 |
|
|
//$write ("%d:%c",i,read_data);
|
68 |
|
|
case (i)
|
69 |
|
|
8'd10 : data[31:28] = char2hex(read_data);
|
70 |
|
|
8'd11 : data[27:24] = char2hex(read_data);
|
71 |
|
|
8'd12 : data[23:20] = char2hex(read_data);
|
72 |
|
|
8'd13 : data[19:16] = char2hex(read_data);
|
73 |
|
|
8'd14 : data[15:12] = char2hex(read_data);
|
74 |
|
|
8'd15 : data[11:8] = char2hex(read_data);
|
75 |
|
|
8'd16 : data[7:4] = char2hex(read_data);
|
76 |
|
|
8'd17 : data[3:0] = char2hex(read_data);
|
77 |
|
|
endcase
|
78 |
|
|
i = i+1;
|
79 |
|
|
end
|
80 |
|
|
end
|
81 |
|
|
join
|
82 |
|
|
//$display("Receoved Data: %x",data);
|
83 |
|
|
|
84 |
|
|
end
|
85 |
|
|
endtask
|
86 |
|
|
|
87 |
|
|
// Character to hex number
|
88 |
|
|
function [3:0] char2hex;
|
89 |
|
|
input [7:0] data_in;
|
90 |
|
|
case (data_in)
|
91 |
|
|
8'h30: char2hex = 4'h0; // character '0'
|
92 |
|
|
8'h31: char2hex = 4'h1; // character '1'
|
93 |
|
|
8'h32: char2hex = 4'h2; // character '2'
|
94 |
|
|
8'h33: char2hex = 4'h3; // character '3'
|
95 |
|
|
8'h34: char2hex = 4'h4; // character '4'
|
96 |
|
|
8'h35: char2hex = 4'h5; // character '5'
|
97 |
|
|
8'h36: char2hex = 4'h6; // character '6'
|
98 |
|
|
8'h37: char2hex = 4'h7; // character '7'
|
99 |
|
|
8'h38: char2hex = 4'h8; // character '8'
|
100 |
|
|
8'h39: char2hex = 4'h9; // character '9'
|
101 |
|
|
8'h41: char2hex = 4'hA; // character 'A'
|
102 |
|
|
8'h42: char2hex = 4'hB; // character 'B'
|
103 |
|
|
8'h43: char2hex = 4'hC; // character 'C'
|
104 |
|
|
8'h44: char2hex = 4'hD; // character 'D'
|
105 |
|
|
8'h45: char2hex = 4'hE; // character 'E'
|
106 |
|
|
8'h46: char2hex = 4'hF; // character 'F'
|
107 |
|
|
8'h61: char2hex = 4'hA; // character 'a'
|
108 |
|
|
8'h62: char2hex = 4'hB; // character 'b'
|
109 |
|
|
8'h63: char2hex = 4'hC; // character 'c'
|
110 |
|
|
8'h64: char2hex = 4'hD; // character 'd'
|
111 |
|
|
8'h65: char2hex = 4'hE; // character 'e'
|
112 |
|
|
8'h66: char2hex = 4'hF; // character 'f'
|
113 |
|
|
default : char2hex = 4'hF;
|
114 |
|
|
endcase
|
115 |
|
|
endfunction
|
116 |
|
|
|
117 |
|
|
// Hex to Asci Character
|
118 |
|
|
function [7:0] hex2char;
|
119 |
|
|
input [3:0] data_in;
|
120 |
|
|
case (data_in)
|
121 |
|
|
4'h0: hex2char = 8'h30; // character '0'
|
122 |
|
|
4'h1: hex2char = 8'h31; // character '1'
|
123 |
|
|
4'h2: hex2char = 8'h32; // character '2'
|
124 |
|
|
4'h3: hex2char = 8'h33; // character '3'
|
125 |
|
|
4'h4: hex2char = 8'h34; // character '4'
|
126 |
|
|
4'h5: hex2char = 8'h35; // character '5'
|
127 |
|
|
4'h6: hex2char = 8'h36; // character '6'
|
128 |
|
|
4'h7: hex2char = 8'h37; // character '7'
|
129 |
|
|
4'h8: hex2char = 8'h38; // character '8'
|
130 |
|
|
4'h9: hex2char = 8'h39; // character '9'
|
131 |
|
|
4'hA: hex2char = 8'h41; // character 'A'
|
132 |
|
|
4'hB: hex2char = 8'h42; // character 'B'
|
133 |
|
|
4'hC: hex2char = 8'h43; // character 'C'
|
134 |
|
|
4'hD: hex2char = 8'h44; // character 'D'
|
135 |
|
|
4'hE: hex2char = 8'h45; // character 'E'
|
136 |
|
|
4'hF: hex2char = 8'h46; // character 'F'
|
137 |
|
|
endcase
|
138 |
|
|
endfunction
|