[2] | 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 | |
---|
| 21 | template <unsigned int NWORD, |
---|
| 22 | unsigned int NBIT> |
---|
| 23 | |
---|
| 24 | struct soclib_generic_fifo { |
---|
| 25 | |
---|
| 26 | //////////////////////////// |
---|
| 27 | // internal FIFO registers |
---|
| 28 | //////////////////////////// |
---|
| 29 | |
---|
| 30 | sc_signal<sc_uint<NBIT> > DATA[NWORD]; |
---|
| 31 | sc_signal<int> PTR; |
---|
| 32 | sc_signal<int> PTW; |
---|
| 33 | sc_signal<int> STATE; |
---|
| 34 | |
---|
| 35 | /////////////////////// |
---|
| 36 | // method init() |
---|
| 37 | /////////////////////// |
---|
| 38 | void init() |
---|
| 39 | { |
---|
| 40 | PTR = 0; |
---|
| 41 | PTW = 0; |
---|
| 42 | STATE = 0; |
---|
| 43 | }; // end init() |
---|
| 44 | |
---|
| 45 | /////////////////////// |
---|
| 46 | // method filled_status() |
---|
| 47 | /////////////////////// |
---|
| 48 | |
---|
| 49 | int filled_status() |
---|
| 50 | { |
---|
| 51 | return (int)STATE; |
---|
| 52 | }; |
---|
| 53 | //end filled_status() |
---|
| 54 | |
---|
| 55 | /////////////////////// |
---|
| 56 | // method simple_put() |
---|
| 57 | /////////////////////// |
---|
| 58 | |
---|
| 59 | void 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 | /////////////////////// |
---|
| 71 | void 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 | ////////////////////////// |
---|
| 82 | void 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 | /////////////////////// |
---|
| 101 | bool rok() |
---|
| 102 | { |
---|
| 103 | if(STATE != 0) return(true); |
---|
| 104 | else return(false); |
---|
| 105 | }; // end rok() |
---|
| 106 | |
---|
| 107 | //////////////////////// |
---|
| 108 | // method wok() |
---|
| 109 | /////////////////////// |
---|
| 110 | bool wok() |
---|
| 111 | { |
---|
| 112 | if(STATE != NWORD) return(true); |
---|
| 113 | else return(false); |
---|
| 114 | }; // end wok() |
---|
| 115 | |
---|
| 116 | //////////////////////// |
---|
| 117 | // method read() |
---|
| 118 | /////////////////////// |
---|
| 119 | sc_uint<NBIT> read() |
---|
| 120 | { |
---|
| 121 | return(DATA[PTR]); |
---|
| 122 | }; // end read() |
---|
| 123 | |
---|
| 124 | }; // end struct generic_fifo |
---|
| 125 | |
---|
| 126 | #endif |
---|