OpenCores
URL https://opencores.org/ocsvn/v586/v586/trunk

Subversion Repositories v586

[/] [v586/] [trunk/] [core_rtl/] [realign.v] - Blame information for rev 123

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 121 ultro
module realign (
2
clk,
3
rstn,
4
read_req_in,write_req_in,
5
read_req_out,write_req_out,
6
 
7
read_ack_in,write_ack_in,
8
read_ack_out,write_ack_out,
9
 
10
addr_in,
11
addr_out,
12
 
13
read_data_in,
14
read_data_out,
15
 
16
write_data_in,
17
write_data_out,
18
write_sz_in,
19
write_msk_out
20
 
21
);
22
 
23
input  [31:0] write_data_in ,read_data_in ,addr_in;
24
output [31:0] write_data_out,read_data_out,addr_out;
25
input         rstn,clk;
26
input         read_req_in,write_req_in,read_ack_in,write_ack_in;
27
input   [1:0] write_sz_in;
28
output  [3:0] write_msk_out;
29
output        write_req_out,read_req_out,read_ack_out,write_ack_out;
30
 
31
reg write_req_ff, write_ack_ff, read_req_ff, read_ack_ff;
32
reg [31:0] addr_out_ff;
33
reg even;
34
reg [31:0] read_data_sav;
35
reg [31:0] read_data_out_ff,write_data_out_ff;
36
reg  [3:0] write_msk_ff;
37
 
38
wire not_align   = ((addr_in[1] == 1'b1) || (addr_in[0] == 1'b1))  ? 1'b1 : 1'b0;
39
 
40
assign read_req_out  = not_align ? read_req_ff : read_req_in;
41
assign read_ack_out  = not_align ? read_ack_ff : read_ack_in;
42
 
43
assign write_req_out = ((not_align == 1'b1) && (write_sz_in !=2'b00)) ? write_req_ff : write_req_in;
44
assign write_ack_out = ((not_align == 1'b1) && (write_sz_in !=2'b00)) ? write_ack_ff : write_ack_in;
45
 
46
assign write_msk_out = ((not_align    == 1'b1)  && (write_sz_in != 2'b00)) ? write_msk_ff :
47
                       ((addr_in[1:0] == 2'b00) && (write_sz_in == 2'b00)) ? 4'b0001 :
48
                       ((addr_in[1:0] == 2'b01) && (write_sz_in == 2'b00)) ? 4'b0010 :
49
                       ((addr_in[1:0] == 2'b10) && (write_sz_in == 2'b00)) ? 4'b0100 :
50
                       ((addr_in[1:0] == 2'b11) && (write_sz_in == 2'b00)) ? 4'b1000 :
51
                                                   (write_sz_in == 2'b01)  ? 4'b0011 :
52
                                                                             4'b1111 ;
53
 
54
assign write_data_out = ((not_align    == 1'b1)  && (write_sz_in != 2'b00)) ?           write_data_out_ff :
55
                        ((addr_in[1:0] == 2'b01) && (write_sz_in == 2'b00)) ? {16'h5555,write_data_in[7:0],8'h55} :
56
                        ((addr_in[1:0] == 2'b10) && (write_sz_in == 2'b00)) ? {   8'h55,write_data_in[7:0],16'h5555} :
57
                        ((addr_in[1:0] == 2'b11) && (write_sz_in == 2'b00)) ? {         write_data_in[7:0],24'h555555} :
58
                                                                                        write_data_in;
59
 
60
assign read_data_out = not_align ? read_data_out_ff : read_data_in;
61
 
62
assign addr_out      = ((not_align   == 1'b1) && ( read_req_in == 1'b1))                          ? addr_out_ff :
63
                       ((not_align   == 1'b1) && (write_req_in == 1'b1) && (write_sz_in !=2'b00)) ? addr_out_ff :
64
                                                                                {addr_in[31:2],2'b00};
65
 
66
always @(posedge clk or negedge rstn)
67
if (~rstn)
68
begin
69
 write_req_ff <= 1'b0;
70
 write_ack_ff <= 1'b0;
71
 read_req_ff  <= 1'b0;
72
 read_ack_ff  <= 1'b0;
73
 even         <= 1'b0;
74
 write_msk_ff <= 4'b1111;
75
 read_data_out_ff <= 32'h0;
76
 write_data_out_ff <= 32'h0;
77
end
78
else
79
begin
80
 if (write_ack_ff == 1'b1)
81
  begin
82
   write_req_ff <= 1'b0;
83
   write_ack_ff <= 1'b0;
84
   even         <= 1'b0;
85
   write_msk_ff <= 4'b0000;
86
  end
87
else if (read_ack_ff == 1'b1)
88
   begin
89
    read_req_ff <= 1'b0;
90
    read_ack_ff <= 1'b0;
91
    even        <= 1'b0;
92
   end
93
 else
94
 if ((not_align == 1'b1) && (read_req_ff == 1'b0) && (read_req_in == 1'b1) && (even == 1'b0))
95
    begin
96
     read_req_ff <= 1'b1;
97
     addr_out_ff <= {addr_in[31:2],2'b00};
98
     even        <= 1'b1;
99
    end
100
 else
101
 if ((not_align == 1'b1) && (read_req_ff == 1'b1) && (read_ack_in == 1'b1) && (even == 1'b1))
102
    begin
103
     addr_out_ff <= {addr_in[31:2],2'b00} + 3'b100;
104
     read_data_sav<= read_data_in;
105
     even        <= 1'b0;
106
    end
107
 else
108
 if ((not_align == 1'b1) && (read_req_ff == 1'b1) && (read_ack_in == 1'b1) && (even == 1'b0))
109
    begin
110
     even        <= 1'b0;
111
     read_ack_ff <= 1'b1;
112
     read_req_ff <= 1'b0;
113
     case(addr_in[1:0])
114
      2'b00: read_data_out_ff <= read_data_sav;
115
      2'b01: read_data_out_ff <= {read_data_in[ 7:0],read_data_sav[31: 8]};
116
      2'b10: read_data_out_ff <= {read_data_in[15:0],read_data_sav[31:16]};
117
      2'b11: read_data_out_ff <= {read_data_in[23:0],read_data_sav[31:24]};
118
     endcase
119
    end
120
 else
121
 if ((not_align == 1'b1) && (write_req_ff == 1'b0) && (write_req_in == 1'b1) && (even == 1'b0) && (write_sz_in != 2'b00))
122
       begin
123
        addr_out_ff <= {addr_in[31:2],2'b00};
124
        even        <= 1'b1;
125
        write_req_ff <= 1'b1;
126
        if ((addr_in[1:0] == 2'b01) && (write_sz_in ==2'b01)) begin write_msk_ff <= 4'b0110; write_data_out_ff <= {write_data_in[23:0], 8'b0}; end else
127
        if ((addr_in[1:0] == 2'b01) && (write_sz_in ==2'b10)) begin write_msk_ff <= 4'b1110; write_data_out_ff <= {write_data_in[23:0], 8'b0}; end else
128
        if ((addr_in[1:0] == 2'b10) && (write_sz_in ==2'b01)) begin write_msk_ff <= 4'b1100; write_data_out_ff <= {write_data_in[15:0],16'b0}; end else
129
        if ((addr_in[1:0] == 2'b10) && (write_sz_in ==2'b10)) begin write_msk_ff <= 4'b1100; write_data_out_ff <= {write_data_in[15:0],16'b0}; end else
130
        if ((addr_in[1:0] == 2'b11) && (write_sz_in ==2'b01)) begin write_msk_ff <= 4'b1000; write_data_out_ff <= {write_data_in[ 7:0],24'b0}; end else
131
        if ((addr_in[1:0] == 2'b11) && (write_sz_in ==2'b10)) begin write_msk_ff <= 4'b1000; write_data_out_ff <= {write_data_in[ 7:0],24'b0}; end
132
       end
133
    else
134
    if ((not_align == 1'b1) && (write_req_ff == 1'b1) && (write_ack_in == 1'b1) && (even == 1'b1))
135
       begin
136
        addr_out_ff  <= {addr_in[31:2],2'b00} + 3'b100;
137
        even         <= 1'b0;
138
        if ((addr_in[1:0] == 2'b01) && (write_sz_in ==2'b10)) begin write_msk_ff <= 4'b0001; write_data_out_ff <= {24'b0,write_data_in[31:24]}; end else
139
        if ((addr_in[1:0] == 2'b10) && (write_sz_in ==2'b10)) begin write_msk_ff <= 4'b0011; write_data_out_ff <= {16'b0,write_data_in[31:16]}; end else
140
        if ((addr_in[1:0] == 2'b11) && (write_sz_in ==2'b01)) begin write_msk_ff <= 4'b0001; write_data_out_ff <= { 8'b0,write_data_in[31: 8]}; end else
141
        if ((addr_in[1:0] == 2'b11) && (write_sz_in ==2'b10)) begin write_msk_ff <= 4'b0111; write_data_out_ff <= { 8'b0,write_data_in[31: 8]}; end else
142
                                                    begin write_msk_ff <= 4'b0000; end
143
       end
144
    else
145
    if ((not_align == 1'b1) && (write_req_ff == 1'b1) && (write_ack_in == 1'b1) && (even == 1'b0))
146
       begin
147
        even        <= 1'b0;
148
        write_ack_ff <= 1'b1;
149
        write_req_ff <= 1'b0;
150
       end
151
end
152
 
153
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.