-
Notifications
You must be signed in to change notification settings - Fork 9
/
simplessi.vhd
250 lines (227 loc) · 7.89 KB
/
simplessi.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.math_real.all;
use ieee.numeric_std.all;
--
-- Copyright (C) 2009, Peter C. Wallace, Mesa Electronics
-- http://www.mesanet.com
--
-- This program is is licensed under a disjunctive dual license giving you
-- the choice of one of the two following sets of free software/open source
-- licensing terms:
--
-- * GNU General Public License (GPL), version 2.0 or later
-- * 3-clause BSD License
--
--
-- The GNU GPL License:
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
--
-- The 3-clause BSD License:
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions
-- are met:
--
-- * Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
--
-- * Redistributions in binary form must reproduce the above
-- copyright notice, this list of conditions and the following
-- disclaimer in the documentation and/or other materials
-- provided with the distribution.
--
-- * Neither the name of Mesa Electronics nor the names of its
-- contributors may be used to endorse or promote products
-- derived from this software without specific prior written
-- permission.
--
--
-- Disclaimer:
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--
-- added 200 ns digital filter to SSI data 7/6/18
-- should skew clock to compensate, next time...
entity SimpleSSI is
generic (
Clock : integer
);
Port ( clk : in std_logic;
ibus : in std_logic_vector(31 downto 0);
obus : out std_logic_vector(31 downto 0);
loadcontrol : in std_logic;
lstart : in std_logic;
pstart : in std_logic;
timers : in std_logic_vector(4 downto 0);
readdata0 : in std_logic;
readdata1 : in std_logic;
readcontrol : in std_logic;
busyout : out std_logic;
davout : out std_logic;
ssiclk : out std_logic;
ssidata : in std_logic
);
end SimpleSSI;
architecture Behavioral of SimpleSSI is
signal BitrateDDSReg : std_logic_vector(15 downto 0);
signal BitrateDDSAccum : std_logic_vector(15 downto 0);
alias DDSMSB : std_logic is BitrateDDSAccum(15);
signal OldDDSMSB: std_logic;
signal BitcountReg : std_logic_vector(6 downto 0);
signal BitCount : std_logic_vector(6 downto 0);
signal SkewReg : std_logic_vector(3 downto 0);
signal SSISreg: std_logic_vector(63 downto 0);
signal SSILatch: std_logic_vector(63 downto 0);
signal Go: std_logic;
signal Start: std_logic;
signal BitZero: std_logic;
signal OldBitZero: std_logic;
signal PStartmask: std_logic;
signal TStartmask: std_logic;
signal TimerSelect: std_logic_vector(2 downto 0);
signal Timer: std_logic;
signal OldTimer: std_logic;
signal TStart: std_logic;
signal MaskFirst: std_logic;
signal SampleTime: std_logic;
signal DAV: std_logic;
constant defaultfilter : real := round((real(Clock)/5000000.0)); --default filter TC is 200 ns
signal FilterReg: std_logic_vector(7 downto 0) := std_logic_vector(to_unsigned(integer(defaultfilter),8));
signal FilterCount: std_logic_vector(7 downto 0);
signal SSIDataD: std_logic;
signal FiltSSIData: std_logic;
begin
assiinterface: process (clk,go,lstart,pstartmask,tstartmask,bitcountreg,
readdata0,readdata1,ssilatch,readcontrol,Timer,Timers,
OldTimer,TimerSelect,TStart,PStart,OldDDSMSB,
BitRateDDSAccum,DAv,BitRateDDSReg)
begin
if clk'event and clk = '1' then
SSIDataD <= ssidata;
if (SSIDataD = '1') and (FilterCount < FilterReg) then -- simple digital filter on rxdata
FilterCount <= FilterCount + 1;
end if;
if (SSIDataD = '0') and (FilterCount /= 0) then
FilterCount <= FilterCount -1;
end if;
if FilterCount >= FilterReg then
FiltSSIData<= '1';
end if;
if FilterCount = 0 then
FiltSSIData<= '0';
end if;
if Start = '1' then
BitCount <= BitCountReg;
Go <= '1';
SSISreg <= (Others => '0');
MaskFirst <= '0';
BitZero <= '0';
end if;
if Go = '1' then
BitRateDDSAccum <= BitRateDDSAccum + BitRateDDSReg;
else
BitRateDDSAccum <= (others => '0');
end if;
if SampleTime = '1' then
if MaskFirst = '1' then
SSISreg <= SSISreg(62 downto 0) & FiltSSIData;
end if;
if BitCount /= "0000000" then
BitCount <= BitCount -1;
MaskFirst <= '1'; -- first clock just latches data so dont shift in
end if;
if BitCount = "0000001" then
BitZero <= '1'; -- at bit count of zero, (delayed count of 1);
else
BitZero <= '0';
end if;
end if;
if BitZero = '0' and OldBitZero = '1' then
Go <= '0';
DAV <= '1';
SSILatch <= SSISReg;
end if;
OldDDSMSB <= DDSMSB;
OldBitZero <= BitZero;
if loadcontrol = '1' then
BitCountReg <= ibus(6 downto 0);
PStartMask <= ibus(8);
TStartMask <= ibus(9);
TimerSelect <= ibus(14 downto 12);
BitRateDDSReg <= ibus(31 downto 16);
end if;
OldTimer <= Timer;
if readdata0 = '1' then
DAV <= '0';
end if;
end if; -- clk
if Timer = '1' and OldTimer = '0' then -- rising edge of selected timer
TStart <= '1';
else
TStart <= '0';
end if;
case TimerSelect is
when "000" => Timer <= timers(0);
when "001" => Timer <= timers(1);
when "010" => Timer <= timers(2);
when "011" => Timer <= timers(3);
when "100" => Timer <= timers(4);
when others => Timer <= Timers(0);
end case;
if lstart = '1' or (TStart = '1' and TStartMask = '1') or (pstart = '1' and PStartMask = '1')then
Start <= '1';
else
Start <= '0';
end if;
SampleTime <= OldDDSMSB and not DDSMSB;
obus <= (others => 'Z');
if readdata0 = '1' then
obus <= SSILatch(31 downto 0);
end if;
if readdata1 = '1' then
obus <= SSILatch(63 downto 32);
end if;
if readcontrol = '1' then
obus(6 downto 0) <= BitCountReg;
obus(7) <= '0';
obus(8) <= PStartMask;
obus(9) <= TStartMask;
obus(10) <= '0';
obus(11) <= Go;
obus(14 downto 12) <= TimerSelect;
obus(15) <= DAV;
obus(31 downto 16) <= BitRateDDSReg;
end if;
ssiclk <= not DDSMSB; -- hold time is guaranteed by two directional propagation delay
busyout <= Go or (not DAV);
davout <= DAV;
end process assiinterface;
end Behavioral;