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 241

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
 
44
library ieee;
45
  use ieee.std_logic_1164.all;
46
  use ieee.std_logic_unsigned.all;
47
  use ieee.std_logic_arith.all;
48
  use ieee.std_logic_misc.all;
49
 
50
library work;
51
  use work.Open8_pkg.all;
52
 
53
entity o8_vector_rx is
54
generic(
55
  Bit_Rate                   : real;
56
  Enable_Parity              : boolean;
57
  Parity_Odd_Even_n          : std_logic;
58
  Clock_Frequency            : real;
59
  Address                    : ADDRESS_TYPE
60
);
61
port(
62
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
63
  Rd_Data                    : out DATA_TYPE;
64
  Interrupt                  : out std_logic;
65
  --
66
  Rx_In                      : in  std_logic
67
);
68
end entity;
69
 
70
architecture behave of o8_vector_rx is
71
 
72
  alias Clock                is Open8_Bus.Clock;
73
  alias Reset                is Open8_Bus.Reset;
74
 
75
  constant User_Addr         : std_logic_vector(15 downto 2) :=
76
                                Address(15 downto 2);
77
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
78
  signal Addr_Match          : std_logic := '0';
79
 
80
  alias  Reg_Addr            is Open8_Bus.Address(1 downto 0);
81
  signal Reg_Sel             : std_logic_vector(1 downto 0) := "00";
82
  signal Rd_En               : std_logic := '0';
83
 
84
  constant BAUD_RATE_DIV     : integer := integer(Clock_Frequency / Bit_Rate);
85
 
86
  -- Period of each bit in sub-clocks (subtract one to account for zero)
87
  constant Full_Per_i        : integer := BAUD_RATE_DIV - 1;
88
  constant Baud_Bits         : integer := ceil_log2(Full_Per_i);
89
 
90
  constant FULL_PERIOD       : std_logic_vector(Baud_Bits - 1 downto 0) :=
91
                                 conv_std_logic_vector(Full_Per_i, Baud_Bits);
92
 
93
  signal Rx_Baud_Cntr        : std_logic_vector(Baud_Bits - 1 downto 0) :=
94
                                 (others => '0');
95
  signal Rx_Baud_Tick        : std_logic;
96
 
97
  signal Rx_In_SR            : std_logic_vector(2 downto 0);
98
  alias  Rx_In_MS            is Rx_In_SR(2);
99
  signal Rx_Idle_Cntr        : std_logic_vector(3 downto 0);
100
  signal RX_Idle             : std_logic;
101
 
102
  type VECTOR_RX_STATES is ( GET_VECTOR_CMD, GET_VECTOR_ARG_LB, GET_VECTOR_ARG_UB,
103
                             SEND_INTERRUPT );
104
  signal Vector_State        : VECTOR_RX_STATES := GET_VECTOR_CMD;
105
 
106
  signal Vector_Cmd          : DATA_TYPE := x"00";
107
  signal Vector_Arg_LB       : DATA_TYPE := x"00";
108
  signal Vector_Arg_UB       : DATA_TYPE := x"00";
109
 
110
  signal Rx_Data             : DATA_TYPE := x"00";
111
  signal Rx_Valid            : std_logic;
112
 
113
begin
114
 
115
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
116
 
117
  io_reg: process( Clock, Reset )
118
  begin
119
    if( Reset = Reset_Level )then
120
      Rd_En             <= '0';
121
      Reg_Sel           <= (others => '0');
122
      Rd_Data           <= OPEN8_NULLBUS;
123
    elsif( rising_edge( Clock ) )then
124
      Rd_Data           <= OPEN8_NULLBUS;
125
      Rd_En             <= Addr_Match and Open8_Bus.Rd_En;
126
      Reg_Sel           <= Reg_Addr;
127
      if( Rd_En = '1'  )then
128
        case( Reg_Sel )is
129
          when "00" =>
130
            Rd_Data     <= Vector_Cmd;
131
          when "01" =>
132
            Rd_Data     <= Vector_Arg_LB;
133
          when "10" =>
134
            Rd_Data     <= Vector_Arg_UB;
135
          when others =>
136
            null;
137
      end case;
138
      end if;
139
    end if;
140
  end process;
141
 
142
  RX_Idle_proc: process( Clock, Reset )
143
  begin
144
    if( Reset = Reset_Level )then
145
      Rx_Baud_Cntr     <= (others => '0');
146
      Rx_Baud_Tick     <= '0';
147
      Rx_In_SR         <= (others => '1');
148
      Rx_Idle_Cntr     <= (others => '0');
149
      Rx_Idle          <= '0';
150
    elsif( rising_edge(Clock) )then
151
      Rx_Baud_Cntr     <= Rx_Baud_Cntr - 1;
152
      Rx_Baud_Tick     <= '0';
153
      if( Rx_Baud_Cntr = 0 )then
154
        Rx_Baud_Cntr   <= FULL_PERIOD;
155
        Rx_Baud_Tick   <= '1';
156
      end if;
157
 
158
      Rx_In_SR         <= Rx_In_SR(1 downto 0) & Rx_In;
159
      Rx_Idle_Cntr     <= Rx_Idle_Cntr - Rx_Baud_Tick;
160
      if( Rx_In_MS = '0' )then
161
        Rx_Idle_Cntr   <= (others => '1');
162
      elsif( Rx_Idle_Cntr = 0 )then
163
        Rx_Idle_Cntr   <= (others => '0');
164
      end if;
165
 
166
      Rx_Idle          <= nor_reduce(Rx_Idle_Cntr);
167
    end if;
168
  end process;
169
 
170
  U_RX : entity work.async_ser_rx
171
  generic map(
172
    Reset_Level              => Reset_Level,
173
    Enable_Parity            => Enable_Parity,
174
    Parity_Odd_Even_n        => Parity_Odd_Even_n,
175
    Clock_Divider            => BAUD_RATE_DIV
176
  )
177
  port map(
178
    Clock                    => Clock,
179
    Reset                    => Reset,
180
    --
181
    Rx_In                    => RX_In,
182
    --
183
    Rx_Data                  => RX_Data,
184
    Rx_Valid                 => RX_Valid,
185
    Rx_PErr                  => open
186
  );
187
 
188
  Vector_RX_proc: process( Clock, Reset )
189
  begin
190
    if( Reset = Reset_Level )then
191
      Vector_State           <= GET_VECTOR_CMD;
192
      Vector_Cmd             <= x"00";
193
      Vector_Arg_LB          <= x"00";
194
      Vector_Arg_UB          <= x"00";
195
      Interrupt              <= '0';
196
    elsif( rising_edge(Clock) )then
197
      Interrupt              <= '0';
198
      case( Vector_State )is
199
        when GET_VECTOR_CMD =>
200
          if( Rx_Valid = '1' )then
201
            Vector_Cmd       <= Rx_Data;
202
            Vector_State     <= GET_VECTOR_ARG_LB;
203
          end if;
204
 
205
        when GET_VECTOR_ARG_LB =>
206
          if( Rx_Valid = '1' )then
207
            Vector_Arg_LB    <= Rx_Data;
208
            Vector_State     <= GET_VECTOR_ARG_UB;
209
          end if;
210
 
211
        when GET_VECTOR_ARG_UB =>
212
          if( Rx_Valid = '1' )then
213
            Vector_Arg_UB    <= Rx_Data;
214
            Vector_State     <= SEND_INTERRUPT;
215
          end if;
216
 
217
        when SEND_INTERRUPT =>
218
          Interrupt          <= '1';
219
          Vector_State       <= GET_VECTOR_CMD;
220
        when others => null;
221
      end case;
222
 
223
      if( Rx_Idle = '1' )then
224
        Vector_State         <= GET_VECTOR_CMD;
225
      end if;
226
 
227
    end if;
228
  end process;
229
 
230
end architecture;

powered by: WebSVN 2.1.0

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