| 1 |
47 |
magro732 |
-------------------------------------------------------------------------------
|
| 2 |
|
|
--
|
| 3 |
|
|
-- RapidIO IP Library Core
|
| 4 |
|
|
--
|
| 5 |
|
|
-- This file is part of the RapidIO IP library project
|
| 6 |
|
|
-- http://www.opencores.org/cores/rio/
|
| 7 |
|
|
--
|
| 8 |
|
|
-- Description
|
| 9 |
48 |
magro732 |
-- Contains a converter of RapidIO maintenance packets into a Wishbone similar
|
| 10 |
|
|
-- access. It relies on the Maintenance-packet modules from
|
| 11 |
|
|
-- RioLogicalPackets.vhd to function.
|
| 12 |
47 |
magro732 |
--
|
| 13 |
|
|
-- To Do:
|
| 14 |
48 |
magro732 |
-- - Clean up the code for reading. Works but it is messy.
|
| 15 |
47 |
magro732 |
--
|
| 16 |
|
|
-- Author(s):
|
| 17 |
|
|
-- - Magnus Rosenius, magro732@opencores.org
|
| 18 |
|
|
--
|
| 19 |
|
|
-------------------------------------------------------------------------------
|
| 20 |
|
|
--
|
| 21 |
|
|
-- Copyright (C) 2013 Authors and OPENCORES.ORG
|
| 22 |
|
|
--
|
| 23 |
|
|
-- This source file may be used and distributed without
|
| 24 |
|
|
-- restriction provided that this copyright statement is not
|
| 25 |
|
|
-- removed from the file and that any derivative work contains
|
| 26 |
|
|
-- the original copyright notice and the associated disclaimer.
|
| 27 |
|
|
--
|
| 28 |
|
|
-- This source file is free software; you can redistribute it
|
| 29 |
|
|
-- and/or modify it under the terms of the GNU Lesser General
|
| 30 |
|
|
-- Public License as published by the Free Software Foundation;
|
| 31 |
|
|
-- either version 2.1 of the License, or (at your option) any
|
| 32 |
|
|
-- later version.
|
| 33 |
|
|
--
|
| 34 |
|
|
-- This source is distributed in the hope that it will be
|
| 35 |
|
|
-- useful, but WITHOUT ANY WARRANTY; without even the implied
|
| 36 |
|
|
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
| 37 |
|
|
-- PURPOSE. See the GNU Lesser General Public License for more
|
| 38 |
|
|
-- details.
|
| 39 |
|
|
--
|
| 40 |
|
|
-- You should have received a copy of the GNU Lesser General
|
| 41 |
|
|
-- Public License along with this source; if not, download it
|
| 42 |
|
|
-- from http://www.opencores.org/lgpl.shtml
|
| 43 |
|
|
--
|
| 44 |
|
|
-------------------------------------------------------------------------------
|
| 45 |
|
|
|
| 46 |
|
|
-------------------------------------------------------------------------------
|
| 47 |
|
|
-- RioLogicalMaintenance
|
| 48 |
|
|
-- This logical layer module handles ingress maintenance requests and converts
|
| 49 |
|
|
-- them into accesses on a Wishbone similar bus accessing the configuration
|
| 50 |
|
|
-- space.
|
| 51 |
|
|
-------------------------------------------------------------------------------
|
| 52 |
|
|
library ieee;
|
| 53 |
|
|
use ieee.std_logic_1164.all;
|
| 54 |
|
|
use ieee.numeric_std.all;
|
| 55 |
|
|
use work.rio_common.all;
|
| 56 |
|
|
|
| 57 |
|
|
|
| 58 |
|
|
-------------------------------------------------------------------------------
|
| 59 |
|
|
-- Entity for RioLogicalMaintenance.
|
| 60 |
|
|
-------------------------------------------------------------------------------
|
| 61 |
|
|
entity RioLogicalMaintenance is
|
| 62 |
|
|
port(
|
| 63 |
|
|
clk : in std_logic;
|
| 64 |
|
|
areset_n : in std_logic;
|
| 65 |
|
|
enable : in std_logic;
|
| 66 |
|
|
|
| 67 |
|
|
readRequestReady_i : in std_logic;
|
| 68 |
|
|
writeRequestReady_i : in std_logic;
|
| 69 |
|
|
size_i : in std_logic_vector(3 downto 0);
|
| 70 |
|
|
offset_i : in std_logic_vector(20 downto 0);
|
| 71 |
|
|
wdptr_i : in std_logic;
|
| 72 |
|
|
payloadLength_i : in std_logic_vector(2 downto 0);
|
| 73 |
|
|
payloadIndex_o : out std_logic_vector(2 downto 0);
|
| 74 |
|
|
payload_i : in std_logic_vector(63 downto 0);
|
| 75 |
|
|
done_o : out std_logic;
|
| 76 |
|
|
|
| 77 |
|
|
readResponseReady_o : out std_logic;
|
| 78 |
|
|
writeResponseReady_o : out std_logic;
|
| 79 |
|
|
status_o : out std_logic_vector(3 downto 0);
|
| 80 |
|
|
payloadLength_o : out std_logic_vector(2 downto 0);
|
| 81 |
|
|
payloadIndex_i : in std_logic_vector(2 downto 0);
|
| 82 |
|
|
payload_o : out std_logic_vector(63 downto 0);
|
| 83 |
|
|
done_i : in std_logic;
|
| 84 |
|
|
|
| 85 |
|
|
configStb_o : out std_logic;
|
| 86 |
|
|
configWe_o : out std_logic;
|
| 87 |
|
|
configAdr_o : out std_logic_vector(21 downto 0);
|
| 88 |
|
|
configDat_o : out std_logic_vector(31 downto 0);
|
| 89 |
|
|
configDat_i : in std_logic_vector(31 downto 0);
|
| 90 |
|
|
configAck_i : in std_logic);
|
| 91 |
|
|
end entity;
|
| 92 |
|
|
|
| 93 |
|
|
|
| 94 |
|
|
-------------------------------------------------------------------------------
|
| 95 |
|
|
--
|
| 96 |
|
|
-------------------------------------------------------------------------------
|
| 97 |
|
|
architecture RioLogicalMaintenance of RioLogicalMaintenance is
|
| 98 |
|
|
|
| 99 |
|
|
type StateType is (IDLE,
|
| 100 |
|
|
CONFIG_READ_START, CONFIG_READ, CONFIG_READ_NEXT, CONFIG_READ_RESPONSE,
|
| 101 |
|
|
CONFIG_WRITE_START, CONFIG_WRITE, CONFIG_WRITE_NEXT, CONFIG_WRITE_RESPONSE,
|
| 102 |
|
|
WAIT_REQUEST);
|
| 103 |
|
|
signal state : StateType;
|
| 104 |
|
|
|
| 105 |
|
|
signal payloadLength : std_logic_vector(3 downto 0);
|
| 106 |
|
|
signal payloadIndex : std_logic_vector(3 downto 0);
|
| 107 |
|
|
|
| 108 |
|
|
signal payloadWrite : std_logic;
|
| 109 |
|
|
signal payloadAddress : std_logic_vector(2 downto 0);
|
| 110 |
|
|
signal payload : std_logic_vector(63 downto 0);
|
| 111 |
|
|
|
| 112 |
|
|
signal configAdr : std_logic_vector(21 downto 0);
|
| 113 |
|
|
signal configDat : std_logic_vector(31 downto 0);
|
| 114 |
|
|
|
| 115 |
|
|
begin
|
| 116 |
|
|
|
| 117 |
|
|
configAdr_o <= configAdr;
|
| 118 |
|
|
configDat_o <= configDat;
|
| 119 |
|
|
|
| 120 |
|
|
payloadLength_o <= payloadLength(3 downto 1);
|
| 121 |
|
|
payloadIndex_o <= payloadIndex(3 downto 1);
|
| 122 |
|
|
|
| 123 |
|
|
-----------------------------------------------------------------------------
|
| 124 |
|
|
--
|
| 125 |
|
|
-----------------------------------------------------------------------------
|
| 126 |
|
|
Maintenance: process(clk, areset_n)
|
| 127 |
|
|
begin
|
| 128 |
|
|
if (areset_n = '0') then
|
| 129 |
|
|
state <= IDLE;
|
| 130 |
|
|
|
| 131 |
|
|
readResponseReady_o <= '0';
|
| 132 |
|
|
writeResponseReady_o <= '0';
|
| 133 |
|
|
done_o <= '0';
|
| 134 |
|
|
|
| 135 |
|
|
configStb_o <= '0';
|
| 136 |
|
|
configWe_o <= '0';
|
| 137 |
|
|
configAdr <= (others=>'0');
|
| 138 |
|
|
configDat <= (others=>'0');
|
| 139 |
|
|
|
| 140 |
|
|
payloadWrite <= '0';
|
| 141 |
|
|
payloadIndex <= (others=>'0');
|
| 142 |
|
|
payload <= (others=>'0');
|
| 143 |
|
|
elsif (clk'event and clk = '1') then
|
| 144 |
|
|
payloadWrite <= '0';
|
| 145 |
|
|
|
| 146 |
|
|
case state is
|
| 147 |
|
|
when IDLE =>
|
| 148 |
|
|
---------------------------------------------------------------------
|
| 149 |
|
|
--
|
| 150 |
|
|
---------------------------------------------------------------------
|
| 151 |
48 |
magro732 |
payloadIndex <= (others=>'0');
|
| 152 |
47 |
magro732 |
done_o <= '0';
|
| 153 |
|
|
if (readRequestReady_i = '1') then
|
| 154 |
|
|
state <= CONFIG_READ_START;
|
| 155 |
|
|
elsif (writeRequestReady_i = '1') then
|
| 156 |
|
|
state <= CONFIG_WRITE_START;
|
| 157 |
|
|
end if;
|
| 158 |
|
|
|
| 159 |
|
|
when CONFIG_READ_START =>
|
| 160 |
|
|
---------------------------------------------------------------------
|
| 161 |
|
|
--
|
| 162 |
|
|
---------------------------------------------------------------------
|
| 163 |
|
|
configStb_o <= '1';
|
| 164 |
|
|
configWe_o <= '0';
|
| 165 |
|
|
if (size_i = "1000") then
|
| 166 |
|
|
configAdr <= offset_i & wdptr_i;
|
| 167 |
|
|
else
|
| 168 |
|
|
configAdr <= offset_i & '0';
|
| 169 |
|
|
end if;
|
| 170 |
|
|
payloadIndex <= "0000";
|
| 171 |
|
|
payload <= (others=>'0');
|
| 172 |
|
|
state <= CONFIG_READ;
|
| 173 |
|
|
|
| 174 |
|
|
when CONFIG_READ =>
|
| 175 |
|
|
---------------------------------------------------------------------
|
| 176 |
|
|
--
|
| 177 |
|
|
---------------------------------------------------------------------
|
| 178 |
|
|
if (configAck_i = '1') then
|
| 179 |
|
|
configStb_o <= '0';
|
| 180 |
|
|
configAdr <= std_logic_vector(unsigned(configAdr) + 1);
|
| 181 |
|
|
state <= CONFIG_READ_NEXT;
|
| 182 |
|
|
end if;
|
| 183 |
|
|
|
| 184 |
|
|
if (size_i = "1000") and (wdptr_i = '0') then
|
| 185 |
|
|
payload(63 downto 32) <= configDat_i;
|
| 186 |
|
|
elsif (size_i = "1000") and (wdptr_i = '1') then
|
| 187 |
|
|
payload(31 downto 0) <= configDat_i;
|
| 188 |
|
|
else
|
| 189 |
|
|
if (payloadIndex(0) = '0') then
|
| 190 |
|
|
payload(63 downto 32) <= configDat_i;
|
| 191 |
|
|
else
|
| 192 |
|
|
payload(31 downto 0) <= configDat_i;
|
| 193 |
|
|
end if;
|
| 194 |
|
|
end if;
|
| 195 |
|
|
|
| 196 |
|
|
when CONFIG_READ_NEXT =>
|
| 197 |
|
|
---------------------------------------------------------------------
|
| 198 |
|
|
--
|
| 199 |
|
|
---------------------------------------------------------------------
|
| 200 |
|
|
if (size_i = "1000") and (wdptr_i = '0') then
|
| 201 |
|
|
-- 1 word.
|
| 202 |
|
|
status_o <= "0000";
|
| 203 |
|
|
payloadLength <= "0010";
|
| 204 |
|
|
payloadWrite <= '1';
|
| 205 |
|
|
state <= CONFIG_READ_RESPONSE;
|
| 206 |
|
|
elsif (size_i = "1000") and (wdptr_i = '1') then
|
| 207 |
|
|
-- 1 word.
|
| 208 |
|
|
status_o <= "0000";
|
| 209 |
|
|
payloadLength <= "0010";
|
| 210 |
|
|
payloadWrite <= '1';
|
| 211 |
|
|
state <= CONFIG_READ_RESPONSE;
|
| 212 |
|
|
elsif (size_i = "1011") and (wdptr_i = '0') then
|
| 213 |
|
|
-- 2 words.
|
| 214 |
|
|
status_o <= "0000";
|
| 215 |
|
|
payloadLength <= "0010";
|
| 216 |
|
|
payloadWrite <= payloadIndex(0);
|
| 217 |
|
|
if (payloadIndex = "0001") then
|
| 218 |
|
|
state <= CONFIG_READ_RESPONSE;
|
| 219 |
|
|
else
|
| 220 |
|
|
configStb_o <= '1';
|
| 221 |
|
|
state <= CONFIG_READ;
|
| 222 |
|
|
end if;
|
| 223 |
|
|
elsif (size_i = "1011") and (wdptr_i = '1') then
|
| 224 |
|
|
-- 4 words.
|
| 225 |
|
|
status_o <= "0000";
|
| 226 |
|
|
payloadLength <= "0100";
|
| 227 |
|
|
payloadWrite <= payloadIndex(0);
|
| 228 |
|
|
if (payloadIndex = "0011") then
|
| 229 |
|
|
state <= CONFIG_READ_RESPONSE;
|
| 230 |
|
|
else
|
| 231 |
|
|
configStb_o <= '1';
|
| 232 |
|
|
state <= CONFIG_READ;
|
| 233 |
|
|
end if;
|
| 234 |
|
|
elsif (size_i = "1100") and (wdptr_i = '0') then
|
| 235 |
|
|
-- 8 words.
|
| 236 |
|
|
status_o <= "0000";
|
| 237 |
|
|
payloadLength <= "1000";
|
| 238 |
|
|
payloadWrite <= payloadIndex(0);
|
| 239 |
|
|
if (payloadIndex = "0111") then
|
| 240 |
|
|
state <= CONFIG_READ_RESPONSE;
|
| 241 |
|
|
else
|
| 242 |
|
|
configStb_o <= '1';
|
| 243 |
|
|
state <= CONFIG_READ;
|
| 244 |
|
|
end if;
|
| 245 |
|
|
elsif (size_i = "1100") and (wdptr_i = '1') then
|
| 246 |
|
|
-- 16 words.
|
| 247 |
|
|
status_o <= "0000";
|
| 248 |
|
|
payloadLength <= "0000";
|
| 249 |
|
|
payloadWrite <= payloadIndex(0);
|
| 250 |
|
|
if (payloadIndex = "1111") then
|
| 251 |
|
|
state <= CONFIG_READ_RESPONSE;
|
| 252 |
|
|
else
|
| 253 |
|
|
configStb_o <= '1';
|
| 254 |
|
|
state <= CONFIG_READ;
|
| 255 |
|
|
end if;
|
| 256 |
|
|
else
|
| 257 |
|
|
-- Unallowed packet.
|
| 258 |
|
|
-- Send write-response with status indicating error.
|
| 259 |
|
|
status_o <= "0111";
|
| 260 |
|
|
state <= CONFIG_READ_RESPONSE;
|
| 261 |
|
|
end if;
|
| 262 |
|
|
|
| 263 |
|
|
payloadAddress <= payloadIndex(3 downto 1);
|
| 264 |
|
|
payloadIndex <= std_logic_vector(unsigned(payloadIndex) + 1);
|
| 265 |
|
|
|
| 266 |
|
|
when CONFIG_READ_RESPONSE =>
|
| 267 |
|
|
---------------------------------------------------------------------
|
| 268 |
|
|
--
|
| 269 |
|
|
---------------------------------------------------------------------
|
| 270 |
|
|
if (done_i = '1') then
|
| 271 |
|
|
readResponseReady_o <= '0';
|
| 272 |
|
|
state <= WAIT_REQUEST;
|
| 273 |
|
|
else
|
| 274 |
|
|
readResponseReady_o <= '1';
|
| 275 |
|
|
end if;
|
| 276 |
|
|
|
| 277 |
|
|
when CONFIG_WRITE_START =>
|
| 278 |
|
|
---------------------------------------------------------------------
|
| 279 |
|
|
--
|
| 280 |
|
|
---------------------------------------------------------------------
|
| 281 |
|
|
configWe_o <= '1';
|
| 282 |
|
|
if (size_i = "1000") then
|
| 283 |
|
|
configAdr <= offset_i & wdptr_i;
|
| 284 |
|
|
else
|
| 285 |
|
|
configAdr <= offset_i & '0';
|
| 286 |
|
|
end if;
|
| 287 |
|
|
if (size_i = "1000") and (wdptr_i = '0') then
|
| 288 |
|
|
-- 1 word.
|
| 289 |
|
|
configStb_o <= '1';
|
| 290 |
|
|
configDat <= payload_i(63 downto 32);
|
| 291 |
|
|
payloadLength <= "0001";
|
| 292 |
|
|
status_o <= "0000";
|
| 293 |
|
|
state <= CONFIG_WRITE;
|
| 294 |
|
|
elsif (size_i = "1000") and (wdptr_i = '1') then
|
| 295 |
|
|
-- 1 word.
|
| 296 |
|
|
configStb_o <= '1';
|
| 297 |
|
|
configDat <= payload_i(31 downto 0);
|
| 298 |
|
|
payloadLength <= "0001";
|
| 299 |
|
|
status_o <= "0000";
|
| 300 |
|
|
state <= CONFIG_WRITE;
|
| 301 |
|
|
elsif (size_i = "1011") and (wdptr_i = '0') then
|
| 302 |
|
|
-- 2 words.
|
| 303 |
|
|
configStb_o <= '1';
|
| 304 |
|
|
configDat <= payload_i(63 downto 32);
|
| 305 |
|
|
payloadLength <= "0010";
|
| 306 |
|
|
status_o <= "0000";
|
| 307 |
|
|
state <= CONFIG_WRITE;
|
| 308 |
|
|
elsif (size_i = "1011") and (wdptr_i = '1') then
|
| 309 |
|
|
-- maximum 4 words.
|
| 310 |
|
|
configStb_o <= '1';
|
| 311 |
|
|
configDat <= payload_i(63 downto 32);
|
| 312 |
|
|
payloadLength <= payloadLength_i & '0';
|
| 313 |
|
|
status_o <= "0000";
|
| 314 |
|
|
state <= CONFIG_WRITE;
|
| 315 |
|
|
elsif (size_i = "1100") and (wdptr_i = '0') then
|
| 316 |
|
|
-- maximum 8 words.
|
| 317 |
|
|
configStb_o <= '1';
|
| 318 |
|
|
configDat <= payload_i(63 downto 32);
|
| 319 |
|
|
payloadLength <= payloadLength_i & '0';
|
| 320 |
|
|
status_o <= "0000";
|
| 321 |
|
|
state <= CONFIG_WRITE;
|
| 322 |
|
|
elsif (size_i = "1100") and (wdptr_i = '1') then
|
| 323 |
|
|
-- maximum 16 words.
|
| 324 |
|
|
configStb_o <= '1';
|
| 325 |
|
|
configDat <= payload_i(63 downto 32);
|
| 326 |
|
|
payloadLength <= payloadLength_i & '0';
|
| 327 |
|
|
status_o <= "0000";
|
| 328 |
|
|
state <= CONFIG_WRITE;
|
| 329 |
|
|
else
|
| 330 |
|
|
-- Unallowed packet.
|
| 331 |
|
|
-- Send write-response with status indicating error.
|
| 332 |
|
|
status_o <= "0111";
|
| 333 |
|
|
state <= CONFIG_WRITE_RESPONSE;
|
| 334 |
|
|
end if;
|
| 335 |
48 |
magro732 |
payloadIndex <= std_logic_vector(unsigned(payloadIndex) + 1);
|
| 336 |
47 |
magro732 |
|
| 337 |
|
|
when CONFIG_WRITE =>
|
| 338 |
|
|
---------------------------------------------------------------------
|
| 339 |
|
|
--
|
| 340 |
|
|
---------------------------------------------------------------------
|
| 341 |
|
|
if (configAck_i = '1') then
|
| 342 |
|
|
configStb_o <= '0';
|
| 343 |
|
|
configAdr <= std_logic_vector(unsigned(configAdr) + 1);
|
| 344 |
|
|
state <= CONFIG_WRITE_NEXT;
|
| 345 |
|
|
end if;
|
| 346 |
|
|
|
| 347 |
|
|
when CONFIG_WRITE_NEXT =>
|
| 348 |
|
|
---------------------------------------------------------------------
|
| 349 |
|
|
--
|
| 350 |
|
|
---------------------------------------------------------------------
|
| 351 |
|
|
if (payloadIndex(0) = '0') then
|
| 352 |
|
|
configDat <= payload_i(63 downto 32);
|
| 353 |
|
|
else
|
| 354 |
|
|
configDat <= payload_i(31 downto 0);
|
| 355 |
|
|
end if;
|
| 356 |
|
|
|
| 357 |
|
|
payloadIndex <= std_logic_vector(unsigned(payloadIndex) + 1);
|
| 358 |
|
|
if (payloadIndex /= payloadLength) then
|
| 359 |
|
|
configStb_o <= '1';
|
| 360 |
|
|
state <= CONFIG_WRITE;
|
| 361 |
|
|
else
|
| 362 |
|
|
state <= CONFIG_WRITE_RESPONSE;
|
| 363 |
|
|
end if;
|
| 364 |
|
|
|
| 365 |
|
|
when CONFIG_WRITE_RESPONSE =>
|
| 366 |
|
|
---------------------------------------------------------------------
|
| 367 |
|
|
--
|
| 368 |
|
|
---------------------------------------------------------------------
|
| 369 |
|
|
if (done_i = '1') then
|
| 370 |
|
|
writeResponseReady_o <= '0';
|
| 371 |
|
|
state <= WAIT_REQUEST;
|
| 372 |
|
|
else
|
| 373 |
|
|
writeResponseReady_o <= '1';
|
| 374 |
|
|
end if;
|
| 375 |
|
|
|
| 376 |
|
|
when WAIT_REQUEST =>
|
| 377 |
|
|
---------------------------------------------------------------------
|
| 378 |
|
|
--
|
| 379 |
|
|
---------------------------------------------------------------------
|
| 380 |
|
|
done_o <= '1';
|
| 381 |
|
|
if (readRequestReady_i = '0') and (writeRequestReady_i = '0') then
|
| 382 |
|
|
state <= IDLE;
|
| 383 |
|
|
end if;
|
| 384 |
|
|
when others =>
|
| 385 |
|
|
|
| 386 |
|
|
end case;
|
| 387 |
|
|
end if;
|
| 388 |
|
|
end process;
|
| 389 |
|
|
|
| 390 |
|
|
-----------------------------------------------------------------------------
|
| 391 |
|
|
-- Payload content memory.
|
| 392 |
|
|
-----------------------------------------------------------------------------
|
| 393 |
|
|
|
| 394 |
|
|
PayloadMemory: MemorySimpleDualPort
|
| 395 |
|
|
generic map(ADDRESS_WIDTH=>3, DATA_WIDTH=>64)
|
| 396 |
|
|
port map(clkA_i=>clk,
|
| 397 |
|
|
enableA_i=>payloadWrite,
|
| 398 |
|
|
addressA_i=>payloadAddress,
|
| 399 |
|
|
dataA_i=>payload,
|
| 400 |
|
|
clkB_i=>clk,
|
| 401 |
|
|
enableB_i=>'1',
|
| 402 |
|
|
addressB_i=>payloadIndex_i,
|
| 403 |
|
|
dataB_o=>payload_o);
|
| 404 |
|
|
|
| 405 |
|
|
end architecture;
|