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 11

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
 
57
entity search_item is
58
   port (
59
        RX_CLK: in std_logic;
60
        -- control flag(s) on the incoming bus
61
           b1_px_valid: in std_logic;
62
        -- pxdata: in price_packet
63
           b1_px_type: out std_logic_vector(4 downto 0);
64
           b1_buy_sell: out std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
65
           b1_px: out std_logic_vector(15 downto 0);     -- price
66
           b1_qty: out std_logic_vector(15 downto 0);    -- quantity
67
           b1_sec: out std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
68
           b1_id: out std_logic_vector(15 downto 0);    -- unique/identifier/counter
69
        -- pxdata: out price_packet
70
           b2_px_type: out std_logic_vector(4 downto 0);
71
           b2_buy_sell: out std_logic_vector(2 downto 0);   -- 111 buy, 000 sell
72
           b2_px: out std_logic_vector(15 downto 0);     -- price
73
           b2_qty: out std_logic_vector(15 downto 0);    -- quantity
74
           b2_sec: out std_logic_vector(55 downto 0);    -- 7x 8bits securities identifier
75
           b2_id: out std_logic_vector(15 downto 0);     -- unique/identifier/counter
76
   );
77
end search_item;
78
 
79
architecture search_item_implementation of search_item is
80
      signal state : integer range 0 to 16 := 16;
81
   -- pxdata: out price_packet
82
      signal store_px_type: std_logic_vector(4 downto 0) := (others => '0');
83
      signal store_buy_sell: std_logic_vector(2 downto 0) := (others => '0');   -- 111 buy, 000 sell
84
      signal store_px: std_logic_vector(15 downto 0) := (others => '0');     -- price
85
      signal store_qty: std_logic_vector(15 downto 0) := (others => '0');    -- quantity
86
      signal store_sec: std_logic_vector(55 downto 0) := (others => '0');    -- 7x 8bits securities identifier
87
      signal store_id: std_logic_vector(15 downto 0) := (others => '0');     -- unique/identifier/counter
88
begin
89
   match: process (RX_CLK) is
90
   begin
91
      if rising_edge(RX_CLK) then
92
         if b1_px_valid then
93
 
94
            case b1_px_type is
95
               when '0000' =>
96
                   -- do reset store and outputs
97
                   store_px_type  <= (others => '0');
98
                   store_buy_sell <= (others => '0');   -- 111 buy, 000 sell
99
                   store_px       <= (others => '0');   -- price
100
                   store_qty      <= (others => '0');   -- quantity
101
                   store_sec      <= (others => '0');   -- 7x 8bits securities identifier
102
                   store_id       <= (others => '0');   -- unique/identifier/counter
103
                   --
104
                   b2_px_type  <= (others => 'Z');
105
                   b2_buy_sell <= (others => 'Z');   -- 111 buy, 000 sell
106
                   b2_px       <= (others => 'Z');   -- price
107
                   b2_qty      <= (others => 'Z');   -- quantity
108
                   b2_sec      <= (others => 'Z');   -- 7x 8bits securities identifier
109
                   b2_id       <= (others => 'Z');   -- unique/identifier/counter
110
                   --
111
                   b2_px_type <== '0000';
112
                   state <= 8;
113
 
114
               when '0110' =>
115
                   -- do set store from incoming price 
116
                   store_px_type  <= b1_px_type;
117
                   store_buy_sell <= b1_buy_sell;
118
                   store_px       <= b1_px;
119
                   store_qty      <= b1_qty;
120
                   store_sec      <= b1_sec;
121
                   store_id       <= b1_id;
122
                   --
123
                   b2_px_type <== '0000';
124
                   state <= 8;
125
 
126
               when '0101' =>
127
                   -- incoming price, register it and start the state machine
128
                   if (store_sec != b1_sec or store_buy_sell == b1_buy_sell or store_px_type != '0110')
129
                      -- not this store_item instance no action, also stop anything that might be going on
130
                      state <= 14;
131
                   elsif (store_qty == 0 or b1_qty == 0 or
132
                             (store_buy_sell == '111' and store_px < b1_px) or
133
                             (store_buy_sell == '000' and store_px > b1_px) )
134
                      -- no deal: this is the correct store_item but there's no match
135
                      b2_px_type <== '0000';
136
                      state <= 8;
137
                   else
138
                      -- send a return order
139
                      b2_px_type <= '1010';
140
                      b2_buy_sell <= store_buy_sell;   -- 111 buy, 000 sell
141
                      b2_px <= b1_px;                   -- price
142
                      b2_qty <= b1_qty when (b1_qty < store_qty) else store_qty;    -- quantity
143
                      b2_sec <= store_sec:                                          -- 7x 8bits securities identifier
144
                      b2_id <= store_id;                                            -- unique/identifier/counter
145
                      -- update the store
146
                      store_qty <= (store_qty-b1_qty) when (b1_qty < store_qty) else 0;
147
                      state <= 1;
148
                   end if;
149
 
150
               when others => null;
151
            end case;   -- b1_px_type
152
 
153
         else     -- b1_px_valid
154
            -- no incoming b1_px so check for state machine actions
155
            case state is
156
               when 1 =>
157
                   -- sent return order, so clean up
158
                   b2_px_type  <= (others => 'Z');
159
                   b2_buy_sell <= (others => 'Z');    -- 111 buy, 000 sell
160
                   b2_px       <= (others => 'Z');    -- price
161
                   b2_qty      <= (others => 'Z');    -- quantity
162
                   b2_sec      <= (others => 'Z');    -- 7x 8bits securities identifier
163
                   b2_id       <= (others => 'Z'):    -- unique/identifier/counter
164
                   state <= 16;
165
 
166
               when 8 =>
167
                    -- correct store_item but there was no match
168
                    b2_px_type <== 'ZZZZ';
169
                   state <= 16;
170
 
171
               when others => null;
172
            end case;   -- state
173
 
174
            if (state < 16) then
175
               state <= state + 1;
176
            end if;
177
 
178
         end if;     -- b1_px_valid
179
 
180
      end if;
181
   end process match;
182
 
183
end search_item_implementation;
184
 

powered by: WebSVN 2.1.0

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