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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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