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

Subversion Repositories uart_plb

[/] [uart_plb/] [trunk/] [pcores/] [uart_plb_v1_00_a/] [hdl/] [vhdl/] [user_logic.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 gavinux
------------------------------------------------------------------------------
2
-- user_logic.vhd - entity/architecture pair
3
------------------------------------------------------------------------------
4
--
5
-- ***************************************************************************
6
-- ** Copyright (c) 1995-2010 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.
29
-- Date:              Fri Jun 03 17:26:27 2011 (by Create and Import Peripheral Wizard)
30
-- VHDL Standard:     VHDL'93
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
-- DO NOT EDIT BELOW THIS LINE --------------------
52
library ieee;
53
use ieee.std_logic_1164.all;
54
use ieee.std_logic_arith.all;
55
use ieee.std_logic_unsigned.all;
56
use work.uart_components.uart;
57
 
58
library proc_common_v3_00_a;
59
use proc_common_v3_00_a.proc_common_pkg.all;
60
 
61
-- DO NOT EDIT ABOVE THIS LINE --------------------
62
 
63
--USER libraries added here
64
 
65
------------------------------------------------------------------------------
66
-- Entity section
67
------------------------------------------------------------------------------
68
-- Definition of Generics:
69
--   C_SLV_DWIDTH                 -- Slave interface data bus width
70
--   C_NUM_REG                    -- Number of software accessible registers
71
--   C_NUM_INTR                   -- Number of interrupt event
72
--
73
-- Definition of Ports:
74
--   Bus2IP_Clk                   -- Bus to IP clock
75
--   Bus2IP_Reset                 -- Bus to IP reset
76
--   Bus2IP_Data                  -- Bus to IP data bus
77
--   Bus2IP_BE                    -- Bus to IP byte enables
78
--   Bus2IP_RdCE                  -- Bus to IP read chip enable
79
--   Bus2IP_WrCE                  -- Bus to IP write chip enable
80
--   IP2Bus_Data                  -- IP to Bus data bus
81
--   IP2Bus_RdAck                 -- IP to Bus read transfer acknowledgement
82
--   IP2Bus_WrAck                 -- IP to Bus write transfer acknowledgement
83
--   IP2Bus_Error                 -- IP to Bus error response
84
--   IP2Bus_IntrEvent             -- IP to Bus interrupt event
85
------------------------------------------------------------------------------
86
 
87
entity user_logic is
88
  generic
89
  (
90
    -- ADD USER GENERICS BELOW THIS LINE ---------------
91
    --USER generics added here
92
    -- ADD USER GENERICS ABOVE THIS LINE ---------------
93
 
94
    -- DO NOT EDIT BELOW THIS LINE ---------------------
95
    -- Bus protocol parameters, do not add to or delete
96
    C_SLV_DWIDTH                   : integer              := 32;
97
    C_NUM_REG                      : integer              := 8;
98
    C_NUM_INTR                     : integer              := 1
99
    -- DO NOT EDIT ABOVE THIS LINE ---------------------
100
  );
101
  port
102
  (
103
    -- ADD USER PORTS BELOW THIS LINE ------------------
104
    --USER ports added here
105
    tx_sout                        : out std_logic;
106
    rx_sin                         : in  std_logic;
107
    -- ADD USER PORTS ABOVE THIS LINE ------------------
108
 
109
    -- DO NOT EDIT BELOW THIS LINE ---------------------
110
    -- Bus protocol ports, do not add to or delete
111
    Bus2IP_Clk                     : in  std_logic;
112
    Bus2IP_Reset                   : in  std_logic;
113
    Bus2IP_Data                    : in  std_logic_vector(0 to C_SLV_DWIDTH-1);
114
    Bus2IP_BE                      : in  std_logic_vector(0 to C_SLV_DWIDTH/8-1);
115
    Bus2IP_RdCE                    : in  std_logic_vector(0 to C_NUM_REG-1);
116
    Bus2IP_WrCE                    : in  std_logic_vector(0 to C_NUM_REG-1);
117
    IP2Bus_Data                    : out std_logic_vector(0 to C_SLV_DWIDTH-1);
118
    IP2Bus_RdAck                   : out std_logic;
119
    IP2Bus_WrAck                   : out std_logic;
120
    IP2Bus_Error                   : out std_logic;
121
    IP2Bus_IntrEvent               : out std_logic_vector(0 to C_NUM_INTR-1)
122
    -- DO NOT EDIT ABOVE THIS LINE ---------------------
123
  );
124
 
125
  attribute SIGIS : string;
126
  attribute SIGIS of Bus2IP_Clk    : signal is "CLK";
127
  attribute SIGIS of Bus2IP_Reset  : signal is "RST";
128
 
129
end entity user_logic;
130
 
131
------------------------------------------------------------------------------
132
-- Architecture section
133
------------------------------------------------------------------------------
134
 
135
architecture IMP of user_logic is
136
 
137
  --USER signal declarations added here, as needed for user logic
138
 
139
  ------------------------------------------
140
  -- Signals for user logic slave model s/w accessible register example
141
  ------------------------------------------
142
  signal slv_rxd                        : std_logic_vector(0 to C_SLV_DWIDTH-1);
143
  signal slv_txd                        : std_logic_vector(0 to C_SLV_DWIDTH-1);
144
  signal slv_ctrl                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
145
  signal slv_status                     : std_logic_vector(0 to C_SLV_DWIDTH-1);
146
  signal slv_dlw                        : std_logic_vector(0 to C_SLV_DWIDTH-1) := X"00000019"; -- 115200Hz @50MHz
147
  signal slv_reg5                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
148
  signal slv_reg6                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
149
  signal slv_reg7                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
150
  signal slv_reg_write_sel              : std_logic_vector(0 to 7);
151
  signal slv_reg_read_sel               : std_logic_vector(0 to 7);
152
  signal slv_ip2bus_data                : std_logic_vector(0 to C_SLV_DWIDTH-1);
153
  signal slv_read_ack                   : std_logic;
154
  signal slv_write_ack                  : std_logic;
155
 
156
begin
157
 
158
  --USER logic implementation added here
159
    inst_uart_plb_ip : uart
160
    generic map(DATA_BITS => 8)
161
    Port map(
162
        rst                  => Bus2IP_Reset,
163
        clk                  => Bus2IP_Clk,
164
        dlw                  => slv_dlw(16 to 31),
165
        --
166
        tx_wr                => Bus2IP_WrCE(1),        -- pulse signal
167
        tx_fifo_reset        => slv_ctrl(31),       -- pulse
168
        tx_din               => Bus2IP_Data(24 to 31),
169
        tx_fifo_full         => slv_status(15),        -- level signal
170
        tx_fifo_almost_full  => slv_status(14),
171
        tx_fifo_empty        => slv_status(13),        -- level signal
172
        tx_fifo_almost_empty => slv_status(12),        -- level signal
173
        tx_xmt_empty         => slv_status(11),        -- level signal, transmit shift register empty
174
        --
175
        rx_rd                => slv_reg_read_sel(0),   -- pulse signal
176
        rx_fifo_reset        => slv_ctrl(30),       -- pulse
177
        rx_dout              => slv_rxd(24 to 31),
178
        rx_fifo_full         => slv_status(7),        -- level signal
179
        rx_fifo_almost_full  => slv_status(6),
180
        rx_fifo_empty        => slv_status(5),        -- level signal
181
        rx_fifo_almost_empty => slv_status(4),
182
        rx_timeout           => slv_status(3),        -- pulse signal
183
        --
184
        tx_sout              => tx_sout,
185
        rx_sin               => rx_sin
186
    );
187
 
188
    IP2Bus_IntrEvent(0) <= slv_ctrl(27) and
189
                        ( (slv_ctrl(15) or slv_status(15)) or
190
                          (slv_ctrl(14) or slv_status(14)) or
191
                          (slv_ctrl(13) or slv_status(13)) or
192
                          (slv_ctrl(12) or slv_status(12)) or
193
                          (slv_ctrl(11) or slv_status(11)) or
194
                          (slv_ctrl(7)  or slv_status(7))  or
195
                          (slv_ctrl(6)  or slv_status(6))  or
196
                          (slv_ctrl(5)  or slv_status(5))  or
197
                          (slv_ctrl(4)  or slv_status(4))  or
198
                          (slv_ctrl(3)  or slv_status(3))
199
                        );
200
    slv_status(27) <= slv_ctrl(27);
201
    slv_status(30) <= slv_ctrl(30);
202
    slv_status(31) <= slv_ctrl(31);
203
 
204
  ------------------------------------------
205
  -- Example code to read/write user logic slave model s/w accessible registers
206
  -- 
207
  -- Note:
208
  -- The example code presented here is to show you one way of reading/writing
209
  -- software accessible registers implemented in the user logic slave model.
210
  -- Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to correspond
211
  -- to one software accessible register by the top level template. For example,
212
  -- if you have four 32 bit software accessible registers in the user logic,
213
  -- you are basically operating on the following memory mapped registers:
214
  -- 
215
  --    Bus2IP_WrCE/Bus2IP_RdCE   Memory Mapped Register
216
  --                     "1000"   C_BASEADDR + 0x0
217
  --                     "0100"   C_BASEADDR + 0x4
218
  --                     "0010"   C_BASEADDR + 0x8
219
  --                     "0001"   C_BASEADDR + 0xC
220
  -- 
221
  ------------------------------------------
222
  slv_reg_write_sel <= Bus2IP_WrCE(0 to 7);
223
  slv_reg_read_sel  <= Bus2IP_RdCE(0 to 7);
224
  slv_write_ack     <= Bus2IP_WrCE(0) or Bus2IP_WrCE(1) or Bus2IP_WrCE(2) or Bus2IP_WrCE(3) or Bus2IP_WrCE(4) or Bus2IP_WrCE(5) or Bus2IP_WrCE(6) or Bus2IP_WrCE(7);
225
  slv_read_ack      <= Bus2IP_RdCE(0) or Bus2IP_RdCE(1) or Bus2IP_RdCE(2) or Bus2IP_RdCE(3) or Bus2IP_RdCE(4) or Bus2IP_RdCE(5) or Bus2IP_RdCE(6) or Bus2IP_RdCE(7);
226
 
227
  -- implement slave model software accessible register(s)
228
  SLAVE_REG_WRITE_PROC : process( Bus2IP_Clk ) is
229
  begin
230
 
231
    if Bus2IP_Clk'event and Bus2IP_Clk = '1' then
232
      if Bus2IP_Reset = '1' then
233
        slv_rxd(0 to 23)    <= (others => '0');
234
        slv_txd    <= (others => '0');
235
        slv_ctrl   <= (others => '0');
236
--        slv_status <= (others => '0');
237
        slv_dlw    <= X"0000001B";
238
 
239
        slv_reg5 <= (others => '0');
240
        slv_reg6 <= (others => '0');
241
        slv_reg7 <= (others => '0');
242
      else
243
        case slv_reg_write_sel is
244
          when "10000000" =>
245
            for byte_index in 0 to (C_SLV_DWIDTH/8)-2 loop
246
              if ( Bus2IP_BE(byte_index) = '1' ) then
247
                slv_rxd(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
248
              end if;
249
            end loop;
250
          when "01000000" =>
251
            for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
252
              if ( Bus2IP_BE(byte_index) = '1' ) then
253
                slv_txd(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
254
              end if;
255
            end loop;
256
          when "00100000" =>
257
            for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
258
              if ( Bus2IP_BE(byte_index) = '1' ) then
259
                slv_ctrl(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
260
              end if;
261
            end loop;
262
          when "00010000" =>
263
--            for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
264
--              if ( Bus2IP_BE(byte_index) = '1' ) then
265
--                slv_reg3(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
266
--              end if;
267
 
268
--            end loop;
269
          when "00001000" =>
270
            for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
271
              if ( Bus2IP_BE(byte_index) = '1' ) then
272
                slv_dlw(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
273
              end if;
274
            end loop;
275
          when "00000100" =>
276
            for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
277
              if ( Bus2IP_BE(byte_index) = '1' ) then
278
                slv_reg5(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
279
              end if;
280
            end loop;
281
          when "00000010" =>
282
            for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
283
              if ( Bus2IP_BE(byte_index) = '1' ) then
284
                slv_reg6(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
285
              end if;
286
            end loop;
287
          when "00000001" =>
288
            for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
289
              if ( Bus2IP_BE(byte_index) = '1' ) then
290
                slv_reg7(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
291
              end if;
292
            end loop;
293
          when others => null;
294
        end case;
295
      end if;
296
    end if;
297
 
298
  end process SLAVE_REG_WRITE_PROC;
299
 
300
  -- implement slave model software accessible register(s) read mux
301
  SLAVE_REG_READ_PROC : process( slv_reg_read_sel, slv_rxd, slv_txd, slv_ctrl, slv_status, slv_dlw, slv_reg5, slv_reg6, slv_reg7 ) is
302
  begin
303
 
304
    case slv_reg_read_sel is
305
      when "10000000" => slv_ip2bus_data <= slv_rxd;
306
      when "01000000" => slv_ip2bus_data <= slv_txd;
307
      when "00100000" => slv_ip2bus_data <= slv_ctrl;
308
      when "00010000" => slv_ip2bus_data <= slv_status;
309
      when "00001000" => slv_ip2bus_data <= slv_dlw;
310
      when "00000100" => slv_ip2bus_data <= slv_reg5;
311
      when "00000010" => slv_ip2bus_data <= slv_reg6;
312
      when "00000001" => slv_ip2bus_data <= slv_reg7;
313
      when others => slv_ip2bus_data <= (others => '0');
314
    end case;
315
 
316
  end process SLAVE_REG_READ_PROC;
317
 
318
  ------------------------------------------
319
  -- Example code to drive IP to Bus signals
320
  ------------------------------------------
321
  IP2Bus_Data  <= slv_ip2bus_data when slv_read_ack = '1' else
322
                  (others => '0');
323
 
324
  IP2Bus_WrAck <= slv_write_ack;
325
  IP2Bus_RdAck <= slv_read_ack;
326
  IP2Bus_Error <= '0';
327
 
328
end IMP;

powered by: WebSVN 2.1.0

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