-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadcs747x_to_axism.v
109 lines (88 loc) · 2.89 KB
/
adcs747x_to_axism.v
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
`timescale 1ps/1ps
module adcs747x_to_axism
#(
parameter DATA_WIDTH = 16,
parameter PACKET_SIZE = 128,
parameter SPI_SCK_DIV = 200
)
(
output wire SPI_SSN,
output wire SPI_SCK,
input wire SPI_MISO,
input wire AXIS_ACLK,
input wire AXIS_ARESETN,
output wire M_AXIS_TVALID,
output wire [15:0] M_AXIS_TDATA,
output wire [1:0] M_AXIS_TSTRB,
output wire M_AXIS_TLAST,
input wire M_AXIS_TREADY
);
localparam SPI_SCK_PERIOD_DIV = SPI_SCK_DIV / 2;
reg [$clog2(SPI_SCK_PERIOD_DIV) - 1:0] spi_sck_counter;
reg spi_sck;
reg spi_sck_last;
reg [$clog2(DATA_WIDTH) - 1:0] spi_ssn_counter;
reg spi_ssn;
reg spi_ssn_last;
reg [DATA_WIDTH - 1:0] spi_sample;
reg [DATA_WIDTH - 1:0] m_axis_tdata;
reg m_axis_tvalid;
reg m_axis_tlast;
reg [$clog2(PACKET_SIZE) - 1:0] packet_counter;
always@(posedge AXIS_ACLK) begin
if(!AXIS_ARESETN) begin
spi_ssn_counter <= 0;
spi_ssn <= 0;
spi_ssn_last <= 0;
spi_sck_counter <= 0;
spi_sck <= 0;
spi_sck_last <= 0;
m_axis_tvalid <= 1'b0;
m_axis_tlast <= 1'b0;
m_axis_tdata <= {DATA_WIDTH{1'b0}};
packet_counter <= 0;
end else begin
if (spi_sck_counter == SPI_SCK_PERIOD_DIV - 1) begin
spi_sck <= !spi_sck;
spi_sck_counter <= 0;
end else begin
spi_sck_counter <= spi_sck_counter + 1;
end
if (!spi_sck_last && spi_sck) begin
spi_sample <= {spi_sample[DATA_WIDTH - 2:0], SPI_MISO};
end
if (spi_sck_last && !spi_sck) begin
if (spi_ssn_counter == DATA_WIDTH - 1) begin
spi_ssn <= !spi_ssn;
spi_ssn_counter <= 0;
end else begin
spi_ssn_counter <= spi_ssn_counter + 1;
end
end
if (!spi_ssn_last && spi_ssn) begin
m_axis_tvalid <= 1'b1;
m_axis_tlast <= 1'b0;
if (M_AXIS_TREADY) begin
if (packet_counter == PACKET_SIZE - 1) begin
m_axis_tlast <= 1'b1;
packet_counter <= 0;
end else begin
packet_counter <= packet_counter + 1;
end
end
m_axis_tdata <= spi_sample;
end else begin
m_axis_tvalid <= 1'b0;
m_axis_tlast <= 1'b0;
end
spi_ssn_last <= spi_ssn;
spi_sck_last <= spi_sck;
end
end
assign SPI_SCK = spi_sck;
assign SPI_SSN = spi_ssn;
assign M_AXIS_TSTRB = 2'b1;
assign M_AXIS_TVALID = m_axis_tvalid;
assign M_AXIS_TLAST = m_axis_tlast;
assign M_AXIS_TDATA = m_axis_tdata;
endmodule