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

Subversion Repositories manchesterwireless

[/] [manchesterwireless/] [tags/] [release-1.0/] [singleDouble/] [singleDouble.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kingmu
-----------------------------------------------------------------------------
2
--      Copyright (C) 2009 José Rodríguez-Navarro
3
--
4
-- This code is free software; you can redistribute it and/or
5
-- modify it under the terms of the GNU Lesser General Public
6
-- License as published by the Free Software Foundation; either
7
-- version 2.1 of the License, or (at your option) any later version.
8
--
9
-- This code is distributed in the hope that it will be useful,
10
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
-- Lesser General Public License for more details.
13
--
14 3 kingmu
--  Identify single/double ones/zeros based on length 
15
--  of time data_i is high/low
16 2 kingmu
--
17
--  Revision  Date        Author                Comment
18
--  --------  ----------  --------------------  ----------------
19
--  1.0       20/02/09    J. Rodriguez-Navarro  Initial revision
20 3 kingmu
--  Future revisions tracked in Subversion at OpenCores.org
21
--  under the manchesterwireless project
22 2 kingmu
-----------------------------------------------------------------------------
23
 
24
library ieee;
25
use ieee.std_logic_1164.all;
26
use ieee.std_logic_arith.all;
27
use work.globals.all;
28
 
29
--------------------------------------------------------------------------------
30
 
31 3 kingmu
entity singleDouble is
32 2 kingmu
  port (
33
    clk_i   :  in  std_logic;
34
    ce_i    :  in  std_logic;
35
    rst_i   :  in  std_logic;
36
    data_i  :  in  std_logic;
37
    q_o     :  out std_logic_vector(3 downto 0);
38
    ready_o :  out std_logic
39
  );
40 3 kingmu
end;
41 2 kingmu
 
42
--------------------------------------------------------------------------------
43
--------------------------------------------------------------------------------
44
 
45 3 kingmu
architecture behavioral of singleDouble is
46 2 kingmu
 
47 3 kingmu
  signal transition_n:   std_logic;
48
  signal transition_i:   std_logic;
49 2 kingmu
 
50 3 kingmu
  signal count_ones    : integer range 0 to INTERVAL_MAX_DOUBLE;
51
  signal count_ones_n  : integer range 0 to INTERVAL_MAX_DOUBLE;
52
  signal count_zeros   : integer range 0 to INTERVAL_MAX_DOUBLE;
53
  signal count_zeros_n : integer range 0 to INTERVAL_MAX_DOUBLE;
54 2 kingmu
 
55 3 kingmu
  signal single_one:      std_logic;
56
  signal double_one:      std_logic;
57
  signal single_zero:     std_logic;
58
  signal double_zero:     std_logic;
59 2 kingmu
 
60 3 kingmu
  signal data_i_d  :         std_logic;
61
  signal data_i_d2 :         std_logic;
62
  signal data_i_d3 :         std_logic;
63
  signal data_i_d3b:         std_logic;
64 2 kingmu
 
65 3 kingmu
  begin
66 2 kingmu
 
67 3 kingmu
  --------------------------------------------------------------------------------
68
  -- SEQUENTIAL ------------------------------------------------------------------
69
  --------------------------------------------------------------------------------
70 2 kingmu
 
71 3 kingmu
  -- Domain Clock (clk_i)
72
  process (rst_i, clk_i)
73
  begin
74 2 kingmu
 
75 3 kingmu
    if rst_i = '1' then
76
      data_i_d        <= '1';
77
      data_i_d2       <= '1';
78
      data_i_d3       <= '1';
79
      transition_i    <= '0';
80
      count_ones      <= 0;
81
      count_zeros     <= 0;
82
    elsif (rising_edge(clk_i) and ce_i = '1') then -- posedge
83
      data_i_d3       <= data_i_d2;
84
      data_i_d2       <= data_i_d;
85
      data_i_d        <= data_i;
86
      transition_i    <= transition_n;
87
      count_ones      <= count_ones_n;
88
      count_zeros     <= count_zeros_n;
89
    end if;
90 2 kingmu
 
91 3 kingmu
  end process;
92 2 kingmu
 
93
 
94 3 kingmu
  --------------------------------------------------------------------------------
95
  -- COMBINATIONAL ---------------------------------------------------------------
96
  --------------------------------------------------------------------------------
97 2 kingmu
 
98 3 kingmu
  -- Mark transition when an edge on data_i is detected
99
  transition_n <=  data_i_d xor data_i_d2;
100
  ready_o <= transition_i; -- buffered transition_n
101 2 kingmu
 
102 3 kingmu
  -- Invert and count zeroes
103
  data_i_d3b <= not data_i_d3;
104 2 kingmu
 
105 3 kingmu
  --
106
  -- Increment counters between transitions every posedge clk_i
107
  --
108
  process (transition_i, data_i_d3, data_i_d3b, count_ones, count_zeros)
109
  begin
110 2 kingmu
 
111 3 kingmu
    if transition_i = '1' then
112
      count_ones_n  <= 0;
113
      count_zeros_n <= 0;
114
    else
115
      count_ones_n  <= count_ones + conv_integer(data_i_d3);
116
      count_zeros_n <= count_zeros + conv_integer(data_i_d3b);
117
    end if;
118 2 kingmu
 
119 3 kingmu
  end process;
120 2 kingmu
 
121 3 kingmu
  --
122
  -- map single/double one/zero to output
123
  --
124
  transition : process (transition_i, rst_i)
125
  begin
126 2 kingmu
 
127 3 kingmu
    if (rst_i = '1') then
128
      q_o <= "0000"; -- protocol dictates an inital one. used in connecting entity
129
    elsif rising_edge(transition_i) then
130
      q_o(0) <= single_one;
131
      q_o(1) <= double_one;
132
      q_o(2) <= single_zero;
133
      q_o(3) <= double_zero;
134
    end if;
135 2 kingmu
 
136 3 kingmu
  end process;
137 2 kingmu
 
138 3 kingmu
  --
139
  -- unsigned comparators
140
  --
141
  process(count_ones)
142
  begin
143 2 kingmu
 
144 3 kingmu
    if (count_ones >= INTERVAL_MIN_DOUBLE) and (count_ones <= INTERVAL_MAX_DOUBLE) then
145
      double_one <= '1';
146
    else
147
      double_one <= '0';
148
    end if;
149
    if (count_ones >= INTERVAL_MIN_SINGLE) and (count_ones <= INTERVAL_MAX_SINGLE) then
150
      single_one <= '1';
151
    else
152
      single_one <= '0';
153
    end if;
154 2 kingmu
 
155 3 kingmu
  end process;
156 2 kingmu
 
157 3 kingmu
  process(count_zeros)
158
  begin
159 2 kingmu
 
160 3 kingmu
    if (count_zeros >= INTERVAL_MIN_DOUBLE) and (count_zeros <= INTERVAL_MAX_DOUBLE) then
161
      double_zero <= '1';
162
    else
163
      double_zero <= '0';
164
    end if;
165
    if (count_zeros >= INTERVAL_MIN_SINGLE) and (count_zeros <= INTERVAL_MAX_SINGLE) then
166
      single_zero <= '1';
167
    else
168
      single_zero <= '0';
169
    end if;
170 2 kingmu
 
171 3 kingmu
  end process;
172 2 kingmu
 
173
end;
174
 
175
 

powered by: WebSVN 2.1.0

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