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 18

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

powered by: WebSVN 2.1.0

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