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

Subversion Repositories spi_slave

[/] [spi_slave/] [trunk/] [pcore/] [opb_spi_slave_v1_00_a/] [hdl/] [vhdl/] [opb_spi_slave.vhd] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dkoethe
-------------------------------------------------------------------------------
2 30 dkoethe
-------------------------------------------------------
3
--! @file
4
--! @brief 2:1 Mux using with-select
5
-------------------------------------------------------
6
 
7 2 dkoethe
--* 
8
--* @short Top entity of the project opi_spi_slave
9
--* 
10
--* @generic C_FAMILY virtex-4 and generic supported
11
--*    @author: Daniel Köthe
12 4 dkoethe
--*   @version: 1.1
13
--* @date: 2007-11-19
14 2 dkoethe
--/
15 4 dkoethe
-- Version 1.1
16
-- Bugfix
17
-- IRQ-Flag RX_Overflow shows prog_empty insteed rx_overflow
18
-- opb_irq_flg(5) <= opb_fifo_flg(9); to opb_irq_flg(5) <= opb_fifo_flg(8); 
19
 
20 2 dkoethe
-------------------------------------------------------------------------------
21
 
22
library ieee;
23
use ieee.std_logic_1164.all;
24
use IEEE.STD_LOGIC_UNSIGNED.all;
25
 
26
 
27
library UNISIM;
28
use UNISIM.vcomponents.all;
29
 
30
library work;
31
use work.opb_spi_slave_pack.all;
32
 
33
 
34
entity opb_spi_slave is
35
 
36
  generic (
37
    C_BASEADDR     : std_logic_vector(0 to 31) := X"00000000";
38
    C_HIGHADDR     : std_logic_vector(0 to 31) := X"FFFFFFFF";
39
    C_USER_ID_CODE : integer                   := 0;
40
    C_OPB_AWIDTH   : integer                   := 32;
41
    C_OPB_DWIDTH   : integer                   := 32;
42
 
43
    C_FAMILY          : string               := "virtex4";
44
    -- user ports
45
    C_SR_WIDTH        : integer              := 8;
46
    C_MSB_FIRST       : boolean              := true;
47
    C_CPOL            : integer range 0 to 1 := 0;
48
    C_PHA             : integer range 0 to 1 := 0;
49
    C_FIFO_SIZE_WIDTH : integer range 4 to 7 := 5;  -- depth 32
50 23 dkoethe
    C_DMA_EN          : boolean              := false;
51
    C_CRC_EN          : boolean              := false);
52 2 dkoethe
 
53
  port (
54
    -- OPB signals (Slave Side)
55
    OPB_ABus    : in  std_logic_vector(0 to C_OPB_AWIDTH-1);
56
    OPB_BE      : in  std_logic_vector(0 to C_OPB_DWIDTH/8-1);
57
    OPB_Clk     : in  std_logic;
58
    OPB_DBus    : in  std_logic_vector(0 to C_OPB_DWIDTH-1);
59
    OPB_RNW     : in  std_logic;
60
    OPB_Rst     : in  std_logic;
61
    OPB_select  : in  std_logic;
62
    OPB_seqAddr : in  std_logic;
63
    Sln_DBus    : out std_logic_vector(0 to C_OPB_DWIDTH-1);
64
    Sln_errAck  : out std_logic;
65
    Sln_retry   : out std_logic;
66
    Sln_toutSup : out std_logic;
67
    Sln_xferAck : out std_logic;
68
 
69
    -- OPB signals (Master Side)
70
    -- Arbitration
71
    M_request    : out std_logic;
72
    MOPB_MGrant  : in  std_logic;
73
    M_busLock    : out std_logic;
74
    -- 
75
    M_ABus       : out std_logic_vector(0 to C_OPB_AWIDTH-1);
76
    M_BE         : out std_logic_vector(0 to C_OPB_DWIDTH/8-1);
77
    M_DBus       : out std_logic_vector(0 to C_OPB_DWIDTH-1);
78
    M_RNW        : out std_logic;
79
    M_select     : out std_logic;
80
    M_seqAddr    : out std_logic;
81
    MOPB_errAck  : in  std_logic;
82
    MOPB_retry   : in  std_logic;
83
    MOPB_timeout : in  std_logic;
84
    MOPB_xferAck : in  std_logic;
85
    -- spi ports
86
    sclk         : in  std_logic;
87
    ss_n         : in  std_logic;
88
    mosi         : in  std_logic;
89
    miso_o       : out std_logic;
90
    miso_i       : in  std_logic;
91
    miso_t       : out std_logic;
92
    -- irq output
93
    opb_irq      : out std_logic);
94
 
95
end opb_spi_slave;
96
 
97
architecture behavior of opb_spi_slave is
98
 
99
  component opb_if
100
    generic (
101
      C_BASEADDR        : std_logic_vector(0 to 31);
102
      C_HIGHADDR        : std_logic_vector(0 to 31);
103
      C_USER_ID_CODE    : integer;
104
      C_OPB_AWIDTH      : integer;
105
      C_OPB_DWIDTH      : integer;
106
      C_FAMILY          : string;
107
      C_SR_WIDTH        : integer;
108
      C_FIFO_SIZE_WIDTH : integer;
109 23 dkoethe
      C_DMA_EN          : boolean;
110
      C_CRC_EN          : boolean);
111 2 dkoethe
    port (
112 23 dkoethe
      OPB_ABus         : in  std_logic_vector(0 to C_OPB_AWIDTH-1);
113
      OPB_BE           : in  std_logic_vector(0 to C_OPB_DWIDTH/8-1);
114
      OPB_Clk          : in  std_logic;
115
      OPB_DBus         : in  std_logic_vector(0 to C_OPB_DWIDTH-1);
116
      OPB_RNW          : in  std_logic;
117
      OPB_Rst          : in  std_logic;
118
      OPB_select       : in  std_logic;
119
      OPB_seqAddr      : in  std_logic;
120
      Sln_DBus         : out std_logic_vector(0 to C_OPB_DWIDTH-1);
121
      Sln_errAck       : out std_logic;
122
      Sln_retry        : out std_logic;
123
      Sln_toutSup      : out std_logic;
124
      Sln_xferAck      : out std_logic;
125
      opb_s_tx_en      : out std_logic;
126
      opb_s_tx_data    : out std_logic_vector(C_SR_WIDTH-1 downto 0);
127
      opb_s_rx_en      : out std_logic;
128
      opb_s_rx_data    : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
129
      opb_ctl_reg      : out std_logic_vector(C_OPB_CTL_REG_WIDTH-1 downto 0);
130
      tx_thresh        : out std_logic_vector((2*C_FIFO_SIZE_WIDTH)-1 downto 0);
131
      rx_thresh        : out std_logic_vector((2*C_FIFO_SIZE_WIDTH)-1 downto 0);
132
      opb_fifo_flg     : in  std_logic_vector(C_NUM_FLG-1 downto 0);
133
      opb_dgie         : out std_logic;
134
      opb_ier          : out std_logic_vector(C_NUM_INT-1 downto 0);
135
      opb_isr          : in  std_logic_vector(C_NUM_INT-1 downto 0);
136
      opb_isr_clr      : out std_logic_vector(C_NUM_INT-1 downto 0);
137
      opb_tx_dma_addr  : out std_logic_vector(C_OPB_DWIDTH-1 downto 0);
138
      opb_tx_dma_ctl   : out std_logic_vector(0 downto 0);
139
      opb_tx_dma_num   : out std_logic_vector(C_WIDTH_DMA_NUM-1 downto 0);
140
      opb_rx_dma_addr  : out std_logic_vector(C_OPB_DWIDTH-1 downto 0);
141
      opb_rx_dma_ctl   : out std_logic_vector(0 downto 0);
142
      opb_rx_dma_num   : out std_logic_vector(C_WIDTH_DMA_NUM-1 downto 0);
143
      opb_rx_crc_value : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
144
      opb_tx_crc_value : in  std_logic_vector(C_SR_WIDTH-1 downto 0));
145
 
146 2 dkoethe
  end component;
147
 
148
 
149
  component opb_m_if
150
    generic (
151
      C_BASEADDR        : std_logic_vector(0 to 31);
152
      C_HIGHADDR        : std_logic_vector(0 to 31);
153
      C_USER_ID_CODE    : integer;
154
      C_OPB_AWIDTH      : integer;
155
      C_OPB_DWIDTH      : integer;
156
      C_FAMILY          : string;
157
      C_SR_WIDTH        : integer;
158
      C_MSB_FIRST       : boolean;
159
      C_CPOL            : integer range 0 to 1;
160
      C_PHA             : integer range 0 to 1;
161
      C_FIFO_SIZE_WIDTH : integer range 4 to 7);
162
    port (
163 23 dkoethe
      OPB_Clk          : in  std_logic;
164
      OPB_Rst          : in  std_logic;
165
      OPB_DBus         : in  std_logic_vector(0 to C_OPB_DWIDTH-1);
166
      M_request        : out std_logic;
167
      MOPB_MGrant      : in  std_logic;
168
      M_busLock        : out std_logic;
169
      M_ABus           : out std_logic_vector(0 to C_OPB_AWIDTH-1);
170
      M_BE             : out std_logic_vector(0 to C_OPB_DWIDTH/8-1);
171
      M_DBus           : out std_logic_vector(0 to C_OPB_DWIDTH-1);
172
      M_RNW            : out std_logic;
173
      M_select         : out std_logic;
174
      M_seqAddr        : out std_logic;
175
      MOPB_errAck      : in  std_logic;
176
      MOPB_retry       : in  std_logic;
177
      MOPB_timeout     : in  std_logic;
178
      MOPB_xferAck     : in  std_logic;
179
      opb_m_tx_req     : in  std_logic;
180
      opb_m_tx_en      : out std_logic;
181
      opb_m_tx_data    : out std_logic_vector(C_SR_WIDTH-1 downto 0);
182
      opb_tx_dma_ctl   : in  std_logic_vector(0 downto 0);
183
      opb_tx_dma_addr  : in  std_logic_vector(C_OPB_DWIDTH-1 downto 0);
184
      opb_tx_dma_num   : in  std_logic_vector(C_WIDTH_DMA_NUM-1 downto 0);
185
      opb_tx_dma_done  : out std_logic;
186
      opb_m_rx_req     : in  std_logic;
187
      opb_m_rx_en      : out std_logic;
188
      opb_m_rx_data    : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
189
      opb_rx_dma_ctl   : in  std_logic_vector(0 downto 0);
190
      opb_rx_dma_addr  : in  std_logic_vector(C_OPB_DWIDTH-1 downto 0);
191
      opb_rx_dma_num   : in  std_logic_vector(C_WIDTH_DMA_NUM-1 downto 0);
192
      opb_rx_dma_done  : out std_logic;
193
      opb_abort_flg    : out std_logic;
194
      opb_m_last_block : out std_logic);
195 2 dkoethe
  end component;
196
 
197
  component shift_register
198
    generic (
199
      C_SR_WIDTH  : integer;
200
      C_MSB_FIRST : boolean;
201
      C_CPOL      : integer range 0 to 1;
202
      C_PHA       : integer range 0 to 1);
203
    port (
204
      rst         : in  std_logic;
205
      opb_ctl_reg : in  std_logic_vector(C_OPB_CTL_REG_WIDTH-1 downto 0);
206
      sclk        : in  std_logic;
207
      ss_n        : in  std_logic;
208
      mosi        : in  std_logic;
209
      miso_o      : out std_logic;
210
      miso_i      : in  std_logic;
211
      miso_t      : out std_logic;
212
      sr_tx_clk   : out std_logic;
213
      sr_tx_en    : out std_logic;
214
      sr_tx_data  : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
215
      sr_rx_clk   : out std_logic;
216
      sr_rx_en    : out std_logic;
217
      sr_rx_data  : out std_logic_vector(C_SR_WIDTH-1 downto 0));
218
  end component;
219
 
220
  component fifo
221
    generic (
222
      C_FIFO_WIDTH      : integer;
223
      C_FIFO_SIZE_WIDTH : integer;
224
      C_SYNC_TO         : string);
225
    port (
226
      rst               : in  std_logic;
227
      wr_clk            : in  std_logic;
228
      wr_en             : in  std_logic;
229
      din               : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
230
      rd_clk            : in  std_logic;
231
      rd_en             : in  std_logic;
232
      dout              : out std_logic_vector(C_SR_WIDTH-1 downto 0);
233
      empty             : out std_logic;
234
      full              : out std_logic;
235
      overflow          : out std_logic;
236
      underflow         : out std_logic;
237
      prog_empty_thresh : in  std_logic_vector(C_FIFO_SIZE_WIDTH-1 downto 0);
238
      prog_full_thresh  : in  std_logic_vector(C_FIFO_SIZE_WIDTH-1 downto 0);
239
      prog_empty        : out std_logic;
240
      prog_full         : out std_logic);
241
  end component;
242
 
243
  component irq_ctl
244
    generic (
245
      C_ACTIVE_EDGE : std_logic);
246
    port (
247
      rst          : in  std_logic;
248
      clk          : in  std_logic;
249
      opb_fifo_flg : in  std_logic;
250
      opb_ier      : in  std_logic;
251
      opb_isr      : out std_logic;
252
      opb_isr_clr  : in  std_logic);
253
  end component;
254
 
255 23 dkoethe
  component crc_core
256
    generic (
257
      C_SR_WIDTH : integer);
258
    port (
259
      rst              : in  std_logic;
260
      opb_clk          : in  std_logic;
261
      crc_en           : in  std_logic;
262
      crc_clr          : in  std_logic;
263
      opb_m_last_block : in  std_logic;
264
      fifo_rx_en       : in  std_logic;
265
      fifo_rx_data     : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
266
      opb_rx_crc_value : out std_logic_vector(C_SR_WIDTH-1 downto 0);
267
      fifo_tx_en       : in  std_logic;
268
      fifo_tx_data     : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
269
      tx_crc_insert    : out std_logic;
270
      opb_tx_crc_value : out std_logic_vector(C_SR_WIDTH-1 downto 0));
271
  end component;
272
 
273 2 dkoethe
-- opb_if
274
  signal opb_ctl_reg : std_logic_vector(C_OPB_CTL_REG_WIDTH-1 downto 0);
275
 
276
  signal opb_s_tx_en   : std_logic;
277
  signal opb_s_tx_data : std_logic_vector(C_SR_WIDTH-1 downto 0);
278
  signal opb_s_rx_en   : std_logic;
279
  signal opb_s_rx_data : std_logic_vector(C_SR_WIDTH-1 downto 0);
280
 
281
  signal tx_thresh : std_logic_vector((2*C_FIFO_SIZE_WIDTH)-1 downto 0);
282
  signal rx_thresh : std_logic_vector((2*C_FIFO_SIZE_WIDTH)-1 downto 0);
283
 
284
  signal opb_tx_dma_addr : std_logic_vector(C_OPB_DWIDTH-1 downto 0);
285
  signal opb_tx_dma_ctl  : std_logic_vector(0 downto 0);
286 10 dkoethe
  signal opb_tx_dma_num  : std_logic_vector(C_WIDTH_DMA_NUM-1 downto 0);
287 2 dkoethe
  signal opb_rx_dma_addr : std_logic_vector(C_OPB_DWIDTH-1 downto 0);
288
  signal opb_rx_dma_ctl  : std_logic_vector(0 downto 0);
289 10 dkoethe
  signal opb_rx_dma_num  : std_logic_vector(C_WIDTH_DMA_NUM-1 downto 0);
290 2 dkoethe
 
291 23 dkoethe
  signal opb_rx_crc_value : std_logic_vector(C_SR_WIDTH-1 downto 0);
292
  signal opb_tx_crc_value : std_logic_vector(C_SR_WIDTH-1 downto 0);
293
 
294 2 dkoethe
  -- opb_m_if
295 23 dkoethe
  signal opb_m_tx_en      : std_logic;
296
  signal opb_m_tx_data    : std_logic_vector(C_SR_WIDTH-1 downto 0);
297
  signal opb_m_rx_en      : std_logic;
298
  signal opb_m_rx_data    : std_logic_vector(C_SR_WIDTH-1 downto 0);
299
  signal opb_abort_flg    : std_logic;
300
  signal opb_m_last_block : std_logic;
301 2 dkoethe
 
302
-- shift_register
303
  signal sr_tx_clk  : std_logic;
304
  signal sr_tx_en   : std_logic;
305
  signal sr_tx_data : std_logic_vector(C_SR_WIDTH-1 downto 0);
306
  signal sr_rx_clk  : std_logic;
307
  signal sr_rx_en   : std_logic;
308
  signal sr_rx_data : std_logic_vector(C_SR_WIDTH-1 downto 0);
309
 
310
  signal sclk_ibuf : std_logic;
311
  signal sclk_bufr : std_logic;
312
 
313
  signal opb_fifo_flg : std_logic_vector(C_NUM_FLG-1 downto 0);
314
  signal opb_irq_flg  : std_logic_vector(C_NUM_INT-1 downto 0) := (others => '0');
315
  signal rst          : std_logic;
316
 
317
 
318
  signal opb_dgie    : std_logic;
319
  signal opb_ier     : std_logic_vector(C_NUM_INT-1 downto 0);
320
  signal opb_isr     : std_logic_vector(C_NUM_INT-1 downto 0);
321
  signal opb_isr_clr : std_logic_vector(C_NUM_INT-1 downto 0);
322
 
323
  -- opb_spi_slave
324
  signal fifo_tx_en   : std_logic;
325
  signal fifo_tx_data : std_logic_vector(C_SR_WIDTH-1 downto 0);
326
  signal fifo_rx_en   : std_logic;
327
  signal fifo_rx_data : std_logic_vector(C_SR_WIDTH-1 downto 0);
328 23 dkoethe
 
329
  -- rx crc_core
330
  signal crc_clr       : std_logic;
331
  signal crc_en        : std_logic;
332
  signal tx_crc_insert : std_logic;
333
 
334 2 dkoethe
begin  -- behavior
335
 
336
  --* 
337
  virtex4_slk_buf : if C_FAMILY = "virtex4" generate
338
    --* If C_FAMILY=Virtex-4 use "IBUF"
339
    IBUF_1 : IBUF
340
      port map (
341
        I => sclk,
342
        O => sclk_ibuf);
343
 
344
--* If C_FAMILY=Virtex-4 use "BUFR"
345
    BUFR_1 : BUFR
346
      generic map (
347
        BUFR_DIVIDE => "BYPASS",
348
        SIM_DEVICE  => "VIRTEX4")
349
      port map (
350
        O   => sclk_bufr,
351
        CE  => '0',
352
        CLR => '0',
353
        I   => sclk_ibuf);
354
  end generate virtex4_slk_buf;
355
 
356
  generic_sclk_buf : if C_FAMILY /= "virtex4" generate
357
    sclk_bufr <= sclk;
358
  end generate generic_sclk_buf;
359
 
360
  --* OPB-Slave Interface(Register-Interface)
361
  opb_if_2 : opb_if
362
    generic map (
363
      C_BASEADDR        => C_BASEADDR,
364
      C_HIGHADDR        => C_HIGHADDR,
365
      C_USER_ID_CODE    => C_USER_ID_CODE,
366
      C_OPB_AWIDTH      => C_OPB_AWIDTH,
367
      C_OPB_DWIDTH      => C_OPB_DWIDTH,
368
      C_FAMILY          => C_FAMILY,
369
      C_SR_WIDTH        => C_SR_WIDTH,
370
      C_FIFO_SIZE_WIDTH => C_FIFO_SIZE_WIDTH,
371 23 dkoethe
      C_DMA_EN          => C_DMA_EN,
372
      C_CRC_EN          => C_CRC_EN)
373 2 dkoethe
    port map (
374 23 dkoethe
      OPB_ABus         => OPB_ABus,
375
      OPB_BE           => OPB_BE,
376
      OPB_Clk          => OPB_Clk,
377
      OPB_DBus         => OPB_DBus,
378
      OPB_RNW          => OPB_RNW,
379
      OPB_Rst          => OPB_Rst,
380
      OPB_select       => OPB_select,
381
      OPB_seqAddr      => OPB_seqAddr,
382
      Sln_DBus         => Sln_DBus,
383
      Sln_errAck       => Sln_errAck,
384
      Sln_retry        => Sln_retry,
385
      Sln_toutSup      => Sln_toutSup,
386
      Sln_xferAck      => Sln_xferAck,
387
      opb_s_tx_en      => opb_s_tx_en,
388
      opb_s_tx_data    => opb_s_tx_data,
389
      opb_s_rx_en      => opb_s_rx_en,
390
      opb_s_rx_data    => opb_s_rx_data,
391
      opb_ctl_reg      => opb_ctl_reg,
392
      tx_thresh        => tx_thresh,
393
      rx_thresh        => rx_thresh,
394
      opb_fifo_flg     => opb_fifo_flg,
395
      opb_dgie         => opb_dgie,
396
      opb_ier          => opb_ier,
397
      opb_isr          => opb_isr,
398
      opb_isr_clr      => opb_isr_clr,
399
      opb_tx_dma_addr  => opb_tx_dma_addr,
400
      opb_tx_dma_ctl   => opb_tx_dma_ctl,
401
      opb_tx_dma_num   => opb_tx_dma_num,
402
      opb_rx_dma_addr  => opb_rx_dma_addr,
403
      opb_rx_dma_ctl   => opb_rx_dma_ctl,
404
      opb_rx_dma_num   => opb_rx_dma_num,
405
      opb_rx_crc_value => opb_rx_crc_value,
406
      opb_tx_crc_value => opb_tx_crc_value);
407 2 dkoethe
 
408
  --* OPB-Master-Interface
409
  --*
410
  --* (DMA Read/Write Transfers to TX/RX-FIFO)
411
 
412
  dma_enable : if (C_DMA_EN = true) generate
413
    opb_m_if_1 : opb_m_if
414
      generic map (
415
        C_BASEADDR        => C_BASEADDR,
416
        C_HIGHADDR        => C_HIGHADDR,
417
        C_USER_ID_CODE    => C_USER_ID_CODE,
418
        C_OPB_AWIDTH      => C_OPB_AWIDTH,
419
        C_OPB_DWIDTH      => C_OPB_DWIDTH,
420
        C_FAMILY          => C_FAMILY,
421
        C_SR_WIDTH        => C_SR_WIDTH,
422
        C_MSB_FIRST       => C_MSB_FIRST,
423
        C_CPOL            => C_CPOL,
424
        C_PHA             => C_PHA,
425
        C_FIFO_SIZE_WIDTH => C_FIFO_SIZE_WIDTH)
426
      port map (
427 23 dkoethe
        OPB_Clk          => OPB_Clk,
428
        OPB_Rst          => OPB_Rst,
429
        OPB_DBus         => OPB_DBus,
430
        M_request        => M_request,
431
        MOPB_MGrant      => MOPB_MGrant,
432
        M_busLock        => M_busLock,
433
        M_ABus           => M_ABus,
434
        M_BE             => M_BE,
435
        M_DBus           => M_DBus,
436
        M_RNW            => M_RNW,
437
        M_select         => M_select,
438
        M_seqAddr        => M_seqAddr,
439
        MOPB_errAck      => MOPB_errAck,
440
        MOPB_retry       => MOPB_retry,
441
        MOPB_timeout     => MOPB_timeout,
442
        MOPB_xferAck     => MOPB_xferAck,
443
        opb_m_tx_req     => opb_fifo_flg(3),
444
        opb_m_tx_en      => opb_m_tx_en,
445
        opb_m_tx_data    => opb_m_tx_data,
446
        opb_tx_dma_ctl   => opb_tx_dma_ctl,
447
        opb_tx_dma_addr  => opb_tx_dma_addr,
448
        opb_tx_dma_num   => opb_tx_dma_num,
449
        opb_tx_dma_done  => opb_fifo_flg(13),
450
        opb_m_rx_req     => opb_fifo_flg(6),
451
        opb_m_rx_en      => opb_m_rx_en,
452
        opb_m_rx_data    => opb_m_rx_data,
453
        opb_rx_dma_ctl   => opb_rx_dma_ctl,
454
        opb_rx_dma_addr  => opb_rx_dma_addr,
455
        opb_rx_dma_num   => opb_rx_dma_num,
456
        opb_rx_dma_done  => opb_fifo_flg(14),
457
        opb_abort_flg    => opb_abort_flg,
458
        opb_m_last_block => opb_m_last_block);
459 2 dkoethe
  end generate dma_enable;
460
 
461
  dma_disable : if (C_DMA_EN = false) generate
462
    M_request        <= '0';
463
    M_busLock        <= '0';
464
    M_ABus           <= (others => '0');
465
    M_BE             <= (others => '0');
466
    M_DBus           <= (others => '0');
467
    M_RNW            <= '0';
468
    M_select         <= '0';
469
    M_seqAddr        <= '0';
470
    opb_m_tx_en      <= '0';
471
    opb_m_tx_data    <= (others => '0');
472
    opb_fifo_flg(13) <= '0';
473
    opb_m_rx_en      <= '0';
474
    opb_fifo_flg(14) <= '0';
475
  end generate dma_disable;
476
 
477
  --* Shift-Register 
478
  shift_register_1 : shift_register
479
    generic map (
480
      C_SR_WIDTH  => C_SR_WIDTH,
481
      C_MSB_FIRST => C_MSB_FIRST,
482
      C_CPOL      => C_CPOL,
483
      C_PHA       => C_PHA)
484
    port map (
485
      rst         => rst,
486
      opb_ctl_reg => opb_ctl_reg,
487
      sclk        => sclk_bufr,
488
      ss_n        => ss_n,
489
      mosi        => mosi,
490
      miso_o      => miso_o,
491
      miso_i      => miso_i,
492
      miso_t      => miso_t,
493
      sr_tx_clk   => sr_tx_clk,
494
      sr_tx_en    => sr_tx_en,
495
      sr_tx_data  => sr_tx_data,
496
      sr_rx_clk   => sr_rx_clk,
497
      sr_rx_en    => sr_rx_en,
498
      sr_rx_data  => sr_rx_data);
499
 
500
  --* Transmit FIFO
501
  tx_fifo_1 : fifo
502
    generic map (
503
      C_FIFO_WIDTH      => C_SR_WIDTH,
504
      C_FIFO_SIZE_WIDTH => C_FIFO_SIZE_WIDTH,
505
      C_SYNC_TO         => "WR")
506
    port map (
507
      -- global
508
      rst               => rst,
509
      prog_full_thresh  => tx_thresh(C_FIFO_SIZE_WIDTH-1 downto 0),
510
      prog_empty_thresh => tx_thresh((2*C_FIFO_SIZE_WIDTH)-1 downto C_FIFO_SIZE_WIDTH),
511
      -- write port
512
      wr_clk            => OPB_Clk,
513
      wr_en             => fifo_tx_en,
514
      din               => fifo_tx_data,
515
      -- flags
516
      prog_full         => opb_fifo_flg(0),
517
      full              => opb_fifo_flg(1),
518
      overflow          => opb_fifo_flg(2),
519
      -- read port
520
      rd_clk            => sr_tx_clk,
521
      rd_en             => sr_tx_en,
522
      dout              => sr_tx_data,
523
      -- flags
524
      prog_empty        => opb_fifo_flg(3),
525
      empty             => opb_fifo_flg(4),
526
      underflow         => opb_fifo_flg(5));
527
 
528
  fifo_tx_en   <= opb_s_tx_en or opb_m_tx_en;
529 23 dkoethe
  fifo_tx_data <= opb_tx_crc_value when (C_CRC_EN and tx_crc_insert = '1') else
530
                  opb_m_tx_data when (opb_tx_dma_ctl(0) = '1') else
531 2 dkoethe
                  opb_s_tx_data;
532
 
533
  --* Receive FIFO
534
  rx_fifo_1 : fifo
535
    generic map (
536
      C_FIFO_WIDTH      => C_SR_WIDTH,
537
      C_FIFO_SIZE_WIDTH => C_FIFO_SIZE_WIDTH,
538
      C_SYNC_TO         => "RD")
539
    port map (
540
      -- global
541
      rst               => rst,
542
      prog_full_thresh  => rx_thresh(C_FIFO_SIZE_WIDTH-1 downto 0),
543
      prog_empty_thresh => rx_thresh((2*C_FIFO_SIZE_WIDTH)-1 downto C_FIFO_SIZE_WIDTH),
544
      -- write port
545
      wr_clk            => sr_rx_clk,
546
      wr_en             => sr_rx_en,
547
      din               => sr_rx_data,
548
      -- flags
549
      prog_full         => opb_fifo_flg(6),
550
      full              => opb_fifo_flg(7),
551
      overflow          => opb_fifo_flg(8),
552
      -- read port
553
      rd_clk            => opb_clk,
554
      rd_en             => fifo_rx_en,
555
      dout              => fifo_rx_data,
556
      -- flags
557
      prog_empty        => opb_fifo_flg(9),
558
      empty             => opb_fifo_flg(10),
559
      underflow         => opb_fifo_flg(11));
560
 
561
  fifo_rx_en    <= opb_s_rx_en or opb_m_rx_en;
562
  opb_s_rx_data <= fifo_rx_data;
563
  opb_m_rx_data <= fifo_rx_data;
564
 
565
  rst <= OPB_Rst or opb_ctl_reg(C_OPB_CTL_REG_RST);
566
 
567
  opb_fifo_flg(12) <= ss_n;
568 23 dkoethe
  opb_fifo_flg(15) <= opb_abort_flg;
569 2 dkoethe
 
570
 
571
 
572
  -- Bit 0 : TX_PROG_EMPTY
573 23 dkoethe
  opb_irq_flg(0)  <= opb_fifo_flg(3);
574 2 dkoethe
  -- Bit 1 : TX_EMPTY
575 23 dkoethe
  opb_irq_flg(1)  <= opb_fifo_flg(4);
576 2 dkoethe
  -- Bit 2 : TX_Underflow
577 23 dkoethe
  opb_irq_flg(2)  <= opb_fifo_flg(5);
578 2 dkoethe
  -- Bit 3 : RX_PROG_FULL
579 23 dkoethe
  opb_irq_flg(3)  <= opb_fifo_flg(6);
580 2 dkoethe
  -- Bit 4 : RX_FULL
581 23 dkoethe
  opb_irq_flg(4)  <= opb_fifo_flg(7);
582 2 dkoethe
  -- Bit 5 : RX_Overflow
583 23 dkoethe
  opb_irq_flg(5)  <= opb_fifo_flg(8);
584 2 dkoethe
  -- Bit 6:  CS_H_TO_L
585 23 dkoethe
  opb_irq_flg(6)  <= not opb_fifo_flg(12);
586 2 dkoethe
  -- Bit 7:  CS_L_TO_H
587 23 dkoethe
  opb_irq_flg(7)  <= opb_fifo_flg(12);
588 2 dkoethe
  -- Bit 8: TX DMA Done
589 23 dkoethe
  opb_irq_flg(8)  <= opb_fifo_flg(13);
590 2 dkoethe
  -- Bit 9: RX DMA Done
591 23 dkoethe
  opb_irq_flg(9)  <= opb_fifo_flg(14);
592 14 dkoethe
  -- Bit 10: DMA Transfer Abort
593
  opb_irq_flg(10) <= opb_abort_flg;
594 2 dkoethe
 
595
  --* IRQ Enable, Detection and Flags Control
596
  irq_gen : for i in 0 to C_NUM_INT-1 generate
597
    irq_ctl_1 : irq_ctl
598
      generic map (
599
        C_ACTIVE_EDGE => '1')
600
      port map (
601
        rst          => rst,
602
        clk          => OPB_Clk,
603
        opb_fifo_flg => opb_irq_flg(i),
604
        opb_ier      => opb_ier(i),
605
        opb_isr      => opb_isr(i),
606
        opb_isr_clr  => opb_isr_clr(i));
607
  end generate irq_gen;
608
 
609
  -- assert irq if one Interupt Status bit set
610
  opb_irq <= '1' when (conv_integer(opb_isr) /= 0 and opb_dgie = '1') else
611
             '0';
612
 
613
 
614 23 dkoethe
  -----------------------------------------------------------------------------
615 2 dkoethe
 
616 23 dkoethe
  -- clear start_value at power up and soft_reset
617
  crc_en  <= opb_ctl_reg(C_OPB_CTL_REG_CRC_EN);
618
  crc_clr <= opb_ctl_reg(C_OPB_CTL_REG_CRC_CLR) or rst;
619
 
620
  crc_gen : if (C_CRC_EN) generate
621
    crc_core_1 : crc_core
622
      generic map (
623
        C_SR_WIDTH => C_SR_WIDTH)
624
      port map (
625
        rst              => rst,
626
        opb_clk          => opb_clk,
627
        crc_en           => crc_en,
628
        crc_clr          => crc_clr,
629
        opb_m_last_block => opb_m_last_block,
630
        fifo_rx_en       => fifo_rx_en,
631
        fifo_rx_data     => fifo_rx_data,
632
        opb_rx_crc_value => opb_rx_crc_value,
633
        fifo_tx_en       => fifo_tx_en,
634
        fifo_tx_data     => fifo_tx_data,
635
        tx_crc_insert    => tx_crc_insert,
636
        opb_tx_crc_value => opb_tx_crc_value);
637
  end generate crc_gen;
638
 
639
 
640 2 dkoethe
end behavior;

powered by: WebSVN 2.1.0

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