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 17

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 17 stvhawes
--use std.textio.all; --  Imports the standard textio package.
62 15 stvhawes
 
63
entity search_control is
64
   generic ( searchitems : integer );
65
   port (
66
        RX_CLK: in std_logic;
67
        -- control flag(s) on the incoming bus
68
           search_px_valid_i: in std_logic;
69
        -- pxdata: in price_packet
70
           search_px_type_i: in std_logic_vector(4 downto 0);
71
           search_buy_sell_i: in std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
72
           search_px_i: in std_logic_vector(15 downto 0);     -- price
73
           search_qty_i: in std_logic_vector(15 downto 0);    -- quantity
74
           search_sec_i: in std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
75
           search_id_i: in std_logic_vector(15 downto 0);    -- unique/identifier/counter
76
        -- pxdata: out price_packet
77
           order_px_type_o: out std_logic_vector(4 downto 0);
78
           order_buy_sell_o: out std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
79
           order_px_o: out std_logic_vector(15 downto 0);     -- price
80
           order_qty_o: out std_logic_vector(15 downto 0);    -- quantity
81
           order_sec_o: out std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
82
           order_id_o: out std_logic_vector(15 downto 0);     -- unique/identifier/counter
83
        -- control flag(s) on the outgoing bus
84
           order_px_valid_o: out std_logic
85
   );
86
end search_control;
87
 
88
architecture search_control_implementation of search_control is
89
      component search_item
90
            generic ( item_id: std_logic_vector(15 downto 0) );
91
            port (
92
                 RX_CLK: in std_logic;
93
                 -- control flag(s) on the incoming bus
94
                    b1_px_valid: in std_logic;
95
                 -- pxdata: in price_packet
96
                    b1_px_type: in std_logic_vector(4 downto 0);
97
                    b1_buy_sell: in std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
98
                    b1_px: in std_logic_vector(15 downto 0);     -- price
99
                    b1_qty: in std_logic_vector(15 downto 0);    -- quantity
100
                    b1_sec: in std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
101
                    b1_id: in std_logic_vector(15 downto 0);    -- unique/identifier/counter
102
                 -- pxdata: out price_packet
103
                    b2_px_type: out std_logic_vector(4 downto 0);
104
                    b2_buy_sell: out std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
105
                    b2_px: out std_logic_vector(15 downto 0);     -- price
106
                    b2_qty: out std_logic_vector(15 downto 0);    -- quantity
107
                    b2_sec: out std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
108
                    b2_id: out std_logic_vector(15 downto 0)      -- unique/identifier/counter
109
            );
110
      end component;
111 17 stvhawes
   for search_item_1: search_item use entity work.search_item;
112 16 stvhawes
      signal searchitems_count : integer := 0;
113 15 stvhawes
      --
114
      signal state : integer range 0 to 16 := 16;
115 17 stvhawes
      --
116
      --signal RX_CLK: std_logic;
117 15 stvhawes
   -- pxdata: store price_packet
118 17 stvhawes
      signal store_px_type: std_logic_vector(4 downto 0) := (others => 'Z');
119
      signal store_buy_sell: std_logic_vector(2 downto 0) := (others => 'Z');   -- 111 buy, 000 sell
120
      signal store_px: std_logic_vector(15 downto 0) := (others => 'Z');     -- price
121
      signal store_qty: std_logic_vector(15 downto 0) := (others => 'Z');    -- quantity
122
      signal store_sec: std_logic_vector(55 downto 0) := (others => 'Z');    -- 7x 8bits securities identifier
123
      signal store_id: std_logic_vector(15 downto 0) := (others => 'Z');     -- unique/identifier/counter
124 15 stvhawes
   -- control flag(s) on the incoming bus
125
      signal b1_px_valid: std_logic;
126
   -- pxdata: b1 price_packet
127 17 stvhawes
      signal b1_px_type: std_logic_vector(4 downto 0) := (others => 'Z');
128
      signal b1_buy_sell: std_logic_vector(2 downto 0) := (others => 'Z');   -- 111 buy, 000 sell
129
      signal b1_px: std_logic_vector(15 downto 0) := (others => 'Z');     -- price
130
      signal b1_qty: std_logic_vector(15 downto 0) := (others => 'Z');    -- quantity
131
      signal b1_sec: std_logic_vector(55 downto 0) := (others => 'Z');    -- 7x 8bits securities identifier
132
      signal b1_id: std_logic_vector(15 downto 0) := (others => 'Z');     -- unique/identifier/counter
133 15 stvhawes
   -- pxdata: b2 price_packet
134 17 stvhawes
      signal b2_px_type: std_logic_vector(4 downto 0) := (others => 'Z');
135
      signal b2_buy_sell: std_logic_vector(2 downto 0) := (others => 'Z');   -- 111 buy, 000 sell
136
      signal b2_px: std_logic_vector(15 downto 0) := (others => 'Z');     -- price
137
      signal b2_qty: std_logic_vector(15 downto 0) := (others => 'Z');    -- quantity
138
      signal b2_sec: std_logic_vector(55 downto 0) := (others => 'Z');    -- 7x 8bits securities identifier
139
      signal b2_id: std_logic_vector(15 downto 0) := (others => 'Z');     -- unique/identifier/counter
140 15 stvhawes
begin
141 17 stvhawes
  --    items_array : for iter_id in 0 to 5 generate --  searchitems - 1 generate
142
  --      begin
143
      --    cell_item: entity work.search_item
144
            search_item_1 : search_item
145
      --      generic map ( item_id => std_logic_vector'(X"0000"))  --  std_logic_vector(to_unsigned(iter_id,16)) )
146
            generic map ( item_id => (others => '0'))   --    std_logic_vector'(X"0000"))  --  std_logic_vector(to_unsigned(iter_id,16)) )
147 15 stvhawes
            port map (
148
                         RX_CLK => RX_CLK,
149
                         b1_px_valid => b1_px_valid,
150 17 stvhawes
                         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,
151 15 stvhawes
                         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
152
                     );
153 17 stvhawes
  --      end generate items_array;
154
 
155
  -- RX_CLK <= RX_CLK;   
156
 
157 15 stvhawes
   match: process (RX_CLK) is
158 17 stvhawes
--        variable l : line;
159 15 stvhawes
   begin
160 17 stvhawes
      --if rising_edge(RX_CLK) then
161
      if falling_edge(RX_CLK) then
162
--        write (l, String'("  Rising Edge "));
163
--                for j in b2_id'range loop
164
--                    write(l, std_logic'image(b2_id(j)) );
165
--                 end loop;
166
--        writeline ( output, l);
167
 
168
 
169 15 stvhawes
         if search_px_valid_i = '1' then
170
 
171
            if search_px_type_i = std_logic_vector'("00000") then
172
                   -- do reset store and outputs
173 17 stvhawes
                   order_px_type_o  <= (others => '0');
174 16 stvhawes
                   order_buy_sell_o <= (others => 'Z');   -- 111 buy, 000 sell
175
                   order_px_o       <= (others => 'Z');   -- price
176
                   order_qty_o      <= (others => 'Z');   -- quantity
177
                   order_sec_o      <= (others => 'Z');   -- 7x 8bits securities identifier
178 17 stvhawes
                   order_id_o       <= (others => 'Z');
179 16 stvhawes
                   order_px_valid_o <= '1';
180 15 stvhawes
                   --
181 16 stvhawes
                   b1_px_type  <= (others => '0');
182
                   b1_buy_sell <= (others => '0');   -- 111 buy, 000 sell
183
                   b1_px       <= (others => '0');   -- price
184
                   b1_qty      <= (others => '0');   -- quantity
185
                   b1_sec      <= (others => '0');   -- 7x 8bits securities identifier
186
                   -- b1_id      <= (others => '0');   -- unique/identifier/counter
187
                   b1_px_valid <= '1';
188 15 stvhawes
                   --
189 16 stvhawes
                   searchitems_count <= 0;
190 15 stvhawes
                   state <= 8;
191
 
192 17 stvhawes
            -- purely for test
193
            elsif search_px_type_i = std_logic_vector'("01010") then
194
                         -- send the new security setting
195
                         b1_px_type  <= std_logic_vector'("01010");
196
                         b1_buy_sell <= store_buy_sell;
197
                         b1_px       <= store_px;
198
                         b1_qty      <= store_qty;
199
                         b1_sec      <= store_sec;
200
                         b1_id       <= std_logic_vector'(X"0000"); -- std_logic_vector(to_unsigned(searchitems_count,16));
201
                         b1_px_valid <= '1';
202
                         state <= 4;   -- increment items counter / send success
203
--        write (l, String'("  State=6 "));
204
--                for j in b2_id'range loop
205
--                    write(l, std_logic'image(b2_id(j)) );
206
--                 end loop;
207
--        writeline (output, l);
208
 
209 15 stvhawes
            elsif search_px_type_i = std_logic_vector'("00110") then
210 17 stvhawes
                   -- it's an incoming order price/qty security/buysell setting.
211
                   -- do set bus b1 and store from incoming price 
212
                   b1_px_type  <= search_px_type_i;
213
                   b1_buy_sell <= search_buy_sell_i;
214
                   b1_px       <= search_px_i;
215
                   b1_qty      <= search_qty_i;
216
                   b1_sec      <= search_sec_i;
217
                   b1_id       <= (others => 'Z');
218
                   b1_px_valid <= '1';
219 15 stvhawes
                   -- do set store from incoming price 
220 17 stvhawes
                   store_px_type  <= search_px_type_i;
221
                   store_buy_sell <= search_buy_sell_i;
222
                   store_px       <= search_px_i;
223
                   store_qty      <= search_qty_i;
224
                   store_sec      <= search_sec_i;
225
                   store_id       <= search_id_i;
226
                   --b2_px_type <= std_logic_vector'(std_logic_vector'("00000"));
227
                   state <= 6;
228 15 stvhawes
 
229
            elsif search_px_type_i = std_logic_vector'("00101") then
230
                   -- incoming price, register it and start the state machine
231
                   if (store_sec /= b1_sec or store_buy_sell = b1_buy_sell or store_px_type /= std_logic_vector'(std_logic_vector'("0110")) ) then
232
                      -- not this store_item instance no action, also stop anything that might be going on
233
                      state <= 14;
234
                   elsif (to_integer(unsigned(store_qty)) = 0 or to_integer(unsigned(b1_qty)) = 0 or
235
                             (store_buy_sell = std_logic_vector'("111") and store_px < b1_px) or
236
                             (store_buy_sell = std_logic_vector'("000") and store_px > b1_px) ) then
237
                      -- no deal: this is the correct store_item but there's no match
238
                      b2_px_type <= std_logic_vector'(std_logic_vector'("00000"));
239
                      state <= 8;
240
                   else
241
                      -- send a return order
242
                      b2_px_type <= std_logic_vector'("1010");
243
                      b2_buy_sell <= store_buy_sell;   -- 111 buy, 000 sell
244
                      b2_px <= b1_px;                   -- price
245
                      -- b2_qty <= 
246
                      if b1_qty < store_qty then
247
                         b2_qty <= b1_qty;
248
                      else
249
                         b2_qty <= store_qty;
250
                      end if;    -- quantity
251
                      b2_sec <= store_sec;                                          -- 7x 8bits securities identifier
252
                      b2_id <= store_id;                                            -- unique/identifier/counter
253
                      -- update the store
254
                      -- store_qty
255
                      if (b1_qty < store_qty) then
256
                         store_qty <= std_logic_vector(to_unsigned( to_integer(unsigned(store_qty)) - to_integer(unsigned(b1_qty)) ,16 ));
257
                      else
258
                         store_qty <= (others => '0');
259
                         state <= 1;
260
                      end  if;
261
                   end if;
262
 
263
            else
264 17 stvhawes
               -- no action - flash up Z's
265
                   order_px_type_o  <= (others => 'Z');
266
                   order_buy_sell_o <= (others => 'Z');   -- 111 buy, 000 sell
267
                   order_px_o       <= (others => 'Z');   -- price
268
                   order_qty_o      <= (others => 'Z');   -- quantity
269
                   order_sec_o      <= (others => 'Z');   -- 7x 8bits securities identifier
270
                   order_id_o       <= (others => 'Z');   -- unique/identifier/counter
271
                   order_px_valid_o <= '1';
272
                state <= 8;
273 15 stvhawes
            end if;   -- search_px_type
274
 
275
         else     -- search_px_valid_i
276
            -- no incoming search_px_i so check for state machine actions
277
            case state is
278
               when 1 =>
279
                   -- sent return order, so clean up
280 17 stvhawes
                   order_px_type_o  <= (others => 'Z');
281
                   order_buy_sell_o <= (others => 'Z');    -- 111 buy, 000 sell
282
                   order_px_o       <= (others => 'Z');    -- price
283
                   order_qty_o      <= (others => 'Z');    -- quantity
284
                   order_sec_o      <= (others => 'Z');    -- 7x 8bits securities identifier
285
                   order_id_o       <= (others => 'Z');    -- unique/identifier/counter
286 15 stvhawes
                   state <= 16;
287
 
288 17 stvhawes
               when 6 =>
289
                   -- sent query to set px and qty for a given security
290
                   if b2_px_type = std_logic_vector'("00110") then
291
                      -- it's a known security and the value has been set
292
                      order_px_type_o <= b2_px_type;
293
                      order_px_valid_o <= '1';
294
                      state <= 8;    -- reset next cycle
295
                   else
296
                      -- no response, it's a new security+buysell
297
                      if searchitems_count = searchitems-1 then
298
                         -- all search_items are filled - can't store this item
299
                         order_px_type_o <= std_logic_vector'("11111");
300
                         order_px_valid_o <= '1';
301
                         b1_px_valid <= '0';
302
                         state <= 8;    -- reset next cycle
303
                      else
304
                         -- send the new security setting
305
                         b1_px_type  <= std_logic_vector'("01010");
306
                         b1_buy_sell <= store_buy_sell;
307
                         b1_px       <= store_px;
308
                         b1_qty      <= store_qty;
309
                         b1_sec      <= store_sec;
310
                         b1_id       <= std_logic_vector'(X"0000"); -- std_logic_vector(to_unsigned(searchitems_count,16));
311
                         b1_px_valid <= '1';
312
                         state <= 4;   -- increment items counter / send success
313
                      end if;
314
                   end if;
315
 
316
               when 4 =>
317
                   -- have set a new item, increment count and return
318
                   searchitems_count <= searchitems_count + 1;
319
                   order_px_type_o  <= std_logic_vector'("01010");  -- b2_px_type;     --
320
                   order_buy_sell_o <= (others => 'Z');
321
                   order_px_o       <= (others => 'Z');
322
                   order_qty_o      <= (others => 'Z');
323
                   order_sec_o      <= (others => 'Z');
324
                   order_id_o       <= b2_id;
325
                   --
326
                   order_px_valid_o <= '1';
327
                   b1_px_valid <= '0';
328
                   state <= 8;    -- reset next cycle
329
--        write (l, String'("  State=4 "));
330
--                for j in b2_id'range loop
331
--                    write(l, std_logic'image(b2_id(j)) );
332
--                 end loop;
333
--        writeline (output, l);
334
 
335 15 stvhawes
               when 8 =>
336 17 stvhawes
                   -- correct store_item but there was no match
337
                   order_px_type_o <= std_logic_vector'("ZZZZZ");
338
                   order_px_valid_o <= '0';
339
                   -- reset b1
340
                   b1_px_type  <= (others => 'Z');
341
                   b1_buy_sell <= (others => 'Z');
342
                   b1_px       <= (others => 'Z');
343
                   b1_qty      <= (others => 'Z');
344
                   b1_sec      <= (others => 'Z');
345
                   b1_id       <= (others => 'Z');
346
                   b1_px_valid <= '0';
347
                   --
348 15 stvhawes
                   state <= 16;
349
 
350
               when others => null;
351
            end case;   -- state
352
 
353 17 stvhawes
      --      if (state < 16) then
354
      --         state <= state + 1;
355
      --      end if;
356 15 stvhawes
 
357
         end if;     -- search_px_valid_i
358
 
359
      end if;
360
   end process match;
361
 
362 17 stvhawes
--              b1_id       <=  std_logic_vector'(X"1010");  -- testing
363
 
364 15 stvhawes
end search_control_implementation;
365
 

powered by: WebSVN 2.1.0

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