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

Subversion Repositories open_hitter

[/] [open_hitter/] [trunk/] [rtl/] [vhdl/] [search_item.vhd] - Blame information for rev 12

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

Line No. Rev Author Line
1 11 stvhawes
--////////////////////////////////////////////////////////////////////
2
--//                                                              ////
3
--// search_item.vhd                                              ////
4
--//                                                              ////
5
--// This file is part of the open_hitter opencores effort.       ////
6
--// <http://www.opencores.org/cores/open_hitter/>                ////
7
--//                                                              ////
8
--// Module Description:                                          ////
9
--// This is the multipelexed search's repeated item. The project ////
10
--// buses perform the multiplex and are experienced by each item ////
11
--// as b1_* - input to search_item                               ////
12
--//    b2_* - output from search_item                            ////
13
--// there is also a small state-machine in each search_item.     ////
14
--// For now, the count of number of states is fixed, per px_type ////
15
--//                                                              ////
16
--// To Do:                                                       ////
17
--//                                                              ////
18
--// Author(s):                                                   ////
19
--// - Stephen Hawes                                              ////
20
--//                                                              ////
21
--////////////////////////////////////////////////////////////////////
22
--//                                                              ////
23
--// Copyright (C) 2015 Stephen Hawes and OPENCORES.ORG           ////
24
--//                                                              ////
25
--// This source file may be used and distributed without         ////
26
--// restriction provided that this copyright statement is not    ////
27
--// removed from the file and that any derivative work contains  ////
28
--// the original copyright notice and the associated disclaimer. ////
29
--//                                                              ////
30
--// This source file is free software; you can redistribute it   ////
31
--// and/or modify it under the terms of the GNU Lesser General   ////
32
--// Public License as published by the Free Software Foundation; ////
33
--// either version 2.1 of the License, or (at your option) any   ////
34
--// later version.                                               ////
35
--//                                                              ////
36
--// This source is distributed in the hope that it will be       ////
37
--// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
38
--// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
39
--// PURPOSE. See the GNU Lesser General Public License for more  ////
40
--// details.                                                     ////
41
--//                                                              ////
42
--// You should have received a copy of the GNU Lesser General    ////
43
--// Public License along with this source; if not, download it   ////
44
--// from <http://www.opencores.org/lgpl.shtml>                   ////
45
--//                                                              ////
46
--////////////////////////////////////////////////////////////////////
47
--//
48
--// \$Id\$  TAKE OUT THE \'s and this comment in order to get this to work
49
--//
50
--// CVS Revision History
51
--//
52
--// \$Log\$  TAKE OUT THE \'s and this comment in order to get this to work
53
--//
54
library ieee;
55
use ieee.std_logic_1164.all;
56 12 stvhawes
use ieee.numeric_std.ALL;
57 11 stvhawes
 
58
entity search_item is
59
   port (
60
        RX_CLK: in std_logic;
61
        -- control flag(s) on the incoming bus
62
           b1_px_valid: in std_logic;
63
        -- pxdata: in price_packet
64 12 stvhawes
           b1_px_type: in std_logic_vector(4 downto 0);
65
           b1_buy_sell: in std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
66
           b1_px: in std_logic_vector(15 downto 0);     -- price
67
           b1_qty: in std_logic_vector(15 downto 0);    -- quantity
68
           b1_sec: in std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
69
           b1_id: in std_logic_vector(15 downto 0);    -- unique/identifier/counter
70 11 stvhawes
        -- pxdata: out price_packet
71
           b2_px_type: out std_logic_vector(4 downto 0);
72
           b2_buy_sell: out std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
73
           b2_px: out std_logic_vector(15 downto 0);     -- price
74
           b2_qty: out std_logic_vector(15 downto 0);    -- quantity
75
           b2_sec: out std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
76 12 stvhawes
           b2_id: out std_logic_vector(15 downto 0)      -- unique/identifier/counter
77 11 stvhawes
   );
78
end search_item;
79
 
80
architecture search_item_implementation of search_item is
81
      signal state : integer range 0 to 16 := 16;
82
   -- pxdata: out price_packet
83
      signal store_px_type: std_logic_vector(4 downto 0) := (others => '0');
84
      signal store_buy_sell: std_logic_vector(2 downto 0) := (others => '0');   -- 111 buy, 000 sell
85
      signal store_px: std_logic_vector(15 downto 0) := (others => '0');     -- price
86
      signal store_qty: std_logic_vector(15 downto 0) := (others => '0');    -- quantity
87
      signal store_sec: std_logic_vector(55 downto 0) := (others => '0');    -- 7x 8bits securities identifier
88
      signal store_id: std_logic_vector(15 downto 0) := (others => '0');     -- unique/identifier/counter
89
begin
90
   match: process (RX_CLK) is
91
   begin
92
      if rising_edge(RX_CLK) then
93 12 stvhawes
         if b1_px_valid = '0' then
94 11 stvhawes
 
95 12 stvhawes
            if b1_px_type = std_logic_vector'("0000") then
96 11 stvhawes
                   -- do reset store and outputs
97
                   store_px_type  <= (others => '0');
98
                   store_buy_sell <= (others => '0');   -- 111 buy, 000 sell
99
                   store_px       <= (others => '0');   -- price
100
                   store_qty      <= (others => '0');   -- quantity
101
                   store_sec      <= (others => '0');   -- 7x 8bits securities identifier
102
                   store_id       <= (others => '0');   -- unique/identifier/counter
103
                   --
104
                   b2_px_type  <= (others => 'Z');
105
                   b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
106
                   b2_px       <= (others => 'Z');   -- price
107
                   b2_qty      <= (others => 'Z');   -- quantity
108
                   b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
109
                   b2_id       <= (others => 'Z');   -- unique/identifier/counter
110
                   --
111 12 stvhawes
                   b2_px_type <= std_logic_vector'(std_logic_vector'("0000"));
112 11 stvhawes
                   state <= 8;
113
 
114 12 stvhawes
            elsif b1_px_type = std_logic_vector'("0110") then
115 11 stvhawes
                   -- do set store from incoming price 
116
                   store_px_type  <= b1_px_type;
117
                   store_buy_sell <= b1_buy_sell;
118
                   store_px       <= b1_px;
119
                   store_qty      <= b1_qty;
120
                   store_sec      <= b1_sec;
121
                   store_id       <= b1_id;
122
                   --
123 12 stvhawes
                   b2_px_type <= std_logic_vector'(std_logic_vector'("0000"));
124 11 stvhawes
                   state <= 8;
125
 
126 12 stvhawes
            elsif b1_px_type = std_logic_vector'("0101") then
127 11 stvhawes
                   -- incoming price, register it and start the state machine
128 12 stvhawes
                   if (store_sec /= b1_sec or store_buy_sell = b1_buy_sell or store_px_type /= std_logic_vector'(std_logic_vector'("0110")) ) then
129 11 stvhawes
                      -- not this store_item instance no action, also stop anything that might be going on
130
                      state <= 14;
131 12 stvhawes
                   elsif (to_integer(unsigned(store_qty)) = 0 or to_integer(unsigned(b1_qty)) = 0 or
132
                             (store_buy_sell = std_logic_vector'("111") and store_px < b1_px) or
133
                             (store_buy_sell = std_logic_vector'("000") and store_px > b1_px) ) then
134 11 stvhawes
                      -- no deal: this is the correct store_item but there's no match
135 12 stvhawes
                      b2_px_type <= std_logic_vector'(std_logic_vector'("0000"));
136 11 stvhawes
                      state <= 8;
137
                   else
138
                      -- send a return order
139 12 stvhawes
                      b2_px_type <= std_logic_vector'("1010");
140 11 stvhawes
                      b2_buy_sell <= store_buy_sell;   -- 111 buy, 000 sell
141
                      b2_px <= b1_px;                   -- price
142 12 stvhawes
                      -- b2_qty <= 
143
                      if b1_qty < store_qty then
144
                         b2_qty <= b1_qty;
145
                      else
146
                         b2_qty <= store_qty;
147
                      end if;    -- quantity
148
                      b2_sec <= store_sec;                                          -- 7x 8bits securities identifier
149 11 stvhawes
                      b2_id <= store_id;                                            -- unique/identifier/counter
150
                      -- update the store
151 12 stvhawes
                      -- store_qty
152
                      if (b1_qty < store_qty) then
153
                         store_qty <= std_logic_vector(to_unsigned( to_integer(unsigned(store_qty)) - to_integer(unsigned(b1_qty)) ,16 ));
154
                      else
155
                         store_qty <= (others => '0');
156
                         state <= 1;
157
                      end  if;
158 11 stvhawes
                   end if;
159
 
160 12 stvhawes
            else
161
               -- no action
162
               null;
163
            end if;   -- b1_px_type
164 11 stvhawes
 
165
         else     -- b1_px_valid
166
            -- no incoming b1_px so check for state machine actions
167
            case state is
168
               when 1 =>
169
                   -- sent return order, so clean up
170
                   b2_px_type  <= (others => 'Z');
171
                   b2_buy_sell <= (others => 'Z');    -- 111 buy, 000 sell
172
                   b2_px       <= (others => 'Z');    -- price
173
                   b2_qty      <= (others => 'Z');    -- quantity
174
                   b2_sec      <= (others => 'Z');    -- 7x 8bits securities identifier
175 12 stvhawes
                   b2_id       <= (others => 'Z');    -- unique/identifier/counter
176 11 stvhawes
                   state <= 16;
177
 
178
               when 8 =>
179
                    -- correct store_item but there was no match
180 12 stvhawes
                    b2_px_type <= std_logic_vector'("ZZZZ");
181 11 stvhawes
                   state <= 16;
182
 
183
               when others => null;
184
            end case;   -- state
185
 
186
            if (state < 16) then
187
               state <= state + 1;
188
            end if;
189
 
190
         end if;     -- b1_px_valid
191
 
192
      end if;
193
   end process match;
194
 
195
end search_item_implementation;
196
 

powered by: WebSVN 2.1.0

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