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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 wfjm
-- $Id: serport_xontx.vhd 476 2013-01-26 22:23:53Z mueller $
2 16 wfjm
--
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:    serport_xontx - syn
16
-- Description:    serial port: xon/xoff logic tx path
17
--
18
-- Dependencies:   -
19
-- Test bench:     -
20
-- Target Devices: generic
21
-- Tool versions:  xst 13.1; ghdl 0.29
22
-- Revision History: 
23
-- Date         Rev Version  Comment
24
-- 2011-11-13   425   1.0    Initial version
25
-- 2011-10-22   417   0.5    First draft 
26
------------------------------------------------------------------------------
27
 
28
library ieee;
29
use ieee.std_logic_1164.all;
30
use ieee.numeric_std.all;
31
 
32
use work.slvtypes.all;
33 19 wfjm
use work.serportlib.all;
34 16 wfjm
 
35
entity serport_xontx is                 -- serial port: xon/xoff logic tx path
36
  port (
37
    CLK : in slbit;                     -- clock
38
    RESET : in slbit;                   -- reset
39
    ENAXON : in slbit;                  -- enable xon/xoff handling
40
    ENAESC : in slbit;                  -- enable xon/xoff escaping
41
    UART_TXDATA : out slv8;             -- uart data in
42
    UART_TXENA : out slbit;             -- uart data enable
43
    UART_TXBUSY : in slbit;             -- uart data busy
44
    TXDATA : in slv8;                   -- user data in
45
    TXENA : in slbit;                   -- user data enable
46
    TXBUSY : out slbit;                 -- user data busy
47
    RXOK : in slbit;                    -- rx channel ok
48
    TXOK : in slbit                     -- tx channel ok
49
  );
50
end serport_xontx;
51
 
52
 
53
architecture syn of serport_xontx is
54
 
55
  type regs_type is record
56
    ibuf : slv8;                        -- input buffer
57
    ival : slbit;                       -- ibuf has valid data
58
    obuf : slv8;                        -- output buffer
59
    oval : slbit;                       -- obuf has valid data
60
    rxok : slbit;                       -- rx channel ok state
61
    enaxon_1 : slbit;                   -- last enaxon
62
    escpend : slbit;                    -- escape pending
63
  end record regs_type;
64
 
65
  constant regs_init : regs_type := (
66
    (others=>'0'),'0',                  -- ibuf,ival
67
    (others=>'0'),'0',                  -- obuf,oval
68
    '1',                                -- rxok (startup default is ok !!)
69
    '0',                                -- enaxon_1
70
    '0'                                 -- escpend
71
  );
72
 
73
  signal R_REGS : regs_type := regs_init;  -- state registers
74
  signal N_REGS : regs_type := regs_init;  -- next value state regs
75
 
76
begin
77
 
78
  proc_regs: process (CLK)
79
  begin
80
 
81
    if rising_edge(CLK) then
82
      if RESET = '1' then
83
        R_REGS <= regs_init;
84
      else
85
        R_REGS <= N_REGS;
86
      end if;
87
    end if;
88
 
89
  end process proc_regs;
90
 
91
  proc_next: process (R_REGS, ENAXON, ENAESC, UART_TXBUSY,
92
                      TXDATA, TXENA, RXOK, TXOK)
93
 
94
    variable r : regs_type := regs_init;
95
    variable n : regs_type := regs_init;
96
 
97
  begin
98
 
99
    r := R_REGS;
100
    n := R_REGS;
101
 
102
    if TXENA='1' and r.ival='0' then
103
      n.ibuf := TXDATA;
104
      n.ival := '1';
105
    end if;
106
 
107
    if r.oval = '0' then
108
      if ENAXON='1' and r.rxok/=RXOK then
109
        n.rxok := RXOK;
110
        n.oval := '1';
111
        if r.rxok = '0' then
112
          n.obuf := c_serport_xon;
113
        else
114
          n.obuf := c_serport_xoff;
115
        end if;
116
      elsif TXOK = '1' then
117
        if r.escpend = '1' then
118
          n.obuf := not r.ibuf;
119
          n.oval := '1';
120
          n.escpend := '0';
121
          n.ival := '0';
122
        elsif r.ival = '1' then
123
          if ENAESC='1' and (r.ibuf=c_serport_xon or
124
                             r.ibuf=c_serport_xoff or
125
                             r.ibuf=c_serport_xesc)
126
          then
127
            n.obuf := c_serport_xesc;
128
            n.oval := '1';
129
            n.escpend := '1';
130
          else
131
            n.obuf := r.ibuf;
132
            n.oval := '1';
133
            n.ival := '0';
134
          end if;
135
        end if;
136
      end if;
137
    end if;
138
 
139
    if r.oval='1' and UART_TXBUSY='0' then
140
      n.oval := '0';
141
    end if;
142
 
143
    -- FIXME: document this hack
144
    n.enaxon_1 := ENAXON;
145
    if ENAXON='1' and r.enaxon_1='0' then
146
      n.rxok := not RXOK;
147
    end if;
148
 
149
    N_REGS <= n;
150
 
151
    TXBUSY      <= r.ival;
152
    UART_TXDATA <= r.obuf;
153
    UART_TXENA  <= r.oval;
154
 
155
  end process proc_next;
156
 
157
end syn;

powered by: WebSVN 2.1.0

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