[240] | 1 | #ifndef IOB_TRANSACTION_H_ |
---|
| 2 | #define IOB_TRANSACTION_H_ |
---|
| 3 | |
---|
| 4 | #include <inttypes.h> |
---|
| 5 | #include <systemc> |
---|
| 6 | #include <cassert> |
---|
| 7 | #include "arithmetics.h" |
---|
| 8 | |
---|
| 9 | #define DEBUG_IOB_TRANSACTION 0 |
---|
| 10 | |
---|
| 11 | // The index of Transaction Tab Entry corresponds to the trdid of the VCI packet on XRAM network |
---|
| 12 | |
---|
| 13 | //////////////////////////////////////////////////////////////////////// |
---|
| 14 | // A transaction tab entry |
---|
| 15 | //////////////////////////////////////////////////////////////////////// |
---|
| 16 | |
---|
| 17 | class TransactionTabIOEntry { |
---|
| 18 | typedef uint32_t size_t; |
---|
| 19 | |
---|
| 20 | public: |
---|
| 21 | bool valid; // entry valid |
---|
| 22 | size_t srcid; // processor requesting the transaction |
---|
| 23 | size_t trdid; // processor requesting the transaction |
---|
| 24 | |
---|
| 25 | ///////////////////////////////////////////////////////////////////// |
---|
| 26 | // The init() function initializes the entry |
---|
| 27 | ///////////////////////////////////////////////////////////////////// |
---|
| 28 | void init() |
---|
| 29 | { |
---|
| 30 | valid = false; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | //////////////////////////////////////////////////////////////////// |
---|
| 34 | // The copy() function copies an existing entry |
---|
| 35 | // Its arguments are : |
---|
| 36 | // - source : the transaction tab entry to copy |
---|
| 37 | //////////////////////////////////////////////////////////////////// |
---|
| 38 | void copy(const TransactionTabIOEntry &source) |
---|
| 39 | { |
---|
| 40 | valid = source.valid; |
---|
| 41 | srcid = source.srcid; |
---|
| 42 | trdid = source.trdid; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | //////////////////////////////////////////////////////////////////// |
---|
| 46 | // The print() function prints the entry |
---|
| 47 | //////////////////////////////////////////////////////////////////// |
---|
| 48 | void print(){ |
---|
| 49 | std::cout << "valid = " << valid << std::endl; |
---|
| 50 | std::cout << "srcid = " << srcid << std::endl; |
---|
| 51 | std::cout << "trdid = " << trdid << std::endl; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | ///////////////////////////////////////////////////////////////////// |
---|
| 55 | // Constructors |
---|
| 56 | ///////////////////////////////////////////////////////////////////// |
---|
| 57 | |
---|
| 58 | TransactionTabIOEntry() |
---|
| 59 | { |
---|
| 60 | valid=false; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | TransactionTabIOEntry(const TransactionTabIOEntry &source){ |
---|
| 64 | valid = source.valid; |
---|
| 65 | srcid = source.srcid; |
---|
| 66 | trdid = source.trdid; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | }; // end class TransactionTabIOEntry |
---|
| 70 | |
---|
| 71 | //////////////////////////////////////////////////////////////////////// |
---|
| 72 | // The transaction tab |
---|
| 73 | //////////////////////////////////////////////////////////////////////// |
---|
| 74 | class TransactionTabIO{ |
---|
| 75 | // typedef uint32_t size_t; |
---|
| 76 | |
---|
| 77 | private: |
---|
| 78 | size_t size_tab; // The size of the tab |
---|
| 79 | |
---|
| 80 | public: |
---|
| 81 | TransactionTabIOEntry *tab; // The transaction tab |
---|
| 82 | |
---|
| 83 | //////////////////////////////////////////////////////////////////// |
---|
| 84 | // Constructors |
---|
| 85 | //////////////////////////////////////////////////////////////////// |
---|
| 86 | TransactionTabIO() |
---|
| 87 | { |
---|
| 88 | size_tab=0; |
---|
| 89 | tab=NULL; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | TransactionTabIO(size_t n_entries) |
---|
| 93 | { |
---|
| 94 | size_tab = n_entries; |
---|
| 95 | tab = new TransactionTabIOEntry[size_tab]; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | ~TransactionTabIO() |
---|
| 99 | { |
---|
| 100 | delete [] tab; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | ///////////////////////////////////////////////////////////////////// |
---|
| 104 | // The size() function returns the size of the tab |
---|
| 105 | ///////////////////////////////////////////////////////////////////// |
---|
| 106 | size_t size() |
---|
| 107 | { |
---|
| 108 | return size_tab; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | ///////////////////////////////////////////////////////////////////// |
---|
| 112 | // The init() function initializes the transaction tab entries |
---|
| 113 | ///////////////////////////////////////////////////////////////////// |
---|
| 114 | void init() |
---|
| 115 | { |
---|
| 116 | for ( size_t i=0; i<size_tab; i++) { |
---|
| 117 | tab[i].init(); |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | ///////////////////////////////////////////////////////////////////// |
---|
| 122 | // The print() function prints a transaction tab entry |
---|
| 123 | // Arguments : |
---|
| 124 | // - index : the index of the entry to print |
---|
| 125 | ///////////////////////////////////////////////////////////////////// |
---|
| 126 | void print(const size_t index) |
---|
| 127 | { |
---|
| 128 | assert( (index < size_tab) |
---|
| 129 | && "Invalid Transaction Tab Entry"); |
---|
| 130 | tab[index].print(); |
---|
| 131 | return; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | ///////////////////////////////////////////////////////////////////// |
---|
| 135 | // The read() function returns a transaction tab entry. |
---|
| 136 | // Arguments : |
---|
| 137 | // - index : the index of the entry to read |
---|
| 138 | ///////////////////////////////////////////////////////////////////// |
---|
| 139 | TransactionTabIOEntry read(const size_t index) |
---|
| 140 | { |
---|
| 141 | assert( (index < size_tab) |
---|
| 142 | && "Invalid Transaction Tab Entry"); |
---|
| 143 | return tab[index]; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | ///////////////////////////////////////////////////////////////////// |
---|
| 147 | // The readSrcid() function returns the srcid field of a transaction tab entry. |
---|
| 148 | // Arguments : |
---|
| 149 | // - index : the index of the entry to read |
---|
| 150 | ///////////////////////////////////////////////////////////////////// |
---|
| 151 | size_t readSrcid(const size_t index) |
---|
| 152 | { |
---|
| 153 | assert( (index < size_tab) |
---|
| 154 | && "Invalid Transaction Tab Entry"); |
---|
| 155 | return tab[index].srcid; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | ///////////////////////////////////////////////////////////////////// |
---|
| 159 | // The readTrdid() function returns the trdid field of a transaction tab entry. |
---|
| 160 | // Arguments : |
---|
| 161 | // - index : the index of the entry to read |
---|
| 162 | ///////////////////////////////////////////////////////////////////// |
---|
| 163 | size_t readTrdid(const size_t index) |
---|
| 164 | { |
---|
| 165 | assert( (index < size_tab) |
---|
| 166 | && "Invalid Transaction Tab Entry"); |
---|
| 167 | return tab[index].trdid; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | ///////////////////////////////////////////////////////////////////// |
---|
| 171 | // The full() function returns the state of the transaction tab |
---|
| 172 | // Arguments : |
---|
| 173 | // - index : (return argument) the index of an empty entry |
---|
| 174 | // The function returns true if the transaction tab is full |
---|
| 175 | ///////////////////////////////////////////////////////////////////// |
---|
| 176 | bool full(size_t &index) |
---|
| 177 | { |
---|
| 178 | for(size_t i=0; i<size_tab; i++){ |
---|
| 179 | if(!tab[i].valid){ |
---|
| 180 | index=i; |
---|
| 181 | return false; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | return true; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | ///////////////////////////////////////////////////////////////////// |
---|
| 188 | // The set() function registers a transaction (read or write) |
---|
| 189 | // to the XRAM in the transaction tab. |
---|
| 190 | // Arguments : |
---|
| 191 | // - index : index in the transaction tab |
---|
| 192 | // - srcid : srcid of the initiator that caused the transaction |
---|
| 193 | // - trdid : trdid of the initiator that caused the transaction |
---|
| 194 | ///////////////////////////////////////////////////////////////////// |
---|
| 195 | void set(const size_t index, |
---|
| 196 | const size_t srcid, |
---|
| 197 | const size_t trdid) |
---|
| 198 | { |
---|
| 199 | assert( (index < size_tab) |
---|
| 200 | && "The selected entry is out of range in set() Transaction Tab"); |
---|
| 201 | |
---|
| 202 | tab[index].valid = true; |
---|
| 203 | tab[index].srcid = srcid; |
---|
| 204 | tab[index].trdid = trdid; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | ///////////////////////////////////////////////////////////////////// |
---|
| 208 | // The erase() function erases an entry in the transaction tab. |
---|
| 209 | // Arguments : |
---|
| 210 | // - index : the index of the request in the transaction tab |
---|
| 211 | ///////////////////////////////////////////////////////////////////// |
---|
| 212 | void erase(const size_t index) |
---|
| 213 | { |
---|
| 214 | assert( (index < size_tab) |
---|
| 215 | && "The selected entry is out of range in erase() Transaction Tab"); |
---|
| 216 | tab[index].valid = false; |
---|
| 217 | } |
---|
| 218 | }; // end class TransactionTabIO |
---|
| 219 | |
---|
| 220 | #endif |
---|
| 221 | |
---|
| 222 | // Local Variables: |
---|
| 223 | // tab-width: 4 |
---|
| 224 | // c-basic-offset: 4 |
---|
| 225 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 226 | // indent-tabs-mode: nil |
---|
| 227 | // End: |
---|
| 228 | |
---|
| 229 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 230 | |
---|