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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.5/] [rtl/] [vlib/] [serport/] [serport_uart_tx.vhd] - Blame information for rev 16

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

Line No. Rev Author Line
1 2 wfjm
-- $Id: serport_uart_tx.vhd 314 2010-07-09 17:38:41Z mueller $
2
--
3
-- Copyright 2007- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
--
14
------------------------------------------------------------------------------
15
-- Module Name:    serport_uart_tx - syn
16
-- Description:    serial port UART - transmitter
17
--
18
-- Dependencies:   -
19
-- Test bench:     tb/tb_serport_uart_rxtx
20
-- Target Devices: generic
21
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2; ghdl 0.18-0.25
22
-- Revision History: 
23
-- Date         Rev Version  Comment
24
-- 2007-10-21    91   1.0.3  use 1 stop bits (redesigned _rx allows this)
25
-- 2007-10-19    90   1.0.2  use 2 stop bits (allow CLKDIV=0 operation in sim)
26
-- 2007-10-12    88   1.0.1  avoid ieee.std_logic_unsigned, use cast to unsigned
27
-- 2007-06-30    62   1.0    Initial version 
28
------------------------------------------------------------------------------
29
 
30
library ieee;
31
use ieee.std_logic_1164.all;
32
use ieee.std_logic_arith.all;
33
 
34
use work.slvtypes.all;
35
 
36
entity serport_uart_tx is               -- serial port uart: transmit part
37
  generic (
38
    CDWIDTH : positive := 13);          -- clk divider width
39
  port (
40
    CLK : in slbit;                     -- clock
41
    RESET : in slbit;                   -- reset
42
    CLKDIV : in slv(CDWIDTH-1 downto 0); -- clock divider setting
43
    TXSD : out slbit;                   -- transmit serial data (uart view)
44
    TXDATA : in slv8;                   -- transmit data in
45
    TXENA : in slbit;                   -- transmit data enable
46
    TXBUSY : out slbit                  -- transmit busy
47
  );
48
end serport_uart_tx;
49
 
50
 
51
architecture syn of serport_uart_tx is
52
 
53
  type regs_type is record
54
    ccnt : slv(CDWIDTH-1 downto 0);     -- clock divider counter
55
    bcnt : slv4;                        -- bit counter
56
    sreg : slv9;                        -- output shift register
57
    busy : slbit;
58
  end record regs_type;
59
 
60
  constant cntzero : slv(CDWIDTH-1 downto 0) := (others=>'0');
61
  constant regs_init : regs_type := (
62
    cntzero,
63
    (others=>'0'),
64
    (others=>'1'),                      -- sreg to all 1 !!
65
    '0'
66
  );
67
 
68
  signal R_REGS : regs_type := regs_init;  -- state registers
69
  signal N_REGS : regs_type := regs_init;  -- next value state regs
70
 
71
begin
72
 
73
  proc_regs: process (CLK)
74
  begin
75
 
76
    if CLK'event and CLK='1' then
77
      R_REGS <= N_REGS;
78
    end if;
79
 
80
  end process proc_regs;
81
 
82
  proc_next: process (R_REGS, RESET, CLKDIV, TXDATA, TXENA)
83
 
84
    variable r : regs_type := regs_init;
85
    variable n : regs_type := regs_init;
86
    variable ld_ccnt : slbit := '0';
87
 
88
  begin
89
 
90
    r := R_REGS;
91
    n := R_REGS;
92
    ld_ccnt := '0';
93
 
94
    if r.busy = '0' then
95
      ld_ccnt := '1';
96
      n.bcnt := (others=>'0');
97
      if TXENA = '1' then
98
        n.sreg := TXDATA & '0';         -- add start (0) bit
99
        n.busy := '1';
100
      end if;
101
 
102
    else
103
 
104
      if unsigned(r.ccnt) = 0 then
105
        ld_ccnt := '1';
106
        n.sreg := '1' & r.sreg(8 downto 1);
107
        n.bcnt := unsigned(r.bcnt) + 1;
108
        if unsigned(r.bcnt) = 9 then    -- if 10 bits send
109
          n.busy := '0';                -- declare all done
110
        end if;
111
      end if;
112
    end if;
113
 
114
    if RESET = '1' then
115
      ld_ccnt := '1';
116
      n.busy  := '0';
117
    end if;
118
 
119
    if ld_ccnt = '1' then
120
      n.ccnt := CLKDIV;
121
    else
122
      n.ccnt := unsigned(r.ccnt) - 1;
123
    end if;
124
 
125
    N_REGS <= n;
126
 
127
    TXBUSY <= r.busy;
128
    TXSD   <= r.sreg(0);
129
 
130
  end process proc_next;
131
 
132
end syn;

powered by: WebSVN 2.1.0

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