forked from pulp-platform/axi_spi_slave
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspi_slave_syncro.sv
53 lines (48 loc) · 1.83 KB
/
spi_slave_syncro.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2017 ETH Zurich and University of Bologna.
// Copyright and related rights are licensed under the Solderpad Hardware
// License, Version 0.51 (the “License”); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law
// or agreed to in writing, software, hardware and materials distributed under
// this License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
module spi_slave_syncro
#(
parameter AXI_ADDR_WIDTH = 32
)
(
input logic sys_clk,
input logic rstn,
input logic cs,
input logic [AXI_ADDR_WIDTH-1:0] address,
input logic address_valid,
input logic rd_wr,
output logic cs_sync,
output logic [AXI_ADDR_WIDTH-1:0] address_sync,
output logic address_valid_sync,
output logic rd_wr_sync
);
logic [1:0] cs_reg;
logic [2:0] valid_reg;
logic [1:0] rdwr_reg;
assign cs_sync = cs_reg[1];
assign address_valid_sync = ~valid_reg[2] & valid_reg[1]; //detect rising edge of addr valid
assign address_sync = address;
assign rd_wr_sync = rdwr_reg[1];
always @(posedge sys_clk or negedge rstn)
begin
if(rstn == 1'b0)
begin
cs_reg <= 2'b11;
valid_reg <= 3'b000;
rdwr_reg <= 2'b00;
end
else
begin
cs_reg <= {cs_reg[0],cs};
valid_reg <= {valid_reg[1:0],address_valid};
rdwr_reg <= {rdwr_reg[0],rd_wr};
end
end
endmodule