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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [vector_tx.vhd] - Blame information for rev 333

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

Line No. Rev Author Line
1 296 jshamlet
-- Copyright (c)2021 Jeremy Seth Henry
2 240 jshamlet
-- 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: vector_tx
25
-- Description: Reads  the pushbuttons and switches on the DE1-SOC board and
26
--               sends a vector command and argument to a vector_rx receiver
27
--               which executes them in lieu of a parallel controller.
28
--
29
-- Revision History
30
-- Author          Date     Change
31
------------------ -------- ---------------------------------------------------
32
-- Seth Henry      05/06/20 Added version block
33 285 jshamlet
-- Seth Henry      04/07/21 Modified to replace hard-coded blocks with true
34
--                           argument inputs.
35 296 jshamlet
-- Seth Henry      09/15/21 Added flow control and made the Magic_Num a generic
36 240 jshamlet
 
37
library ieee;
38
  use ieee.std_logic_1164.all;
39
  use ieee.std_logic_unsigned.all;
40
  use ieee.std_logic_arith.all;
41
  use ieee.std_logic_misc.all;
42
 
43 285 jshamlet
library work;
44
  use work.open8_pkg.all;
45
 
46 240 jshamlet
entity vector_tx is
47
generic(
48 296 jshamlet
  Magic_Num                  : DATA_TYPE := x"4D";
49 240 jshamlet
  Bit_Rate                   : real;
50
  Enable_Parity              : boolean;
51
  Parity_Odd_Even_n          : std_logic;
52 296 jshamlet
  Clock_Frequency            : real;
53 240 jshamlet
  Reset_Level                : std_logic
54
);
55
port(
56
  Clock                      : in  std_logic;
57
  Reset                      : in  std_logic;
58
  --
59 285 jshamlet
  Tx_Enable                  : in  std_logic;
60
  Tx_Command                 : in  DATA_TYPE;
61
  Tx_Arg_Lower               : in  DATA_TYPE;
62
  Tx_Arg_Upper               : in  DATA_TYPE;
63 240 jshamlet
  --
64 285 jshamlet
  Tx_Busy                    : out std_logic;
65
  --
66
  Tx_Out                     : out std_logic;
67
  Tx_FC                      : in  std_logic := '1'
68 240 jshamlet
);
69
end entity;
70
 
71
architecture behave of vector_tx is
72
 
73 285 jshamlet
  signal Command_Buffer      : DATA_TYPE := x"00";
74
  signal Arg_Lower_Buffer    : DATA_TYPE := x"00";
75
  signal Arg_Upper_Buffer    : DATA_TYPE := x"00";
76 240 jshamlet
 
77 296 jshamlet
  type VECTOR_TX_STATES is (IDLE, WAIT_FC,
78 285 jshamlet
                            SEND_CMD, WAIT_CMD,
79
                            SEND_ARG_LB, WAIT_ARG_LB,
80
                            SEND_ARG_UB, WAIT_ARG_UB,
81 296 jshamlet
                            SEND_SUM_LB, WAIT_SUM_LB,
82
                            SEND_SUM_UB, WAIT_SUM_UB );
83 240 jshamlet
  signal Vector_State        : VECTOR_TX_STATES := IDLE;
84
 
85 296 jshamlet
  constant BAUD_RATE_DIV     : integer := integer(Clock_Frequency / Bit_Rate);
86 240 jshamlet
 
87 296 jshamlet
  signal Checksum            : ADDRESS_TYPE := x"0000";
88
  alias  Checksum_LB         is Checksum(7 downto 0);
89
  alias  Checksum_UB         is Checksum(15 downto 8);
90 285 jshamlet
 
91
  signal Tx_Data             : DATA_TYPE := x"00";
92 240 jshamlet
  signal Tx_Valid            : std_logic := '0';
93
  signal Tx_Done             : std_logic := '0';
94
 
95
begin
96
 
97
  TX_FSM_proc: process( Clock, Reset )
98
  begin
99
    if( Reset = Reset_Level )then
100
      Vector_State           <= IDLE;
101 285 jshamlet
      Command_Buffer         <= x"00";
102
      Arg_Lower_Buffer       <= x"00";
103
      Arg_Upper_Buffer       <= x"00";
104
      Tx_Busy                <= '0';
105 240 jshamlet
      Tx_Data                <= x"00";
106
      Tx_Valid               <= '0';
107
    elsif( rising_edge(Clock) )then
108 285 jshamlet
      Tx_Busy                <= '1';
109 240 jshamlet
      Tx_Data                <= x"00";
110
      Tx_Valid               <= '0';
111
      case( Vector_State )is
112
        when IDLE =>
113 285 jshamlet
          Tx_Busy            <= '0';
114 296 jshamlet
          Checksum           <= x"00" & MAGIC_NUM;
115 285 jshamlet
          if( Tx_Enable = '1' )then
116
            Command_Buffer   <= Tx_Command;
117
            Arg_Lower_Buffer <= Tx_Arg_Lower;
118
            Arg_Upper_Buffer <= Tx_Arg_Upper;
119 296 jshamlet
            Vector_State     <= WAIT_FC;
120
          end if;
121
 
122
        when WAIT_FC =>
123
          if( Tx_FC = '1' )then
124 240 jshamlet
            Vector_State     <= SEND_CMD;
125
          end if;
126
 
127
        when SEND_CMD =>
128 285 jshamlet
          Tx_Data            <= Command_Buffer;
129 240 jshamlet
          Tx_Valid           <= '1';
130 285 jshamlet
          Checksum           <= Checksum + Command_Buffer;
131 240 jshamlet
          Vector_State       <= WAIT_CMD;
132
 
133
        when WAIT_CMD =>
134
          if( Tx_Done = '1' )then
135
            Vector_State     <= SEND_ARG_LB;
136
          end if;
137
 
138
        when SEND_ARG_LB =>
139 285 jshamlet
          Tx_Data            <= Arg_Lower_Buffer;
140 240 jshamlet
          Tx_Valid           <= '1';
141 285 jshamlet
          Checksum           <= Checksum + Arg_Lower_Buffer;
142 240 jshamlet
          Vector_State       <= WAIT_ARG_LB;
143
 
144
        when WAIT_ARG_LB =>
145
          if( Tx_Done = '1' )then
146
            Vector_State     <= SEND_ARG_UB;
147
          end if;
148
 
149
        when SEND_ARG_UB =>
150 285 jshamlet
          Tx_Data            <= Arg_Upper_Buffer;
151 240 jshamlet
          Tx_Valid           <= '1';
152 285 jshamlet
          Checksum           <= Checksum + Arg_Upper_Buffer;
153 240 jshamlet
          Vector_State       <= WAIT_ARG_UB;
154
 
155
        when WAIT_ARG_UB =>
156
          if( Tx_Done = '1' )then
157 296 jshamlet
            Vector_State     <= SEND_SUM_LB;
158 285 jshamlet
          end if;
159
 
160 296 jshamlet
        when SEND_SUM_LB =>
161
          Tx_Data            <= Checksum_LB;
162 285 jshamlet
          Tx_Valid           <= '1';
163 296 jshamlet
          Vector_State       <= WAIT_SUM_LB;
164 285 jshamlet
 
165 296 jshamlet
        when WAIT_SUM_LB =>
166 285 jshamlet
          if( Tx_Done = '1' )then
167 296 jshamlet
            Vector_State     <= SEND_SUM_UB;
168
          end if;
169
 
170
        when SEND_SUM_UB =>
171
          Tx_Data            <= Checksum_UB;
172
          Tx_Valid           <= '1';
173
          Vector_State       <= WAIT_SUM_UB;
174
 
175
        when WAIT_SUM_UB =>
176
          if( Tx_Done = '1' )then
177 240 jshamlet
            Vector_State     <= IDLE;
178
          end if;
179
 
180
      end case;
181
    end if;
182
  end process;
183
 
184
  U_TX : entity work.async_ser_tx
185
  generic map(
186
    Reset_Level              => Reset_Level,
187
    Enable_Parity            => Enable_Parity,
188
    Parity_Odd_Even_n        => Parity_Odd_Even_n,
189
    Clock_Divider            => BAUD_RATE_DIV
190
  )
191
  port map(
192
    Clock                    => Clock,
193
    Reset                    => Reset,
194
    --
195
    Tx_Data                  => Tx_Data,
196
    Tx_Valid                 => Tx_Valid,
197
    --
198
    Tx_Out                   => Tx_Out,
199
    Tx_Done                  => Tx_Done
200
  );
201
 
202
end architecture;

powered by: WebSVN 2.1.0

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