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 287

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 285 jshamlet
-- Seth Henry      04/07/21 Added checksum to prevent glitching on serial noise
45 240 jshamlet
 
46
library ieee;
47
  use ieee.std_logic_1164.all;
48
  use ieee.std_logic_unsigned.all;
49
  use ieee.std_logic_arith.all;
50
  use ieee.std_logic_misc.all;
51
 
52
library work;
53
  use work.Open8_pkg.all;
54
 
55
entity o8_vector_rx is
56
generic(
57
  Bit_Rate                   : real;
58
  Enable_Parity              : boolean;
59
  Parity_Odd_Even_n          : std_logic;
60
  Clock_Frequency            : real;
61
  Address                    : ADDRESS_TYPE
62
);
63
port(
64
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
65
  Rd_Data                    : out DATA_TYPE;
66
  Interrupt                  : out std_logic;
67 246 jshamlet
  -- Parallel Interface
68
  Vec_Req                    : in  std_logic;
69
  Vec_Index                  : in  std_logic_vector(5 downto 0);
70
  Vec_Data                   : in  std_logic_vector(15 downto 0);
71
  -- Serial Interface
72
  Vec_Rx                     : in  std_logic
73 240 jshamlet
);
74
end entity;
75
 
76
architecture behave of o8_vector_rx is
77
 
78
  alias Clock                is Open8_Bus.Clock;
79
  alias Reset                is Open8_Bus.Reset;
80
 
81
  constant User_Addr         : std_logic_vector(15 downto 2) :=
82
                                Address(15 downto 2);
83
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
84
  signal Addr_Match          : std_logic := '0';
85
 
86 244 jshamlet
  alias  Reg_Sel_d           is Open8_Bus.Address(1 downto 0);
87
  signal Reg_Sel_q           : std_logic_vector(1 downto 0) := "00";
88
  signal Rd_En_d             : std_logic := '0';
89
  signal Rd_En_q             : std_logic := '0';
90 240 jshamlet
 
91
  constant BAUD_RATE_DIV     : integer := integer(Clock_Frequency / Bit_Rate);
92
 
93
  -- Period of each bit in sub-clocks (subtract one to account for zero)
94
  constant Full_Per_i        : integer := BAUD_RATE_DIV - 1;
95
  constant Baud_Bits         : integer := ceil_log2(Full_Per_i);
96
 
97
  constant FULL_PERIOD       : std_logic_vector(Baud_Bits - 1 downto 0) :=
98
                                 conv_std_logic_vector(Full_Per_i, Baud_Bits);
99
 
100
  signal Rx_Baud_Cntr        : std_logic_vector(Baud_Bits - 1 downto 0) :=
101
                                 (others => '0');
102
  signal Rx_Baud_Tick        : std_logic;
103
 
104 246 jshamlet
  signal Vec_Rx_SR           : std_logic_vector(2 downto 0);
105
  alias  Vec_Rx_MS            is Vec_Rx_SR(2);
106 240 jshamlet
  signal Rx_Idle_Cntr        : std_logic_vector(3 downto 0);
107
  signal RX_Idle             : std_logic;
108 246 jshamlet
  signal Rx_Data             : DATA_TYPE := x"00";
109
  signal Rx_Valid            : std_logic;
110 240 jshamlet
 
111 285 jshamlet
  type VECTOR_RX_STATES is ( CHECKSUM_INIT,
112
                             GET_VECTOR_CMD,
113
                             GET_VECTOR_ARG_LB,
114
                             GET_VECTOR_ARG_UB,
115
                             GET_VECTOR_SUM,
116 240 jshamlet
                             SEND_INTERRUPT );
117
  signal Vector_State        : VECTOR_RX_STATES := GET_VECTOR_CMD;
118
 
119 246 jshamlet
  signal Vec_Req_SR           : std_logic_vector(2 downto 0);
120 247 jshamlet
  alias  Vec_Req_MS           is Vec_Req_SR(2);
121 240 jshamlet
 
122 246 jshamlet
  signal Vector_Index        : DATA_TYPE := x"00";
123
  signal Vector_Data         : ADDRESS_TYPE := x"0000";
124
  alias  Vector_Data_LB      is Vector_Data(7 downto 0);
125
  alias  Vector_Data_UB      is Vector_Data(15 downto 8);
126 285 jshamlet
  signal Vector_RX_Sum       : DATA_TYPE := x"00";
127 240 jshamlet
 
128 285 jshamlet
  constant MAGIC_NUM         : DATA_TYPE := x"4D";
129
  signal Checksum            : DATA_TYPE := x"00";
130
 
131 240 jshamlet
begin
132
 
133
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
134 244 jshamlet
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
135 240 jshamlet
 
136
  io_reg: process( Clock, Reset )
137
  begin
138
    if( Reset = Reset_Level )then
139 246 jshamlet
      Reg_Sel_q              <= (others => '0');
140
      Rd_En_q                <= '0';
141
      Rd_Data                <= OPEN8_NULLBUS;
142 240 jshamlet
    elsif( rising_edge( Clock ) )then
143 246 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
144 244 jshamlet
 
145 246 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
146
      Rd_En_q                <= Rd_En_d;
147 244 jshamlet
      if( Rd_En_q = '1'  )then
148
        case( Reg_Sel_q )is
149 240 jshamlet
          when "00" =>
150 246 jshamlet
            Rd_Data          <= Vector_Index;
151 240 jshamlet
          when "01" =>
152 246 jshamlet
            Rd_Data          <= Vector_Data_LB;
153 240 jshamlet
          when "10" =>
154 246 jshamlet
            Rd_Data          <= Vector_Data_UB;
155 240 jshamlet
          when others =>
156
            null;
157
      end case;
158
      end if;
159
    end if;
160
  end process;
161
 
162
  RX_Idle_proc: process( Clock, Reset )
163
  begin
164
    if( Reset = Reset_Level )then
165 246 jshamlet
      Rx_Baud_Cntr           <= (others => '0');
166
      Rx_Baud_Tick           <= '0';
167
      Vec_Rx_SR              <= (others => '1');
168
      Rx_Idle_Cntr           <= (others => '0');
169
      Rx_Idle                <= '0';
170 240 jshamlet
    elsif( rising_edge(Clock) )then
171 246 jshamlet
      Rx_Baud_Cntr           <= Rx_Baud_Cntr - 1;
172
      Rx_Baud_Tick           <= '0';
173 240 jshamlet
      if( Rx_Baud_Cntr = 0 )then
174 246 jshamlet
        Rx_Baud_Cntr         <= FULL_PERIOD;
175
        Rx_Baud_Tick         <= '1';
176 240 jshamlet
      end if;
177
 
178 246 jshamlet
      Vec_Rx_SR              <= Vec_Rx_SR(1 downto 0) & Vec_Rx;
179
      Rx_Idle_Cntr           <= Rx_Idle_Cntr - Rx_Baud_Tick;
180
      if( Vec_Rx_MS = '0' )then
181
        Rx_Idle_Cntr         <= (others => '1');
182 240 jshamlet
      elsif( Rx_Idle_Cntr = 0 )then
183 246 jshamlet
        Rx_Idle_Cntr         <= (others => '0');
184 240 jshamlet
      end if;
185 246 jshamlet
 
186
      Rx_Idle                <= nor_reduce(Rx_Idle_Cntr);
187 240 jshamlet
    end if;
188
  end process;
189
 
190
  U_RX : entity work.async_ser_rx
191
  generic map(
192
    Reset_Level              => Reset_Level,
193
    Enable_Parity            => Enable_Parity,
194
    Parity_Odd_Even_n        => Parity_Odd_Even_n,
195
    Clock_Divider            => BAUD_RATE_DIV
196
  )
197
  port map(
198
    Clock                    => Clock,
199
    Reset                    => Reset,
200
    --
201 246 jshamlet
    RX_In                    => Vec_Rx,
202 240 jshamlet
    --
203
    Rx_Data                  => RX_Data,
204
    Rx_Valid                 => RX_Valid,
205
    Rx_PErr                  => open
206
  );
207
 
208
  Vector_RX_proc: process( Clock, Reset )
209
  begin
210
    if( Reset = Reset_Level )then
211 246 jshamlet
      Vec_Req_SR             <= (others => '0');
212 285 jshamlet
      Vector_State           <= CHECKSUM_INIT;
213 246 jshamlet
      Vector_Index           <= x"00";
214
      Vector_Data            <= x"0000";
215 240 jshamlet
      Interrupt              <= '0';
216
    elsif( rising_edge(Clock) )then
217 246 jshamlet
      Vec_Req_SR             <= Vec_Req_SR(1 downto 0) & Vec_Req;
218
 
219 240 jshamlet
      Interrupt              <= '0';
220 246 jshamlet
 
221
      if( Vec_Req_MS = '1' )then
222
        Vector_Index         <= "00" & Vec_Index;
223
        Vector_Data          <= Vec_Data;
224
        Interrupt            <= '1';
225
      end if;
226
 
227 240 jshamlet
      case( Vector_State )is
228 285 jshamlet
        when CHECKSUM_INIT =>
229
          Checksum           <= MAGIC_NUM;
230
          Vector_State       <= GET_VECTOR_CMD;
231
 
232 240 jshamlet
        when GET_VECTOR_CMD =>
233
          if( Rx_Valid = '1' )then
234 285 jshamlet
            Checksum         <= Checksum + Rx_Data;
235 246 jshamlet
            Vector_Index     <= "00" & Rx_Data(5 downto 0);
236 240 jshamlet
            Vector_State     <= GET_VECTOR_ARG_LB;
237
          end if;
238
 
239
        when GET_VECTOR_ARG_LB =>
240
          if( Rx_Valid = '1' )then
241 285 jshamlet
            Checksum         <= Checksum + Rx_Data;
242 246 jshamlet
            Vector_Data_LB   <= Rx_Data;
243 240 jshamlet
            Vector_State     <= GET_VECTOR_ARG_UB;
244
          end if;
245
 
246
        when GET_VECTOR_ARG_UB =>
247
          if( Rx_Valid = '1' )then
248 285 jshamlet
            Checksum         <= Checksum + Rx_Data;
249 246 jshamlet
            Vector_Data_UB   <= Rx_Data;
250 285 jshamlet
            Vector_State     <= GET_VECTOR_SUM;
251
          end if;
252
 
253
        when GET_VECTOR_SUM =>
254
          if( Rx_Valid = '1' )then
255
            Vector_RX_Sum    <= Rx_Data;
256 240 jshamlet
            Vector_State     <= SEND_INTERRUPT;
257
          end if;
258
 
259
        when SEND_INTERRUPT =>
260 285 jshamlet
          if( Checksum = Vector_RX_Sum )then
261
            Interrupt        <= '1';
262
          end if;
263
          Vector_State       <= CHECKSUM_INIT;
264 240 jshamlet
        when others => null;
265
      end case;
266
 
267
      if( Rx_Idle = '1' )then
268 285 jshamlet
        Vector_State         <= CHECKSUM_INIT;
269 240 jshamlet
      end if;
270
 
271
    end if;
272
  end process;
273
 
274
end architecture;

powered by: WebSVN 2.1.0

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