w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
serport_uart_tx_tb.vhd
Go to the documentation of this file.
1-- $Id: serport_uart_tx_tb.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2007-2016 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: serport_uart_tx_tb - sim
7-- Description: serial port UART - transmitter (SIM only!)
8--
9-- Dependencies: -
10-- Target Devices: generic
11-- Tool versions: ghdl 0.18-0.31
12-- Revision History:
13-- Date Rev Version Comment
14-- 2016-01-03 724 1.0 Initial version (copied from serport_uart_tx)
15------------------------------------------------------------------------------
16
17library ieee;
18use ieee.std_logic_1164.all;
19use ieee.numeric_std.all;
20
21use work.slvtypes.all;
22
23entity serport_uart_tx_tb is -- serial port uart: transmit part
24 generic (
25 CDWIDTH : positive := 13); -- clk divider width
26 port (
27 CLK : in slbit; -- clock
28 RESET : in slbit; -- reset
29 CLKDIV : in slv(CDWIDTH-1 downto 0); -- clock divider setting
30 TXSD : out slbit; -- transmit serial data (uart view)
31 TXDATA : in slv8; -- transmit data in
32 TXENA : in slbit; -- transmit data enable
33 TXBUSY : out slbit -- transmit busy
34 );
36
37
38architecture sim of serport_uart_tx_tb is
39
40 type regs_type is record
41 ccnt : slv(CDWIDTH-1 downto 0); -- clock divider counter
42 bcnt : slv4; -- bit counter
43 sreg : slv9; -- output shift register
44 busy : slbit;
45 end record regs_type;
46
47 constant cntzero : slv(CDWIDTH-1 downto 0) := (others=>'0');
48 constant regs_init : regs_type := (
49 cntzero,
50 (others=>'0'),
51 (others=>'1'), -- sreg to all 1 !!
52 '0'
53 );
54
55 signal R_REGS : regs_type := regs_init; -- state registers
56 signal N_REGS : regs_type := regs_init; -- next value state regs
57
58begin
59
60 proc_regs: process (CLK)
61 begin
62
63 if rising_edge(CLK) then
64 R_REGS <= N_REGS;
65 end if;
66
67 end process proc_regs;
68
69 proc_next: process (R_REGS, RESET, CLKDIV, TXDATA, TXENA)
70
71 variable r : regs_type := regs_init;
72 variable n : regs_type := regs_init;
73 variable ld_ccnt : slbit := '0';
74
75 begin
76
77 r := R_REGS;
78 n := R_REGS;
79 ld_ccnt := '0';
80
81 if r.busy = '0' then
82 ld_ccnt := '1';
83 n.bcnt := (others=>'0');
84 if TXENA = '1' then
85 n.sreg := TXDATA & '0'; -- add start (0) bit
86 n.busy := '1';
87 end if;
88
89 else
90
91 if unsigned(r.ccnt) = 0 then
92 ld_ccnt := '1';
93 n.sreg := '1' & r.sreg(8 downto 1);
94 n.bcnt := slv(unsigned(r.bcnt) + 1);
95 if unsigned(r.bcnt) = 9 then -- if 10 bits send
96 n.busy := '0'; -- declare all done
97 end if;
98 end if;
99 end if;
100
101 if RESET = '1' then
102 ld_ccnt := '1';
103 n.busy := '0';
104 end if;
105
106 if ld_ccnt = '1' then
107 n.ccnt := CLKDIV;
108 else
109 n.ccnt := slv(unsigned(r.ccnt) - 1);
110 end if;
111
112 N_REGS <= n;
113
114 TXBUSY <= r.busy;
115 TXSD <= r.sreg(0);
116
117 end process proc_next;
118
119end sim;
regs_type :=( cntzero,( others => '0'),( others => '1'), '0') regs_init
regs_type := regs_init N_REGS
regs_type := regs_init R_REGS
slv( CDWIDTH- 1 downto 0) :=( others => '0') cntzero
CDWIDTH positive := 13
in CLKDIV slv( CDWIDTH- 1 downto 0)
std_logic_vector( 3 downto 0) slv4
Definition: slvtypes.vhd:36
std_logic_vector( 8 downto 0) slv9
Definition: slvtypes.vhd:41
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 7 downto 0) slv8
Definition: slvtypes.vhd:40
std_logic_vector slv
Definition: slvtypes.vhd:31