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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [rtl/] [sys_gen/] [tst_serloop/] [tst_serloop.vhd] - Blame information for rev 16

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

Line No. Rev Author Line
1 16 wfjm
-- $Id: tst_serloop.vhd 441 2011-12-20 17:01:16Z mueller $
2
--
3
-- Copyright 2011- 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:    tst_serloop - syn
16
-- Description:    simple stand-alone tester for serport components
17
--
18
-- Dependencies:   -
19
-- Test bench:     -
20
--
21
-- Target Devices: generic
22
-- Tool versions:  xst 13.1; ghdl 0.29
23
--
24
-- Revision History: 
25
-- Date         Rev Version  Comment
26
-- 2011-12-10   438   1.0.2  clr fecnt when abact; add rxui(cnt|dat) regs
27
-- 2011-12-09   437   1.0.1  rename serport stat->moni port
28
-- 2011-11-06   420   1.0    Initial version
29
-- 2011-10-14   416   0.5    First draft
30
------------------------------------------------------------------------------
31
 
32
library ieee;
33
use ieee.std_logic_1164.all;
34
use ieee.numeric_std.all;
35
 
36
use work.slvtypes.all;
37
use work.serport.all;
38
use work.tst_serlooplib.all;
39
 
40
-- ----------------------------------------------------------------------------
41
 
42
entity tst_serloop is                   -- tester for serport components
43
  port (
44
    CLK : in slbit;                     -- clock
45
    RESET : in slbit;                   -- reset
46
    CE_MSEC : in slbit;                 -- msec pulse
47
    HIO_CNTL : in hio_cntl_type;        -- humanio controls
48
    HIO_STAT : out hio_stat_type;       -- humanio status
49
    SER_MONI : in serport_moni_type;    -- serport monitor
50
    RXDATA : in slv8;                   -- receiver data out
51
    RXVAL : in slbit;                   -- receiver data valid
52
    RXHOLD : out slbit;                 -- receiver data hold
53
    TXDATA : out slv8;                  -- transmit data in
54
    TXENA : out slbit;                  -- transmit data enable
55
    TXBUSY : in slbit                   -- transmit busy
56
  );
57
end tst_serloop;
58
 
59
architecture syn of tst_serloop is
60
 
61
  type regs_type is record
62
    rxdata : slv8;                      -- next rx char
63
    txdata : slv8;                      -- next tx char
64
    rxfecnt : slv16;                    -- rx frame error counter
65
    rxoecnt : slv16;                    -- rx overrun error counter
66
    rxsecnt : slv16;                    -- rx sequence error counter
67
    rxcnt : slv32;                      -- rx char counter
68
    txcnt : slv32;                      -- tx char counter
69
    rxuicnt : slv8;                     -- rx unsolicited input counter
70
    rxuidat : slv8;                     -- rx unsolicited input data
71
    rxokcnt : slv16;                    -- rxok 1->0 transition counter
72
    txokcnt : slv16;                    -- txok 1->0 transition counter
73
    rxok_1 : slbit;                     -- rxok last cycle
74
    txok_1 : slbit;                     -- txok last cycle
75
    rxthrottle : slbit;                 -- rx throttle flag
76
  end record regs_type;
77
 
78
  constant regs_init : regs_type := (
79
    (others=>'0'),                      -- rxdata
80
    (others=>'0'),                      -- txdata
81
    (others=>'0'),                      -- rxfecnt
82
    (others=>'0'),                      -- rxoecnt
83
    (others=>'0'),                      -- rxsecnt
84
    (others=>'0'),                      -- rxcnt
85
    (others=>'0'),                      -- txcnt
86
    (others=>'0'),                      -- rxuicnt
87
    (others=>'0'),                      -- rxuidat
88
    (others=>'0'),                      -- rxokcnt
89
    (others=>'0'),                      -- txokcnt
90
    '0','0',                            -- rxok_1,txok_1
91
    '0'                                 -- rxthrottle
92
  );
93
 
94
  signal R_REGS : regs_type := regs_init;  -- state registers
95
  signal N_REGS : regs_type := regs_init;  -- next value state regs
96
 
97
begin
98
 
99
  proc_regs: process (CLK)
100
  begin
101
 
102
    if rising_edge(CLK) then
103
      if RESET = '1' then
104
        R_REGS <= regs_init;
105
      else
106
        R_REGS <= N_REGS;
107
      end if;
108
    end if;
109
 
110
  end process proc_regs;
111
 
112
  proc_next: process (R_REGS, CE_MSEC, HIO_CNTL, SER_MONI,
113
                      RXDATA, RXVAL, TXBUSY)
114
 
115
    variable r : regs_type := regs_init;
116
    variable n : regs_type := regs_init;
117
 
118
    variable irxhold : slbit := '1';
119
    variable itxena  : slbit := '0';
120
    variable itxdata : slv8 := (others=>'0');
121
    variable skipxon : slbit := '0';
122
 
123
    function nextchar(skipxon: in slbit; data: in slv8) return slv8 is
124
      variable inc : slv8 := (others=>'0');
125
    begin
126
      inc := "00000001";
127
      if skipxon='1' and (data=c_serport_xon or data=c_serport_xoff) then
128
        inc := "00000010";
129
      end if;
130
      return slv(unsigned(data)+unsigned(inc));
131
    end function nextchar;
132
 
133
  begin
134
    r := R_REGS;
135
    n := R_REGS;
136
 
137
    irxhold := '1';
138
    itxena  := '0';
139
 
140
    itxdata  := RXDATA;
141
    if HIO_CNTL.mode = c_mode_txblast then
142
      itxdata := r.txdata;
143
    end if;
144
 
145
    skipxon := '0';
146
    if HIO_CNTL.enaxon='1' and HIO_CNTL.enaesc='0'  then
147
      skipxon := '1';
148
    end if;
149
 
150
    if HIO_CNTL.enathrottle = '1' then
151
      if CE_MSEC = '1' then
152
        n.rxthrottle := not r.rxthrottle;
153
      end if;
154
    else
155
      n.rxthrottle := '0';
156
    end if;
157
 
158
 
159
    case HIO_CNTL.mode is
160
      when c_mode_idle =>
161
        null;
162
 
163
      when c_mode_rxblast =>
164
        if RXVAL='1' and r.rxthrottle='0' then
165
          irxhold := '0';
166
          if RXDATA /= r.rxdata then
167
            n.rxsecnt := slv(unsigned(r.rxsecnt) + 1);
168
          end if;
169
          n.rxdata := nextchar(skipxon, RXDATA);
170
        end if;
171
 
172
      when c_mode_txblast =>
173
        if TXBUSY = '0' then
174
          itxena := '1';
175
          n.txdata := nextchar(skipxon, r.txdata);
176
        end if;
177
        irxhold := '0';
178
        if RXVAL = '1' then
179
          n.rxuicnt := slv(unsigned(r.rxuicnt) + 1);
180
          n.rxuidat := RXDATA;
181
        end if;
182
 
183
      when c_mode_loop =>
184
        if RXVAL='1' and r.rxthrottle='0' and TXBUSY = '0' then
185
          irxhold := '0';
186
          itxena  := '1';
187
        end if;
188
 
189
      when others => null;
190
    end case;
191
 
192
 
193
    if SER_MONI.abact = '1' then        -- if auto bauder active 
194
      n.rxfecnt := (others=>'0');         -- reset frame error counter
195
    else                                -- otherwise
196
      if SER_MONI.rxerr = '1' then        -- count rx frame errors
197
        n.rxfecnt := slv(unsigned(r.rxfecnt) + 1);
198
      end if;
199
    end if;
200
 
201
    if SER_MONI.rxovr = '1' then
202
      n.rxoecnt := slv(unsigned(r.rxoecnt) + 1);
203
    end if;
204
 
205
    if RXVAL='1' and irxhold='0' then
206
      n.rxcnt := slv(unsigned(r.rxcnt) + 1);
207
    end if;
208
 
209
    if itxena = '1' then
210
      n.txcnt := slv(unsigned(r.txcnt) + 1);
211
    end if;
212
 
213
    n.rxok_1 := SER_MONI.rxok;
214
    n.txok_1 := SER_MONI.txok;
215
 
216
    if SER_MONI.rxok='0' and r.rxok_1='1' then
217
      n.rxokcnt := slv(unsigned(r.rxokcnt) + 1);
218
    end if;
219
    if SER_MONI.txok='0' and r.txok_1='1' then
220
      n.txokcnt := slv(unsigned(r.txokcnt) + 1);
221
    end if;
222
 
223
    N_REGS <= n;
224
 
225
    RXHOLD <= irxhold;
226
    TXENA  <= itxena;
227
    TXDATA <= itxdata;
228
 
229
    HIO_STAT.rxfecnt <= r.rxfecnt;
230
    HIO_STAT.rxoecnt <= r.rxoecnt;
231
    HIO_STAT.rxsecnt <= r.rxsecnt;
232
    HIO_STAT.rxcnt   <= r.rxcnt;
233
    HIO_STAT.txcnt   <= r.txcnt;
234
    HIO_STAT.rxuicnt <= r.rxuicnt;
235
    HIO_STAT.rxuidat <= r.rxuidat;
236
    HIO_STAT.rxokcnt <= r.rxokcnt;
237
    HIO_STAT.txokcnt <= r.txokcnt;
238
 
239
  end process proc_next;
240
 
241
end syn;

powered by: WebSVN 2.1.0

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