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 22

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 17 stvhawes
--// this version of search_item is stateless i.e. can be queried ////
14
--// every clock cycle                                            ////
15 11 stvhawes
--//                                                              ////
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 18 stvhawes
-- use std.textio.all; --  Imports the standard textio package.
58 11 stvhawes
 
59
entity search_item is
60 14 stvhawes
   generic ( item_id: std_logic_vector(15 downto 0) );
61 11 stvhawes
   port (
62
        RX_CLK: in std_logic;
63
        -- control flag(s) on the incoming bus
64
           b1_px_valid: in std_logic;
65
        -- pxdata: in price_packet
66 12 stvhawes
           b1_px_type: in std_logic_vector(4 downto 0);
67
           b1_buy_sell: in std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
68
           b1_px: in std_logic_vector(15 downto 0);     -- price
69
           b1_qty: in std_logic_vector(15 downto 0);    -- quantity
70
           b1_sec: in std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
71
           b1_id: in std_logic_vector(15 downto 0);    -- unique/identifier/counter
72 11 stvhawes
        -- pxdata: out price_packet
73
           b2_px_type: out std_logic_vector(4 downto 0);
74
           b2_buy_sell: out std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
75
           b2_px: out std_logic_vector(15 downto 0);     -- price
76
           b2_qty: out std_logic_vector(15 downto 0);    -- quantity
77
           b2_sec: out std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
78 12 stvhawes
           b2_id: out std_logic_vector(15 downto 0)      -- unique/identifier/counter
79 11 stvhawes
   );
80
end search_item;
81
 
82
architecture search_item_implementation of search_item is
83 17 stvhawes
      signal requires_reset: std_logic := '0';
84 18 stvhawes
      -- pxdata: out price_packet
85 17 stvhawes
      signal store_px_type: std_logic_vector(4 downto 0) := (others => 'Z');
86
      signal store_buy_sell: std_logic_vector(2 downto 0) := (others => 'Z');   -- 111 buy, 000 sell
87
      signal store_px: std_logic_vector(15 downto 0) := (others => 'Z');     -- price
88
      signal store_qty: std_logic_vector(15 downto 0) := (others => 'Z');    -- quantity
89
      signal store_sec: std_logic_vector(55 downto 0) := (others => 'Z');    -- 7x 8bits securities identifier
90 11 stvhawes
begin
91
   match: process (RX_CLK) is
92 18 stvhawes
        -- variable l : line;
93 11 stvhawes
   begin
94 22 stvhawes
     if rising_edge(RX_CLK) then
95 11 stvhawes
 
96 18 stvhawes
        -- diagnostic (uncomment)
97 22 stvhawes
        -- write (l, String'("      Item Rising Edge"));
98 18 stvhawes
        --         write (l, String'(" b1_px_type: "));
99
        --         for j in b1_px_type'range loop
100
        --             write(l, std_logic'image(b1_px_type(j)) );
101
        --          end loop;
102
        --         write (l, String'(" item_id: "));
103
        --         for j in item_id'range loop
104
        --             write(l, std_logic'image(item_id(j)) );
105
        --          end loop;
106
        --         write (l, String'(" b1_id: "));
107
        --         for j in b1_id'range loop
108
        --             write(l, std_logic'image(b1_id(j)) );
109 22 stvhawes
        --         end loop;
110
        --         write (l, String'(" store_qty: "));
111
        --         for j in store_qty'range loop
112
        --             write(l, std_logic'image(store_qty(j)) );
113 18 stvhawes
        --          end loop;
114
        --         write (l, String'(" b1_px_valid: "));
115
        --         write (l, std_logic'image(b1_px_valid) );
116
        -- writeline ( output, l);
117 17 stvhawes
 
118 18 stvhawes
         if b1_px_valid = '1' then
119 13 stvhawes
            if b1_px_type = std_logic_vector'("00000") then
120 11 stvhawes
                   -- do reset store and outputs
121
                   store_px_type  <= (others => '0');
122
                   store_buy_sell <= (others => '0');   -- 111 buy, 000 sell
123
                   store_px       <= (others => '0');   -- price
124
                   store_qty      <= (others => '0');   -- quantity
125
                   store_sec      <= (others => '0');   -- 7x 8bits securities identifier
126
                   --
127
                   b2_px_type  <= (others => 'Z');
128
                   b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
129
                   b2_px       <= (others => 'Z');   -- price
130
                   b2_qty      <= (others => 'Z');   -- quantity
131
                   b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
132
                   b2_id       <= (others => 'Z');   -- unique/identifier/counter
133
                   --
134 17 stvhawes
                   requires_reset <= '0';
135 13 stvhawes
            elsif b1_px_type = std_logic_vector'("00110") then
136 14 stvhawes
                  if store_buy_sell = b1_buy_sell and
137
                     store_sec      = b1_sec  then
138
                       -- do set store from incoming price 
139
                       store_px_type  <= b1_px_type;
140
                       -- store_buy_sell <= b1_buy_sell;
141
                       store_px       <= b1_px;
142
                       store_qty      <= b1_qty;
143
                       --
144
                       b2_px_type <= std_logic_vector'(std_logic_vector'("00110"));
145 17 stvhawes
                       b2_buy_sell <= (others => 'Z');
146
                       b2_px       <= (others => 'Z');
147
                       b2_qty      <= (others => 'Z');
148
                       b2_sec      <= (others => 'Z');
149 18 stvhawes
                       b2_id       <= item_id;
150 17 stvhawes
                       requires_reset <= '1';
151
                   else
152
                       if requires_reset = '1' then
153
                          b2_px_type  <= (others => 'Z');
154
                          b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
155
                          b2_px       <= (others => 'Z');   -- price
156
                          b2_qty      <= (others => 'Z');   -- quantity
157
                          b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
158
                          b2_id       <= (others => 'Z');   -- unique/identifier/counter
159
                          requires_reset <= '0';
160
                       end if;
161 14 stvhawes
                   end if;
162
            elsif b1_px_type = std_logic_vector'("01010") then
163
                   if item_id = b1_id then
164
                       -- do set store and security from incoming price 
165
                       store_px_type  <= b1_px_type;
166
                       store_buy_sell <= b1_buy_sell;
167
                       store_px       <= b1_px;
168
                       store_qty      <= b1_qty;
169
                       store_sec      <= b1_sec;
170
                       --
171 17 stvhawes
                       b2_px_type  <= std_logic_vector'(std_logic_vector'("01010"));
172
                       b2_buy_sell <= (others => 'Z');
173
                       b2_px       <= (others => 'Z');
174
                       b2_qty      <= (others => 'Z');
175
                       b2_sec      <= (others => 'Z');
176
                       b2_id       <= item_id;
177
                       requires_reset <= '1';
178
                   else
179
                       if requires_reset = '1' then
180
                          b2_px_type  <= (others => 'Z');
181
                          b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
182
                          b2_px       <= (others => 'Z');   -- price
183
                          b2_qty      <= (others => 'Z');   -- quantity
184
                          b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
185
                          b2_id       <= (others => 'Z');   -- unique/identifier/counter
186
                          requires_reset <= '0';
187
                       end if;
188 14 stvhawes
                   end if;
189
            elsif b1_px_type = std_logic_vector'("11100") then
190 11 stvhawes
                   -- incoming price, register it and start the state machine
191 14 stvhawes
                   if (store_sec /= b1_sec or store_buy_sell = b1_buy_sell ) then
192 17 stvhawes
                       if requires_reset = '1' then
193
                          b2_px_type  <= (others => 'Z');
194
                          b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
195
                          b2_px       <= (others => 'Z');   -- price
196
                          b2_qty      <= (others => 'Z');   -- quantity
197
                          b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
198
                          b2_id       <= (others => 'Z');   -- unique/identifier/counter
199
                          requires_reset <= '0';
200
                       end if;
201 12 stvhawes
                   elsif (to_integer(unsigned(store_qty)) = 0 or to_integer(unsigned(b1_qty)) = 0 or
202
                             (store_buy_sell = std_logic_vector'("111") and store_px < b1_px) or
203
                             (store_buy_sell = std_logic_vector'("000") and store_px > b1_px) ) then
204 11 stvhawes
                      -- no deal: this is the correct store_item but there's no match
205 17 stvhawes
                      b2_px_type  <= std_logic_vector'(std_logic_vector'("11101"));
206
                      b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
207
                      b2_px       <= (others => 'Z');   -- price
208
                      b2_qty      <= (others => 'Z');   -- quantity
209
                      b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
210
                      b2_id       <= (others => 'Z');   -- unique/identifier/counter
211
                      requires_reset <= '1';
212 11 stvhawes
                   else
213
                      -- send a return order
214
                      b2_buy_sell <= store_buy_sell;   -- 111 buy, 000 sell
215 14 stvhawes
                      b2_sec <= store_sec;                                          -- 7x 8bits securities identifier
216 17 stvhawes
                      b2_id <= item_id;                                            -- unique/identifier/counter
217 11 stvhawes
                      b2_px <= b1_px;                   -- price
218 22 stvhawes
                      -- update the store qty and adjust the return value
219
                      if ( to_integer(unsigned(b1_qty)) < to_integer(unsigned(store_qty)) ) then
220 12 stvhawes
                         b2_qty <= b1_qty;
221
                         store_qty <= std_logic_vector(to_unsigned( to_integer(unsigned(store_qty)) - to_integer(unsigned(b1_qty)) ,16 ));
222
                      else
223 22 stvhawes
                         b2_qty <= store_qty;
224 12 stvhawes
                         store_qty <= (others => '0');
225 22 stvhawes
                      end if;
226 14 stvhawes
                      b2_px_type <= std_logic_vector'(std_logic_vector'("11100"));
227 17 stvhawes
                      requires_reset <= '1';
228 11 stvhawes
                   end if;
229 12 stvhawes
            else
230
               -- no action
231 18 stvhawes
               if requires_reset = '1' then
232
                   b2_px_type  <= (others => 'Z');
233
                   b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
234
                   b2_px       <= (others => 'Z');   -- price
235
                   b2_qty      <= (others => 'Z');   -- quantity
236
                   b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
237
                   b2_id       <= (others => 'Z');   -- unique/identifier/counter
238
                   requires_reset <= '0';
239
               end if;
240 12 stvhawes
            end if;   -- b1_px_type
241 11 stvhawes
         else     -- b1_px_valid
242 17 stvhawes
            if requires_reset = '1' then
243
               b2_px_type  <= (others => 'Z');
244
               b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
245
               b2_px       <= (others => 'Z');   -- price
246
               b2_qty      <= (others => 'Z');   -- quantity
247
               b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
248
               b2_id       <= (others => 'Z');   -- unique/identifier/counter
249
               requires_reset <= '0';
250 11 stvhawes
            end if;
251 17 stvhawes
         end if;     -- b1_px_valid
252 11 stvhawes
      end if;
253
   end process match;
254
end search_item_implementation;
255
 

powered by: WebSVN 2.1.0

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