add first peripheral set
[shakti-peripherals.git] / src / uncore / axi4 / Semi_FIFOF.bsv
1 /*
2 Copyright (c) 2013, IIT Madras
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 * Neither the name of IIT Madras nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 -----------------------------------------------------------------------
30
31 */
32 // Copyright (c) 2017 Bluespec, Inc. All Rights Reserved
33
34 package Semi_FIFOF;
35
36 // ================================================================
37 // Separate interfaces for input-side and output-side of FIFOF.
38 // Conversion functions to these, from FIFOF interfaces.
39
40 // ================================================================
41 // BSV library imports
42
43 import FIFOF :: *;
44 import Connectable :: *;
45
46 // ================================================================
47 // Semi-FIFOF interfaces
48
49 interface FIFOF_I #(type t);
50 method Action enq (t x);
51 method Bool notFull ();
52 endinterface
53
54 interface FIFOF_O #(type t);
55 method t first ();
56 method Action deq ();
57 method Bool notEmpty ();
58 endinterface
59
60 // ================================================================
61 // Converters from FIFOF
62
63 function FIFOF_I #(t) to_FIFOF_I (FIFOF #(t) f);
64 return interface FIFOF_I;
65 method enq (x) = f.enq (x);
66 method notFull = f.notFull;
67 endinterface;
68 endfunction
69
70 function FIFOF_O #(t) to_FIFOF_O (FIFOF #(t) f);
71 return interface FIFOF_O;
72 method first = f.first;
73 method deq = f.deq;
74 method notEmpty = f.notEmpty;
75 endinterface;
76 endfunction
77
78 // ================================================================
79 // Connections
80
81 // ----------------
82 // FIFOF_O to a FIFOF_I
83
84 instance Connectable #(FIFOF_O #(t), FIFOF_I #(t));
85 module mkConnection #(FIFOF_O #(t) fo, FIFOF_I #(t) fi) (Empty);
86 rule rl_connect;
87 fi.enq (fo.first);
88 fo.deq;
89 endrule
90 endmodule
91 endinstance
92
93 // ----------------
94 // FIFOF_O to a FIFOF
95
96 instance Connectable #(FIFOF_O #(t), FIFOF #(t));
97 module mkConnection #(FIFOF_O #(t) fo, FIFOF #(t) fi) (Empty);
98 rule rl_connect;
99 fi.enq (fo.first);
100 fo.deq;
101 endrule
102 endmodule
103 endinstance
104
105 // ----------------
106 // FIFOF to a FIFOF_I
107
108 instance Connectable #(FIFOF #(t), FIFOF_I #(t));
109 module mkConnection #(FIFOF #(t) fo, FIFOF_I #(t) fi) (Empty);
110 rule rl_connect;
111 fi.enq (fo.first);
112 fo.deq;
113 endrule
114 endmodule
115 endinstance
116
117 // ================================================================
118 // Convenience function combining first/enq
119
120 function ActionValue #(t) pop_o (FIFOF_O #(t) f);
121 actionvalue
122 f.deq;
123 return f.first;
124 endactionvalue
125 endfunction
126
127 // ================================================================
128
129 endpackage