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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.5/] [rtl/] [vlib/] [serport/] [serport_uart_autobaud.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_autobaud.vhd 314 2010-07-09 17:38:41Z mueller $
2
--
3
-- Copyright 2007-2010 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_autobaud - syn
16
-- Description:    serial port UART - autobauder
17
--
18
-- Dependencies:   -
19
-- Test bench:     tb/tb_serport_autobaud
20
-- Target Devices: generic
21
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2, 11.4; ghdl 0.18-0.26
22
-- Revision History: 
23
-- Date         Rev Version  Comment
24
-- 2010-04-18   279   1.0.3  change ccnt start value to -3, better rounding
25
-- 2007-10-14    89   1.0.2  all instantiation with CDINIT=0
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_autobaud is         -- serial port uart: autobauder
37
  generic (
38
    CDWIDTH : positive := 13;           -- clk divider width
39
    CDINIT: natural := 15);             -- clk divider initial/reset setting
40
  port (
41
    CLK : in slbit;                     -- clock
42
    CE_MSEC : in slbit;                 -- 1 msec clock enable
43
    RESET : in slbit;                   -- reset
44
    RXSD : in slbit;                    -- receive serial data (uart view)
45
    CLKDIV : out slv(CDWIDTH-1 downto 0); -- clock divider setting
46
    ACT : out slbit;                    -- active; if 1 clkdiv is invalid
47
    DONE : out slbit                    -- resync done
48
  );
49
end serport_uart_autobaud;
50
 
51
 
52
architecture syn of serport_uart_autobaud is
53
 
54
  type state_type is (
55
    s_idle,
56
    s_break,
57
    s_wait,
58
    s_sync
59
  );
60
 
61
  type regs_type is record
62
    ccnt : slv(CDWIDTH-1+3 downto 0);   -- clock divider counter
63
    mcnt : slv7;                        -- msec counter
64
    seen1 : slbit;                      -- seen a '1' in this msec
65
    state : state_type;                 -- state
66
  end record regs_type;
67
 
68
  -- Note on initialization of ccnt:
69
  -- - in the current logic ccnt is incremented n-1 times when n is number
70
  --   clock cycles with a RXD of '0'. When running at 50 MBaud, ccnt will
71
  --   be incremented 7 (not 8!) times.
72
  -- - the three LSBs of ccnt should be at 100 under perfect conditions, this
73
  --   gives the best rounded estimate of CLKDIV.
74
  -- - therefore ccnt is inititialized with 111111.101: 101 + 111 -> 1100 
75
  --   --> ccntinit = -3
76
 
77
  constant ccntinit : slv(CDWIDTH-1+3 downto 0) :=
78
    conv_std_logic_vector(2**(CDWIDTH+3)-3, CDWIDTH+3);
79
  constant mcntzero : slv7 := (others=>'0');
80
  constant mcntlast : slv7 := (others=>'1');
81
  constant regs_init : regs_type := (
82
    conv_std_logic_vector(CDINIT,CDWIDTH)&"000",
83
    (others=>'0'),
84
    '0',
85
    s_idle
86
  );
87
 
88
  signal R_REGS : regs_type := regs_init;  -- state registers
89
  signal N_REGS : regs_type := regs_init;  -- next value state regs
90
 
91
begin
92
 
93
  assert CDINIT <= 2**CDWIDTH-1
94
  report "assert(CDINIT <= 2**CDWIDTH-1): CDINIT too large for given CDWIDTH"
95
  severity FAILURE;
96
 
97
  proc_regs: process (CLK)
98
  begin
99
 
100
    if CLK'event and CLK='1' then
101
      if RESET = '1' then
102
        R_REGS <= regs_init;
103
      else
104
        R_REGS <= N_REGS;
105
      end if;
106
    end if;
107
 
108
  end process proc_regs;
109
 
110
  proc_next: process (R_REGS, CE_MSEC, RESET, RXSD)
111
 
112
    variable r : regs_type := regs_init;
113
    variable n : regs_type := regs_init;
114
 
115
    variable iact : slbit := '0';
116
    variable idone : slbit := '0';
117
 
118
  begin
119
 
120
    r := R_REGS;
121
    n := R_REGS;
122
 
123
    iact  := '1';
124
    idone := '0';
125
 
126
    case r.state is
127
      when s_idle =>                    -- s_idle: idle, detect break --------
128
        iact := '0';
129
        if CE_MSEC = '1' then             -- if end of msec
130
          if r.seen1 = '0' then             -- if no '1' seen on RXD
131
            n.mcnt := unsigned(r.mcnt) + 1;   -- up break timer counter
132
            if r.mcnt = mcntlast then         -- after 127 msec
133
              n.state := s_break;                -- break detected !
134
            end if;
135
          else                              -- otherwise if '1' seen
136
            n.mcnt := mcntzero;               -- clear break timer again
137
          end if;
138
          n.seen1 := RXSD;                  -- latch current RXD value
139
        else                              -- otherwise if not at end-of-msec
140
          n.seen1 := r.seen1 or RXSD;       -- remember whether RXS=1 seen
141
        end if;
142
 
143
      when s_break =>                   -- s_break: detect end of break ------
144
        if RXSD = '1' then                -- if end of break seen 
145
          n.state := s_wait;                -- to s_wait to wait for sync char
146
          n.ccnt := ccntinit;               -- and initialize ccnt
147
        end if;                           -- otherwise stay in s_break
148
 
149
      when s_wait =>                    -- s_wait: wait for sync char --------
150
        if RXSD = '0' then                -- if start bit if sync char seen
151
          n.state := s_sync;                -- to s_sync to wait for end of '0'
152
        end if;                           -- otherwise stay in s_wait
153
 
154
      when s_sync =>                    -- s_sync: wait for end of '0' bits --
155
        if RXSD = '1' then                -- if end of '0' bits seen
156
          n.state := s_idle;                -- to s_idle, autobauding done
157
          idone := '1';                     -- emit done pulse
158
        else                              -- otherwise still in '0' of sync
159
          n.ccnt := unsigned(n.ccnt) + 1;   -- increment ccnt
160
        end if;
161
 
162
      when others => null;              -- -----------------------------------
163
    end case;
164
 
165
    N_REGS <= n;
166
 
167
    CLKDIV <= r.ccnt(CDWIDTH-1+3 downto 3);
168
    ACT    <= iact or RESET;
169
    DONE   <= idone;
170
 
171
  end process proc_next;
172
 
173
end syn;

powered by: WebSVN 2.1.0

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