OpenCores
URL https://opencores.org/ocsvn/open_hitter/open_hitter/trunk

Subversion Repositories open_hitter

[/] [open_hitter/] [trunk/] [rtl/] [vhdl/] [search_control.vhd] - Rev 21

Go to most recent revision | Compare with Previous | Blame | View Log

--////////////////////////////////////////////////////////////////////
--//                                                              ////
--// search_control.vhd                                           ////
--//                                                              ////
--// This file is part of the open_hitter opencores effort.       ////
--// <http://www.opencores.org/cores/open_hitter/>                ////
--//                                                              ////
--// Module Description:                                          ////
--// This is the multipelexed search's control item, used to set  ////
--// up, access and control the search.                           ////
--//    search_*_i - input to search_control                      ////
--//    order_*_o - output from search_control                    ////  
--// Buses perform the multiplex and are experienced by each item ////
--// as b1_* - set by search_control, input to search_item        ////
--//    b2_* - output from search_item, read by search_control    ////
--// The state machine in search_control coordinates the search,  ////
--// and the number of transitions is dependant on the incoming   ////
--// instruction (search_*_i).                                    ////
--//                                                              ////
--// To Do:                                                       ////
--//                                                              ////
--// Author(s):                                                   ////
--// - Stephen Hawes                                              ////
--//                                                              ////
--////////////////////////////////////////////////////////////////////
--//                                                              ////
--// Copyright (C) 2015 Stephen Hawes and OPENCORES.ORG           ////
--//                                                              ////
--// This source file may be used and distributed without         ////
--// restriction provided that this copyright statement is not    ////
--// removed from the file and that any derivative work contains  ////
--// the original copyright notice and the associated disclaimer. ////
--//                                                              ////
--// This source file is free software; you can redistribute it   ////
--// and/or modify it under the terms of the GNU Lesser General   ////
--// Public License as published by the Free Software Foundation; ////
--// either version 2.1 of the License, or (at your option) any   ////
--// later version.                                               ////
--//                                                              ////
--// This source 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 Lesser General Public License for more  ////
--// details.                                                     ////
--//                                                              ////
--// You should have received a copy of the GNU Lesser General    ////
--// Public License along with this source; if not, download it   ////
--// from <http://www.opencores.org/lgpl.shtml>                   ////
--//                                                              ////
--////////////////////////////////////////////////////////////////////
--//
--// \$Id\$  TAKE OUT THE \'s and this comment in order to get this to work
--//
--// CVS Revision History
--//
--// \$Log\$  TAKE OUT THE \'s and this comment in order to get this to work
--//
library ieee;
use ieee.std_logic_1164.all;     
use ieee.numeric_std.ALL;
-- use std.textio.all; --  Imports the standard textio package.
 
entity search_control is
   generic ( searchitems : integer );
   port (
        RX_CLK: in std_logic;
        -- control flag(s) on the incoming bus
        search_px_valid_i: in std_logic;
        -- pxdata: in price_packet
        search_px_type_i: in std_logic_vector(4 downto 0);
        search_buy_sell_i: in std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
        search_px_i: in std_logic_vector(15 downto 0);     -- price
        search_qty_i: in std_logic_vector(15 downto 0);    -- quantity
        search_sec_i: in std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
        search_id_i: in std_logic_vector(15 downto 0);    -- unique/identifier/counter
        -- pxdata: out price_packet
        order_px_type_o: out std_logic_vector(4 downto 0);
        order_buy_sell_o: out std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
        order_px_o: out std_logic_vector(15 downto 0);     -- price
        order_qty_o: out std_logic_vector(15 downto 0);    -- quantity
        order_sec_o: out std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
        order_id_o: out std_logic_vector(15 downto 0);     -- unique/identifier/counter
        -- control flag(s) on the outgoing bus
        order_px_valid_o: out std_logic
   );
end search_control;
 
architecture search_control_implementation of search_control is
   component search_item
     generic ( item_id: std_logic_vector(15 downto 0) );
     port (
        RX_CLK: in std_logic;
        -- control flag(s) on the incoming bus
        b1_px_valid: in std_logic;
        -- pxdata: in price_packet
        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_px: in std_logic_vector(15 downto 0);     -- price
        b1_qty: in std_logic_vector(15 downto 0);    -- quantity
        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
        -- pxdata: out price_packet
        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_px: out std_logic_vector(15 downto 0);     -- price
        b2_qty: out std_logic_vector(15 downto 0);    -- quantity
        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
     );
   end component;
      signal searchitems_count : integer;
      signal state : integer range 0 to 16;
      -- pxdata: store price_packet
      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_px: std_logic_vector(15 downto 0) := (others => 'Z');     -- price
      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_id: std_logic_vector(15 downto 0) := (others => 'Z');     -- unique/identifier/counter
      -- control flag(s) on the incoming bus
      signal b1_px_valid: std_logic;
      -- pxdata: in price_packet
      signal b1_px_type: std_logic_vector(4 downto 0);
      signal b1_buy_sell: std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
      signal b1_px: std_logic_vector(15 downto 0);     -- price
      signal b1_qty: std_logic_vector(15 downto 0);    -- quantity
      signal b1_sec: std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
      signal b1_id: std_logic_vector(15 downto 0);    -- unique/identifier/counter
      -- pxdata: out price_packet
      signal b2_px_type: std_logic_vector(4 downto 0);
      signal b2_buy_sell: std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
      signal b2_px: std_logic_vector(15 downto 0);     -- price
      signal b2_qty: std_logic_vector(15 downto 0);    -- quantity
      signal b2_sec: std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
      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
        cell_item: entity work.search_item
           generic map ( item_id => std_logic_vector(to_unsigned(iter_id,16)) )
           port map (
              RX_CLK => RX_CLK,
              -- control flag(s) on the incoming bus
              b1_px_valid => b1_px_valid,
              -- pxdata: in price_packet
              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;
 
   process (RX_CLK) is
        -- variable l : line;
   begin
      if rising_edge(RX_CLK) then
 
      -- 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
      --             write(l, std_logic'image(b2_id(j)) );
      --          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);
 
      if search_px_valid_i = '1' then
            if search_px_type_i = std_logic_vector'("00000") then
                   -- do reset store and outputs
                   order_px_type_o  <= (others => '0');
                   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');   
                   order_px_valid_o <= '1';
                   --
                   b1_px_type  <= (others => '0');
                   b1_buy_sell <= (others => '0');   -- 111 buy, 000 sell
                   b1_px       <= (others => '0');   -- price
                   b1_qty      <= (others => '0');   -- quantity
                   b1_sec      <= (others => '0');   -- 7x 8bits securities identifier
                   b1_px_valid <= '1';
                   searchitems_count <= 0;  
                   state <= 8;
            elsif search_px_type_i = std_logic_vector'("00110") then
                   -- it's an incoming order price/qty security/buysell setting.
                   -- do set bus b1 and store from incoming price 
                   b1_px_type  <= search_px_type_i;
                   b1_buy_sell <= search_buy_sell_i;
                   b1_px       <= search_px_i;
                   b1_qty      <= search_qty_i;
                   b1_sec      <= search_sec_i;
                   b1_id       <= (others => 'Z');
                   b1_px_valid <= '1';
                   -- do set store from incoming price 
                   store_px_type  <= search_px_type_i;
                   store_buy_sell <= search_buy_sell_i;
                   store_px       <= search_px_i;
                   store_qty      <= search_qty_i;
                   store_sec      <= search_sec_i;
                   store_id       <= search_id_i;
                   state <= 6;
            elsif search_px_type_i = std_logic_vector'("11100") then
                   -- incoming price, register it and start the state machine
                   b1_px_type  <= search_px_type_i;
                   b1_buy_sell <= search_buy_sell_i;
                   b1_px       <= search_px_i;
                   b1_qty      <= search_qty_i;
                   b1_sec      <= search_sec_i;
                   b1_id       <= (others => 'Z');
                   b1_px_valid <= '1';
                   -- do set store from incoming price
                   store_px_type  <= search_px_type_i;
                   store_buy_sell <= search_buy_sell_i;
                   store_px       <= search_px_i;
                   store_qty      <= search_qty_i;
                   store_sec      <= search_sec_i;
                   store_id       <= search_id_i;
                   --b2_px_type <= std_logic_vector'(std_logic_vector'("00000"));
                   state <= 10;
            else   -- nothing 10000  (avoid ZZZZZ)
               -- no action - flash up Z's
               order_px_type_o  <= std_logic_vector'("10000");  -- avoiding ZZZZZ
               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
               order_px_valid_o <= '1';
               state <= 8;
            end if;   -- search_px_type
         else     -- search_px_valid_i
            -- no incoming search_px_i so check for state machine actions
            case state is
               when 1 => 
                   -- sent return order, so clean up
                   order_px_type_o  <= (others => 'Z');
                   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
                   state <= 16;
               when 6 =>
                   -- sent query to set px and qty for a given security
                   if b2_px_type = std_logic_vector'("00110") then
                      -- it's a known security and the value has been set
                      order_px_type_o <= b2_px_type;
                      order_px_valid_o <= '1';
                      state <= 8;    -- reset next cycle
                   else
                      -- no response, it's a new security+buysell
                      if searchitems_count = searchitems then
                         -- all search_items are filled - can't store this item
                         order_px_type_o <= std_logic_vector'("11111");
                         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';
                         state <= 8;    -- reset next cycle
                      else
                         -- 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(to_unsigned(searchitems_count,16));
                         b1_px_valid <= '1';
                         state <= 4;   -- increment items counter / send success
                      end if;
                   end if;
               when 4 => 
                   -- have set a new item, increment count and return
                   searchitems_count <= searchitems_count + 1;
                   order_px_type_o  <= std_logic_vector'("01010");  -- b2_px_type;     --
                   order_buy_sell_o <= (others => 'Z');  
                   order_px_o       <= (others => 'Z');   
                   order_qty_o      <= (others => 'Z');   
                   order_sec_o      <= (others => 'Z'); 
                   order_id_o       <= b2_id;   
                   --
                   order_px_valid_o <= '1';
                   b1_px_valid <= '0';
                   state <= 8;    -- reset next cycle
               when 8 =>
                   -- correct store_item but there was no match
                   order_px_type_o <= std_logic_vector'("ZZZZZ");
                   order_px_valid_o <= '0';
                   -- reset b1
                   b1_px_type  <= (others => 'Z');
                   b1_buy_sell <= (others => 'Z');
                   b1_px       <= (others => 'Z');
                   b1_qty      <= (others => 'Z');
                   b1_sec      <= (others => 'Z');
                   b1_id       <= (others => 'Z');
                   b1_px_valid <= '0';
                   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;
            end case;   -- state
         end if;     -- search_px_valid_i
      end if;
   end process;
end search_control_implementation;
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.