[2] | 1 | #ifndef ATOMIC_TAB_V1_H_ |
---|
| 2 | #define ATOMIC_TAB_V1_H_ |
---|
| 3 | |
---|
| 4 | #include <inttypes.h> |
---|
| 5 | #include <systemc> |
---|
| 6 | #include <cassert> |
---|
| 7 | #include "arithmetics.h" |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | //////////////////////////////////////////////////////////////////////// |
---|
| 12 | //////////////////////////////////////////////////////////////////////// |
---|
| 13 | /* The atomic access tab */ |
---|
| 14 | //////////////////////////////////////////////////////////////////////// |
---|
| 15 | //////////////////////////////////////////////////////////////////////// |
---|
| 16 | |
---|
| 17 | class AtomicTab{ |
---|
| 18 | typedef uint32_t size_t; |
---|
| 19 | typedef sc_dt::sc_uint<40> addr_t; |
---|
| 20 | |
---|
| 21 | private: |
---|
| 22 | size_t size_tab; // The size of the tab |
---|
| 23 | std::vector<addr_t> addr_tab; // Address entries |
---|
| 24 | std::vector<bool> valid_tab; // Valid entries |
---|
| 25 | |
---|
| 26 | public: |
---|
| 27 | |
---|
| 28 | AtomicTab() |
---|
| 29 | : addr_tab(0), |
---|
| 30 | valid_tab(0) |
---|
| 31 | { |
---|
| 32 | size_tab=0; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | AtomicTab(size_t size_tab_i) |
---|
| 36 | : addr_tab(size_tab_i), |
---|
| 37 | valid_tab(size_tab_i) |
---|
| 38 | { |
---|
| 39 | size_tab=size_tab_i; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | ///////////////////////////////////////////////////////////////////// |
---|
| 44 | /* The size() function returns the size of the tab */ |
---|
| 45 | ///////////////////////////////////////////////////////////////////// |
---|
| 46 | const size_t size(){ |
---|
| 47 | return size_tab; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | ///////////////////////////////////////////////////////////////////// |
---|
| 52 | /* The init() function initializes the transaction tab entries */ |
---|
| 53 | ///////////////////////////////////////////////////////////////////// |
---|
| 54 | void init(){ |
---|
| 55 | for ( size_t i=0; i<size_tab; i++) { |
---|
| 56 | addr_tab[i]=0; |
---|
| 57 | valid_tab[i]=false; |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | ///////////////////////////////////////////////////////////////////// |
---|
| 63 | /* The set() function sets an entry |
---|
| 64 | Arguments : |
---|
| 65 | - id : the id of the initiator (index of the entry) |
---|
| 66 | - addr : the address of the lock |
---|
| 67 | */ |
---|
| 68 | ///////////////////////////////////////////////////////////////////// |
---|
| 69 | void set(const size_t id, const addr_t addr){ |
---|
| 70 | assert( (id<size_tab) && "Atomic Tab Error : bad entry"); |
---|
| 71 | addr_tab[id]=addr; |
---|
| 72 | valid_tab[id]=true; |
---|
| 73 | return; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | ///////////////////////////////////////////////////////////////////// |
---|
| 78 | /* The isatomic() function tests if the SC request corresponds to an entry |
---|
| 79 | Arguments : |
---|
| 80 | - id : the id of the initiator (index of the entry) |
---|
| 81 | - addr : the address of the lock |
---|
| 82 | |
---|
| 83 | This function return true if the request corresponds |
---|
| 84 | */ |
---|
| 85 | ///////////////////////////////////////////////////////////////////// |
---|
| 86 | bool isatomic(const size_t id, const addr_t addr){ |
---|
| 87 | assert( (id<size_tab) && "Atomic Tab Error : bad entry"); |
---|
| 88 | bool test=valid_tab[id]; |
---|
| 89 | test=test && (addr == addr_tab[id]); |
---|
| 90 | return test; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | ///////////////////////////////////////////////////////////////////// |
---|
| 95 | /* The reset() function resets all the entries for this lock |
---|
| 96 | Arguments : |
---|
| 97 | - addr : the address of the lock |
---|
| 98 | */ |
---|
| 99 | ///////////////////////////////////////////////////////////////////// |
---|
| 100 | void reset(const addr_t addr){ |
---|
| 101 | for(size_t i=0 ; i<size_tab ; i++){ |
---|
| 102 | if(addr == addr_tab[i]){ |
---|
| 103 | valid_tab[i]=false; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | return; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | }; |
---|
| 110 | |
---|
| 111 | #endif |
---|
| 112 | |
---|
| 113 | // Local Variables: |
---|
| 114 | // tab-width: 4 |
---|
| 115 | // c-basic-offset: 4 |
---|
| 116 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 117 | // indent-tabs-mode: nil |
---|
| 118 | // End: |
---|
| 119 | |
---|
| 120 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 121 | |
---|