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