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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [processor/] [VHDL/] [ext_modules/] [ext_miniUART/] [miniUART_transmitter.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jlechner
-----------------------------------------------------------------------
2
-- This file is part of SCARTS.
3
-- 
4
-- SCARTS is free software: you can redistribute it and/or modify
5
-- it under the terms of the GNU General Public License as published by
6
-- the Free Software Foundation, either version 3 of the License, or
7
-- (at your option) any later version.
8
-- 
9
-- SCARTS is distributed in the hope that it will be useful,
10
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
-- GNU General Public License for more details.
13
-- 
14
-- You should have received a copy of the GNU General Public License
15
-- along with SCARTS.  If not, see <http://www.gnu.org/licenses/>.
16
-----------------------------------------------------------------------
17
 
18
 
19
-------------------------------------------------------------------------------
20
-- Title      : miniUART Transmitter v2
21
-- Module     : ext_miniUART
22
-- Project    : HW/SW-Codesign
23
-------------------------------------------------------------------------------
24
-- File       : miniUART_transmitter.vhd
25
-- Author     : Roman Seiger
26
-- Company    : TU Wien - Institut für Technische Informatik
27
-- Created    : 2005-03-07
28
-- Last update: 2007-05-02
29
-------------------------------------------------------------------------------
30
 
31
 
32
 
33
----------------------------------------------------------------------------------
34
-- LIBRARY
35
----------------------------------------------------------------------------------
36
LIBRARY IEEE;
37
USE IEEE.std_logic_1164.all;
38
USE IEEE.std_logic_arith.all;
39
use IEEE.std_logic_UNSIGNED.all;
40
--use IEEE.std_logic_UNSIGNED."-";
41
 
42
use work.pkg_basic.all;
43
use work.pkg_miniUART.all;
44
 
45
----------------------------------------------------------------------------------
46
-- ENTITY
47
----------------------------------------------------------------------------------
48
entity miniUART_transmitter is
49
 
50
  port (
51
    clk : in std_logic;
52
    reset : in std_logic;
53
    MsgLength : in MsgLength_type;
54
    Stop2 : in std_logic;               -- Zweites Stopbit?
55
    ParEna : in std_logic;              -- Parity?
56
    ParBit : in std_logic;              -- Vorberechnetes Paritybit
57
    Data : in Data_type;
58
    tp : in std_logic;                  -- Transmitpulse vom BRG
59
 
60
    TransEna : out std_logic;           -- Busdriver einschalten
61
    TrComp : out std_logic;              -- Transmission complete
62
    TxD : out std_logic                 -- Sendeausgang
63
    );
64
 
65
end miniUART_transmitter;
66
 
67
----------------------------------------------------------------------------------
68
-- ARCHITECTURE
69
----------------------------------------------------------------------------------
70
architecture behaviour of miniUART_transmitter is
71
 
72
  -- Definition der States
73
  type trans_states is (START_S, DATA_S, PARITY_S, STOP_S);
74
 
75
  signal Trans_State : trans_states;
76
  signal next_Trans_State : trans_states;
77
 
78
  -- interne Signale zur synchronisation der Ausgänge
79
  signal TxD_i : std_logic;
80
  signal TransEna_i : std_logic;
81
  signal TrComp_i : std_logic;
82
  signal TxD_old : std_logic;
83
  signal TransEna_old : std_logic;
84
  signal TrComp_old : std_logic;
85
 
86
  -- interne Signale zur Zwischenspeicherung der Eingänge
87
  signal MsgLength_i : MsgLength_type;
88
  signal MsgLength_i_nxt : MsgLength_type;
89
  signal Stop2_i : std_logic;
90
  signal Stop2_i_nxt : std_logic;
91
  signal ParEna_i : std_logic;
92
  signal ParEna_i_nxt : std_logic;
93
  signal ParBit_i : std_logic;
94
  signal ParBit_i_nxt : std_logic;
95
  signal Data_i : Data_type;
96
  signal Data_nxt : Data_type;
97
 
98
  -- Bitzähler
99
  signal Bitcounter : MsgLength_type;
100
  signal next_Bitcounter : MsgLength_type;
101
 
102
  -- Stopzähler (00: 1. Stopbit; 01: 2. Stopbit oder Ende; 10: Ende)
103
  signal Stopcounter : std_logic_vector(1 downto 0);
104
  signal next_Stopcounter : std_logic_vector(1 downto 0);
105
 
106
begin  -- behaviour
107
 
108
  TRANS_OUTPUT : process (clk, reset)
109
  begin  -- process TRANS_OUTPUT
110
    -- Reset, setzt alles auf Standardwerte
111
    if reset = RST_ACT then
112
      TxD <= '1';
113
      TransEna <= not BUSDRIVER_ON;
114
      TrComp <= TRANS_COMP;
115
      TxD_old <= '1';
116
      TransEna_old <= not BUSDRIVER_ON;
117
      TrComp_old <= TRANS_COMP;
118
 
119
      Data_i <= (others => '1');
120
      MsgLength_i <= (others => '0');
121
 
122
      Bitcounter <= (others => '0');
123
      Stopcounter <= (others => '0');
124
      Trans_State <= START_S;
125
 
126
      Stop2_i <= '0';
127
      ParBit_i <= '0';
128
      ParEna_i <= '0';
129
 
130
    elsif (clk'event and clk = '1') then
131
      TxD <= TxD_old;
132
      TransEna <= TransEna_old;
133
      TrComp <= TrComp_old;
134
 
135
      Data_i <= Data_nxt;
136
      MsgLength_i <= MsgLength_i_nxt;
137
 
138
      Bitcounter <= Bitcounter;
139
      Stopcounter <= Stopcounter;
140
      Trans_State <= Trans_State;
141
 
142
      Stop2_i <= Stop2_i_nxt;
143
      ParBit_i <= ParBit_i_nxt;
144
      ParEna_i <= ParEna_i_nxt;
145
 
146
      -- Bei Transmitpulse: ausgeben, Zustandswechsel
147
      if tp = '1' then
148
        TxD <= TxD_i;
149
        TransEna <= TransEna_i;
150
        TrComp <= TrComp_i;
151
        TxD_old <= TxD_i;
152
        TransEna_old <= TransEna_i;
153
        TrComp_old <= TrComp_i;
154
 
155
        Bitcounter <= next_Bitcounter;   -- Datenbits mitzählen
156
        Stopcounter <= next_Stopcounter;  -- Stopbits mitzählen
157
 
158
        Trans_State <= next_Trans_State;  -- Zustandswechsel
159
 
160
      end if;
161
    end if;
162
  end process TRANS_OUTPUT;
163
 
164
 
165
 
166
  TRANS_STATEMACHINE: process (Trans_State, Bitcounter, Stopcounter,
167
                               MsgLength, MsgLength_i, Data, Data_i,
168
                               ParEna, ParEna_i, ParBit, ParBit_i,
169
                               Stop2, Stop2_i)
170
  begin  -- process TRANS_STATEMACHINE
171
    -- Defaultwerte (halten)
172
    Data_nxt <= Data_i;
173
    MsgLength_i_nxt <= MsgLength_i;
174
    ParEna_i_nxt <= ParEna_i;
175
    ParBit_i_nxt <= ParBit_i;
176
    Stop2_i_nxt <= Stop2_i;
177
 
178
 
179
    case Trans_State is
180
      when DATA_S =>
181
        TrComp_i <= not TRANS_COMP;
182
        TransEna_i <= BUSDRIVER_ON;
183
        next_Bitcounter <= Bitcounter + '1';
184
        next_Stopcounter <= (others => '0');
185
 
186
        -- letztes Bit des Datenwortes
187
        if Bitcounter = MsgLength_i then
188
          TxD_i <= Data_i(conv_Integer(unsigned(Bitcounter)));
189
 
190
          if ParEna_i = PARITY_ENABLE then
191
            next_Trans_State <= PARITY_S;
192
          else
193
            next_Trans_State <= STOP_S;
194
          end if;
195
 
196
        -- irgendeine Position im Datenwort
197
        else
198
          TxD_i <= Data_i(conv_Integer(unsigned(Bitcounter)));
199
          next_Trans_State <= DATA_S;
200
        end if;
201
 
202
      when PARITY_S =>
203
        TxD_i <= ParBit_i;
204
        TrComp_i <= not TRANS_COMP;
205
        TransEna_i <= BUSDRIVER_ON;
206
        next_Bitcounter <= (others => '0');
207
        next_Stopcounter <= (others => '0');
208
 
209
        next_Trans_State <= STOP_S;
210
 
211
      when STOP_S =>
212
        TxD_i <= '1';
213
 
214
        next_Bitcounter <= (others => '0');
215
        next_Stopcounter <= Stopcounter + '1';
216
 
217
        case Stopcounter is
218
          -- erstes Stopbit
219
          when "00" =>
220
            TrComp_i <= not TRANS_COMP;
221
            TransEna_i <= BUSDRIVER_ON;
222
            next_Trans_State <= STOP_S;
223
 
224
          -- zweites Stopbit oder Ende
225
          when "01" =>
226
            if Stop2_i = SECOND_STOPBIT then
227
              TrComp_i <= not TRANS_COMP;
228
              TransEna_i <= BUSDRIVER_ON;
229
              next_Trans_State <= STOP_S;
230
            else
231
              TrComp_i <= TRANS_COMP;
232
              TransEna_i <= not BUSDRIVER_ON;
233
              next_Trans_State <= START_S;
234
            end if;
235
 
236
          -- Ende
237
          when others =>
238
            TrComp_i <= TRANS_COMP;
239
            TransEna_i <= not BUSDRIVER_ON;
240
            next_Trans_State <= START_S;
241
        end case;
242
 
243
      when others =>                    -- START_S
244
        TxD_i <= '0';
245
 
246
        -- halten, erst nach Datenübernahme freigeben (DATA_S)
247
        TrComp_i <= TRANS_COMP;
248
 
249
        TransEna_i <= BUSDRIVER_ON;
250
 
251
        -- neue Daten holen
252
        Data_nxt <= Data;
253
        MsgLength_i_nxt <= MsgLength;
254
        ParEna_i_nxt <= ParEna;
255
        ParBit_i_nxt <= ParBit;
256
        Stop2_i_nxt <= Stop2;
257
 
258
        next_Bitcounter <= (others => '0');
259
        next_Stopcounter <= (others => '0');
260
        next_Trans_State <= DATA_S;
261
 
262
    end case;
263
  end process TRANS_STATEMACHINE;
264
 
265
end behaviour;

powered by: WebSVN 2.1.0

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