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 21

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 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 18 stvhawes
     if falling_edge(RX_CLK) then
95 11 stvhawes
 
96 18 stvhawes
        -- diagnostic (uncomment)
97
        -- write (l, String'("      Item Falling Edge"));
98
        --         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
        --          end loop;
110
        --         write (l, String'(" b1_px_valid: "));
111
        --         write (l, std_logic'image(b1_px_valid) );
112
        -- writeline ( output, l);
113 17 stvhawes
 
114 18 stvhawes
         if b1_px_valid = '1' then
115 13 stvhawes
            if b1_px_type = std_logic_vector'("00000") then
116 11 stvhawes
                   -- do reset store and outputs
117
                   store_px_type  <= (others => '0');
118
                   store_buy_sell <= (others => '0');   -- 111 buy, 000 sell
119
                   store_px       <= (others => '0');   -- price
120
                   store_qty      <= (others => '0');   -- quantity
121
                   store_sec      <= (others => '0');   -- 7x 8bits securities identifier
122
                   --
123
                   b2_px_type  <= (others => 'Z');
124
                   b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
125
                   b2_px       <= (others => 'Z');   -- price
126
                   b2_qty      <= (others => 'Z');   -- quantity
127
                   b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
128
                   b2_id       <= (others => 'Z');   -- unique/identifier/counter
129
                   --
130 17 stvhawes
                   requires_reset <= '0';
131 13 stvhawes
            elsif b1_px_type = std_logic_vector'("00110") then
132 14 stvhawes
                  if store_buy_sell = b1_buy_sell and
133
                     store_sec      = b1_sec  then
134
                       -- do set store from incoming price 
135
                       store_px_type  <= b1_px_type;
136
                       -- store_buy_sell <= b1_buy_sell;
137
                       store_px       <= b1_px;
138
                       store_qty      <= b1_qty;
139
                       --
140
                       b2_px_type <= std_logic_vector'(std_logic_vector'("00110"));
141 17 stvhawes
                       b2_buy_sell <= (others => 'Z');
142
                       b2_px       <= (others => 'Z');
143
                       b2_qty      <= (others => 'Z');
144
                       b2_sec      <= (others => 'Z');
145 18 stvhawes
                       b2_id       <= item_id;
146 17 stvhawes
                       requires_reset <= '1';
147
                   else
148
                       if requires_reset = '1' then
149
                          b2_px_type  <= (others => 'Z');
150
                          b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
151
                          b2_px       <= (others => 'Z');   -- price
152
                          b2_qty      <= (others => 'Z');   -- quantity
153
                          b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
154
                          b2_id       <= (others => 'Z');   -- unique/identifier/counter
155
                          requires_reset <= '0';
156
                       end if;
157 14 stvhawes
                   end if;
158
            elsif b1_px_type = std_logic_vector'("01010") then
159
                   if item_id = b1_id then
160
                       -- do set store and security from incoming price 
161
                       store_px_type  <= b1_px_type;
162
                       store_buy_sell <= b1_buy_sell;
163
                       store_px       <= b1_px;
164
                       store_qty      <= b1_qty;
165
                       store_sec      <= b1_sec;
166
                       --
167 17 stvhawes
                       b2_px_type  <= std_logic_vector'(std_logic_vector'("01010"));
168
                       b2_buy_sell <= (others => 'Z');
169
                       b2_px       <= (others => 'Z');
170
                       b2_qty      <= (others => 'Z');
171
                       b2_sec      <= (others => 'Z');
172
                       b2_id       <= item_id;
173
                       requires_reset <= '1';
174
                   else
175
                       if requires_reset = '1' then
176
                          b2_px_type  <= (others => 'Z');
177
                          b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
178
                          b2_px       <= (others => 'Z');   -- price
179
                          b2_qty      <= (others => 'Z');   -- quantity
180
                          b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
181
                          b2_id       <= (others => 'Z');   -- unique/identifier/counter
182
                          requires_reset <= '0';
183
                       end if;
184 14 stvhawes
                   end if;
185
            elsif b1_px_type = std_logic_vector'("11100") then
186 11 stvhawes
                   -- incoming price, register it and start the state machine
187 14 stvhawes
                   if (store_sec /= b1_sec or store_buy_sell = b1_buy_sell ) then
188 17 stvhawes
                       if requires_reset = '1' then
189
                          b2_px_type  <= (others => 'Z');
190
                          b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
191
                          b2_px       <= (others => 'Z');   -- price
192
                          b2_qty      <= (others => 'Z');   -- quantity
193
                          b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
194
                          b2_id       <= (others => 'Z');   -- unique/identifier/counter
195
                          requires_reset <= '0';
196
                       end if;
197 12 stvhawes
                   elsif (to_integer(unsigned(store_qty)) = 0 or to_integer(unsigned(b1_qty)) = 0 or
198
                             (store_buy_sell = std_logic_vector'("111") and store_px < b1_px) or
199
                             (store_buy_sell = std_logic_vector'("000") and store_px > b1_px) ) then
200 11 stvhawes
                      -- no deal: this is the correct store_item but there's no match
201 17 stvhawes
                      b2_px_type  <= std_logic_vector'(std_logic_vector'("11101"));
202
                      b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
203
                      b2_px       <= (others => 'Z');   -- price
204
                      b2_qty      <= (others => 'Z');   -- quantity
205
                      b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
206
                      b2_id       <= (others => 'Z');   -- unique/identifier/counter
207
                      requires_reset <= '1';
208 11 stvhawes
                   else
209
                      -- send a return order
210
                      b2_buy_sell <= store_buy_sell;   -- 111 buy, 000 sell
211 14 stvhawes
                      b2_sec <= store_sec;                                          -- 7x 8bits securities identifier
212 17 stvhawes
                      b2_id <= item_id;                                            -- unique/identifier/counter
213 11 stvhawes
                      b2_px <= b1_px;                   -- price
214 12 stvhawes
                      -- b2_qty <= 
215
                      if b1_qty < store_qty then
216
                         b2_qty <= b1_qty;
217
                      else
218
                         b2_qty <= store_qty;
219
                      end if;    -- quantity
220 11 stvhawes
                      -- update the store
221 12 stvhawes
                      -- store_qty
222
                      if (b1_qty < store_qty) then
223
                         store_qty <= std_logic_vector(to_unsigned( to_integer(unsigned(store_qty)) - to_integer(unsigned(b1_qty)) ,16 ));
224
                      else
225
                         store_qty <= (others => '0');
226
                      end  if;
227 14 stvhawes
                      b2_px_type <= std_logic_vector'(std_logic_vector'("11100"));
228 17 stvhawes
                      requires_reset <= '1';
229 11 stvhawes
                   end if;
230 12 stvhawes
            else
231
               -- no action
232 18 stvhawes
               if requires_reset = '1' then
233
                   b2_px_type  <= (others => 'Z');
234
                   b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
235
                   b2_px       <= (others => 'Z');   -- price
236
                   b2_qty      <= (others => 'Z');   -- quantity
237
                   b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
238
                   b2_id       <= (others => 'Z');   -- unique/identifier/counter
239
                   requires_reset <= '0';
240
               end if;
241 12 stvhawes
            end if;   -- b1_px_type
242 11 stvhawes
         else     -- b1_px_valid
243 17 stvhawes
            if requires_reset = '1' then
244
               b2_px_type  <= (others => 'Z');
245
               b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
246
               b2_px       <= (others => 'Z');   -- price
247
               b2_qty      <= (others => 'Z');   -- quantity
248
               b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
249
               b2_id       <= (others => 'Z');   -- unique/identifier/counter
250
               requires_reset <= '0';
251 11 stvhawes
            end if;
252 17 stvhawes
         end if;     -- b1_px_valid
253 11 stvhawes
      end if;
254
   end process match;
255
end search_item_implementation;
256
 

powered by: WebSVN 2.1.0

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