1 // synopsys translate_off
3 // synopsys translate_on
4 //`include "can_defines.v"
6 module can_ifc_axi_sync_duplex #
8 // Users to add parameters here
10 // User parameters ends
11 // Do not modify the parameters beyond this line
13 // Width of S_AXI data bus
14 parameter integer C_S_AXI_DATA_WIDTH = 32,
15 // Width of S_AXI address bus
16 parameter integer C_S_AXI_ADDR_WIDTH = 8
19 // Users to add ports here
20 output wire reg_rst_o,
23 output wire [7:0] reg_addr_read_o,
24 output wire [7:0] reg_addr_write_o,
25 output wire [7:0] reg_data_in_o,
26 input wire [7:0] reg_data_out_i,
29 // Do not modify the ports beyond this line
31 // Global Clock Signal
32 input wire S_AXI_ACLK,
33 // Global Reset Signal. This Signal is Active LOW
34 input wire S_AXI_ARESETN,
35 // Write address (issued by master, acceped by Slave)
36 input wire [C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_AWADDR,
37 // Write channel Protection type. This signal indicates the
38 // privilege and security level of the transaction, and whether
39 // the transaction is a data access or an instruction access.
40 input wire [2 : 0] S_AXI_AWPROT,
41 // Write address valid. This signal indicates that the master signaling
42 // valid write address and control information.
43 input wire S_AXI_AWVALID,
44 // Write address ready. This signal indicates that the slave is ready
45 // to accept an address and associated control signals.
46 output wire S_AXI_AWREADY,
47 // Write data (issued by master, acceped by Slave)
48 input wire [C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_WDATA,
49 // Write strobes. This signal indicates which byte lanes hold
50 // valid data. There is one write strobe bit for each eight
51 // bits of the write data bus.
52 input wire [(C_S_AXI_DATA_WIDTH/8)-1 : 0] S_AXI_WSTRB,
53 // Write valid. This signal indicates that valid write
54 // data and strobes are available.
55 input wire S_AXI_WVALID,
56 // Write ready. This signal indicates that the slave
57 // can accept the write data.
58 output wire S_AXI_WREADY,
59 // Write response. This signal indicates the status
60 // of the write transaction.
61 output wire [1 : 0] S_AXI_BRESP,
62 // Write response valid. This signal indicates that the channel
63 // is signaling a valid write response.
64 output wire S_AXI_BVALID,
65 // Response ready. This signal indicates that the master
66 // can accept a write response.
67 input wire S_AXI_BREADY,
68 // Read address (issued by master, acceped by Slave)
69 input wire [C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_ARADDR,
70 // Protection type. This signal indicates the privilege
71 // and security level of the transaction, and whether the
72 // transaction is a data access or an instruction access.
73 input wire [2 : 0] S_AXI_ARPROT,
74 // Read address valid. This signal indicates that the channel
75 // is signaling valid read address and control information.
76 input wire S_AXI_ARVALID,
77 // Read address ready. This signal indicates that the slave is
78 // ready to accept an address and associated control signals.
79 output wire S_AXI_ARREADY,
80 // Read data (issued by slave)
81 output wire [C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_RDATA,
82 // Read response. This signal indicates the status of the
84 output wire [1 : 0] S_AXI_RRESP,
85 // Read valid. This signal indicates that the channel is
86 // signaling the required read data.
87 output wire S_AXI_RVALID,
88 // Read ready. This signal indicates that the master can
89 // accept the read data and response information.
90 input wire S_AXI_RREADY
94 reg [C_S_AXI_ADDR_WIDTH-1 : 0] axi_awaddr;
97 reg [1 : 0] axi_bresp;
99 reg [C_S_AXI_ADDR_WIDTH-1 : 0] axi_araddr;
101 reg [C_S_AXI_DATA_WIDTH-1 : 0] axi_rdata;
102 reg [1 : 0] axi_rresp;
105 // Example-specific design signals
106 // local parameter for addressing 32 bit / 64 bit C_S_AXI_DATA_WIDTH
107 // ADDR_LSB is used for addressing 32/64 bit registers/memories
108 // ADDR_LSB = 2 for 32 bits (n downto 2)
109 // ADDR_LSB = 3 for 64 bits (n downto 3)
110 localparam integer ADDR_LSB = (C_S_AXI_DATA_WIDTH/32) + 1;
111 localparam integer OPT_MEM_ADDR_BITS = 1;
112 //----------------------------------------------
113 //-- Signals for user logic register space example
114 //------------------------------------------------
115 //-- Number of Slave Registers 4
116 /*reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg0;
117 reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg1;
118 reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg2;
119 reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg3;*/
122 //reg [C_S_AXI_DATA_WIDTH-1:0] reg_data_out;
123 //integer byte_index;
125 // I/O Connections assignments
127 assign S_AXI_AWREADY = axi_awready;
128 assign S_AXI_WREADY = axi_wready;
129 assign S_AXI_BRESP = axi_bresp;
130 assign S_AXI_BVALID = axi_bvalid;
131 assign S_AXI_ARREADY = axi_arready;
132 assign S_AXI_RDATA = axi_rdata;
133 assign S_AXI_RRESP = axi_rresp;
134 assign S_AXI_RVALID = axi_rvalid;
135 // Implement axi_awready generation
136 // axi_awready is asserted for one S_AXI_ACLK clock cycle when both
137 // S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_awready is
138 // de-asserted when reset is low.
140 always @( posedge S_AXI_ACLK )
142 if ( S_AXI_ARESETN == 1'b0 )
148 if (~axi_awready && S_AXI_AWVALID && S_AXI_WVALID)
150 // slave is ready to accept write address when
151 // there is a valid write address and write data
152 // on the write address and data bus. This design
153 // expects no outstanding transactions.
163 // Implement axi_awaddr latching
164 // This process is used to latch the address when both
165 // S_AXI_AWVALID and S_AXI_WVALID are valid.
167 always @( posedge S_AXI_ACLK )
169 if ( S_AXI_ARESETN == 1'b0 )
175 if (~axi_awready && S_AXI_AWVALID && S_AXI_WVALID)
177 // Write Address latching
178 axi_awaddr <= S_AXI_AWADDR;
183 // Implement axi_wready generation
184 // axi_wready is asserted for one S_AXI_ACLK clock cycle when both
185 // S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_wready is
186 // de-asserted when reset is low.
188 always @( posedge S_AXI_ACLK )
190 if ( S_AXI_ARESETN == 1'b0 )
196 if (~axi_wready && S_AXI_WVALID && S_AXI_AWVALID)
198 // slave is ready to accept write data when
199 // there is a valid write address and write data
200 // on the write address and data bus. This design
201 // expects no outstanding transactions.
211 // Implement memory mapped register select and write logic generation
212 // The write data is accepted and written to memory mapped registers when
213 // axi_awready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted. Write strobes are used to
214 // select byte enables of slave registers while writing.
215 // These registers are cleared when reset (active low) is applied.
216 // Slave register write enable is asserted when valid address and data are available
217 // and the slave is ready to accept the write address and write data.
218 assign slv_reg_wren = axi_wready && S_AXI_WVALID && axi_awready && S_AXI_AWVALID;
220 always @( posedge S_AXI_ACLK )
222 if ( S_AXI_ARESETN == 1'b0 )
232 case ( axi_awaddr[ADDR_LSB+OPT_MEM_ADDR_BITS:ADDR_LSB] )
234 for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
235 if ( S_AXI_WSTRB[byte_index] == 1 ) begin
236 // Respective byte enables are asserted as per write strobes
238 slv_reg0[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
241 for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
242 if ( S_AXI_WSTRB[byte_index] == 1 ) begin
243 // Respective byte enables are asserted as per write strobes
245 slv_reg1[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
248 for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
249 if ( S_AXI_WSTRB[byte_index] == 1 ) begin
250 // Respective byte enables are asserted as per write strobes
252 slv_reg2[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
255 for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
256 if ( S_AXI_WSTRB[byte_index] == 1 ) begin
257 // Respective byte enables are asserted as per write strobes
259 slv_reg3[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
262 slv_reg0 <= slv_reg0;
263 slv_reg1 <= slv_reg1;
264 slv_reg2 <= slv_reg2;
265 slv_reg3 <= slv_reg3;
273 // Implement write response logic generation
274 // The write response and response valid signals are asserted by the slave
275 // when axi_wready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted.
276 // This marks the acceptance of address and indicates the status of
277 // write transaction.
279 always @( posedge S_AXI_ACLK )
281 if ( S_AXI_ARESETN == 1'b0 )
288 if (axi_awready && S_AXI_AWVALID && ~axi_bvalid && axi_wready && S_AXI_WVALID)
290 // indicates a valid write response is available
292 axi_bresp <= 2'b0; // 'OKAY' response
293 end // work error responses in future
296 if (S_AXI_BREADY && axi_bvalid)
297 //check if bready is asserted while bvalid is high)
298 //(there is a possibility that bready is always asserted high)
306 // Implement axi_arready generation
307 // axi_arready is asserted for one S_AXI_ACLK clock cycle when
308 // S_AXI_ARVALID is asserted. axi_awready is
309 // de-asserted when reset (active low) is asserted.
310 // The read address is also latched when S_AXI_ARVALID is
311 // asserted. axi_araddr is reset to zero on reset assertion.
313 always @( posedge S_AXI_ACLK )
315 if ( S_AXI_ARESETN == 1'b0 )
322 if (~axi_arready && S_AXI_ARVALID)
324 // indicates that the slave has acceped the valid read address
326 // Read address latching
327 axi_araddr <= S_AXI_ARADDR;
336 // Implement axi_arvalid generation
337 // axi_rvalid is asserted for one S_AXI_ACLK clock cycle when both
338 // S_AXI_ARVALID and axi_arready are asserted. The slave registers
339 // data are available on the axi_rdata bus at this instance. The
340 // assertion of axi_rvalid marks the validity of read data on the
341 // bus and axi_rresp indicates the status of read transaction.axi_rvalid
342 // is deasserted on reset (active low). axi_rresp and axi_rdata are
343 // cleared to zero on reset (active low).
344 always @( posedge S_AXI_ACLK )
346 if ( S_AXI_ARESETN == 1'b0 )
353 if (axi_arready && S_AXI_ARVALID && ~axi_rvalid)
355 // Valid read data is available at the read data bus
357 axi_rresp <= 2'b0; // 'OKAY' response
359 else if (axi_rvalid && S_AXI_RREADY)
361 // Read data is accepted by the master
367 // Implement memory mapped register select and read logic generation
368 // Slave register read enable is asserted when valid address is available
369 // and the slave is ready to accept the read address.
370 assign slv_reg_rden = axi_arready & S_AXI_ARVALID & ~axi_rvalid;
374 // Address decoding for reading registers
375 case ( axi_araddr[ADDR_LSB+OPT_MEM_ADDR_BITS:ADDR_LSB] )
376 2'h0 : reg_data_out <= slv_reg0;
377 2'h1 : reg_data_out <= slv_reg1;
378 2'h2 : reg_data_out <= slv_reg2;
379 2'h3 : reg_data_out <= slv_reg3;
380 default : reg_data_out <= 0;
385 // Output register or memory read data
386 always @( posedge S_AXI_ACLK )
388 if ( S_AXI_ARESETN == 1'b0 )
394 // When there is a valid read address (S_AXI_ARVALID) with
395 // acceptance of read address by the slave (axi_arready),
396 // output the read dada
399 axi_rdata[7:0] <= reg_data_out_i; // register read data
400 axi_rdata[C_S_AXI_DATA_WIDTH-1 : 8] <= 0;
405 // Add user logic here
406 assign reg_addr_read_o = S_AXI_ARADDR;
407 assign reg_addr_write_o= S_AXI_AWADDR;
408 assign reg_rst_o = ~S_AXI_ARESETN;
409 assign reg_re_o = slv_reg_rden;
410 assign reg_we_o = slv_reg_wren;
411 assign reg_data_in_o = S_AXI_WDATA[7:0];
412 //assign reg_data_out = reg_data_out_i;