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

Subversion Repositories uart_fpga_slow_control_migrated

[/] [uart_fpga_slow_control/] [trunk/] [code/] [ab_register_rx_handler.vhd] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 aborga
-------------------------------------------------------------------------------
2
--                                                                           --
3
--                                                                           --
4
--                                                                           --
5
--                                                                           --
6
-------------------------------------------------------------------------------
7
--
8
-- unit name: register_rx_handler
9
--
10 15 aborga
-- author: Mauro Predonzani (predmauro@libero.it)
11 3 aborga
--         Andrea Borga     (andrea.borga@nikhef.nl)
12
--
13
-- date: 20/02/2009    $: created
14
--
15
-- version: $Rev 1.0      $:
16
--
17
-- description: 
18
--
19
--      the module acquires byte
20
--      and decodes the data as follows:
21
--
22
--                      -----------------------------------------------------
23
--                      |        ADDRESS               |        DATA    |
24
--                      -----------------------------------------------------
25
--                      | 15-08 | 07-00 | 31-24 | 23-16 | 15-08 |07-00 |        
26
--                      | reghnd_full_add | reghnd_full_data  |
27
--                      -----------------------------------------------------
28
--          BYTE NUM    | BYTEO | BYTE1 | BYTE2 | BYTE3 | BYTE4 | BYTE5 |
29
--                      -----------------------------------------------------
30
--
31
--      number of register cells: 2^16
32
--      data word lenght: 32 bits
33
--
34
--
35 19 aborga
-- dependencies:        uart_wrapper
36 3 aborga
--                                                              uart_lbus_slave
37
--                                                              gh_uart_16550
38
--
39
-- references: <reference one>
40
-- <reference two> ...
41
--
42
-- modified by: $Author:: $:
43
--               04-08-2011 Andrea Borga
44
--                   missing s_tick reset value
45
--               18-08-2011 Andrea Borga
46
--                   removed unused vraious v_registers
47
--
48
-------------------------------------------------------------------------------
49
-- last changes: <date> <initials> <log>
50
-- <extended description>
51
-------------------------------------------------------------------------------
52
-- TODO:
53
--
54
--
55
-- 
56
--
57
-------------------------------------------------------------------------------
58
 
59
--=============================================================================
60
-- Libraries
61
--=============================================================================
62
 
63
library ieee ;
64
use ieee.std_logic_1164.all ;
65
use ieee.std_logic_arith.all;
66
use ieee.std_logic_unsigned.all;
67
 
68
--=============================================================================
69
-- Entity declaration for ada_register_handler
70
--=============================================================================
71
 
72
entity register_rx_handler is
73
  port(
74
    reghnd_clk          : in std_logic;         -- system clock
75
    reghnd_rst          : in std_logic;         -- system reset
76
    reghnd_data_in      : in std_logic_vector(7 downto 0);                       -- 8 bits fragments 
77
    reghnd_data_cs_rd   : in std_logic;   -- cs strobe of gh16550 during a read process
78
    reghnd_data_wr_rd   : in std_logic;   -- wr state of gh16550 during a read process
79
    reghnd_rd_rdy       : out std_logic;        -- Read data ready
80
    reghnd_full_add     : out std_logic_vector(15 downto 0);             -- 16 bits RAM address
81
    reghnd_full_data    : out std_logic_vector(31 downto 0);     -- 32 bits RAM data
82
    reghnd_full_cs      : in std_logic          -- strobe data/address acquired (1 acquired - 0 not acquired)
83
    );
84
end entity;
85
 
86
--=============================================================================
87
-- architecture declaration
88
--=============================================================================
89
 
90
architecture a of register_rx_handler is
91
 
92
  -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93
  -- Components declaration 
94
  -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95
 
96
 
97
  --
98
  -- Internal signal declaration 
99
  --
100
 
101
  signal s_rst                  : std_logic;                    -- global reset
102
  signal s_clk                  : std_logic;                    -- uart to parallel interface clock
103
 
104
  signal s_read_mem             : std_logic;                     -- read data from memory
105
 
106
  signal s_write_mem            : std_logic;                     -- write data into memory
107
  signal v_wr_add               : std_logic_vector(15 downto 0); -- full write ADDRESS
108
  signal v_wr_data              : std_logic_vector(31 downto 0); -- full write DATA
109
 
110
  signal s_tick                                                                 : std_logic;
111
 
112
  --
113
  -- State Machine states 
114
  --
115
 
116
  type t_reg_decoder is (IDLE, BYTE0, BYTE1, BYTE2, BYTE3, BYTE4, BYTE5, WRITE_MEM);
117
  signal s_reg_decoder  : t_reg_decoder;
118
 
119
--=============================================================================
120
-- architecture begin
121
--=============================================================================
122
 
123
begin
124
 
125
  s_rst                 <= reghnd_rst;
126
  s_clk                 <= reghnd_clk;
127
        reghnd_rd_rdy         <= s_write_mem;
128
 
129
p_register_decoder : process(s_rst, s_clk)
130
begin
131
  if s_rst = '1' then   -- reset
132
      s_write_mem       <= '0';
133
      reghnd_full_add           <= (others => '0');
134
      reghnd_full_data  <= (others => '0');
135
      v_wr_add          <= (others => '0');
136
      v_wr_data         <= (others => '0');
137
      s_tick <= '0';
138
      s_reg_decoder <= IDLE;
139
    elsif Rising_edge(s_clk) then
140
      case s_reg_decoder is
141
        when IDLE =>                            -- IDLE state
142
          s_write_mem           <= '0';
143
          reghnd_full_add               <= (others => '0');
144
          reghnd_full_data  <= (others => '0');
145
          v_wr_add          <= (others => '0');
146
          v_wr_data         <= (others => '0');
147
          if reghnd_data_cs_rd  = '1' and reghnd_data_wr_rd = '0' then  -- check if BYTE0 is ready
148
            s_reg_decoder <= BYTE0;
149
          else
150
            s_reg_decoder <= IDLE;
151
            s_tick <= '0';
152
          end if;
153
        when BYTE0 =>                                       -- decode byte 0 ADDRESS upper
154
          s_write_mem                                           <= '0';
155
          if s_tick = '0' then   -- only first time in this cycle acq the byte
156
            v_wr_add (15 downto 8)  <= reghnd_data_in;
157
            s_tick <= '1';
158
          elsif reghnd_data_cs_rd  = '1' and reghnd_data_wr_rd = '0' then        -- check if BYTE1 is ready
159
            s_reg_decoder <= BYTE1;
160
            s_tick <= '0';
161
          else
162
            s_reg_decoder <= BYTE0;
163
            s_tick <= '1';
164
          end if;
165
        when BYTE1 =>                                     -- decode byte 1 ADDRESS lower
166
          s_write_mem           <= '0';
167
          if s_tick = '0' then           -- only first time in this cycle acq the byte
168
            v_wr_add (7 downto 0)  <= reghnd_data_in;
169
            s_tick <= '1';
170
          elsif reghnd_data_cs_rd  = '1' and reghnd_data_wr_rd = '0' then        -- check if BYTE2 is ready
171
            s_reg_decoder <= BYTE2;
172
            s_tick <= '0';
173
          else
174
            s_reg_decoder <= BYTE1;
175
            s_tick <= '1';
176
          end if;
177
        when BYTE2  =>                                          -- decode byte 2 = DATA1
178
          s_write_mem                                           <= '0';
179
          if s_tick = '0' then           -- only first time in this cycle acq the byte
180
            v_wr_data (31 downto 24)  <= reghnd_data_in;
181
            s_tick <= '1';
182
          elsif reghnd_data_cs_rd  = '1' and reghnd_data_wr_rd = '0' then        -- check if BYTE3 is ready
183
            s_reg_decoder <= BYTE3;
184
            s_tick <= '0';
185
          else
186
            s_reg_decoder <= BYTE2;
187
            s_tick <= '1';
188
          end if;
189
        when BYTE3 =>                                           -- decode byte 3 = DATA2 
190
          s_write_mem                                           <= '0';
191
          if s_tick = '0' then           -- only first time in this cycle acq the byte
192
            v_wr_data (23 downto 16)  <= reghnd_data_in;
193
            s_tick <= '1';
194
          elsif reghnd_data_cs_rd  = '1' and reghnd_data_wr_rd = '0' then        -- check if BYTE4 is ready
195
            s_reg_decoder <= BYTE4;
196
            s_tick <= '0';
197
          else
198
            s_reg_decoder <= BYTE3;
199
            s_tick <= '1';
200
          end if;
201
        when BYTE4 =>           -- decode byte 4 = DATA3
202
          s_write_mem                                   <= '0';
203
          if s_tick = '0' then   -- only first time in this cycle acq the byte
204
            v_wr_data (15 downto 8)  <= reghnd_data_in;
205
            s_tick <= '1';
206
          elsif reghnd_data_cs_rd  = '1' and reghnd_data_wr_rd = '0' then        -- check if BYTE5 is ready
207
            s_reg_decoder <= BYTE5;
208
            s_tick <= '0';
209
          else
210
            s_reg_decoder <= BYTE4;
211
            s_tick <= '1';
212
          end if;
213
        when BYTE5 =>                                           -- decode byte 5 = DATA4
214
          s_write_mem                                           <= '0';
215
          if s_tick = '0' then   -- only first time in this cycle acq the byte
216
            v_wr_data (7 downto 0)  <= reghnd_data_in;
217
            s_tick <= '1';
218
          else          -- add and data are ready => ready to use
219
            s_reg_decoder <= WRITE_MEM;
220
            s_tick <= '0';
221
            reghnd_full_add          <= v_wr_add;               -- address latch to the ouput
222
            reghnd_full_data         <= v_wr_data;      -- data latch to the output
223
          end if;
224
        when WRITE_MEM =>                                       -- write data into RAM
225
          s_write_mem           <= '1';                         -- data and address stable and ready
226
          if reghnd_full_cs = '1' then                          -- check if data is transfer to RAM or not
227
            s_reg_decoder <= IDLE;
228
          else
229
            s_reg_decoder <= WRITE_MEM;
230
          end if;
231
        when others =>
232
          s_reg_decoder <= IDLE;
233
      end case;
234
    end if;
235
end process p_register_decoder;
236
 
237
 
238
end a;
239
 
240
--=============================================================================
241
-- architecture end
242
--=============================================================================

powered by: WebSVN 2.1.0

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