| 1 |
2 |
jorisvr |
--
|
| 2 |
|
|
-- SpaceWire VHDL package
|
| 3 |
|
|
--
|
| 4 |
|
|
|
| 5 |
|
|
library ieee;
|
| 6 |
|
|
use ieee.std_logic_1164.all;
|
| 7 |
|
|
|
| 8 |
|
|
package spwpkg is
|
| 9 |
|
|
|
| 10 |
|
|
|
| 11 |
|
|
-- Indicates a platform-specific implementation.
|
| 12 |
|
|
type spw_implementation_type is ( impl_generic, impl_fast );
|
| 13 |
|
|
|
| 14 |
|
|
|
| 15 |
|
|
-- Input signals to spwlink.
|
| 16 |
|
|
type spw_link_in_type is record
|
| 17 |
|
|
|
| 18 |
|
|
-- Enables automatic link start on receipt of a NULL character.
|
| 19 |
|
|
autostart: std_logic;
|
| 20 |
|
|
|
| 21 |
|
|
-- Enables link start once the Ready state is reached.
|
| 22 |
|
|
-- Without either "autostart" or "linkstart", the link remains in
|
| 23 |
|
|
-- state Ready.
|
| 24 |
|
|
linkstart: std_logic;
|
| 25 |
|
|
|
| 26 |
|
|
-- Do not start link (overrides "linkstart" and "autostart") and/or
|
| 27 |
|
|
-- disconnect the currently running link.
|
| 28 |
|
|
linkdis: std_logic;
|
| 29 |
|
|
|
| 30 |
|
|
-- Number of bytes available in the receive buffer. Used to for
|
| 31 |
|
|
-- flow-control operation. At least 8 bytes must be available
|
| 32 |
|
|
-- initially, otherwise the link can not start. Values larger than 63
|
| 33 |
|
|
-- are irrelevant and may be presented as 63. The available room may
|
| 34 |
|
|
-- decrease by one byte due to the reception of an N-Char; in that case
|
| 35 |
|
|
-- the "rxroom" signal must be updated on the clock following the clock
|
| 36 |
|
|
-- on which "rxchar" is high. Under no other circumstances may "rxroom"
|
| 37 |
|
|
-- be decreased.
|
| 38 |
|
|
rxroom: std_logic_vector(5 downto 0);
|
| 39 |
|
|
|
| 40 |
|
|
-- High for one clock cycle to request transmission of a TimeCode.
|
| 41 |
|
|
-- The request is registered inside spwxmit until it can be processed.
|
| 42 |
|
|
tick_in: std_logic;
|
| 43 |
|
|
|
| 44 |
|
|
-- Control bits of the TimeCode to be sent.
|
| 45 |
|
|
-- Must be valid while tick_in is high.
|
| 46 |
|
|
ctrl_in: std_logic_vector(1 downto 0);
|
| 47 |
|
|
|
| 48 |
|
|
-- Counter value of the TimeCode to be sent.
|
| 49 |
|
|
-- Must be valid while tick_in is high.
|
| 50 |
|
|
time_in: std_logic_vector(5 downto 0);
|
| 51 |
|
|
|
| 52 |
|
|
-- Requests transmission of an N-Char.
|
| 53 |
|
|
-- Keep this signal high until confirmed by "txack".
|
| 54 |
|
|
txwrite: std_logic;
|
| 55 |
|
|
|
| 56 |
|
|
-- Control flag to be sent with the next N-Char.
|
| 57 |
|
|
-- Must be valid while "txwrite" is high.
|
| 58 |
|
|
txflag: std_logic;
|
| 59 |
|
|
|
| 60 |
|
|
-- Byte to be sent, or "00000000" for EOP or "00000001" for EEP.
|
| 61 |
|
|
-- Must be valid while "txwrite" is high.
|
| 62 |
|
|
txdata: std_logic_vector(7 downto 0);
|
| 63 |
|
|
end record;
|
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
-- Output signals from spwlink.
|
| 67 |
|
|
type spw_link_out_type is record
|
| 68 |
|
|
|
| 69 |
|
|
-- High if the link state machine is currently in state Started.
|
| 70 |
|
|
started: std_logic;
|
| 71 |
|
|
|
| 72 |
|
|
-- High if the link state machine is currently in state Connecting.
|
| 73 |
|
|
connecting: std_logic;
|
| 74 |
|
|
|
| 75 |
|
|
-- High if the link state machine is currently in state Run.
|
| 76 |
|
|
running: std_logic;
|
| 77 |
|
|
|
| 78 |
|
|
-- Disconnect detected in state Run. Triggers a reset and reconnect.
|
| 79 |
|
|
-- This indication is auto-clearing.
|
| 80 |
|
|
errdisc: std_logic;
|
| 81 |
|
|
|
| 82 |
|
|
-- Parity error detected in state Run. Triggers a reset and reconnect.
|
| 83 |
|
|
-- This indication is auto-clearing.
|
| 84 |
|
|
errpar: std_logic;
|
| 85 |
|
|
|
| 86 |
|
|
-- Invalid escape sequence detected in state Run.
|
| 87 |
|
|
-- Triggers a reset and reconnect; auto-clearing.
|
| 88 |
|
|
erresc: std_logic;
|
| 89 |
|
|
|
| 90 |
|
|
-- Credit error detected. Triggers a reset and reconnect.
|
| 91 |
|
|
-- This indication is auto-clearing.
|
| 92 |
|
|
errcred: std_logic;
|
| 93 |
|
|
|
| 94 |
|
|
-- High to confirm the transmission of an N-Char.
|
| 95 |
|
|
-- This is a Wishbone-style handshake signal. It has a combinatorial
|
| 96 |
|
|
-- dependency on "txwrite".
|
| 97 |
|
|
txack: std_logic;
|
| 98 |
|
|
|
| 99 |
|
|
-- High for one clock cycle if a TimeCode was just received.
|
| 100 |
|
|
-- Verification of the TimeCode as described in 8.12.2 of ECSS-E-50
|
| 101 |
|
|
-- is not implemented; all received timecodes are reported.
|
| 102 |
|
|
tick_out: std_logic;
|
| 103 |
|
|
|
| 104 |
|
|
-- Control bits of last received TimeCode.
|
| 105 |
|
|
ctrl_out: std_logic_vector(1 downto 0);
|
| 106 |
|
|
|
| 107 |
|
|
-- Counter value of last received TimeCode.
|
| 108 |
|
|
time_out: std_logic_vector(5 downto 0);
|
| 109 |
|
|
|
| 110 |
|
|
-- High for one clock cycle if an N-Char (data byte or EOP or EEP) was
|
| 111 |
|
|
-- just received. The data bits must be accepted immediately from
|
| 112 |
|
|
-- "rxflag" and "rxdata".
|
| 113 |
|
|
rxchar: std_logic;
|
| 114 |
|
|
|
| 115 |
|
|
-- High if the received character is EOP or EEP, low if it is a data
|
| 116 |
|
|
-- byte. Valid when "rxchar" is high.
|
| 117 |
|
|
rxflag: std_logic;
|
| 118 |
|
|
|
| 119 |
|
|
|
| 120 |
|
|
-- Received byte, or "00000000" for EOP or "00000001" for EEP.
|
| 121 |
|
|
-- Valid when "rxchar" is high.
|
| 122 |
|
|
rxdata: std_logic_vector(7 downto 0);
|
| 123 |
|
|
end record;
|
| 124 |
|
|
|
| 125 |
|
|
|
| 126 |
|
|
-- Output signals from spwrecv to spwlink.
|
| 127 |
|
|
type spw_recv_out_type is record
|
| 128 |
|
|
|
| 129 |
|
|
-- High if at least one signal change was seen since enable.
|
| 130 |
|
|
-- Resets to low when rxen is low.
|
| 131 |
|
|
gotbit: std_logic;
|
| 132 |
|
|
|
| 133 |
|
|
-- High if at least one valid NULL pattern was detected since enable.
|
| 134 |
|
|
-- Resets to low when rxen is low.
|
| 135 |
|
|
gotnull: std_logic;
|
| 136 |
|
|
|
| 137 |
|
|
-- High for one clock cycle if an FCT token was just received.
|
| 138 |
|
|
gotfct: std_logic;
|
| 139 |
|
|
|
| 140 |
|
|
-- High for one clock cycle if a TimeCode was just received.
|
| 141 |
|
|
tick_out: std_logic;
|
| 142 |
|
|
|
| 143 |
|
|
-- Control bits of last received TimeCode.
|
| 144 |
|
|
ctrl_out: std_logic_vector(1 downto 0);
|
| 145 |
|
|
|
| 146 |
|
|
-- Counter value of last received TimeCode.
|
| 147 |
|
|
time_out: std_logic_vector(5 downto 0);
|
| 148 |
|
|
|
| 149 |
|
|
-- High for one clock cycle if an N-Char (data byte or EOP/EEP) was just received.
|
| 150 |
|
|
rxchar: std_logic;
|
| 151 |
|
|
|
| 152 |
|
|
-- High if rxchar is high and the received character is EOP or EEP.
|
| 153 |
|
|
-- Low if rxchar is high and the received character is a data byte.
|
| 154 |
|
|
rxflag: std_logic;
|
| 155 |
|
|
|
| 156 |
|
|
-- Received byte, or "00000000" for EOP or "00000001" for EEP.
|
| 157 |
|
|
-- Valid when "rxchar" is high.
|
| 158 |
|
|
rxdata: std_logic_vector(7 downto 0);
|
| 159 |
|
|
|
| 160 |
|
|
-- Disconnect detected (after a signal change was seen).
|
| 161 |
|
|
-- Resets to low when rxen is low or when a signal change is seen.
|
| 162 |
|
|
errdisc: std_logic;
|
| 163 |
|
|
|
| 164 |
|
|
-- Parity error detected (after a valid NULL pattern was seen).
|
| 165 |
|
|
-- Sticky; resets to low when rxen is low.
|
| 166 |
|
|
errpar: std_logic;
|
| 167 |
|
|
|
| 168 |
|
|
-- Escape sequence error detected (after a valid NULL pattern was seen).
|
| 169 |
|
|
-- Sticky; resets to low when rxen is low.
|
| 170 |
|
|
erresc: std_logic;
|
| 171 |
|
|
end record;
|
| 172 |
|
|
|
| 173 |
|
|
|
| 174 |
|
|
-- Input signals to spwxmit from spwlink.
|
| 175 |
|
|
type spw_xmit_in_type is record
|
| 176 |
|
|
|
| 177 |
|
|
-- High to enable transmitter; low to disable and reset transmitter.
|
| 178 |
|
|
txen: std_logic;
|
| 179 |
|
|
|
| 180 |
|
|
-- Indicates that only NULL characters may be transmitted.
|
| 181 |
|
|
stnull: std_logic;
|
| 182 |
|
|
|
| 183 |
|
|
-- Indicates that only NULL and/or FCT characters may be transmitted.
|
| 184 |
|
|
stfct: std_logic;
|
| 185 |
|
|
|
| 186 |
|
|
-- Requests transmission of an FCT character.
|
| 187 |
|
|
-- Keep this signal high until confirmed by "fctack".
|
| 188 |
|
|
fct_in: std_logic;
|
| 189 |
|
|
|
| 190 |
|
|
-- High for one clock cycle to request transmission of a TimeCode.
|
| 191 |
|
|
-- The request is registered inside spwxmit until it can be processed.
|
| 192 |
|
|
tick_in: std_logic;
|
| 193 |
|
|
|
| 194 |
|
|
-- Control bits of the TimeCode to be sent.
|
| 195 |
|
|
-- Must be valid while "tick_in" is high.
|
| 196 |
|
|
ctrl_in: std_logic_vector(1 downto 0);
|
| 197 |
|
|
|
| 198 |
|
|
-- Counter value of the TimeCode to be sent.
|
| 199 |
|
|
-- Must be valid while "tick_in" is high.
|
| 200 |
|
|
time_in: std_logic_vector(5 downto 0);
|
| 201 |
|
|
|
| 202 |
|
|
-- Request transmission of an N-Char.
|
| 203 |
|
|
-- Keep this signal high until confirmed by "txack".
|
| 204 |
|
|
txwrite: std_logic;
|
| 205 |
|
|
|
| 206 |
|
|
-- Control flag to be sent with the next N-Char.
|
| 207 |
|
|
-- Must be valid while "txwrite" is high.
|
| 208 |
|
|
txflag: std_logic;
|
| 209 |
|
|
|
| 210 |
|
|
-- Byte to send, or "00000000" for EOP or "00000001" for EEP.
|
| 211 |
|
|
-- Must be valid while "txwrite" is high.
|
| 212 |
|
|
txdata: std_logic_vector(7 downto 0);
|
| 213 |
|
|
end record;
|
| 214 |
|
|
|
| 215 |
|
|
|
| 216 |
|
|
-- Output signals from spwxmit to spwlink.
|
| 217 |
|
|
type spw_xmit_out_type is record
|
| 218 |
|
|
|
| 219 |
|
|
-- High to confirm transmission on an FCT character.
|
| 220 |
|
|
-- This is a Wishbone-style handshaking signal; it is combinatorially
|
| 221 |
|
|
-- dependent on "fct_in".
|
| 222 |
|
|
fctack: std_logic;
|
| 223 |
|
|
|
| 224 |
|
|
-- High to confirm transmission of an N-Char.
|
| 225 |
|
|
-- This is a Wishbone-style handshaking signal; it is combinatorially
|
| 226 |
|
|
-- dependent on both "fct_in" and "txwrite".
|
| 227 |
|
|
txack: std_logic;
|
| 228 |
|
|
end record;
|
| 229 |
|
|
|
| 230 |
|
|
|
| 231 |
|
|
-- Character-stream interface
|
| 232 |
|
|
component spwstream is
|
| 233 |
|
|
generic (
|
| 234 |
|
|
sysfreq: real; -- clk freq in Hz
|
| 235 |
3 |
jorisvr |
txclkfreq: real := 0.0; -- txclk freq in Hz
|
| 236 |
2 |
jorisvr |
rximpl: spw_implementation_type := impl_generic;
|
| 237 |
|
|
rxchunk: integer range 1 to 4 := 1; -- max bits per clk
|
| 238 |
|
|
tximpl: spw_implementation_type := impl_generic;
|
| 239 |
|
|
rxfifosize_bits: integer range 6 to 14 := 11; -- rx fifo size
|
| 240 |
|
|
txfifosize_bits: integer range 2 to 14 := 11 -- tx fifo size
|
| 241 |
|
|
);
|
| 242 |
|
|
port (
|
| 243 |
|
|
clk: in std_logic; -- system clock
|
| 244 |
|
|
rxclk: in std_logic; -- receiver sample clock
|
| 245 |
|
|
txclk: in std_logic; -- transmit clock
|
| 246 |
|
|
rst: in std_logic; -- synchronous reset
|
| 247 |
|
|
autostart: in std_logic; -- automatic link start
|
| 248 |
|
|
linkstart: in std_logic; -- forced link start
|
| 249 |
|
|
linkdis: in std_logic; -- stop link
|
| 250 |
|
|
txdivcnt: in std_logic_vector(7 downto 0); -- tx scale factor
|
| 251 |
|
|
tick_in: in std_logic; -- request timecode xmit
|
| 252 |
|
|
ctrl_in: in std_logic_vector(1 downto 0);
|
| 253 |
|
|
time_in: in std_logic_vector(5 downto 0);
|
| 254 |
|
|
txwrite: in std_logic; -- request character xmit
|
| 255 |
|
|
txflag: in std_logic; -- control flag of tx char
|
| 256 |
|
|
txdata: in std_logic_vector(7 downto 0);
|
| 257 |
|
|
txrdy: out std_logic; -- room in tx fifo
|
| 258 |
|
|
txhalff: out std_logic; -- tx fifo half full
|
| 259 |
|
|
tick_out: out std_logic; -- timecode received
|
| 260 |
|
|
ctrl_out: out std_logic_vector(1 downto 0);
|
| 261 |
|
|
time_out: out std_logic_vector(5 downto 0);
|
| 262 |
|
|
rxvalid: out std_logic; -- rx fifo not empty
|
| 263 |
|
|
rxhalff: out std_logic; -- rx fifo half full
|
| 264 |
|
|
rxflag: out std_logic; -- control flag of rx char
|
| 265 |
|
|
rxdata: out std_logic_vector(7 downto 0);
|
| 266 |
|
|
rxread: in std_logic; -- accept rx character
|
| 267 |
|
|
started: out std_logic; -- link in Started state
|
| 268 |
|
|
connecting: out std_logic; -- link in Connecting state
|
| 269 |
|
|
running: out std_logic; -- link in Run state
|
| 270 |
|
|
errdisc: out std_logic; -- disconnect error
|
| 271 |
|
|
errpar: out std_logic; -- parity error
|
| 272 |
|
|
erresc: out std_logic; -- escape error
|
| 273 |
|
|
errcred: out std_logic; -- credit error
|
| 274 |
|
|
spw_di: in std_logic;
|
| 275 |
|
|
spw_si: in std_logic;
|
| 276 |
|
|
spw_do: out std_logic;
|
| 277 |
|
|
spw_so: out std_logic
|
| 278 |
|
|
);
|
| 279 |
|
|
end component spwstream;
|
| 280 |
|
|
|
| 281 |
|
|
|
| 282 |
|
|
-- Link Level Interface
|
| 283 |
|
|
component spwlink is
|
| 284 |
|
|
generic (
|
| 285 |
|
|
reset_time: integer -- reset time in clocks (6.4 us)
|
| 286 |
|
|
);
|
| 287 |
|
|
port (
|
| 288 |
|
|
clk: in std_logic; -- system clock
|
| 289 |
|
|
rst: in std_logic; -- synchronous reset (active-high)
|
| 290 |
|
|
linki: in spw_link_in_type;
|
| 291 |
|
|
linko: out spw_link_out_type;
|
| 292 |
|
|
rxen: out std_logic;
|
| 293 |
|
|
recvo: in spw_recv_out_type;
|
| 294 |
|
|
xmiti: out spw_xmit_in_type;
|
| 295 |
|
|
xmito: in spw_xmit_out_type
|
| 296 |
|
|
);
|
| 297 |
|
|
end component spwlink;
|
| 298 |
|
|
|
| 299 |
|
|
|
| 300 |
|
|
-- Receiver
|
| 301 |
|
|
component spwrecv is
|
| 302 |
|
|
generic (
|
| 303 |
|
|
disconnect_time: integer range 1 to 255; -- disconnect period in system clock cycles
|
| 304 |
|
|
rxchunk: integer range 1 to 4 -- nr of bits per system clock
|
| 305 |
|
|
);
|
| 306 |
|
|
port (
|
| 307 |
|
|
clk: in std_logic; -- system clock
|
| 308 |
|
|
rxen: in std_logic; -- receiver enabled
|
| 309 |
|
|
recvo: out spw_recv_out_type;
|
| 310 |
|
|
inact: in std_logic;
|
| 311 |
|
|
inbvalid: in std_logic;
|
| 312 |
|
|
inbits: in std_logic_vector(rxchunk-1 downto 0)
|
| 313 |
|
|
);
|
| 314 |
|
|
end component spwrecv;
|
| 315 |
|
|
|
| 316 |
|
|
|
| 317 |
|
|
-- Transmitter (generic implementation)
|
| 318 |
|
|
component spwxmit is
|
| 319 |
|
|
port (
|
| 320 |
|
|
clk: in std_logic; -- system clock
|
| 321 |
|
|
rst: in std_logic; -- synchronous reset (active-high)
|
| 322 |
|
|
divcnt: in std_logic_vector(7 downto 0);
|
| 323 |
|
|
xmiti: in spw_xmit_in_type;
|
| 324 |
|
|
xmito: out spw_xmit_out_type;
|
| 325 |
|
|
spw_do: out std_logic; -- tx data to SPW bus
|
| 326 |
|
|
spw_so: out std_logic -- tx strobe to SPW bus
|
| 327 |
|
|
);
|
| 328 |
|
|
end component spwxmit;
|
| 329 |
|
|
|
| 330 |
|
|
|
| 331 |
|
|
-- Transmitter (separate tx clock domain)
|
| 332 |
|
|
component spwxmit_fast is
|
| 333 |
|
|
port (
|
| 334 |
|
|
clk: in std_logic; -- system clock
|
| 335 |
|
|
txclk: in std_logic; -- transmit clock
|
| 336 |
|
|
rst: in std_logic; -- synchronous reset (active-high)
|
| 337 |
|
|
divcnt: in std_logic_vector(7 downto 0);
|
| 338 |
|
|
xmiti: in spw_xmit_in_type;
|
| 339 |
|
|
xmito: out spw_xmit_out_type;
|
| 340 |
|
|
spw_do: out std_logic; -- tx data to SPW bus
|
| 341 |
|
|
spw_so: out std_logic -- tx strobe to SPW bus
|
| 342 |
|
|
);
|
| 343 |
|
|
end component spwxmit_fast;
|
| 344 |
|
|
|
| 345 |
|
|
|
| 346 |
|
|
-- Front-end for SpaceWire Receiver (generic implementation)
|
| 347 |
|
|
component spwrecvfront_generic is
|
| 348 |
|
|
port (
|
| 349 |
|
|
clk: in std_logic; -- system clock
|
| 350 |
|
|
rxen: in std_logic; -- high to enable receiver
|
| 351 |
|
|
inact: out std_logic; -- high if activity on input
|
| 352 |
|
|
inbvalid: out std_logic; -- high if inbits contains a valid received bit
|
| 353 |
|
|
inbits: out std_logic_vector(0 downto 0); -- received bit
|
| 354 |
|
|
spw_di: in std_logic; -- Data In signal from SpaceWire bus
|
| 355 |
|
|
spw_si: in std_logic -- Strobe In signal from SpaceWire bus
|
| 356 |
|
|
);
|
| 357 |
|
|
end component spwrecvfront_generic;
|
| 358 |
|
|
|
| 359 |
|
|
|
| 360 |
|
|
-- Front-end for SpaceWire Receiver (separate rx clock domain)
|
| 361 |
|
|
component spwrecvfront_fast is
|
| 362 |
|
|
generic (
|
| 363 |
|
|
rxchunk: integer range 1 to 4 -- max number of bits per system clock
|
| 364 |
|
|
);
|
| 365 |
|
|
port (
|
| 366 |
|
|
clk: in std_logic; -- system clock
|
| 367 |
|
|
rxclk: in std_logic; -- sample clock (DDR)
|
| 368 |
|
|
rxen: in std_logic; -- high to enable receiver
|
| 369 |
|
|
inact: out std_logic; -- high if activity on input
|
| 370 |
|
|
inbvalid: out std_logic; -- high if inbits contains a valid group of received bits
|
| 371 |
|
|
inbits: out std_logic_vector(rxchunk-1 downto 0); -- received bits
|
| 372 |
|
|
spw_di: in std_logic; -- Data In signal from SpaceWire bus
|
| 373 |
|
|
spw_si: in std_logic -- Strobe In signal from SpaceWire bus
|
| 374 |
|
|
);
|
| 375 |
|
|
end component spwrecvfront_fast;
|
| 376 |
|
|
|
| 377 |
|
|
|
| 378 |
|
|
-- Synchronous dual-port memory.
|
| 379 |
|
|
component spwram is
|
| 380 |
|
|
generic (
|
| 381 |
|
|
abits: integer;
|
| 382 |
|
|
dbits: integer );
|
| 383 |
|
|
port (
|
| 384 |
|
|
rclk: in std_logic;
|
| 385 |
|
|
wclk: in std_logic;
|
| 386 |
|
|
ren: in std_logic;
|
| 387 |
|
|
raddr: in std_logic_vector(abits-1 downto 0);
|
| 388 |
|
|
rdata: out std_logic_vector(dbits-1 downto 0);
|
| 389 |
|
|
wen: in std_logic;
|
| 390 |
|
|
waddr: in std_logic_vector(abits-1 downto 0);
|
| 391 |
|
|
wdata: in std_logic_vector(dbits-1 downto 0) );
|
| 392 |
|
|
end component spwram;
|
| 393 |
|
|
|
| 394 |
|
|
end package;
|