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 Control
|
21 |
|
|
-- Module : ext_miniUART
|
22 |
|
|
-- Project : HW/SW-Codesign
|
23 |
|
|
-------------------------------------------------------------------------------
|
24 |
|
|
-- File : miniUART_control.vhd
|
25 |
|
|
-- Author : Roman Seiger
|
26 |
|
|
-- Company : TU Wien - Institut für Technische Informatik
|
27 |
|
|
-- Created : 2005-03-10
|
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 |
|
|
|
40 |
|
|
use work.pkg_basic.all;
|
41 |
|
|
USE work.pkg_miniUART.all;
|
42 |
|
|
|
43 |
|
|
----------------------------------------------------------------------------------
|
44 |
|
|
-- ENTITY
|
45 |
|
|
----------------------------------------------------------------------------------
|
46 |
|
|
entity miniUART_control is
|
47 |
|
|
|
48 |
|
|
port (
|
49 |
|
|
clk : in std_logic;
|
50 |
|
|
reset : in std_logic;
|
51 |
|
|
-- MsgLength : in MsgLength_type;
|
52 |
|
|
ParEna : in std_logic; -- Parity?
|
53 |
|
|
Odd : in std_logic; -- Odd or Even Parity?
|
54 |
|
|
AsA : in std_logic_vector(2 downto 0); -- Assigned Action
|
55 |
|
|
EvS : in std_logic_vector(1 downto 0); -- Event Selector
|
56 |
|
|
|
57 |
|
|
Data_r : in Data_type; -- received Data
|
58 |
|
|
ParBit_r : in std_logic; -- empfangenes Paritybit
|
59 |
|
|
FrameErr : in std_logic;
|
60 |
|
|
RecComp : in std_logic; -- Receive Complete
|
61 |
|
|
RecBusy : in std_logic; -- Reciever Busy (Startbit detected)
|
62 |
|
|
|
63 |
|
|
TransComp : in std_logic; -- Transmission complete
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
EnaRec : out std_logic; -- Enable receiver
|
67 |
|
|
Data_r_out : out Data_type; -- empfangene Daten
|
68 |
|
|
FrameErr_out : out std_logic;
|
69 |
|
|
ParityErr : out std_logic;
|
70 |
|
|
RBR : out std_logic; -- Receive Buffer Ready (Rec Complete)
|
71 |
|
|
|
72 |
|
|
StartTrans : out std_logic; -- Start Transmitter (halten bis TrComp!)
|
73 |
|
|
TBR : out std_logic; -- Transmit Buffer Ready (MSGREG read,
|
74 |
|
|
-- transmitter started)
|
75 |
|
|
event : out std_logic -- Selected Event occured!
|
76 |
|
|
);
|
77 |
|
|
|
78 |
|
|
end miniUART_control;
|
79 |
|
|
|
80 |
|
|
----------------------------------------------------------------------------------
|
81 |
|
|
-- ARCHITECTURE
|
82 |
|
|
----------------------------------------------------------------------------------
|
83 |
|
|
architecture behaviour of miniUART_control is
|
84 |
|
|
|
85 |
|
|
-- interne Signale zur synchronisation der Ausgänge
|
86 |
|
|
signal EnaRec_i : std_logic;
|
87 |
|
|
signal StartTrans_i : std_logic;
|
88 |
|
|
signal EnaRec_old : std_logic;
|
89 |
|
|
signal StartTrans_old : std_logic;
|
90 |
|
|
signal ParityErr_i : std_logic;
|
91 |
|
|
|
92 |
|
|
signal TBR_i : std_logic;
|
93 |
|
|
signal RBR_i : std_logic;
|
94 |
|
|
|
95 |
|
|
-- in/out
|
96 |
|
|
signal Data_r_i : Data_type;
|
97 |
|
|
signal FrameErr_i : std_logic;
|
98 |
|
|
|
99 |
|
|
-- interne Signale zur Zwischenspeicherung der Eingänge
|
100 |
|
|
-- signal MsgLength_i : MsgLength_type;
|
101 |
|
|
signal ParEna_i : std_logic;
|
102 |
|
|
signal Odd_i : std_logic;
|
103 |
|
|
signal ParBit_r_i : std_logic;
|
104 |
|
|
|
105 |
|
|
signal old_TransComp : std_logic;
|
106 |
|
|
signal old_RecBusy : std_logic;
|
107 |
|
|
signal old_RecComp : std_logic;
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
-- Events
|
111 |
|
|
signal event_i : std_logic;
|
112 |
|
|
|
113 |
|
|
begin -- behaviour
|
114 |
|
|
|
115 |
|
|
-- empfangene Daten direkt übernehmen
|
116 |
|
|
Data_r_i <= Data_r;
|
117 |
|
|
ParBit_r_i <= ParBit_r;
|
118 |
|
|
FrameErr_i <= FrameErr;
|
119 |
|
|
|
120 |
|
|
-------------------------------------------------------------------------------
|
121 |
|
|
-- Control Synchronisierung
|
122 |
|
|
-------------------------------------------------------------------------------
|
123 |
|
|
CTRL_SYNC: process (clk, reset)
|
124 |
|
|
begin -- process CTRL_SYNC
|
125 |
|
|
--reset, alles zurücksetzen
|
126 |
|
|
if reset = RST_ACT then
|
127 |
|
|
Data_r_out <= (others => '0');
|
128 |
|
|
FrameErr_out <= not FRAME_ERROR;
|
129 |
|
|
ParityErr <= not PARITY_ERROR;
|
130 |
|
|
EnaRec <= not RECEIVER_ENABLED;
|
131 |
|
|
EnaRec_old <= not RECEIVER_ENABLED;
|
132 |
|
|
StartTrans <= not BRG_ON;
|
133 |
|
|
StartTrans_old <= not BRG_ON;
|
134 |
|
|
event <= not EV_OCC;
|
135 |
|
|
|
136 |
|
|
TBR <= TB_READY; -- neue Nachricht annehmen
|
137 |
|
|
RBR <= not RB_READY;
|
138 |
|
|
|
139 |
|
|
old_TransComp <= not TRANS_COMP;
|
140 |
|
|
old_RecBusy <= not REC_BUSY;
|
141 |
|
|
old_RecComp <= not REC_COMPLETE;
|
142 |
|
|
|
143 |
|
|
-- MsgLength_i <= (others => '0');
|
144 |
|
|
ParEna_i <= not PARITY_ENABLE;
|
145 |
|
|
Odd_i <= '0';
|
146 |
|
|
|
147 |
|
|
elsif clk'event and clk = '1' then
|
148 |
|
|
-- Daten ausgeben
|
149 |
|
|
Data_r_out <= Data_r_i;
|
150 |
|
|
FrameErr_out <= FrameErr_i;
|
151 |
|
|
ParityErr <= ParityErr_i;
|
152 |
|
|
EnaRec <= EnaRec_i;
|
153 |
|
|
StartTrans <= StartTrans_i;
|
154 |
|
|
EnaRec_old <= EnaRec_i;
|
155 |
|
|
StartTrans_old <= StartTrans_i;
|
156 |
|
|
event <= event_i;
|
157 |
|
|
|
158 |
|
|
TBR <= TBR_i;
|
159 |
|
|
RBR <= RBR_i;
|
160 |
|
|
|
161 |
|
|
-- Zustand merken (um Flanke zu erkennen!)
|
162 |
|
|
old_TransComp <= TransComp;
|
163 |
|
|
old_RecBusy <= RecBusy;
|
164 |
|
|
old_RecComp <= RecComp;
|
165 |
|
|
|
166 |
|
|
-- Daten merken
|
167 |
|
|
-- MsgLength_i <= MsgLength_i;
|
168 |
|
|
ParEna_i <= ParEna_i;
|
169 |
|
|
Odd_i <= Odd_i;
|
170 |
|
|
|
171 |
|
|
-- Daten übernehmen (beim Einschalten des Receivers)
|
172 |
|
|
if (EnaRec_old /= RECEIVER_ENABLED) and (EnaRec_i = RECEIVER_ENABLED) then
|
173 |
|
|
-- Aktuelle Daten übernehmen
|
174 |
|
|
-- MsgLength_i <= MsgLength;
|
175 |
|
|
ParEna_i <= ParEna;
|
176 |
|
|
Odd_i <= Odd;
|
177 |
|
|
end if;
|
178 |
|
|
end if;
|
179 |
|
|
end process CTRL_SYNC;
|
180 |
|
|
|
181 |
|
|
-------------------------------------------------------------------------------
|
182 |
|
|
-- Control Logic
|
183 |
|
|
-------------------------------------------------------------------------------
|
184 |
|
|
CTRL_LOGIC: process (EvS, AsA, StartTrans_old, EnaRec_old, TransComp, old_TransComp,
|
185 |
|
|
RecComp, old_RecComp, RecBusy, old_RecBusy)
|
186 |
|
|
-- ParEna, Odd, ParEna_i, Odd_i)
|
187 |
|
|
|
188 |
|
|
begin -- process CTRL_LOGIC
|
189 |
|
|
StartTrans_i <= StartTrans_old;
|
190 |
|
|
EnaRec_i <= EnaRec_old;
|
191 |
|
|
event_i <= not EV_OCC;
|
192 |
|
|
|
193 |
|
|
TBR_i <= not TB_READY;
|
194 |
|
|
RBR_i <= not RB_READY;
|
195 |
|
|
|
196 |
|
|
-- TRANSMITTER
|
197 |
|
|
-- Transmitter startet (TBR nur 1 clk halten!)
|
198 |
|
|
if (old_TransComp = TRANS_COMP) and (TransComp /= TRANS_COMP) then
|
199 |
|
|
TBR_i <= TB_READY;
|
200 |
|
|
|
201 |
|
|
-- Transmission completed
|
202 |
|
|
elsif (old_TransComp /= TRANS_COMP) and (TransComp = TRANS_COMP) then
|
203 |
|
|
-- BRG und damit Transmitter ausschalten
|
204 |
|
|
StartTrans_i <= not BRG_ON;
|
205 |
|
|
-- Event signalisieren
|
206 |
|
|
if EvS = EV_TCOMP then
|
207 |
|
|
event_i <= EV_OCC;
|
208 |
|
|
if AsA = ASA_STRANS then
|
209 |
|
|
-- Transmitter starten
|
210 |
|
|
StartTrans_i <= BRG_ON;
|
211 |
|
|
elsif AsA = ASA_EREC then
|
212 |
|
|
-- Receiver einschalten
|
213 |
|
|
EnaRec_i <= RECEIVER_ENABLED;
|
214 |
|
|
elsif AsA = ASA_DREC then
|
215 |
|
|
-- Receiver ausschalten
|
216 |
|
|
EnaRec_i <= not RECEIVER_ENABLED;
|
217 |
|
|
end if;
|
218 |
|
|
end if;
|
219 |
|
|
end if;
|
220 |
|
|
|
221 |
|
|
-- RECEIVER
|
222 |
|
|
-- Startbit detected
|
223 |
|
|
if (old_RecBusy /= REC_BUSY) and (RecBusy = REC_BUSY) then
|
224 |
|
|
|
225 |
|
|
if EvS = EV_SBD then
|
226 |
|
|
event_i <= EV_OCC;
|
227 |
|
|
if AsA = ASA_DREC then
|
228 |
|
|
-- Receiver ausschalten
|
229 |
|
|
EnaRec_i <= not RECEIVER_ENABLED;
|
230 |
|
|
elsif AsA = ASA_STRANS then
|
231 |
|
|
-- Transmitter starten
|
232 |
|
|
StartTrans_i <= BRG_ON;
|
233 |
|
|
end if;
|
234 |
|
|
end if;
|
235 |
|
|
|
236 |
|
|
-- ganze Nachricht empfangen (RBR nur 1 clk halten!)
|
237 |
|
|
elsif (old_RecComp /= REC_COMPLETE) and (RecComp = REC_COMPLETE) then
|
238 |
|
|
RBR_i <= RB_READY;
|
239 |
|
|
if EvS = EV_RCOMP then
|
240 |
|
|
event_i <= EV_OCC;
|
241 |
|
|
if AsA = ASA_DREC then
|
242 |
|
|
-- Receiver ausschalten
|
243 |
|
|
EnaRec_i <= not RECEIVER_ENABLED;
|
244 |
|
|
elsif AsA = ASA_STRANS then
|
245 |
|
|
-- Transmitter starten
|
246 |
|
|
StartTrans_i <= BRG_ON;
|
247 |
|
|
end if;
|
248 |
|
|
end if;
|
249 |
|
|
end if;
|
250 |
|
|
|
251 |
|
|
-- NOEVENT
|
252 |
|
|
if EvS = EV_NONE then
|
253 |
|
|
if AsA = ASA_STRANS then
|
254 |
|
|
-- Transmitter starten
|
255 |
|
|
StartTrans_i <= BRG_ON;
|
256 |
|
|
elsif AsA = ASA_EREC then
|
257 |
|
|
-- Receiver einschalten
|
258 |
|
|
EnaRec_i <= RECEIVER_ENABLED;
|
259 |
|
|
elsif AsA = ASA_DREC then
|
260 |
|
|
-- Receiver ausschalten
|
261 |
|
|
EnaRec_i <= not RECEIVER_ENABLED;
|
262 |
|
|
end if;
|
263 |
|
|
end if;
|
264 |
|
|
|
265 |
|
|
end process CTRL_LOGIC;
|
266 |
|
|
|
267 |
|
|
-------------------------------------------------------------------------------
|
268 |
|
|
-- Parity
|
269 |
|
|
-------------------------------------------------------------------------------
|
270 |
|
|
PARITY_CALC: process (Data_r_i, Odd_i, ParBit_r_i, ParEna_i)
|
271 |
|
|
-- variable i : integer;
|
272 |
|
|
variable parity : std_logic;
|
273 |
|
|
begin -- process PARITY_CALC
|
274 |
|
|
parity := '0';
|
275 |
|
|
|
276 |
|
|
-- for i in conv_Integer(unsigned(MsgLength_i)) downto 0 loop
|
277 |
|
|
for i in 15 downto 0 loop
|
278 |
|
|
parity := parity xor Data_r_i(i);
|
279 |
|
|
end loop;
|
280 |
|
|
|
281 |
|
|
-- Odd oder even?
|
282 |
|
|
if ((parity xor Odd_i) /= ParBit_r_i) and (ParEna_i = PARITY_ENABLE) then
|
283 |
|
|
ParityErr_i <= PARITY_ERROR;
|
284 |
|
|
else
|
285 |
|
|
ParityErr_i <= not PARITY_ERROR;
|
286 |
|
|
end if;
|
287 |
|
|
end process PARITY_CALC;
|
288 |
|
|
|
289 |
|
|
end behaviour;
|