Line 106... |
Line 106... |
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 component;
|
end component;
|
for search_item_1: search_item use entity work.search_item;
|
|
signal searchitems_count : integer := 0;
|
signal searchitems_count : integer := 0;
|
--
|
|
signal state : integer range 0 to 16 := 16;
|
signal state : integer range 0 to 16 := 16;
|
--
|
|
--signal RX_CLK: std_logic;
|
|
-- pxdata: store price_packet
|
-- pxdata: store 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
|
signal store_id: std_logic_vector(15 downto 0) := (others => 'Z'); -- unique/identifier/counter
|
signal store_id: std_logic_vector(15 downto 0) := (others => 'Z'); -- unique/identifier/counter
|
-- control flag(s) on the incoming bus
|
-- control flag(s) on the incoming bus
|
signal b1_px_valid: std_logic;
|
signal b1_px_valid: std_logic;
|
-- pxdata: b1 price_packet
|
-- pxdata: in price_packet
|
signal b1_px_type: std_logic_vector(4 downto 0) := (others => 'Z');
|
signal b1_px_type: std_logic_vector(4 downto 0);
|
signal b1_buy_sell: std_logic_vector(2 downto 0) := (others => 'Z'); -- 111 buy, 000 sell
|
signal b1_buy_sell: std_logic_vector(2 downto 0); -- 111 buy, 000 sell
|
signal b1_px: std_logic_vector(15 downto 0) := (others => 'Z'); -- price
|
signal b1_px: std_logic_vector(15 downto 0); -- price
|
signal b1_qty: std_logic_vector(15 downto 0) := (others => 'Z'); -- quantity
|
signal b1_qty: std_logic_vector(15 downto 0); -- quantity
|
signal b1_sec: std_logic_vector(55 downto 0) := (others => 'Z'); -- 7x 8bits securities identifier
|
signal b1_sec: std_logic_vector(55 downto 0); -- 7x 8bits securities identifier
|
signal b1_id: std_logic_vector(15 downto 0) := (others => 'Z'); -- unique/identifier/counter
|
signal b1_id: std_logic_vector(15 downto 0); -- unique/identifier/counter
|
-- pxdata: b2 price_packet
|
-- pxdata: out price_packet
|
signal b2_px_type: std_logic_vector(4 downto 0) := (others => 'Z');
|
signal b2_px_type: std_logic_vector(4 downto 0);
|
signal b2_buy_sell: std_logic_vector(2 downto 0) := (others => 'Z'); -- 111 buy, 000 sell
|
signal b2_buy_sell: std_logic_vector(2 downto 0); -- 111 buy, 000 sell
|
signal b2_px: std_logic_vector(15 downto 0) := (others => 'Z'); -- price
|
signal b2_px: std_logic_vector(15 downto 0); -- price
|
signal b2_qty: std_logic_vector(15 downto 0) := (others => 'Z'); -- quantity
|
signal b2_qty: std_logic_vector(15 downto 0); -- quantity
|
signal b2_sec: std_logic_vector(55 downto 0) := (others => 'Z'); -- 7x 8bits securities identifier
|
signal b2_sec: std_logic_vector(55 downto 0); -- 7x 8bits securities identifier
|
signal b2_id: std_logic_vector(15 downto 0) := (others => 'Z'); -- unique/identifier/counter
|
signal b2_id: std_logic_vector(15 downto 0); -- unique/identifier/counter
|
|
begin
|
|
items_array : for iter_id in 0 to searchitems-1 generate
|
begin
|
begin
|
-- items_array : for iter_id in 0 to 5 generate -- searchitems - 1 generate
|
cell_item: entity work.search_item
|
-- begin
|
generic map ( item_id => std_logic_vector(to_unsigned(iter_id,16)) )
|
-- cell_item: entity work.search_item
|
|
search_item_1 : search_item
|
|
-- generic map ( item_id => std_logic_vector'(X"0000")) -- std_logic_vector(to_unsigned(iter_id,16)) )
|
|
generic map ( item_id => (others => '0')) -- std_logic_vector'(X"0000")) -- std_logic_vector(to_unsigned(iter_id,16)) )
|
|
port map (
|
port map (
|
RX_CLK => RX_CLK,
|
RX_CLK => RX_CLK,
|
|
-- control flag(s) on the incoming bus
|
b1_px_valid => b1_px_valid,
|
b1_px_valid => b1_px_valid,
|
b1_px_type => b1_px_type, b1_buy_sell => b1_buy_sell, b1_px => b1_px, b1_qty => b1_qty, b1_sec => b1_sec, b1_id => b1_id,
|
-- pxdata: in price_packet
|
b2_px_type => b2_px_type, b2_buy_sell => b2_buy_sell, b2_px => b2_px, b2_qty => b2_qty, b2_sec => b2_sec, b2_id => b2_id
|
b1_px_type => b1_px_type,
|
|
b1_buy_sell => b1_buy_sell,
|
|
b1_px => b1_px,
|
|
b1_qty => b1_qty,
|
|
b1_sec => b1_sec,
|
|
b1_id => b1_id,
|
|
-- pxdata: out price_packet
|
|
b2_px_type => b2_px_type,
|
|
b2_buy_sell => b2_buy_sell,
|
|
b2_px => b2_px,
|
|
b2_qty => b2_qty,
|
|
b2_sec => b2_sec,
|
|
b2_id => b2_id
|
);
|
);
|
-- end generate items_array;
|
end generate items_array;
|
|
|
-- RX_CLK <= RX_CLK;
|
|
|
|
match: process (RX_CLK) is
|
process (RX_CLK) is
|
-- variable l : line;
|
-- variable l : line;
|
begin
|
begin
|
--if rising_edge(RX_CLK) then
|
if rising_edge(RX_CLK) then
|
if falling_edge(RX_CLK) then
|
|
-- write (l, String'(" Rising Edge "));
|
-- diagnostic (uncomment)
|
|
-- write (l, String'(" Control Rising Edge search_px_type_i: "));
|
|
-- for j in search_px_type_i'range loop
|
|
-- write(l, std_logic'image(search_px_type_i(j)) );
|
|
-- end loop;
|
|
-- write (l, String'(" search_px_valid_i: "));
|
|
-- write(l, std_logic'image(search_px_valid_i) );
|
|
-- write (l, String'(" state: "));
|
|
-- write(l, state );
|
|
-- write (l, String'(" b2_id: "));
|
-- for j in b2_id'range loop
|
-- for j in b2_id'range loop
|
-- write(l, std_logic'image(b2_id(j)) );
|
-- write(l, std_logic'image(b2_id(j)) );
|
-- end loop;
|
-- end loop;
|
|
-- write (l, String'(" b2_px_type: "));
|
|
-- for j in b2_px_type'range loop
|
|
-- write(l, std_logic'image(b2_px_type(j)) );
|
|
-- end loop;
|
-- writeline ( output, l);
|
-- writeline ( output, l);
|
|
|
|
|
if search_px_valid_i = '1' then
|
if search_px_valid_i = '1' then
|
|
|
if search_px_type_i = std_logic_vector'("00000") then
|
if search_px_type_i = std_logic_vector'("00000") then
|
-- do reset store and outputs
|
-- do reset store and outputs
|
order_px_type_o <= (others => '0');
|
order_px_type_o <= (others => '0');
|
order_buy_sell_o <= (others => 'Z'); -- 111 buy, 000 sell
|
order_buy_sell_o <= (others => 'Z'); -- 111 buy, 000 sell
|
order_px_o <= (others => 'Z'); -- price
|
order_px_o <= (others => 'Z'); -- price
|
Line 181... |
Line 197... |
b1_px_type <= (others => '0');
|
b1_px_type <= (others => '0');
|
b1_buy_sell <= (others => '0'); -- 111 buy, 000 sell
|
b1_buy_sell <= (others => '0'); -- 111 buy, 000 sell
|
b1_px <= (others => '0'); -- price
|
b1_px <= (others => '0'); -- price
|
b1_qty <= (others => '0'); -- quantity
|
b1_qty <= (others => '0'); -- quantity
|
b1_sec <= (others => '0'); -- 7x 8bits securities identifier
|
b1_sec <= (others => '0'); -- 7x 8bits securities identifier
|
-- b1_id <= (others => '0'); -- unique/identifier/counter
|
|
b1_px_valid <= '1';
|
b1_px_valid <= '1';
|
--
|
|
searchitems_count <= 0;
|
searchitems_count <= 0;
|
state <= 8;
|
state <= 8;
|
|
|
-- purely for test
|
|
elsif search_px_type_i = std_logic_vector'("01010") then
|
|
-- send the new security setting
|
|
b1_px_type <= std_logic_vector'("01010");
|
|
b1_buy_sell <= store_buy_sell;
|
|
b1_px <= store_px;
|
|
b1_qty <= store_qty;
|
|
b1_sec <= store_sec;
|
|
b1_id <= std_logic_vector'(X"0000"); -- std_logic_vector(to_unsigned(searchitems_count,16));
|
|
b1_px_valid <= '1';
|
|
state <= 4; -- increment items counter / send success
|
|
-- write (l, String'(" State=6 "));
|
|
-- for j in b2_id'range loop
|
|
-- write(l, std_logic'image(b2_id(j)) );
|
|
-- end loop;
|
|
-- writeline (output, l);
|
|
|
|
elsif search_px_type_i = std_logic_vector'("00110") then
|
elsif search_px_type_i = std_logic_vector'("00110") then
|
-- it's an incoming order price/qty security/buysell setting.
|
-- it's an incoming order price/qty security/buysell setting.
|
-- do set bus b1 and store from incoming price
|
-- do set bus b1 and store from incoming price
|
b1_px_type <= search_px_type_i;
|
b1_px_type <= search_px_type_i;
|
b1_buy_sell <= search_buy_sell_i;
|
b1_buy_sell <= search_buy_sell_i;
|
Line 221... |
Line 217... |
store_buy_sell <= search_buy_sell_i;
|
store_buy_sell <= search_buy_sell_i;
|
store_px <= search_px_i;
|
store_px <= search_px_i;
|
store_qty <= search_qty_i;
|
store_qty <= search_qty_i;
|
store_sec <= search_sec_i;
|
store_sec <= search_sec_i;
|
store_id <= search_id_i;
|
store_id <= search_id_i;
|
--b2_px_type <= std_logic_vector'(std_logic_vector'("00000"));
|
|
state <= 6;
|
state <= 6;
|
|
elsif search_px_type_i = std_logic_vector'("11100") then
|
elsif search_px_type_i = std_logic_vector'("00101") 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 or store_px_type /= std_logic_vector'(std_logic_vector'("0110")) ) then
|
b1_px_type <= search_px_type_i;
|
-- not this store_item instance no action, also stop anything that might be going on
|
b1_buy_sell <= search_buy_sell_i;
|
state <= 14;
|
b1_px <= search_px_i;
|
elsif (to_integer(unsigned(store_qty)) = 0 or to_integer(unsigned(b1_qty)) = 0 or
|
b1_qty <= search_qty_i;
|
(store_buy_sell = std_logic_vector'("111") and store_px < b1_px) or
|
b1_sec <= search_sec_i;
|
(store_buy_sell = std_logic_vector'("000") and store_px > b1_px) ) then
|
b1_id <= (others => 'Z');
|
-- no deal: this is the correct store_item but there's no match
|
b1_px_valid <= '1';
|
b2_px_type <= std_logic_vector'(std_logic_vector'("00000"));
|
-- do set store from incoming price
|
state <= 8;
|
store_px_type <= search_px_type_i;
|
else
|
store_buy_sell <= search_buy_sell_i;
|
-- send a return order
|
store_px <= search_px_i;
|
b2_px_type <= std_logic_vector'("1010");
|
store_qty <= search_qty_i;
|
b2_buy_sell <= store_buy_sell; -- 111 buy, 000 sell
|
store_sec <= search_sec_i;
|
b2_px <= b1_px; -- price
|
store_id <= search_id_i;
|
-- b2_qty <=
|
--b2_px_type <= std_logic_vector'(std_logic_vector'("00000"));
|
if b1_qty < store_qty then
|
state <= 10;
|
b2_qty <= b1_qty;
|
|
else
|
|
b2_qty <= store_qty;
|
|
end if; -- quantity
|
|
b2_sec <= store_sec; -- 7x 8bits securities identifier
|
|
b2_id <= store_id; -- unique/identifier/counter
|
|
-- update the store
|
|
-- store_qty
|
|
if (b1_qty < store_qty) then
|
|
store_qty <= std_logic_vector(to_unsigned( to_integer(unsigned(store_qty)) - to_integer(unsigned(b1_qty)) ,16 ));
|
|
else
|
|
store_qty <= (others => '0');
|
|
state <= 1;
|
|
end if;
|
|
end if;
|
|
|
|
else
|
else
|
-- no action - flash up Z's
|
-- no action - flash up Z's
|
order_px_type_o <= (others => 'Z');
|
order_px_type_o <= (others => 'Z');
|
order_buy_sell_o <= (others => 'Z'); -- 111 buy, 000 sell
|
order_buy_sell_o <= (others => 'Z'); -- 111 buy, 000 sell
|
order_px_o <= (others => 'Z'); -- price
|
order_px_o <= (others => 'Z'); -- price
|
Line 269... |
Line 247... |
order_sec_o <= (others => 'Z'); -- 7x 8bits securities identifier
|
order_sec_o <= (others => 'Z'); -- 7x 8bits securities identifier
|
order_id_o <= (others => 'Z'); -- unique/identifier/counter
|
order_id_o <= (others => 'Z'); -- unique/identifier/counter
|
order_px_valid_o <= '1';
|
order_px_valid_o <= '1';
|
state <= 8;
|
state <= 8;
|
end if; -- search_px_type
|
end if; -- search_px_type
|
|
|
else -- search_px_valid_i
|
else -- search_px_valid_i
|
-- no incoming search_px_i so check for state machine actions
|
-- no incoming search_px_i so check for state machine actions
|
case state is
|
case state is
|
when 1 =>
|
when 1 =>
|
-- sent return order, so clean up
|
-- sent return order, so clean up
|
Line 282... |
Line 259... |
order_px_o <= (others => 'Z'); -- price
|
order_px_o <= (others => 'Z'); -- price
|
order_qty_o <= (others => 'Z'); -- quantity
|
order_qty_o <= (others => 'Z'); -- quantity
|
order_sec_o <= (others => 'Z'); -- 7x 8bits securities identifier
|
order_sec_o <= (others => 'Z'); -- 7x 8bits securities identifier
|
order_id_o <= (others => 'Z'); -- unique/identifier/counter
|
order_id_o <= (others => 'Z'); -- unique/identifier/counter
|
state <= 16;
|
state <= 16;
|
|
|
when 6 =>
|
when 6 =>
|
-- sent query to set px and qty for a given security
|
-- sent query to set px and qty for a given security
|
if b2_px_type = std_logic_vector'("00110") then
|
if b2_px_type = std_logic_vector'("00110") then
|
-- it's a known security and the value has been set
|
-- it's a known security and the value has been set
|
order_px_type_o <= b2_px_type;
|
order_px_type_o <= b2_px_type;
|
order_px_valid_o <= '1';
|
order_px_valid_o <= '1';
|
state <= 8; -- reset next cycle
|
state <= 8; -- reset next cycle
|
else
|
else
|
-- no response, it's a new security+buysell
|
-- no response, it's a new security+buysell
|
if searchitems_count = searchitems-1 then
|
if searchitems_count = searchitems then
|
-- all search_items are filled - can't store this item
|
-- all search_items are filled - can't store this item
|
order_px_type_o <= std_logic_vector'("11111");
|
order_px_type_o <= std_logic_vector'("11111");
|
order_px_valid_o <= '1';
|
order_px_valid_o <= '1';
|
|
order_buy_sell_o <= (others => 'Z'); -- 111 buy, 000 sell
|
|
order_px_o <= (others => 'Z'); -- price
|
|
order_qty_o <= (others => 'Z'); -- quantity
|
|
order_sec_o <= (others => 'Z'); -- 7x 8bits securities identifier
|
|
order_id_o <= (others => 'Z'); -- unique/identifier/counter
|
b1_px_valid <= '0';
|
b1_px_valid <= '0';
|
state <= 8; -- reset next cycle
|
state <= 8; -- reset next cycle
|
else
|
else
|
-- send the new security setting
|
-- send the new security setting
|
b1_px_type <= std_logic_vector'("01010");
|
b1_px_type <= std_logic_vector'("01010");
|
b1_buy_sell <= store_buy_sell;
|
b1_buy_sell <= store_buy_sell;
|
b1_px <= store_px;
|
b1_px <= store_px;
|
b1_qty <= store_qty;
|
b1_qty <= store_qty;
|
b1_sec <= store_sec;
|
b1_sec <= store_sec;
|
b1_id <= std_logic_vector'(X"0000"); -- std_logic_vector(to_unsigned(searchitems_count,16));
|
b1_id <= std_logic_vector(to_unsigned(searchitems_count,16));
|
b1_px_valid <= '1';
|
b1_px_valid <= '1';
|
state <= 4; -- increment items counter / send success
|
state <= 4; -- increment items counter / send success
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
when 4 =>
|
when 4 =>
|
-- have set a new item, increment count and return
|
-- have set a new item, increment count and return
|
searchitems_count <= searchitems_count + 1;
|
searchitems_count <= searchitems_count + 1;
|
order_px_type_o <= std_logic_vector'("01010"); -- b2_px_type; --
|
order_px_type_o <= std_logic_vector'("01010"); -- b2_px_type; --
|
order_buy_sell_o <= (others => 'Z');
|
order_buy_sell_o <= (others => 'Z');
|
Line 324... |
Line 304... |
order_id_o <= b2_id;
|
order_id_o <= b2_id;
|
--
|
--
|
order_px_valid_o <= '1';
|
order_px_valid_o <= '1';
|
b1_px_valid <= '0';
|
b1_px_valid <= '0';
|
state <= 8; -- reset next cycle
|
state <= 8; -- reset next cycle
|
-- write (l, String'(" State=4 "));
|
|
-- for j in b2_id'range loop
|
|
-- write(l, std_logic'image(b2_id(j)) );
|
|
-- end loop;
|
|
-- writeline (output, l);
|
|
|
|
when 8 =>
|
when 8 =>
|
-- correct store_item but there was no match
|
-- correct store_item but there was no match
|
order_px_type_o <= std_logic_vector'("ZZZZZ");
|
order_px_type_o <= std_logic_vector'("ZZZZZ");
|
order_px_valid_o <= '0';
|
order_px_valid_o <= '0';
|
-- reset b1
|
-- reset b1
|
Line 342... |
Line 316... |
b1_px <= (others => 'Z');
|
b1_px <= (others => 'Z');
|
b1_qty <= (others => 'Z');
|
b1_qty <= (others => 'Z');
|
b1_sec <= (others => 'Z');
|
b1_sec <= (others => 'Z');
|
b1_id <= (others => 'Z');
|
b1_id <= (others => 'Z');
|
b1_px_valid <= '0';
|
b1_px_valid <= '0';
|
--
|
|
state <= 16;
|
state <= 16;
|
|
when 10 =>
|
|
if b2_px_type = std_logic_vector'("11100") then
|
|
-- got a hit .. send it
|
|
order_px_type_o <= std_logic_vector'("11100");
|
|
order_px_valid_o <= '1';
|
|
order_buy_sell_o <= b2_buy_sell; -- 111 buy, 000 sell
|
|
order_px_o <= b2_px; -- price
|
|
order_qty_o <= b2_qty; -- quantity
|
|
order_sec_o <= b2_sec; -- 7x 8bits securities identifier
|
|
order_id_o <= b2_id; -- unique/identifier/counter
|
|
b1_px_valid <= '0';
|
|
state <= 8; -- reset next cycle
|
|
else
|
|
-- some kind of non-useful price
|
|
order_buy_sell_o <= (others => 'Z');
|
|
order_px_o <= (others => 'Z');
|
|
order_qty_o <= (others => 'Z');
|
|
order_sec_o <= (others => 'Z');
|
|
order_id_o <= (others => 'Z');
|
|
if b2_px_type = std_logic_vector'("11101") then
|
|
-- incoming px (too low sale price)
|
|
order_px_type_o <= std_logic_vector'("11101");
|
|
else
|
|
-- no match
|
|
order_px_type_o <= std_logic_vector'("11110");
|
|
end if;
|
|
order_px_valid_o <= '1';
|
|
b1_px_valid <= '0';
|
|
state <= 8; -- reset next cycle
|
|
end if;
|
when others => null;
|
when others => null;
|
end case; -- state
|
end case; -- state
|
|
|
-- if (state < 16) then
|
|
-- state <= state + 1;
|
|
-- end if;
|
|
|
|
end if; -- search_px_valid_i
|
end if; -- search_px_valid_i
|
|
|
end if;
|
end if;
|
end process match;
|
end process;
|
|
|
-- b1_id <= std_logic_vector'(X"1010"); -- testing
|
|
|
|
end search_control_implementation;
|
end search_control_implementation;
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|