--////////////////////////////////////////////////////////////////////
|
--////////////////////////////////////////////////////////////////////
|
--// ////
|
--// ////
|
--// search_item.vhd ////
|
--// search_item.vhd ////
|
--// ////
|
--// ////
|
--// This file is part of the open_hitter opencores effort. ////
|
--// This file is part of the open_hitter opencores effort. ////
|
--// <http://www.opencores.org/cores/open_hitter/> ////
|
--// <http://www.opencores.org/cores/open_hitter/> ////
|
--// ////
|
--// ////
|
--// Module Description: ////
|
--// Module Description: ////
|
--// This is the multipelexed search's repeated item. The project ////
|
--// This is the multipelexed search's repeated item. The project ////
|
--// buses perform the multiplex and are experienced by each item ////
|
--// buses perform the multiplex and are experienced by each item ////
|
--// as b1_* - input to search_item ////
|
--// as b1_* - input to search_item ////
|
--// b2_* - output from search_item ////
|
--// b2_* - output from search_item ////
|
--// this version of search_item is stateless i.e. can be queried ////
|
--// this version of search_item is stateless i.e. can be queried ////
|
--// every clock cycle ////
|
--// every clock cycle ////
|
--// ////
|
--// ////
|
--// To Do: ////
|
--// To Do: ////
|
--// ////
|
--// ////
|
--// Author(s): ////
|
--// Author(s): ////
|
--// - Stephen Hawes ////
|
--// - Stephen Hawes ////
|
--// ////
|
--// ////
|
--////////////////////////////////////////////////////////////////////
|
--////////////////////////////////////////////////////////////////////
|
--// ////
|
--// ////
|
--// Copyright (C) 2015 Stephen Hawes and OPENCORES.ORG ////
|
--// Copyright (C) 2015 Stephen Hawes and OPENCORES.ORG ////
|
--// ////
|
--// ////
|
--// This source file may be used and distributed without ////
|
--// This source file may be used and distributed without ////
|
--// restriction provided that this copyright statement is not ////
|
--// restriction provided that this copyright statement is not ////
|
--// removed from the file and that any derivative work contains ////
|
--// removed from the file and that any derivative work contains ////
|
--// the original copyright notice and the associated disclaimer. ////
|
--// the original copyright notice and the associated disclaimer. ////
|
--// ////
|
--// ////
|
--// This source file is free software; you can redistribute it ////
|
--// This source file is free software; you can redistribute it ////
|
--// and/or modify it under the terms of the GNU Lesser General ////
|
--// and/or modify it under the terms of the GNU Lesser General ////
|
--// Public License as published by the Free Software Foundation; ////
|
--// Public License as published by the Free Software Foundation; ////
|
--// either version 2.1 of the License, or (at your option) any ////
|
--// either version 2.1 of the License, or (at your option) any ////
|
--// later version. ////
|
--// later version. ////
|
--// ////
|
--// ////
|
--// This source is distributed in the hope that it will be ////
|
--// This source is distributed in the hope that it will be ////
|
--// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
--// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
--// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
--// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
--// PURPOSE. See the GNU Lesser General Public License for more ////
|
--// PURPOSE. See the GNU Lesser General Public License for more ////
|
--// details. ////
|
--// details. ////
|
--// ////
|
--// ////
|
--// You should have received a copy of the GNU Lesser General ////
|
--// You should have received a copy of the GNU Lesser General ////
|
--// Public License along with this source; if not, download it ////
|
--// Public License along with this source; if not, download it ////
|
--// from <http://www.opencores.org/lgpl.shtml> ////
|
--// from <http://www.opencores.org/lgpl.shtml> ////
|
--// ////
|
--// ////
|
--////////////////////////////////////////////////////////////////////
|
--////////////////////////////////////////////////////////////////////
|
--//
|
--//
|
--// \$Id\$ TAKE OUT THE \'s and this comment in order to get this to work
|
--// \$Id\$ TAKE OUT THE \'s and this comment in order to get this to work
|
--//
|
--//
|
--// CVS Revision History
|
--// CVS Revision History
|
--//
|
--//
|
--// \$Log\$ TAKE OUT THE \'s and this comment in order to get this to work
|
--// \$Log\$ TAKE OUT THE \'s and this comment in order to get this to work
|
--//
|
--//
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.numeric_std.ALL;
|
use ieee.numeric_std.ALL;
|
--use std.textio.all; -- Imports the standard textio package.
|
-- use std.textio.all; -- Imports the standard textio package.
|
|
|
entity search_item is
|
entity search_item is
|
generic ( item_id: std_logic_vector(15 downto 0) );
|
generic ( item_id: std_logic_vector(15 downto 0) );
|
port (
|
port (
|
RX_CLK: in std_logic;
|
RX_CLK: in std_logic;
|
-- control flag(s) on the incoming bus
|
-- control flag(s) on the incoming bus
|
b1_px_valid: in std_logic;
|
b1_px_valid: in std_logic;
|
-- pxdata: in price_packet
|
-- pxdata: in price_packet
|
b1_px_type: in std_logic_vector(4 downto 0);
|
b1_px_type: in std_logic_vector(4 downto 0);
|
b1_buy_sell: in std_logic_vector(2 downto 0); -- 111 buy, 000 sell
|
b1_buy_sell: in std_logic_vector(2 downto 0); -- 111 buy, 000 sell
|
b1_px: in std_logic_vector(15 downto 0); -- price
|
b1_px: in std_logic_vector(15 downto 0); -- price
|
b1_qty: in std_logic_vector(15 downto 0); -- quantity
|
b1_qty: in std_logic_vector(15 downto 0); -- quantity
|
b1_sec: in std_logic_vector(55 downto 0); -- 7x 8bits securities identifier
|
b1_sec: in std_logic_vector(55 downto 0); -- 7x 8bits securities identifier
|
b1_id: in std_logic_vector(15 downto 0); -- unique/identifier/counter
|
b1_id: in std_logic_vector(15 downto 0); -- unique/identifier/counter
|
-- pxdata: out price_packet
|
-- pxdata: out price_packet
|
b2_px_type: out std_logic_vector(4 downto 0);
|
b2_px_type: out std_logic_vector(4 downto 0);
|
b2_buy_sell: out std_logic_vector(2 downto 0); -- 111 buy, 000 sell
|
b2_buy_sell: out std_logic_vector(2 downto 0); -- 111 buy, 000 sell
|
b2_px: out std_logic_vector(15 downto 0); -- price
|
b2_px: out std_logic_vector(15 downto 0); -- price
|
b2_qty: out std_logic_vector(15 downto 0); -- quantity
|
b2_qty: out std_logic_vector(15 downto 0); -- quantity
|
b2_sec: out std_logic_vector(55 downto 0); -- 7x 8bits securities identifier
|
b2_sec: out std_logic_vector(55 downto 0); -- 7x 8bits securities identifier
|
b2_id: out std_logic_vector(15 downto 0) -- unique/identifier/counter
|
b2_id: out std_logic_vector(15 downto 0) -- unique/identifier/counter
|
);
|
);
|
end search_item;
|
end search_item;
|
|
|
architecture search_item_implementation of search_item is
|
architecture search_item_implementation of search_item is
|
-- signal state : integer range 0 to 16 := 16;
|
-- signal state : integer range 0 to 16 := 16;
|
signal requires_reset: std_logic := '0';
|
signal requires_reset: std_logic := '0';
|
-- pxdata: out price_packet
|
-- pxdata: out price_packet
|
signal store_px_type: std_logic_vector(4 downto 0) := (others => 'Z');
|
signal store_px_type: std_logic_vector(4 downto 0) := (others => 'Z');
|
signal store_buy_sell: std_logic_vector(2 downto 0) := (others => 'Z'); -- 111 buy, 000 sell
|
signal store_buy_sell: std_logic_vector(2 downto 0) := (others => 'Z'); -- 111 buy, 000 sell
|
signal store_px: std_logic_vector(15 downto 0) := (others => 'Z'); -- price
|
signal store_px: std_logic_vector(15 downto 0) := (others => 'Z'); -- price
|
signal store_qty: std_logic_vector(15 downto 0) := (others => 'Z'); -- quantity
|
signal store_qty: std_logic_vector(15 downto 0) := (others => 'Z'); -- quantity
|
signal store_sec: std_logic_vector(55 downto 0) := (others => 'Z'); -- 7x 8bits securities identifier
|
signal store_sec: std_logic_vector(55 downto 0) := (others => 'Z'); -- 7x 8bits securities identifier
|
begin
|
begin
|
match: process (RX_CLK) is
|
match: process (RX_CLK) is
|
-- variable l : line;
|
-- variable l : line;
|
begin
|
begin
|
if rising_edge(RX_CLK) then
|
if falling_edge(RX_CLK) then
|
-- if falling_edge(RX_CLK) then
|
|
if b1_px_valid = '1' then
|
|
|
|
-- write (l, String'(" Item Rising Edge "));
|
-- diagnostic (uncomment)
|
-- for j in b1_id'range loop
|
-- write (l, String'(" Item Falling Edge"));
|
-- write(l, std_logic'image(b1_id(j)) );
|
-- write (l, String'(" b1_px_type: "));
|
-- end loop;
|
|
-- write (l, String'(" instruction: "));
|
|
-- for j in b1_px_type'range loop
|
-- for j in b1_px_type'range loop
|
-- write(l, std_logic'image(b1_px_type(j)) );
|
-- write(l, std_logic'image(b1_px_type(j)) );
|
-- end loop;
|
-- end loop;
|
|
-- write (l, String'(" item_id: "));
|
|
-- for j in item_id'range loop
|
|
-- write(l, std_logic'image(item_id(j)) );
|
|
-- end loop;
|
|
-- write (l, String'(" b1_id: "));
|
|
-- for j in b1_id'range loop
|
|
-- write(l, std_logic'image(b1_id(j)) );
|
|
-- end loop;
|
|
-- write (l, String'(" b1_px_valid: "));
|
|
-- write (l, std_logic'image(b1_px_valid) );
|
-- writeline ( output, l);
|
-- writeline ( output, l);
|
|
|
|
if b1_px_valid = '1' then
|
if b1_px_type = std_logic_vector'("00000") then
|
if b1_px_type = std_logic_vector'("00000") then
|
-- do reset store and outputs
|
-- do reset store and outputs
|
store_px_type <= (others => '0');
|
store_px_type <= (others => '0');
|
store_buy_sell <= (others => '0'); -- 111 buy, 000 sell
|
store_buy_sell <= (others => '0'); -- 111 buy, 000 sell
|
store_px <= (others => '0'); -- price
|
store_px <= (others => '0'); -- price
|
store_qty <= (others => '0'); -- quantity
|
store_qty <= (others => '0'); -- quantity
|
store_sec <= (others => '0'); -- 7x 8bits securities identifier
|
store_sec <= (others => '0'); -- 7x 8bits securities identifier
|
--
|
--
|
b2_px_type <= (others => 'Z');
|
b2_px_type <= (others => 'Z');
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_px <= (others => 'Z'); -- price
|
b2_px <= (others => 'Z'); -- price
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
--
|
--
|
requires_reset <= '0';
|
requires_reset <= '0';
|
|
|
elsif b1_px_type = std_logic_vector'("00110") then
|
elsif b1_px_type = std_logic_vector'("00110") then
|
if store_buy_sell = b1_buy_sell and
|
if store_buy_sell = b1_buy_sell and
|
store_sec = b1_sec then
|
store_sec = b1_sec then
|
-- do set store from incoming price
|
-- do set store from incoming price
|
store_px_type <= b1_px_type;
|
store_px_type <= b1_px_type;
|
-- store_buy_sell <= b1_buy_sell;
|
-- store_buy_sell <= b1_buy_sell;
|
store_px <= b1_px;
|
store_px <= b1_px;
|
store_qty <= b1_qty;
|
store_qty <= b1_qty;
|
--
|
--
|
b2_px_type <= std_logic_vector'(std_logic_vector'("00110"));
|
b2_px_type <= std_logic_vector'(std_logic_vector'("00110"));
|
b2_buy_sell <= (others => 'Z');
|
b2_buy_sell <= (others => 'Z');
|
b2_px <= (others => 'Z');
|
b2_px <= (others => 'Z');
|
b2_qty <= (others => 'Z');
|
b2_qty <= (others => 'Z');
|
b2_sec <= (others => 'Z');
|
b2_sec <= (others => 'Z');
|
b2_id <= (others => 'Z');
|
b2_id <= item_id;
|
requires_reset <= '1';
|
requires_reset <= '1';
|
else
|
else
|
if requires_reset = '1' then
|
if requires_reset = '1' then
|
b2_px_type <= (others => 'Z');
|
b2_px_type <= (others => 'Z');
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_px <= (others => 'Z'); -- price
|
b2_px <= (others => 'Z'); -- price
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
requires_reset <= '0';
|
requires_reset <= '0';
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
elsif b1_px_type = std_logic_vector'("01010") then
|
elsif b1_px_type = std_logic_vector'("01010") then
|
if item_id = b1_id then
|
if item_id = b1_id then
|
-- do set store and security from incoming price
|
-- do set store and security from incoming price
|
store_px_type <= b1_px_type;
|
store_px_type <= b1_px_type;
|
store_buy_sell <= b1_buy_sell;
|
store_buy_sell <= b1_buy_sell;
|
store_px <= b1_px;
|
store_px <= b1_px;
|
store_qty <= b1_qty;
|
store_qty <= b1_qty;
|
store_sec <= b1_sec;
|
store_sec <= b1_sec;
|
--
|
--
|
b2_px_type <= std_logic_vector'(std_logic_vector'("01010"));
|
b2_px_type <= std_logic_vector'(std_logic_vector'("01010"));
|
b2_buy_sell <= (others => 'Z');
|
b2_buy_sell <= (others => 'Z');
|
b2_px <= (others => 'Z');
|
b2_px <= (others => 'Z');
|
b2_qty <= (others => 'Z');
|
b2_qty <= (others => 'Z');
|
b2_sec <= (others => 'Z');
|
b2_sec <= (others => 'Z');
|
b2_id <= item_id;
|
b2_id <= item_id;
|
requires_reset <= '1';
|
requires_reset <= '1';
|
else
|
else
|
if requires_reset = '1' then
|
if requires_reset = '1' then
|
b2_px_type <= (others => 'Z');
|
b2_px_type <= (others => 'Z');
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_px <= (others => 'Z'); -- price
|
b2_px <= (others => 'Z'); -- price
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
requires_reset <= '0';
|
requires_reset <= '0';
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
elsif b1_px_type = std_logic_vector'("11100") then
|
elsif b1_px_type = std_logic_vector'("11100") then
|
-- incoming price, register it and start the state machine
|
-- incoming price, register it and start the state machine
|
if (store_sec /= b1_sec or store_buy_sell = b1_buy_sell ) then
|
if (store_sec /= b1_sec or store_buy_sell = b1_buy_sell ) then
|
if requires_reset = '1' then
|
if requires_reset = '1' then
|
b2_px_type <= (others => 'Z');
|
b2_px_type <= (others => 'Z');
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_px <= (others => 'Z'); -- price
|
b2_px <= (others => 'Z'); -- price
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
requires_reset <= '0';
|
requires_reset <= '0';
|
end if;
|
end if;
|
elsif (to_integer(unsigned(store_qty)) = 0 or to_integer(unsigned(b1_qty)) = 0 or
|
elsif (to_integer(unsigned(store_qty)) = 0 or to_integer(unsigned(b1_qty)) = 0 or
|
(store_buy_sell = std_logic_vector'("111") and store_px < b1_px) or
|
(store_buy_sell = std_logic_vector'("111") and store_px < b1_px) or
|
(store_buy_sell = std_logic_vector'("000") and store_px > b1_px) ) then
|
(store_buy_sell = std_logic_vector'("000") and store_px > b1_px) ) then
|
-- no deal: this is the correct store_item but there's no match
|
-- no deal: this is the correct store_item but there's no match
|
b2_px_type <= std_logic_vector'(std_logic_vector'("11101"));
|
b2_px_type <= std_logic_vector'(std_logic_vector'("11101"));
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_px <= (others => 'Z'); -- price
|
b2_px <= (others => 'Z'); -- price
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
requires_reset <= '1';
|
requires_reset <= '1';
|
else
|
else
|
-- send a return order
|
-- send a return order
|
b2_buy_sell <= store_buy_sell; -- 111 buy, 000 sell
|
b2_buy_sell <= store_buy_sell; -- 111 buy, 000 sell
|
b2_sec <= store_sec; -- 7x 8bits securities identifier
|
b2_sec <= store_sec; -- 7x 8bits securities identifier
|
b2_id <= item_id; -- unique/identifier/counter
|
b2_id <= item_id; -- unique/identifier/counter
|
b2_px <= b1_px; -- price
|
b2_px <= b1_px; -- price
|
-- b2_qty <=
|
-- b2_qty <=
|
if b1_qty < store_qty then
|
if b1_qty < store_qty then
|
b2_qty <= b1_qty;
|
b2_qty <= b1_qty;
|
else
|
else
|
b2_qty <= store_qty;
|
b2_qty <= store_qty;
|
end if; -- quantity
|
end if; -- quantity
|
-- update the store
|
-- update the store
|
-- store_qty
|
-- store_qty
|
if (b1_qty < store_qty) then
|
if (b1_qty < store_qty) then
|
store_qty <= std_logic_vector(to_unsigned( to_integer(unsigned(store_qty)) - to_integer(unsigned(b1_qty)) ,16 ));
|
store_qty <= std_logic_vector(to_unsigned( to_integer(unsigned(store_qty)) - to_integer(unsigned(b1_qty)) ,16 ));
|
else
|
else
|
store_qty <= (others => '0');
|
store_qty <= (others => '0');
|
end if;
|
end if;
|
b2_px_type <= std_logic_vector'(std_logic_vector'("11100"));
|
b2_px_type <= std_logic_vector'(std_logic_vector'("11100"));
|
requires_reset <= '1';
|
requires_reset <= '1';
|
end if;
|
end if;
|
|
|
else
|
else
|
-- no action
|
-- no action
|
if requires_reset = '1' then
|
if requires_reset = '1' then
|
b2_px_type <= (others => 'Z');
|
b2_px_type <= (others => 'Z');
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_px <= (others => 'Z'); -- price
|
b2_px <= (others => 'Z'); -- price
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
requires_reset <= '0';
|
requires_reset <= '0';
|
end if;
|
end if;
|
end if; -- b1_px_type
|
end if; -- b1_px_type
|
|
|
else -- b1_px_valid
|
else -- b1_px_valid
|
if requires_reset = '1' then
|
if requires_reset = '1' then
|
b2_px_type <= (others => 'Z');
|
b2_px_type <= (others => 'Z');
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_buy_sell <= (others => 'Z'); -- 111 buy, 000 sell
|
b2_px <= (others => 'Z'); -- price
|
b2_px <= (others => 'Z'); -- price
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_qty <= (others => 'Z'); -- quantity
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_sec <= (others => 'Z'); -- 7x 8bits securities identifier
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
b2_id <= (others => 'Z'); -- unique/identifier/counter
|
requires_reset <= '0';
|
requires_reset <= '0';
|
end if;
|
end if;
|
end if; -- b1_px_valid
|
end if; -- b1_px_valid
|
|
|
-- b2_id <= std_logic_vector'(X"0000"); -- testing
|
|
|
|
end if;
|
end if;
|
end process match;
|
end process match;
|
|
|
end search_item_implementation;
|
end search_item_implementation;
|
|
|
|
|