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

Subversion Repositories open_hitter

[/] [open_hitter/] [trunk/] [rtl/] [vhdl/] [search_control.vhd] - Blame information for rev 16

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

Line No. Rev Author Line
1 15 stvhawes
--////////////////////////////////////////////////////////////////////
2
--//                                                              ////
3
--// search_control.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 control item, used to set  ////
10
--// up, access and control the search.                           ////
11
--//    search_*_i - input to search_control                      ////
12
--//    order_*_o - output from search_control                    ////  
13
--// Buses perform the multiplex and are experienced by each item ////
14
--// as b1_* - set by search_control, input to search_item        ////
15
--//    b2_* - output from search_item, read by search_control    ////
16
--// The state machine in search_control coordinates the search,  ////
17
--// and the number of transitions is dependant on the incoming   ////
18
--// instruction (search_*_i).                                    ////
19
--//                                                              ////
20
--// To Do:                                                       ////
21
--//                                                              ////
22
--// Author(s):                                                   ////
23
--// - Stephen Hawes                                              ////
24
--//                                                              ////
25
--////////////////////////////////////////////////////////////////////
26
--//                                                              ////
27
--// Copyright (C) 2015 Stephen Hawes and OPENCORES.ORG           ////
28
--//                                                              ////
29
--// This source file may be used and distributed without         ////
30
--// restriction provided that this copyright statement is not    ////
31
--// removed from the file and that any derivative work contains  ////
32
--// the original copyright notice and the associated disclaimer. ////
33
--//                                                              ////
34
--// This source file is free software; you can redistribute it   ////
35
--// and/or modify it under the terms of the GNU Lesser General   ////
36
--// Public License as published by the Free Software Foundation; ////
37
--// either version 2.1 of the License, or (at your option) any   ////
38
--// later version.                                               ////
39
--//                                                              ////
40
--// This source is distributed in the hope that it will be       ////
41
--// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
42
--// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
43
--// PURPOSE. See the GNU Lesser General Public License for more  ////
44
--// details.                                                     ////
45
--//                                                              ////
46
--// You should have received a copy of the GNU Lesser General    ////
47
--// Public License along with this source; if not, download it   ////
48
--// from <http://www.opencores.org/lgpl.shtml>                   ////
49
--//                                                              ////
50
--////////////////////////////////////////////////////////////////////
51
--//
52
--// \$Id\$  TAKE OUT THE \'s and this comment in order to get this to work
53
--//
54
--// CVS Revision History
55
--//
56
--// \$Log\$  TAKE OUT THE \'s and this comment in order to get this to work
57
--//
58
library ieee;
59
use ieee.std_logic_1164.all;
60
use ieee.numeric_std.ALL;
61
 
62
entity search_control is
63
   generic ( searchitems : integer );
64
   port (
65
        RX_CLK: in std_logic;
66
        -- control flag(s) on the incoming bus
67
           search_px_valid_i: in std_logic;
68
        -- pxdata: in price_packet
69
           search_px_type_i: in std_logic_vector(4 downto 0);
70
           search_buy_sell_i: in std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
71
           search_px_i: in std_logic_vector(15 downto 0);     -- price
72
           search_qty_i: in std_logic_vector(15 downto 0);    -- quantity
73
           search_sec_i: in std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
74
           search_id_i: in std_logic_vector(15 downto 0);    -- unique/identifier/counter
75
        -- pxdata: out price_packet
76
           order_px_type_o: out std_logic_vector(4 downto 0);
77
           order_buy_sell_o: out std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
78
           order_px_o: out std_logic_vector(15 downto 0);     -- price
79
           order_qty_o: out std_logic_vector(15 downto 0);    -- quantity
80
           order_sec_o: out std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
81
           order_id_o: out std_logic_vector(15 downto 0);     -- unique/identifier/counter
82
        -- control flag(s) on the outgoing bus
83
           order_px_valid_o: out std_logic
84
   );
85
end search_control;
86
 
87
architecture search_control_implementation of search_control is
88
      component search_item
89
            generic ( item_id: std_logic_vector(15 downto 0) );
90
            port (
91
                 RX_CLK: in std_logic;
92
                 -- control flag(s) on the incoming bus
93
                    b1_px_valid: in std_logic;
94
                 -- pxdata: in price_packet
95
                    b1_px_type: in std_logic_vector(4 downto 0);
96
                    b1_buy_sell: in std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
97
                    b1_px: in std_logic_vector(15 downto 0);     -- price
98
                    b1_qty: in std_logic_vector(15 downto 0);    -- quantity
99
                    b1_sec: in std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
100
                    b1_id: in std_logic_vector(15 downto 0);    -- unique/identifier/counter
101
                 -- pxdata: out price_packet
102
                    b2_px_type: out std_logic_vector(4 downto 0);
103
                    b2_buy_sell: out std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
104
                    b2_px: out std_logic_vector(15 downto 0);     -- price
105
                    b2_qty: out std_logic_vector(15 downto 0);    -- quantity
106
                    b2_sec: out std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
107
                    b2_id: out std_logic_vector(15 downto 0)      -- unique/identifier/counter
108
            );
109
      end component;
110 16 stvhawes
       -- for search_item_0: search_item use entity work.search_item;
111
      signal searchitems_count : integer := 0;
112 15 stvhawes
      --
113
      signal state : integer range 0 to 16 := 16;
114
   -- pxdata: store price_packet
115
      signal store_px_type: std_logic_vector(4 downto 0) := (others => '0');
116
      signal store_buy_sell: std_logic_vector(2 downto 0) := (others => '0');   -- 111 buy, 000 sell
117
      signal store_px: std_logic_vector(15 downto 0) := (others => '0');     -- price
118
      signal store_qty: std_logic_vector(15 downto 0) := (others => '0');    -- quantity
119
      signal store_sec: std_logic_vector(55 downto 0) := (others => '0');    -- 7x 8bits securities identifier
120
      signal store_id: std_logic_vector(15 downto 0) := (others => '0');     -- unique/identifier/counter
121
   -- control flag(s) on the incoming bus
122
      signal b1_px_valid: std_logic;
123
   -- pxdata: b1 price_packet
124
      signal b1_px_type: std_logic_vector(4 downto 0) := (others => '0');
125
      signal b1_buy_sell: std_logic_vector(2 downto 0) := (others => '0');   -- 111 buy, 000 sell
126
      signal b1_px: std_logic_vector(15 downto 0) := (others => '0');     -- price
127
      signal b1_qty: std_logic_vector(15 downto 0) := (others => '0');    -- quantity
128
      signal b1_sec: std_logic_vector(55 downto 0) := (others => '0');    -- 7x 8bits securities identifier
129
      signal b1_id: std_logic_vector(15 downto 0) := (others => '0');     -- unique/identifier/counter
130
   -- pxdata: b2 price_packet
131
      signal b2_px_type: std_logic_vector(4 downto 0) := (others => '0');
132
      signal b2_buy_sell: std_logic_vector(2 downto 0) := (others => '0');   -- 111 buy, 000 sell
133
      signal b2_px: std_logic_vector(15 downto 0) := (others => '0');     -- price
134
      signal b2_qty: std_logic_vector(15 downto 0) := (others => '0');    -- quantity
135
      signal b2_sec: std_logic_vector(55 downto 0) := (others => '0');    -- 7x 8bits securities identifier
136
      signal b2_id: std_logic_vector(15 downto 0) := (others => '0');     -- unique/identifier/counter
137
begin
138
      items_array : for iter_id in 0 to searchitems - 1 generate
139
      begin
140
         cell_item : entity work.search_item
141
            generic map ( item_id => std_logic_vector(to_unsigned(iter_id,16)) )
142
            port map (
143
                         RX_CLK => RX_CLK,
144
                         b1_px_valid => b1_px_valid,
145
                         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 => b2_id,
146
                         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
147
                     );
148
      end generate items_array;
149
 
150
   match: process (RX_CLK) is
151
   begin
152
      if rising_edge(RX_CLK) then
153
         if search_px_valid_i = '1' then
154
 
155
            if search_px_type_i = std_logic_vector'("00000") then
156
                   -- do reset store and outputs
157 16 stvhawes
                   order_px_type_o  <= (others => 'Z');
158
                   order_buy_sell_o <= (others => 'Z');   -- 111 buy, 000 sell
159
                   order_px_o       <= (others => 'Z');   -- price
160
                   order_qty_o      <= (others => 'Z');   -- quantity
161
                   order_sec_o      <= (others => 'Z');   -- 7x 8bits securities identifier
162
                   order_px_valid_o <= '1';
163 15 stvhawes
                   --
164 16 stvhawes
                   b1_px_type  <= (others => '0');
165
                   b1_buy_sell <= (others => '0');   -- 111 buy, 000 sell
166
                   b1_px       <= (others => '0');   -- price
167
                   b1_qty      <= (others => '0');   -- quantity
168
                   b1_sec      <= (others => '0');   -- 7x 8bits securities identifier
169
                   -- b1_id      <= (others => '0');   -- unique/identifier/counter
170
                   b1_px_valid <= '1';
171 15 stvhawes
                   --
172 16 stvhawes
                   searchitems_count <= 0;
173 15 stvhawes
                   state <= 8;
174
 
175
            elsif search_px_type_i = std_logic_vector'("00110") then
176
                   -- do set store from incoming price 
177
                   store_px_type  <= b1_px_type;
178
                   store_buy_sell <= b1_buy_sell;
179
                   store_px       <= b1_px;
180
                   store_qty      <= b1_qty;
181
                   store_sec      <= b1_sec;
182
                   store_id       <= b1_id;
183
                   --
184
                   b2_px_type <= std_logic_vector'(std_logic_vector'("00000"));
185
                   state <= 8;
186
 
187
            elsif search_px_type_i = std_logic_vector'("00101") then
188
                   -- incoming price, register it and start the state machine
189
                   if (store_sec /= b1_sec or store_buy_sell = b1_buy_sell or store_px_type /= std_logic_vector'(std_logic_vector'("0110")) ) then
190
                      -- not this store_item instance no action, also stop anything that might be going on
191
                      state <= 14;
192
                   elsif (to_integer(unsigned(store_qty)) = 0 or to_integer(unsigned(b1_qty)) = 0 or
193
                             (store_buy_sell = std_logic_vector'("111") and store_px < b1_px) or
194
                             (store_buy_sell = std_logic_vector'("000") and store_px > b1_px) ) then
195
                      -- no deal: this is the correct store_item but there's no match
196
                      b2_px_type <= std_logic_vector'(std_logic_vector'("00000"));
197
                      state <= 8;
198
                   else
199
                      -- send a return order
200
                      b2_px_type <= std_logic_vector'("1010");
201
                      b2_buy_sell <= store_buy_sell;   -- 111 buy, 000 sell
202
                      b2_px <= b1_px;                   -- price
203
                      -- b2_qty <= 
204
                      if b1_qty < store_qty then
205
                         b2_qty <= b1_qty;
206
                      else
207
                         b2_qty <= store_qty;
208
                      end if;    -- quantity
209
                      b2_sec <= store_sec;                                          -- 7x 8bits securities identifier
210
                      b2_id <= store_id;                                            -- unique/identifier/counter
211
                      -- update the store
212
                      -- store_qty
213
                      if (b1_qty < store_qty) then
214
                         store_qty <= std_logic_vector(to_unsigned( to_integer(unsigned(store_qty)) - to_integer(unsigned(b1_qty)) ,16 ));
215
                      else
216
                         store_qty <= (others => '0');
217
                         state <= 1;
218
                      end  if;
219
                   end if;
220
 
221
            else
222
               -- no action
223
               null;
224
            end if;   -- search_px_type
225
 
226
         else     -- search_px_valid_i
227
            -- no incoming search_px_i so check for state machine actions
228
            case state is
229
               when 1 =>
230
                   -- sent return order, so clean up
231
                   b2_px_type  <= (others => 'Z');
232
                   b2_buy_sell <= (others => 'Z');    -- 111 buy, 000 sell
233
                   b2_px       <= (others => 'Z');    -- price
234
                   b2_qty      <= (others => 'Z');    -- quantity
235
                   b2_sec      <= (others => 'Z');    -- 7x 8bits securities identifier
236
                   b2_id       <= (others => 'Z');    -- unique/identifier/counter
237
                   state <= 16;
238
 
239
               when 8 =>
240
                    -- correct store_item but there was no match
241
                    b2_px_type <= std_logic_vector'("ZZZZZ");
242
                   state <= 16;
243 16 stvhawes
                   order_px_valid_o <= '0';
244 15 stvhawes
 
245
               when others => null;
246
            end case;   -- state
247
 
248
            if (state < 16) then
249
               state <= state + 1;
250
            end if;
251
 
252
         end if;     -- search_px_valid_i
253
 
254
      end if;
255
   end process match;
256
 
257
end search_control_implementation;
258
 

powered by: WebSVN 2.1.0

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