[724] | 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 | //////////////////////////////////////////////////////////////////////// |
---|
| 12 | // A transaction tab entry |
---|
| 13 | //////////////////////////////////////////////////////////////////////// |
---|
| 14 | |
---|
| 15 | class TransactionTabIOEntry { |
---|
| 16 | typedef uint32_t size_t; |
---|
| 17 | |
---|
| 18 | public: |
---|
| 19 | bool valid; // valid entry |
---|
| 20 | size_t srcid; // initiator requesting the transaction |
---|
| 21 | size_t trdid; // thread ID of transaction |
---|
| 22 | |
---|
| 23 | ///////////////////////////////////////////////////////////////////// |
---|
| 24 | // The init() function initializes the entry |
---|
| 25 | ///////////////////////////////////////////////////////////////////// |
---|
| 26 | void init() |
---|
| 27 | { |
---|
| 28 | valid = false; |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | //////////////////////////////////////////////////////////////////// |
---|
| 32 | // The copy() function copies an existing entry |
---|
| 33 | // Its arguments are : |
---|
| 34 | // - source : the transaction tab entry to copy |
---|
| 35 | //////////////////////////////////////////////////////////////////// |
---|
| 36 | void copy(const TransactionTabIOEntry &source) |
---|
| 37 | { |
---|
| 38 | valid = source.valid; |
---|
| 39 | srcid = source.srcid; |
---|
| 40 | trdid = source.trdid; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | //////////////////////////////////////////////////////////////////// |
---|
| 44 | // The print() function prints the entry |
---|
| 45 | //////////////////////////////////////////////////////////////////// |
---|
| 46 | void print(){ |
---|
| 47 | std::cout << " valid = " << valid << std::hex |
---|
| 48 | << " / srcid = " << srcid |
---|
| 49 | << " / trdid = " << trdid << std::dec |
---|
| 50 | << std::endl; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | ///////////////////////////////////////////////////////////////////// |
---|
| 54 | // Constructors |
---|
| 55 | ///////////////////////////////////////////////////////////////////// |
---|
| 56 | |
---|
| 57 | TransactionTabIOEntry() |
---|
| 58 | { |
---|
| 59 | valid = false; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | TransactionTabIOEntry(const TransactionTabIOEntry &source){ |
---|
| 63 | valid = source.valid; |
---|
| 64 | srcid = source.srcid; |
---|
| 65 | trdid = source.trdid; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | }; // end class TransactionTabIOEntry |
---|
| 69 | |
---|
| 70 | //////////////////////////////////////////////////////////////////////// |
---|
| 71 | // The transaction tab |
---|
| 72 | //////////////////////////////////////////////////////////////////////// |
---|
| 73 | class TransactionTabIO{ |
---|
| 74 | private: |
---|
| 75 | const size_t size_tab; // The size of the tab |
---|
| 76 | |
---|
| 77 | public: |
---|
| 78 | TransactionTabIOEntry *tab; // The transaction tab |
---|
| 79 | |
---|
| 80 | //////////////////////////////////////////////////////////////////// |
---|
| 81 | // Constructors |
---|
| 82 | //////////////////////////////////////////////////////////////////// |
---|
| 83 | TransactionTabIO(size_t n_entries) : size_tab(n_entries) |
---|
| 84 | { |
---|
| 85 | tab = new TransactionTabIOEntry[size_tab]; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | ~TransactionTabIO() |
---|
| 89 | { |
---|
| 90 | delete [] tab; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | ///////////////////////////////////////////////////////////////////// |
---|
| 94 | // The size() function returns the size of the tab |
---|
| 95 | ///////////////////////////////////////////////////////////////////// |
---|
| 96 | const size_t& size() |
---|
| 97 | { |
---|
| 98 | return size_tab; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | ///////////////////////////////////////////////////////////////////// |
---|
| 102 | // The init() function initializes the transaction tab entries |
---|
| 103 | ///////////////////////////////////////////////////////////////////// |
---|
| 104 | void init() |
---|
| 105 | { |
---|
| 106 | for ( size_t index = 0; index < size_tab; index++) |
---|
| 107 | { |
---|
| 108 | tab[index].init(); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | ///////////////////////////////////////////////////////////////////// |
---|
| 113 | // The print() function prints a transaction tab entry |
---|
| 114 | // Arguments : |
---|
| 115 | // - index : the index of the entry to print |
---|
| 116 | ///////////////////////////////////////////////////////////////////// |
---|
| 117 | void print(const size_t index) |
---|
| 118 | { |
---|
| 119 | assert( (index < size_tab) && "Invalid Transaction Tab Entry"); |
---|
| 120 | tab[index].print(); |
---|
| 121 | return; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | ///////////////////////////////////////////////////////////////////// |
---|
| 125 | // The printTrace() function prints all transaction tab entries |
---|
| 126 | ///////////////////////////////////////////////////////////////////// |
---|
| 127 | void printTrace() |
---|
| 128 | { |
---|
| 129 | for (size_t index = 0; index < size_tab; index++) |
---|
| 130 | { |
---|
| 131 | tab[index].print(); |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | ///////////////////////////////////////////////////////////////////// |
---|
| 136 | // The read() function returns a transaction tab entry. |
---|
| 137 | // Arguments : |
---|
| 138 | // - index : the index of the entry to read |
---|
| 139 | ///////////////////////////////////////////////////////////////////// |
---|
| 140 | TransactionTabIOEntry& read(const size_t index) |
---|
| 141 | { |
---|
| 142 | assert( (index < size_tab) && "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) && "Invalid Transaction Tab Entry"); |
---|
| 154 | return tab[index].srcid; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | ///////////////////////////////////////////////////////////////////// |
---|
| 158 | // The readTrdid() function returns the trdid field of a transaction tab entry. |
---|
| 159 | // Arguments : |
---|
| 160 | // - index : the index of the entry to read |
---|
| 161 | ///////////////////////////////////////////////////////////////////// |
---|
| 162 | size_t readTrdid(const size_t index) |
---|
| 163 | { |
---|
| 164 | assert( (index < size_tab) && "Invalid Transaction Tab Entry"); |
---|
| 165 | return tab[index].trdid; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | ///////////////////////////////////////////////////////////////////// |
---|
| 169 | // The full() function returns the state of the transaction tab |
---|
| 170 | // Arguments : |
---|
| 171 | // - index : (return argument) the index of an empty entry |
---|
| 172 | // The function returns true if the transaction tab is full |
---|
| 173 | ///////////////////////////////////////////////////////////////////// |
---|
| 174 | bool full(size_t &index) |
---|
| 175 | { |
---|
| 176 | for(size_t i=0; i<size_tab; i++) |
---|
| 177 | { |
---|
| 178 | if(!tab[i].valid) |
---|
| 179 | { |
---|
| 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) && "Invalid Transaction Tab Entry"); |
---|
| 200 | tab[index].valid = true; |
---|
| 201 | tab[index].srcid = srcid; |
---|
| 202 | tab[index].trdid = trdid; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | ///////////////////////////////////////////////////////////////////// |
---|
| 206 | // The erase() function erases an entry in the transaction tab. |
---|
| 207 | // Arguments : |
---|
| 208 | // - index : the index of the request in the transaction tab |
---|
| 209 | ///////////////////////////////////////////////////////////////////// |
---|
| 210 | void erase(const size_t index) |
---|
| 211 | { |
---|
| 212 | assert( (index < size_tab) && "Invalid Transaction Tab Entry"); |
---|
| 213 | tab[index].valid = false; |
---|
| 214 | } |
---|
| 215 | }; // end class TransactionTabIO |
---|
| 216 | |
---|
| 217 | #endif |
---|
| 218 | |
---|
| 219 | // Local Variables: |
---|
| 220 | // tab-width: 2 |
---|
| 221 | // c-basic-offset: 2 |
---|
| 222 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 223 | // indent-tabs-mode: nil |
---|
| 224 | // End: |
---|
| 225 | |
---|
| 226 | // vim: filetype=cpp:expandtab:shiftwidth=2:tabstop=2:softtabstop=2 |
---|
| 227 | |
---|