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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_vector_rx.vhd] - Blame information for rev 255

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 240 jshamlet
-- Copyright (c)2020 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Entity: o8_vector_rx
25
-- Description: Receives a 6-bit vector command and 16-bit argument from the
26
--               vector_tx entity. Issues interrupt to the CPU on receipt of
27
--               three bytes.
28
--
29
-- Register Map:
30
-- Offset  Bitfield Description                        Read/Write
31
--   0x0   --AAAAAA Vector Select
32
--   0x1   AAAAAAAA Vector Argument LB
33
--   0x2   AAAAAAAA Vector Argument UB
34
--
35
-- Revision History
36
-- Author          Date     Change
37
------------------ -------- ---------------------------------------------------
38
-- Seth Henry      04/15/20 Created from o8_epoch_timer due to requirement
39
--                           change.
40
-- Seth Henry      04/16/20 Modified to make use of Open8 bus record
41
-- Seth Henry      05/06/20 Modified to eliminate request line and detect idle
42
--                           conditions instead
43 246 jshamlet
-- Seth Henry      05/23/20 Added the parallel interface
44 240 jshamlet
 
45
library ieee;
46
  use ieee.std_logic_1164.all;
47
  use ieee.std_logic_unsigned.all;
48
  use ieee.std_logic_arith.all;
49
  use ieee.std_logic_misc.all;
50
 
51
library work;
52
  use work.Open8_pkg.all;
53
 
54
entity o8_vector_rx is
55
generic(
56
  Bit_Rate                   : real;
57
  Enable_Parity              : boolean;
58
  Parity_Odd_Even_n          : std_logic;
59
  Clock_Frequency            : real;
60
  Address                    : ADDRESS_TYPE
61
);
62
port(
63
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
64
  Rd_Data                    : out DATA_TYPE;
65
  Interrupt                  : out std_logic;
66 246 jshamlet
  -- Parallel Interface
67
  Vec_Req                    : in  std_logic;
68
  Vec_Index                  : in  std_logic_vector(5 downto 0);
69
  Vec_Data                   : in  std_logic_vector(15 downto 0);
70
  -- Serial Interface
71
  Vec_Rx                     : in  std_logic
72 240 jshamlet
);
73
end entity;
74
 
75
architecture behave of o8_vector_rx is
76
 
77
  alias Clock                is Open8_Bus.Clock;
78
  alias Reset                is Open8_Bus.Reset;
79
 
80
  constant User_Addr         : std_logic_vector(15 downto 2) :=
81
                                Address(15 downto 2);
82
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
83
  signal Addr_Match          : std_logic := '0';
84
 
85 244 jshamlet
  alias  Reg_Sel_d           is Open8_Bus.Address(1 downto 0);
86
  signal Reg_Sel_q           : std_logic_vector(1 downto 0) := "00";
87
  signal Rd_En_d             : std_logic := '0';
88
  signal Rd_En_q             : std_logic := '0';
89 240 jshamlet
 
90
  constant BAUD_RATE_DIV     : integer := integer(Clock_Frequency / Bit_Rate);
91
 
92
  -- Period of each bit in sub-clocks (subtract one to account for zero)
93
  constant Full_Per_i        : integer := BAUD_RATE_DIV - 1;
94
  constant Baud_Bits         : integer := ceil_log2(Full_Per_i);
95
 
96
  constant FULL_PERIOD       : std_logic_vector(Baud_Bits - 1 downto 0) :=
97
                                 conv_std_logic_vector(Full_Per_i, Baud_Bits);
98
 
99
  signal Rx_Baud_Cntr        : std_logic_vector(Baud_Bits - 1 downto 0) :=
100
                                 (others => '0');
101
  signal Rx_Baud_Tick        : std_logic;
102
 
103 246 jshamlet
  signal Vec_Rx_SR           : std_logic_vector(2 downto 0);
104
  alias  Vec_Rx_MS            is Vec_Rx_SR(2);
105 240 jshamlet
  signal Rx_Idle_Cntr        : std_logic_vector(3 downto 0);
106
  signal RX_Idle             : std_logic;
107 246 jshamlet
  signal Rx_Data             : DATA_TYPE := x"00";
108
  signal Rx_Valid            : std_logic;
109 240 jshamlet
 
110
  type VECTOR_RX_STATES is ( GET_VECTOR_CMD, GET_VECTOR_ARG_LB, GET_VECTOR_ARG_UB,
111
                             SEND_INTERRUPT );
112
  signal Vector_State        : VECTOR_RX_STATES := GET_VECTOR_CMD;
113
 
114 246 jshamlet
  signal Vec_Req_SR           : std_logic_vector(2 downto 0);
115 247 jshamlet
  alias  Vec_Req_MS           is Vec_Req_SR(2);
116 240 jshamlet
 
117 246 jshamlet
  signal Vector_Index        : DATA_TYPE := x"00";
118
  signal Vector_Data         : ADDRESS_TYPE := x"0000";
119
  alias  Vector_Data_LB      is Vector_Data(7 downto 0);
120
  alias  Vector_Data_UB      is Vector_Data(15 downto 8);
121 240 jshamlet
 
122
begin
123
 
124
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
125 244 jshamlet
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
126 240 jshamlet
 
127
  io_reg: process( Clock, Reset )
128
  begin
129
    if( Reset = Reset_Level )then
130 246 jshamlet
      Reg_Sel_q              <= (others => '0');
131
      Rd_En_q                <= '0';
132
      Rd_Data                <= OPEN8_NULLBUS;
133 240 jshamlet
    elsif( rising_edge( Clock ) )then
134 246 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
135 244 jshamlet
 
136 246 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
137
      Rd_En_q                <= Rd_En_d;
138 244 jshamlet
      if( Rd_En_q = '1'  )then
139
        case( Reg_Sel_q )is
140 240 jshamlet
          when "00" =>
141 246 jshamlet
            Rd_Data          <= Vector_Index;
142 240 jshamlet
          when "01" =>
143 246 jshamlet
            Rd_Data          <= Vector_Data_LB;
144 240 jshamlet
          when "10" =>
145 246 jshamlet
            Rd_Data          <= Vector_Data_UB;
146 240 jshamlet
          when others =>
147
            null;
148
      end case;
149
      end if;
150
    end if;
151
  end process;
152
 
153
  RX_Idle_proc: process( Clock, Reset )
154
  begin
155
    if( Reset = Reset_Level )then
156 246 jshamlet
      Rx_Baud_Cntr           <= (others => '0');
157
      Rx_Baud_Tick           <= '0';
158
      Vec_Rx_SR              <= (others => '1');
159
      Rx_Idle_Cntr           <= (others => '0');
160
      Rx_Idle                <= '0';
161 240 jshamlet
    elsif( rising_edge(Clock) )then
162 246 jshamlet
      Rx_Baud_Cntr           <= Rx_Baud_Cntr - 1;
163
      Rx_Baud_Tick           <= '0';
164 240 jshamlet
      if( Rx_Baud_Cntr = 0 )then
165 246 jshamlet
        Rx_Baud_Cntr         <= FULL_PERIOD;
166
        Rx_Baud_Tick         <= '1';
167 240 jshamlet
      end if;
168
 
169 246 jshamlet
      Vec_Rx_SR              <= Vec_Rx_SR(1 downto 0) & Vec_Rx;
170
      Rx_Idle_Cntr           <= Rx_Idle_Cntr - Rx_Baud_Tick;
171
      if( Vec_Rx_MS = '0' )then
172
        Rx_Idle_Cntr         <= (others => '1');
173 240 jshamlet
      elsif( Rx_Idle_Cntr = 0 )then
174 246 jshamlet
        Rx_Idle_Cntr         <= (others => '0');
175 240 jshamlet
      end if;
176 246 jshamlet
 
177
      Rx_Idle                <= nor_reduce(Rx_Idle_Cntr);
178 240 jshamlet
    end if;
179
  end process;
180
 
181
  U_RX : entity work.async_ser_rx
182
  generic map(
183
    Reset_Level              => Reset_Level,
184
    Enable_Parity            => Enable_Parity,
185
    Parity_Odd_Even_n        => Parity_Odd_Even_n,
186
    Clock_Divider            => BAUD_RATE_DIV
187
  )
188
  port map(
189
    Clock                    => Clock,
190
    Reset                    => Reset,
191
    --
192 246 jshamlet
    RX_In                    => Vec_Rx,
193 240 jshamlet
    --
194
    Rx_Data                  => RX_Data,
195
    Rx_Valid                 => RX_Valid,
196
    Rx_PErr                  => open
197
  );
198
 
199
  Vector_RX_proc: process( Clock, Reset )
200
  begin
201
    if( Reset = Reset_Level )then
202 246 jshamlet
      Vec_Req_SR             <= (others => '0');
203 240 jshamlet
      Vector_State           <= GET_VECTOR_CMD;
204 246 jshamlet
      Vector_Index           <= x"00";
205
      Vector_Data            <= x"0000";
206 240 jshamlet
      Interrupt              <= '0';
207
    elsif( rising_edge(Clock) )then
208 246 jshamlet
      Vec_Req_SR             <= Vec_Req_SR(1 downto 0) & Vec_Req;
209
 
210 240 jshamlet
      Interrupt              <= '0';
211 246 jshamlet
 
212
      if( Vec_Req_MS = '1' )then
213
        Vector_Index         <= "00" & Vec_Index;
214
        Vector_Data          <= Vec_Data;
215
        Interrupt            <= '1';
216
      end if;
217
 
218 240 jshamlet
      case( Vector_State )is
219
        when GET_VECTOR_CMD =>
220
          if( Rx_Valid = '1' )then
221 246 jshamlet
            Vector_Index     <= "00" & Rx_Data(5 downto 0);
222 240 jshamlet
            Vector_State     <= GET_VECTOR_ARG_LB;
223
          end if;
224
 
225
        when GET_VECTOR_ARG_LB =>
226
          if( Rx_Valid = '1' )then
227 246 jshamlet
            Vector_Data_LB   <= Rx_Data;
228 240 jshamlet
            Vector_State     <= GET_VECTOR_ARG_UB;
229
          end if;
230
 
231
        when GET_VECTOR_ARG_UB =>
232
          if( Rx_Valid = '1' )then
233 246 jshamlet
            Vector_Data_UB   <= Rx_Data;
234 240 jshamlet
            Vector_State     <= SEND_INTERRUPT;
235
          end if;
236
 
237
        when SEND_INTERRUPT =>
238
          Interrupt          <= '1';
239
          Vector_State       <= GET_VECTOR_CMD;
240
        when others => null;
241
      end case;
242
 
243
      if( Rx_Idle = '1' )then
244
        Vector_State         <= GET_VECTOR_CMD;
245
      end if;
246
 
247
    end if;
248
  end process;
249
 
250
end architecture;

powered by: WebSVN 2.1.0

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