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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 wfjm
-- $Id: serport_uart_tx.vhd 417 2011-10-22 10:30:29Z mueller $
2 2 wfjm
--
3 13 wfjm
-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 2 wfjm
--
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 13 wfjm
-- Tool versions:  xst 8.2, 9.1, 9.2, 13.1; ghdl 0.18-0.29
22 2 wfjm
-- Revision History: 
23
-- Date         Rev Version  Comment
24 13 wfjm
-- 2011-10-22   417   1.0.4  now numeric_std clean
25 2 wfjm
-- 2007-10-21    91   1.0.3  use 1 stop bits (redesigned _rx allows this)
26
-- 2007-10-19    90   1.0.2  use 2 stop bits (allow CLKDIV=0 operation in sim)
27
-- 2007-10-12    88   1.0.1  avoid ieee.std_logic_unsigned, use cast to unsigned
28
-- 2007-06-30    62   1.0    Initial version 
29
------------------------------------------------------------------------------
30
 
31
library ieee;
32
use ieee.std_logic_1164.all;
33 13 wfjm
use ieee.numeric_std.all;
34 2 wfjm
 
35
use work.slvtypes.all;
36
 
37
entity serport_uart_tx is               -- serial port uart: transmit part
38
  generic (
39
    CDWIDTH : positive := 13);          -- clk divider width
40
  port (
41
    CLK : in slbit;                     -- clock
42
    RESET : in slbit;                   -- reset
43
    CLKDIV : in slv(CDWIDTH-1 downto 0); -- clock divider setting
44
    TXSD : out slbit;                   -- transmit serial data (uart view)
45
    TXDATA : in slv8;                   -- transmit data in
46
    TXENA : in slbit;                   -- transmit data enable
47
    TXBUSY : out slbit                  -- transmit busy
48
  );
49
end serport_uart_tx;
50
 
51
 
52
architecture syn of serport_uart_tx is
53
 
54
  type regs_type is record
55
    ccnt : slv(CDWIDTH-1 downto 0);     -- clock divider counter
56
    bcnt : slv4;                        -- bit counter
57
    sreg : slv9;                        -- output shift register
58
    busy : slbit;
59
  end record regs_type;
60
 
61
  constant cntzero : slv(CDWIDTH-1 downto 0) := (others=>'0');
62
  constant regs_init : regs_type := (
63
    cntzero,
64
    (others=>'0'),
65
    (others=>'1'),                      -- sreg to all 1 !!
66
    '0'
67
  );
68
 
69
  signal R_REGS : regs_type := regs_init;  -- state registers
70
  signal N_REGS : regs_type := regs_init;  -- next value state regs
71
 
72
begin
73
 
74
  proc_regs: process (CLK)
75
  begin
76
 
77 13 wfjm
    if rising_edge(CLK) then
78 2 wfjm
      R_REGS <= N_REGS;
79
    end if;
80
 
81
  end process proc_regs;
82
 
83
  proc_next: process (R_REGS, RESET, CLKDIV, TXDATA, TXENA)
84
 
85
    variable r : regs_type := regs_init;
86
    variable n : regs_type := regs_init;
87
    variable ld_ccnt : slbit := '0';
88
 
89
  begin
90
 
91
    r := R_REGS;
92
    n := R_REGS;
93
    ld_ccnt := '0';
94
 
95
    if r.busy = '0' then
96
      ld_ccnt := '1';
97
      n.bcnt := (others=>'0');
98
      if TXENA = '1' then
99
        n.sreg := TXDATA & '0';         -- add start (0) bit
100
        n.busy := '1';
101
      end if;
102
 
103
    else
104
 
105
      if unsigned(r.ccnt) = 0 then
106
        ld_ccnt := '1';
107
        n.sreg := '1' & r.sreg(8 downto 1);
108 13 wfjm
        n.bcnt := slv(unsigned(r.bcnt) + 1);
109 2 wfjm
        if unsigned(r.bcnt) = 9 then    -- if 10 bits send
110
          n.busy := '0';                -- declare all done
111
        end if;
112
      end if;
113
    end if;
114
 
115
    if RESET = '1' then
116
      ld_ccnt := '1';
117
      n.busy  := '0';
118
    end if;
119
 
120
    if ld_ccnt = '1' then
121
      n.ccnt := CLKDIV;
122
    else
123 13 wfjm
      n.ccnt := slv(unsigned(r.ccnt) - 1);
124 2 wfjm
    end if;
125
 
126
    N_REGS <= n;
127
 
128
    TXBUSY <= r.busy;
129
    TXSD   <= r.sreg(0);
130
 
131
  end process proc_next;
132
 
133
end syn;

powered by: WebSVN 2.1.0

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