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 17

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 17 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 state : integer range 0 to 16 := 16;
84
      signal requires_reset: std_logic := '0';
85 11 stvhawes
   -- pxdata: out price_packet
86 17 stvhawes
      signal store_px_type: std_logic_vector(4 downto 0) := (others => 'Z');
87
      signal store_buy_sell: std_logic_vector(2 downto 0) := (others => 'Z');   -- 111 buy, 000 sell
88
      signal store_px: std_logic_vector(15 downto 0) := (others => 'Z');     -- price
89
      signal store_qty: std_logic_vector(15 downto 0) := (others => 'Z');    -- quantity
90
      signal store_sec: std_logic_vector(55 downto 0) := (others => 'Z');    -- 7x 8bits securities identifier
91 11 stvhawes
begin
92
   match: process (RX_CLK) is
93 17 stvhawes
--        variable l : line;
94 11 stvhawes
   begin
95
      if rising_edge(RX_CLK) then
96 17 stvhawes
   --   if falling_edge(RX_CLK) then
97 13 stvhawes
         if b1_px_valid = '1' then
98 11 stvhawes
 
99 17 stvhawes
--        write (l, String'("  Item Rising Edge "));
100
--                for j in b1_id'range loop
101
--                    write(l, std_logic'image(b1_id(j)) );
102
--                 end loop;
103
--                write (l, String'(" instruction:  "));
104
--                for j in b1_px_type'range loop
105
--                    write(l, std_logic'image(b1_px_type(j)) );
106
--                 end loop;
107
--        writeline ( output, l);
108
 
109
 
110 13 stvhawes
            if b1_px_type = std_logic_vector'("00000") then
111 11 stvhawes
                   -- do reset store and outputs
112
                   store_px_type  <= (others => '0');
113
                   store_buy_sell <= (others => '0');   -- 111 buy, 000 sell
114
                   store_px       <= (others => '0');   -- price
115
                   store_qty      <= (others => '0');   -- quantity
116
                   store_sec      <= (others => '0');   -- 7x 8bits securities identifier
117
                   --
118
                   b2_px_type  <= (others => 'Z');
119
                   b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
120
                   b2_px       <= (others => 'Z');   -- price
121
                   b2_qty      <= (others => 'Z');   -- quantity
122
                   b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
123
                   b2_id       <= (others => 'Z');   -- unique/identifier/counter
124
                   --
125 17 stvhawes
                   requires_reset <= '0';
126 11 stvhawes
 
127 13 stvhawes
            elsif b1_px_type = std_logic_vector'("00110") then
128 14 stvhawes
                  if store_buy_sell = b1_buy_sell and
129
                     store_sec      = b1_sec  then
130
                       -- do set store from incoming price 
131
                       store_px_type  <= b1_px_type;
132
                       -- store_buy_sell <= b1_buy_sell;
133
                       store_px       <= b1_px;
134
                       store_qty      <= b1_qty;
135
                       --
136
                       b2_px_type <= std_logic_vector'(std_logic_vector'("00110"));
137 17 stvhawes
                       b2_buy_sell <= (others => 'Z');
138
                       b2_px       <= (others => 'Z');
139
                       b2_qty      <= (others => 'Z');
140
                       b2_sec      <= (others => 'Z');
141
                       b2_id       <= (others => 'Z');
142
                       requires_reset <= '1';
143
                   else
144
                       if requires_reset = '1' then
145
                          b2_px_type  <= (others => 'Z');
146
                          b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
147
                          b2_px       <= (others => 'Z');   -- price
148
                          b2_qty      <= (others => 'Z');   -- quantity
149
                          b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
150
                          b2_id       <= (others => 'Z');   -- unique/identifier/counter
151
                          requires_reset <= '0';
152
                       end if;
153 14 stvhawes
                   end if;
154 11 stvhawes
 
155 14 stvhawes
            elsif b1_px_type = std_logic_vector'("01010") then
156
                   if item_id = b1_id then
157
                       -- do set store and security from incoming price 
158
                       store_px_type  <= b1_px_type;
159
                       store_buy_sell <= b1_buy_sell;
160
                       store_px       <= b1_px;
161
                       store_qty      <= b1_qty;
162
                       store_sec      <= b1_sec;
163
                       --
164 17 stvhawes
                       b2_px_type  <= std_logic_vector'(std_logic_vector'("01010"));
165
                       b2_buy_sell <= (others => 'Z');
166
                       b2_px       <= (others => 'Z');
167
                       b2_qty      <= (others => 'Z');
168
                       b2_sec      <= (others => 'Z');
169
                       b2_id       <= item_id;
170
                       requires_reset <= '1';
171
                   else
172
                       if requires_reset = '1' then
173
                          b2_px_type  <= (others => 'Z');
174
                          b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
175
                          b2_px       <= (others => 'Z');   -- price
176
                          b2_qty      <= (others => 'Z');   -- quantity
177
                          b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
178
                          b2_id       <= (others => 'Z');   -- unique/identifier/counter
179
                          requires_reset <= '0';
180
                       end if;
181 14 stvhawes
                   end if;
182
 
183
            elsif b1_px_type = std_logic_vector'("11100") then
184 11 stvhawes
                   -- incoming price, register it and start the state machine
185 14 stvhawes
                   if (store_sec /= b1_sec or store_buy_sell = b1_buy_sell ) then
186 17 stvhawes
                       if requires_reset = '1' then
187
                          b2_px_type  <= (others => 'Z');
188
                          b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
189
                          b2_px       <= (others => 'Z');   -- price
190
                          b2_qty      <= (others => 'Z');   -- quantity
191
                          b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
192
                          b2_id       <= (others => 'Z');   -- unique/identifier/counter
193
                          requires_reset <= '0';
194
                       end if;
195 12 stvhawes
                   elsif (to_integer(unsigned(store_qty)) = 0 or to_integer(unsigned(b1_qty)) = 0 or
196
                             (store_buy_sell = std_logic_vector'("111") and store_px < b1_px) or
197
                             (store_buy_sell = std_logic_vector'("000") and store_px > b1_px) ) then
198 11 stvhawes
                      -- no deal: this is the correct store_item but there's no match
199 17 stvhawes
                      b2_px_type  <= std_logic_vector'(std_logic_vector'("11101"));
200
                      b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
201
                      b2_px       <= (others => 'Z');   -- price
202
                      b2_qty      <= (others => 'Z');   -- quantity
203
                      b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
204
                      b2_id       <= (others => 'Z');   -- unique/identifier/counter
205
                      requires_reset <= '1';
206 11 stvhawes
                   else
207
                      -- send a return order
208
                      b2_buy_sell <= store_buy_sell;   -- 111 buy, 000 sell
209 14 stvhawes
                      b2_sec <= store_sec;                                          -- 7x 8bits securities identifier
210 17 stvhawes
                      b2_id <= item_id;                                            -- unique/identifier/counter
211 11 stvhawes
                      b2_px <= b1_px;                   -- price
212 12 stvhawes
                      -- b2_qty <= 
213
                      if b1_qty < store_qty then
214
                         b2_qty <= b1_qty;
215
                      else
216
                         b2_qty <= store_qty;
217
                      end if;    -- quantity
218 11 stvhawes
                      -- update the store
219 12 stvhawes
                      -- store_qty
220
                      if (b1_qty < store_qty) then
221
                         store_qty <= std_logic_vector(to_unsigned( to_integer(unsigned(store_qty)) - to_integer(unsigned(b1_qty)) ,16 ));
222
                      else
223
                         store_qty <= (others => '0');
224
                      end  if;
225 14 stvhawes
                      b2_px_type <= std_logic_vector'(std_logic_vector'("11100"));
226 17 stvhawes
                      requires_reset <= '1';
227 11 stvhawes
                   end if;
228
 
229 12 stvhawes
            else
230
               -- no action
231 17 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
 
242
         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
 
254
--              b2_id       <=  std_logic_vector'(X"0000");  -- testing
255 11 stvhawes
 
256
      end if;
257
   end process match;
258
 
259
end search_item_implementation;
260
 

powered by: WebSVN 2.1.0

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