-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspi_synchronizer.v
More file actions
38 lines (31 loc) · 933 Bytes
/
spi_synchronizer.v
File metadata and controls
38 lines (31 loc) · 933 Bytes
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
//
// Simple synchronizer for SPI circuits.
//
// UNCLASSIFIED // PROPRIETARY // GOV USE RIGHTS
// This will hopefully be replaced with an FOSS license soon.
//
// Copyright (c) Assured Information Security, inc.
// Author: Kyle J. Temkin
//
`default_nettype none
module spi_synchronizer(
input wire clk,
input wire sck, sdi, cs,
output wire sck_out, sdi_out, cs_out
);
parameter integer SYNC_STAGES = 2;
parameter integer SYNC_MSB = SYNC_STAGES - 1;
reg [SYNC_MSB:0] sck_sync;
reg [SYNC_MSB:0] sdi_sync;
reg [SYNC_MSB:0] cs_sync;
assign sck_out = sck_sync[SYNC_MSB];
assign sdi_out = sdi_sync[SYNC_MSB];
assign cs_out = cs_sync[SYNC_MSB];
// Core synchronizer.
always @(posedge clk)
begin
sck_sync = {sck_sync[SYNC_MSB - 1 : 0], sck};
sdi_sync = {sdi_sync[SYNC_MSB - 1 : 0], sdi};
cs_sync = { cs_sync[SYNC_MSB - 1 : 0], cs};
end
endmodule