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 14

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
--// there is also a small state-machine in each search_item.     ////
14
--// For now, the count of number of states is fixed, per px_type ////
15
--//                                                              ////
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 11 stvhawes
 
58
entity search_item is
59 14 stvhawes
   generic ( item_id: std_logic_vector(15 downto 0) );
60 11 stvhawes
   port (
61
        RX_CLK: in std_logic;
62
        -- control flag(s) on the incoming bus
63
           b1_px_valid: in std_logic;
64
        -- pxdata: in price_packet
65 12 stvhawes
           b1_px_type: in std_logic_vector(4 downto 0);
66
           b1_buy_sell: in std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
67
           b1_px: in std_logic_vector(15 downto 0);     -- price
68
           b1_qty: in std_logic_vector(15 downto 0);    -- quantity
69
           b1_sec: in std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
70
           b1_id: in std_logic_vector(15 downto 0);    -- unique/identifier/counter
71 11 stvhawes
        -- pxdata: out price_packet
72
           b2_px_type: out std_logic_vector(4 downto 0);
73
           b2_buy_sell: out std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
74
           b2_px: out std_logic_vector(15 downto 0);     -- price
75
           b2_qty: out std_logic_vector(15 downto 0);    -- quantity
76
           b2_sec: out std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
77 12 stvhawes
           b2_id: out std_logic_vector(15 downto 0)      -- unique/identifier/counter
78 11 stvhawes
   );
79
end search_item;
80
 
81
architecture search_item_implementation of search_item is
82
      signal state : integer range 0 to 16 := 16;
83
   -- pxdata: out price_packet
84
      signal store_px_type: std_logic_vector(4 downto 0) := (others => '0');
85
      signal store_buy_sell: std_logic_vector(2 downto 0) := (others => '0');   -- 111 buy, 000 sell
86
      signal store_px: std_logic_vector(15 downto 0) := (others => '0');     -- price
87
      signal store_qty: std_logic_vector(15 downto 0) := (others => '0');    -- quantity
88
      signal store_sec: std_logic_vector(55 downto 0) := (others => '0');    -- 7x 8bits securities identifier
89
      signal store_id: std_logic_vector(15 downto 0) := (others => '0');     -- unique/identifier/counter
90
begin
91
   match: process (RX_CLK) is
92
   begin
93
      if rising_edge(RX_CLK) then
94 13 stvhawes
         if b1_px_valid = '1' then
95 11 stvhawes
 
96 13 stvhawes
            if b1_px_type = std_logic_vector'("00000") then
97 11 stvhawes
                   -- do reset store and outputs
98
                   store_px_type  <= (others => '0');
99
                   store_buy_sell <= (others => '0');   -- 111 buy, 000 sell
100
                   store_px       <= (others => '0');   -- price
101
                   store_qty      <= (others => '0');   -- quantity
102
                   store_sec      <= (others => '0');   -- 7x 8bits securities identifier
103 13 stvhawes
              -- not reset / generic     store_id       <= (others => '0');   -- unique/identifier/counter
104 11 stvhawes
                   --
105
                   b2_px_type  <= (others => 'Z');
106
                   b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
107
                   b2_px       <= (others => 'Z');   -- price
108
                   b2_qty      <= (others => 'Z');   -- quantity
109
                   b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
110
                   b2_id       <= (others => 'Z');   -- unique/identifier/counter
111
                   --
112 14 stvhawes
                   b2_px_type <= std_logic_vector'("ZZZZZ");
113
                   state <= 16;
114 11 stvhawes
 
115 13 stvhawes
            elsif b1_px_type = std_logic_vector'("00110") then
116 14 stvhawes
                  if store_buy_sell = b1_buy_sell and
117
                     store_sec      = b1_sec  then
118
                       -- do set store from incoming price 
119
                       store_px_type  <= b1_px_type;
120
                       -- store_buy_sell <= b1_buy_sell;
121
                       store_px       <= b1_px;
122
                       store_qty      <= b1_qty;
123
                       -- store_sec      <= b1_sec;
124
                       store_id       <= b1_id;
125
                       --
126
                       b2_px_type <= std_logic_vector'(std_logic_vector'("00110"));
127
                       state <= 8;
128
                   end if;
129 11 stvhawes
 
130 14 stvhawes
            elsif b1_px_type = std_logic_vector'("01010") then
131
                   if item_id = b1_id then
132
                       -- do set store and security from incoming price 
133
                       store_px_type  <= b1_px_type;
134
                       store_buy_sell <= b1_buy_sell;
135
                       store_px       <= b1_px;
136
                       store_qty      <= b1_qty;
137
                       store_sec      <= b1_sec;
138
                       store_id       <= b1_id;
139
                       --
140
                       b2_px_type <= b1_px_type;
141
                       b2_id      <= item_id;
142
                       state <= 8;
143
                   end if;
144
 
145
            elsif b1_px_type = std_logic_vector'("11100") then
146 11 stvhawes
                   -- incoming price, register it and start the state machine
147 14 stvhawes
                   if (store_sec /= b1_sec or store_buy_sell = b1_buy_sell ) then
148
                      -- not this store_item instance no action
149
                      null;
150 12 stvhawes
                   elsif (to_integer(unsigned(store_qty)) = 0 or to_integer(unsigned(b1_qty)) = 0 or
151
                             (store_buy_sell = std_logic_vector'("111") and store_px < b1_px) or
152
                             (store_buy_sell = std_logic_vector'("000") and store_px > b1_px) ) then
153 11 stvhawes
                      -- no deal: this is the correct store_item but there's no match
154 14 stvhawes
                      b2_px_type <= std_logic_vector'(std_logic_vector'("11101"));
155 11 stvhawes
                   else
156
                      -- send a return order
157
                      b2_buy_sell <= store_buy_sell;   -- 111 buy, 000 sell
158 14 stvhawes
                      b2_sec <= store_sec;                                          -- 7x 8bits securities identifier
159
                      b2_id <= store_id;                                            -- unique/identifier/counter
160 11 stvhawes
                      b2_px <= b1_px;                   -- price
161 12 stvhawes
                      -- b2_qty <= 
162
                      if b1_qty < store_qty then
163
                         b2_qty <= b1_qty;
164
                      else
165
                         b2_qty <= store_qty;
166
                      end if;    -- quantity
167 11 stvhawes
                      -- update the store
168 12 stvhawes
                      -- store_qty
169
                      if (b1_qty < store_qty) then
170
                         store_qty <= std_logic_vector(to_unsigned( to_integer(unsigned(store_qty)) - to_integer(unsigned(b1_qty)) ,16 ));
171
                      else
172
                         store_qty <= (others => '0');
173
                      end  if;
174 14 stvhawes
                      b2_px_type <= std_logic_vector'(std_logic_vector'("11100"));
175 11 stvhawes
                   end if;
176 14 stvhawes
                   state <= 8;
177 11 stvhawes
 
178 12 stvhawes
            else
179
               -- no action
180
               null;
181
            end if;   -- b1_px_type
182 11 stvhawes
 
183
         else     -- b1_px_valid
184
            -- no incoming b1_px so check for state machine actions
185
            case state is
186 14 stvhawes
               when 8 =>
187 11 stvhawes
                   -- sent return order, so clean up
188
                   b2_px_type  <= (others => 'Z');
189
                   b2_buy_sell <= (others => 'Z');    -- 111 buy, 000 sell
190
                   b2_px       <= (others => 'Z');    -- price
191
                   b2_qty      <= (others => 'Z');    -- quantity
192
                   b2_sec      <= (others => 'Z');    -- 7x 8bits securities identifier
193 12 stvhawes
                   b2_id       <= (others => 'Z');    -- unique/identifier/counter
194 14 stvhawes
                   --
195
                   b2_px_type <= std_logic_vector'("ZZZZZ");
196 11 stvhawes
                   state <= 16;
197
 
198
               when others => null;
199
            end case;   -- state
200
 
201
            if (state < 16) then
202
               state <= state + 1;
203
            end if;
204
 
205
         end if;     -- b1_px_valid
206
 
207
      end if;
208
   end process match;
209
 
210
end search_item_implementation;
211
 

powered by: WebSVN 2.1.0

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