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

Subversion Repositories vspi

[/] [vspi/] [trunk/] [projnav/] [xps/] [pcores/] [spiifc_v1_00_a/] [hdl/] [verilog/] [user_logic.v] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 mjlyons
//----------------------------------------------------------------------------
2
// user_logic.vhd - module
3
//----------------------------------------------------------------------------
4
//
5
// ***************************************************************************
6
// ** Copyright (c) 1995-2011 Xilinx, Inc.  All rights reserved.            **
7
// **                                                                       **
8
// ** Xilinx, Inc.                                                          **
9
// ** XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"         **
10
// ** AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND       **
11
// ** SOLUTIONS FOR XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE,        **
12
// ** OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,        **
13
// ** APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION           **
14
// ** THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,     **
15
// ** AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE      **
16
// ** FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY              **
17
// ** WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE               **
18
// ** IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR        **
19
// ** REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF       **
20
// ** INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS       **
21
// ** FOR A PARTICULAR PURPOSE.                                             **
22
// **                                                                       **
23
// ***************************************************************************
24
//
25
//----------------------------------------------------------------------------
26
// Filename:          user_logic.vhd
27
// Version:           1.00.a
28
// Description:       User logic module.
29
// Date:              Tue Feb 28 11:11:15 2012 (by Create and Import Peripheral Wizard)
30
// Verilog Standard:  Verilog-2001
31
//----------------------------------------------------------------------------
32
// Naming Conventions:
33
//   active low signals:                    "*_n"
34
//   clock signals:                         "clk", "clk_div#", "clk_#x"
35
//   reset signals:                         "rst", "rst_n"
36
//   generics:                              "C_*"
37
//   user defined types:                    "*_TYPE"
38
//   state machine next state:              "*_ns"
39
//   state machine current state:           "*_cs"
40
//   combinatorial signals:                 "*_com"
41
//   pipelined or register delay signals:   "*_d#"
42
//   counter signals:                       "*cnt*"
43
//   clock enable signals:                  "*_ce"
44
//   internal version of output port:       "*_i"
45
//   device pins:                           "*_pin"
46
//   ports:                                 "- Names begin with Uppercase"
47
//   processes:                             "*_PROCESS"
48
//   component instantiations:              "<ENTITY_>I_<#|FUNC>"
49
//----------------------------------------------------------------------------
50
 
51
module user_logic
52
(
53
  // -- ADD USER PORTS BELOW THIS LINE ---------------
54
  // --USER ports added here 
55
  SPI_CLK,
56
  SPI_MOSI,
57
  SPI_MISO,
58
  SPI_SS,
59
  // -- ADD USER PORTS ABOVE THIS LINE ---------------
60
 
61
  // -- DO NOT EDIT BELOW THIS LINE ------------------
62
  // -- Bus protocol ports, do not add to or delete 
63
  Bus2IP_Clk,                     // Bus to IP clock
64
  Bus2IP_Reset,                   // Bus to IP reset
65
  Bus2IP_Addr,                    // Bus to IP address bus
66
  Bus2IP_CS,                      // Bus to IP chip select for user logic memory selection
67
  Bus2IP_RNW,                     // Bus to IP read/not write
68
  Bus2IP_Data,                    // Bus to IP data bus
69
  Bus2IP_BE,                      // Bus to IP byte enables
70
  Bus2IP_RdCE,                    // Bus to IP read chip enable
71
  Bus2IP_WrCE,                    // Bus to IP write chip enable
72
  Bus2IP_Burst,                   // Bus to IP burst-mode qualifier
73
  Bus2IP_BurstLength,             // Bus to IP burst length
74
  Bus2IP_RdReq,                   // Bus to IP read request
75
  Bus2IP_WrReq,                   // Bus to IP write request
76
  IP2Bus_AddrAck,                 // IP to Bus address acknowledgement
77
  IP2Bus_Data,                    // IP to Bus data bus
78
  IP2Bus_RdAck,                   // IP to Bus read transfer acknowledgement
79
  IP2Bus_WrAck,                   // IP to Bus write transfer acknowledgement
80
  IP2Bus_Error,                   // IP to Bus error response
81
  IP2Bus_IntrEvent                // IP to Bus interrupt event
82
  // -- DO NOT EDIT ABOVE THIS LINE ------------------
83
); // user_logic
84
 
85
// -- ADD USER PARAMETERS BELOW THIS LINE ------------
86
// --USER parameters added here 
87
// -- ADD USER PARAMETERS ABOVE THIS LINE ------------
88
 
89
// -- DO NOT EDIT BELOW THIS LINE --------------------
90
// -- Bus protocol parameters, do not add to or delete
91
parameter C_SLV_AWIDTH                   = 32;
92
parameter C_SLV_DWIDTH                   = 32;
93
parameter C_NUM_REG                      = 16;
94
parameter C_NUM_MEM                      = 2;
95
parameter C_NUM_INTR                     = 1;
96
// -- DO NOT EDIT ABOVE THIS LINE --------------------
97
 
98
// -- ADD USER PORTS BELOW THIS LINE -----------------
99
// --USER ports added here 
100
input                                     SPI_CLK;
101
input                                     SPI_MOSI;
102
output                                    SPI_MISO;
103
input                                     SPI_SS;
104
// -- ADD USER PORTS ABOVE THIS LINE -----------------
105
 
106
// -- DO NOT EDIT BELOW THIS LINE --------------------
107
// -- Bus protocol ports, do not add to or delete
108
input                                     Bus2IP_Clk;
109
input                                     Bus2IP_Reset;
110
input      [0 : C_SLV_AWIDTH-1]           Bus2IP_Addr;
111
input      [0 : C_NUM_MEM-1]              Bus2IP_CS;
112
input                                     Bus2IP_RNW;
113
input      [0 : C_SLV_DWIDTH-1]           Bus2IP_Data;
114
input      [0 : C_SLV_DWIDTH/8-1]         Bus2IP_BE;
115
input      [0 : C_NUM_REG-1]              Bus2IP_RdCE;
116
input      [0 : C_NUM_REG-1]              Bus2IP_WrCE;
117
input                                     Bus2IP_Burst;
118
input      [0 : 8]                        Bus2IP_BurstLength;
119
input                                     Bus2IP_RdReq;
120
input                                     Bus2IP_WrReq;
121
output                                    IP2Bus_AddrAck;
122
output     [0 : C_SLV_DWIDTH-1]           IP2Bus_Data;
123
output                                    IP2Bus_RdAck;
124
output                                    IP2Bus_WrAck;
125
output                                    IP2Bus_Error;
126
output     [0 : C_NUM_INTR-1]             IP2Bus_IntrEvent;
127
// -- DO NOT EDIT ABOVE THIS LINE --------------------
128
 
129
//----------------------------------------------------------------------------
130
// Implementation
131
//----------------------------------------------------------------------------
132
 
133
  // --USER nets declarations added here, as needed for user logic
134
 
135
  // Memmap memory logic lines
136
  wire       [0 : C_NUM_MEM-1 ]             mem_enb;      // Port B: sysbus/dma
137
  wire       [0 : C_NUM_MEM-1 ]             mem_web;
138
  wire       [0 : C_NUM_MEM-1]              mem_write;
139
  wire       [0 : C_NUM_MEM-1]              mem_read;
140
  reg        [0 : C_NUM_MEM-1 ]             mem_read_prev;
141
 
142
  //   mosiMem (mem0): data received from master
143
  wire                                      mosiMem_wea;
144
  wire       [0 : 11]                       mosiMem_addra;
145
  wire       [0 : 7 ]                       mosiMem_dina;
146
  wire       [0 : 9 ]                       mosiMem_addrb;
147
  wire       [0 : 31]                       mosiMem_dinb;
148
  wire       [0 : 31]                       mosiMem_doutb;
149
  //   misoMem (mem1): data to send to master
150
  wire       [0 : 11]                       misoMem_addra;
151
  wire       [0 : 7 ]                       misoMem_douta;
152
  wire       [0 : 9 ]                       misoMem_addrb;
153
  wire       [0 : 31]                       misoMem_dinb;
154
  wire       [0 : 31]                       misoMem_doutb;
155
 
156
  // Nets for user logic slave model s/w accessible register example
157
  reg        [0 : C_SLV_DWIDTH-1]           slv_reg                   [0:15];
158
  wire       [0 : 15]                       slv_reg_write_sel;
159
  wire       [0 : 15]                       slv_reg_read_sel;
160
  reg        [0 : C_SLV_DWIDTH-1]           slv_ip2bus_data;
161
  wire                                      slv_read_ack;
162
  wire                                      slv_write_ack;
163
  integer                                   byte_index, bit_index;
164
 
165
  // SPI register access
166
  wire       [3 : 0]                        spiRegAddr;
167
  wire       [C_SLV_DWIDTH-1 : 0]           spiRegWriteData;
168
  wire                                      spiRegWE;
169
  reg        [C_SLV_DWIDTH-1 : 0]           spiRegReadData_wreg;
170
 
171
  // --USER logic implementation added here
172
 
173
  //   memory interface logic
174
  assign mem_enb       = mem_write | mem_read;
175
  assign mem_web       = mem_write;
176
  assign mosiMem_addrb = Bus2IP_Addr[20:29];
177
  assign mosiMem_dinb  = Bus2IP_Data;
178
  assign misoMem_addrb = Bus2IP_Addr[20:29];
179
  assign misoMem_dinb  = Bus2IP_Data;
180
 
181
  assign mem_write     = Bus2IP_CS & {C_NUM_MEM{Bus2IP_WrReq & (~Bus2IP_RNW)}};
182
  assign mem_read      = Bus2IP_CS & {C_NUM_MEM{Bus2IP_RdReq & Bus2IP_RNW}};
183
 
184
  always @(posedge Bus2IP_Clk) begin
185
    mem_read_prev <= mem_read;
186
  end
187
 
188
  // Mem0: Memory buffer storing data coming from master
189
  buffermem mosiMem (
190
    .clka(Bus2IP_Clk),        // input clka
191
    .ena(1'b1),         // input ena
192
    .wea(mosiMem_wea),               // Always writing, never reading
193
    .addra({mosiMem_addra}),  // input [11 : 0] addra
194
    .dina({mosiMem_dina}),    // input [7 : 0] dina
195
 // .douta(mosiMem_douta),    // NEVER USED: output [7 : 0] douta
196
    .clkb(Bus2IP_Clk),        // input clkb
197
    .enb(mem_enb[0]),         // input enb
198
    .web(mem_web[0]),         // input [0 : 0] web
199
    .addrb({mosiMem_addrb}),  // input [9 : 0] addrb
200
    .dinb({mosiMem_dinb}),    // input [31 : 0] dinb
201
    .doutb({mosiMem_doutb})   // output [31 : 0] doutb
202
  );
203
 
204
  // Mem1: Memory buffer storing data to send to master
205
  buffermem misoMem (
206
    .clka(Bus2IP_Clk),        // input clka
207
    .ena(1'b1),               // input ena
208
    .wea(1'b0),               // Always reading, never writing
209
    .addra({misoMem_addra}),  // input [11 : 0] addra
210
//  .dina(dina),              // input [7 : 0] dina
211
    .douta({misoMem_douta}),  // output [7 : 0] douta
212
    .clkb(Bus2IP_Clk),        // input clkb
213
    .enb(mem_enb[1]),         // input enb
214
    .web(mem_web[1]),         // input [0 : 0] web
215
    .addrb({misoMem_addrb}),  // input [9 : 0] addrb
216
    .dinb({misoMem_dinb}),    // input [31 : 0] dinb
217
    .doutb({misoMem_doutb})   // output [31 : 0] doutb
218
  );
219
 
220
  spiifc spi (
221
    .Reset(Bus2IP_Reset),
222
    .SysClk(Bus2IP_Clk),
223
    .SPI_CLK(SPI_CLK),
224
    .SPI_MISO(SPI_MISO),
225
    .SPI_MOSI(SPI_MOSI),
226
    .SPI_SS(SPI_SS),
227
    .txMemAddr(misoMem_addra),
228
    .txMemData(misoMem_douta),
229
    .rcMemAddr(mosiMem_addra),
230
    .rcMemData(mosiMem_dina),
231
    .rcMemWE(mosiMem_wea),
232
    .regAddr(spiRegAddr),
233
    .regReadData(spiRegReadData_wreg),
234
    .regWriteData(spiRegWriteData),
235
    .regWriteEn(spiRegWE)
236
  );
237
 
238
  // ------------------------------------------------------
239
  // Example code to read/write user logic slave model s/w accessible registers
240
  // 
241
  // Note:
242
  // The example code presented here is to show you one way of reading/writing
243
  // software accessible registers implemented in the user logic slave model.
244
  // Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to correspond
245
  // to one software accessible register by the top level template. For example,
246
  // if you have four 32 bit software accessible registers in the user logic,
247
  // you are basically operating on the following memory mapped registers:
248
  // 
249
  //    Bus2IP_WrCE/Bus2IP_RdCE   Memory Mapped Register
250
  //                     "1000"   C_BASEADDR + 0x0
251
  //                     "0100"   C_BASEADDR + 0x4
252
  //                     "0010"   C_BASEADDR + 0x8
253
  //                     "0001"   C_BASEADDR + 0xC
254
  // 
255
  // ------------------------------------------------------
256
 
257
  assign
258
    slv_reg_write_sel = Bus2IP_WrCE[0:15],
259
    slv_reg_read_sel  = Bus2IP_RdCE[0:15],
260
    slv_write_ack     = Bus2IP_WrCE[0] || Bus2IP_WrCE[1] || Bus2IP_WrCE[2] || Bus2IP_WrCE[3] || Bus2IP_WrCE[4] || Bus2IP_WrCE[5] || Bus2IP_WrCE[6] || Bus2IP_WrCE[7] || Bus2IP_WrCE[8] || Bus2IP_WrCE[9] || Bus2IP_WrCE[10] || Bus2IP_WrCE[11] || Bus2IP_WrCE[12] || Bus2IP_WrCE[13] || Bus2IP_WrCE[14] || Bus2IP_WrCE[15],
261
    slv_read_ack      = Bus2IP_RdCE[0] || Bus2IP_RdCE[1] || Bus2IP_RdCE[2] || Bus2IP_RdCE[3] || Bus2IP_RdCE[4] || Bus2IP_RdCE[5] || Bus2IP_RdCE[6] || Bus2IP_RdCE[7] || Bus2IP_RdCE[8] || Bus2IP_RdCE[9] || Bus2IP_RdCE[10] || Bus2IP_RdCE[11] || Bus2IP_RdCE[12] || Bus2IP_RdCE[13] || Bus2IP_RdCE[14] || Bus2IP_RdCE[15];
262
 
263
  genvar regIndex;
264
  generate
265
    for (regIndex = 0; regIndex < 16; regIndex = regIndex + 1) begin : REG_LOGIC
266
      // Reg write logic
267
      always @(posedge Bus2IP_Clk) begin
268
        if (Bus2IP_Reset == 1) begin
269
          slv_reg[regIndex] <= 0;
270
        end else if (spiRegWE && regIndex == spiRegAddr) begin
271
          slv_reg[regIndex] <= spiRegWriteData;
272
        end else if (slv_reg_write_sel[regIndex]) begin
273
          for ( byte_index = 0; byte_index <= (C_SLV_DWIDTH/8)-1; byte_index = byte_index + 1 ) begin
274
            if ( Bus2IP_BE[byte_index] == 1) begin
275
              for ( bit_index = byte_index*8; bit_index <= byte_index*8+7; bit_index = bit_index+1) begin
276
                slv_reg[regIndex][bit_index] <= Bus2IP_Data[bit_index];
277
              end
278
            end
279
          end
280
        end
281
      end
282
    end
283
  endgenerate
284
 
285
  // implement slave model register read mux
286
  always @( slv_reg_read_sel or slv_reg[0] or slv_reg[1] or slv_reg[2]
287
            or slv_reg[3] or slv_reg[4] or slv_reg[5] or slv_reg[6] or slv_reg[7]
288
            or slv_reg[8] or slv_reg[9] or slv_reg[10] or slv_reg[11] or slv_reg[12]
289
            or slv_reg[13] or slv_reg[14] or slv_reg[15] )
290
    begin: SLAVE_REG_READ_PROC
291
 
292
      case ( slv_reg_read_sel )
293
        16'b1000000000000000 : slv_ip2bus_data <= slv_reg[0];
294
        16'b0100000000000000 : slv_ip2bus_data <= slv_reg[1];
295
        16'b0010000000000000 : slv_ip2bus_data <= slv_reg[2];
296
        16'b0001000000000000 : slv_ip2bus_data <= slv_reg[3];
297
        16'b0000100000000000 : slv_ip2bus_data <= slv_reg[4];
298
        16'b0000010000000000 : slv_ip2bus_data <= slv_reg[5];
299
        16'b0000001000000000 : slv_ip2bus_data <= slv_reg[6];
300
        16'b0000000100000000 : slv_ip2bus_data <= slv_reg[7];
301
        16'b0000000010000000 : slv_ip2bus_data <= slv_reg[8];
302
        16'b0000000001000000 : slv_ip2bus_data <= slv_reg[9];
303
        16'b0000000000100000 : slv_ip2bus_data <= slv_reg[10];
304
        16'b0000000000010000 : slv_ip2bus_data <= slv_reg[11];
305
        16'b0000000000001000 : slv_ip2bus_data <= slv_reg[12];
306
        16'b0000000000000100 : slv_ip2bus_data <= slv_reg[13];
307
        16'b0000000000000010 : slv_ip2bus_data <= slv_reg[14];
308
        16'b0000000000000001 : slv_ip2bus_data <= slv_reg[15];
309
        default : slv_ip2bus_data <= 0;
310
      endcase
311
 
312
    end // SLAVE_REG_READ_PROC
313
 
314
  // implement spi register read mux
315
  always @( spiRegAddr or slv_reg[0] or slv_reg[1] or slv_reg[2]
316
            or slv_reg[3] or slv_reg[4] or slv_reg[5] or slv_reg[6] or slv_reg[7]
317
            or slv_reg[8] or slv_reg[9] or slv_reg[10] or slv_reg[11] or slv_reg[12]
318
            or slv_reg[13] or slv_reg[14] or slv_reg[15] ) begin
319
    spiRegReadData_wreg <= slv_reg[spiRegAddr];
320
  end
321
 
322
  // ------------------------------------------------------------
323
  // Example code to drive IP to Bus signals
324
  // ------------------------------------------------------------
325
 
326
  assign IP2Bus_AddrAck = slv_write_ack || slv_read_ack || (|mem_read) || (|mem_write);
327
  assign IP2Bus_Data    = (mem_read_prev[0] ? mosiMem_doutb : (
328
                           mem_read_prev[1] ? misoMem_doutb :
329
                                              slv_ip2bus_data));
330
  assign IP2Bus_WrAck   = slv_write_ack || (|mem_write);
331
  assign IP2Bus_RdAck   = slv_read_ack || (|mem_read_prev);
332
  assign IP2Bus_Error   = 0;
333
 
334
endmodule

powered by: WebSVN 2.1.0

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