source: trunk/IPs/systemC/shared/soclib_generic_fifo.h @ 2

Last change on this file since 2 was 2, checked in by kane, 17 years ago

Import Morpheo

File size: 2.6 KB
Line 
1
2/**************************************************************************
3 * File : soclib_generic_fifo.h
4 * Date : 28/08/2003
5 * author : Alain Greiner
6 * This program is released under the GNU public license
7 * Copyright : UPMC - LIP6
8 *
9 * This model describes a generic snchronous FIFO.
10 * The two parameters are the number of bit per word (NBIT) and
11 * the number of word (NWORD)
12 * - The 4 methods init(), simple_put(), simple_get(), put_and_get()
13 * change the internal state of the FIFO, but return no data or status !
14 * - The 4 methods rok(), wok(), filled_status() and read() return a
15 * status or a data, but does not change the FIFO internal state!
16***************************************************************************/
17
18#ifndef SOCLIB_GENERIC_FIFO_H
19#define SOCLIB_GENERIC_FIFO_H
20
21template <unsigned int NWORD,
22          unsigned int NBIT>
23         
24struct soclib_generic_fifo {
25
26////////////////////////////
27// internal FIFO registers
28////////////////////////////
29
30sc_signal<sc_uint<NBIT> >       DATA[NWORD];
31sc_signal<int>                  PTR;
32sc_signal<int>                  PTW;
33sc_signal<int>                  STATE;
34
35///////////////////////
36//  method init()
37///////////////////////
38void init()
39{
40        PTR = 0;
41        PTW = 0;
42        STATE = 0;
43}; // end init()
44
45///////////////////////
46// method filled_status()
47///////////////////////
48
49int filled_status()
50{
51  return (int)STATE;
52};
53//end filled_status()
54
55///////////////////////
56// method simple_put()
57///////////////////////
58
59void simple_put(sc_uint<NBIT> din)
60{
61        if (STATE != NWORD) { 
62                STATE = STATE + 1;
63                PTW = (PTW + 1) % NWORD;
64                DATA[PTW] = din; 
65        }
66}; // end simple_put()
67
68///////////////////////
69// method simple_get()
70///////////////////////
71void simple_get()
72{
73        if (STATE != 0) {
74                STATE = STATE - 1;
75                PTR = (PTR + 1) % NWORD;
76        }
77}; // end simple_get()
78
79//////////////////////////
80// method put_and_get() 
81//////////////////////////
82void put_and_get(sc_uint<NBIT> din)
83{
84        if (STATE == NWORD) {
85                STATE = STATE - 1;
86                PTR = (PTR + 1) % NWORD;
87        } else if (STATE == 0) {
88                STATE = STATE + 1;
89                PTW = (PTW + 1) % NWORD;
90                DATA[PTW] = din; 
91        } else {
92                PTR = (PTR + 1) % NWORD;
93                PTW = (PTW + 1) % NWORD;
94                DATA[PTW] = din; 
95        }
96}; // end put_and_get()
97
98////////////////////////
99//  method rok()
100///////////////////////
101bool rok()
102{
103        if(STATE != 0)  return(true);
104        else            return(false);
105}; // end rok()
106
107////////////////////////
108//  method wok() 
109///////////////////////
110bool wok()
111{
112        if(STATE != NWORD)  return(true);
113        else                return(false);
114}; // end wok()
115
116////////////////////////
117//  method read()
118///////////////////////
119sc_uint<NBIT> read()
120{
121        return(DATA[PTR]);
122}; // end read()
123
124}; // end struct generic_fifo
125
126#endif
Note: See TracBrowser for help on using the repository browser.