[878] | 1 | /* -*- c++ -*- |
---|
| 2 | * |
---|
| 3 | * SOCLIB_LGPL_HEADER_BEGIN |
---|
| 4 | * |
---|
| 5 | * This file is part of SoCLib, GNU LGPLv2.1. |
---|
| 6 | * |
---|
| 7 | * SoCLib is free software; you can redistribute it and/or modify it |
---|
| 8 | * under the terms of the GNU Lesser General Public License as published |
---|
| 9 | * by the Free Software Foundation; version 2.1 of the License. |
---|
| 10 | * |
---|
| 11 | * SoCLib is distributed in the hope that it will be useful, but |
---|
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 14 | * Lesser General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU Lesser General Public |
---|
| 17 | * License along with SoCLib; if not, write to the Free Software |
---|
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
| 19 | * 02110-1301 USA |
---|
| 20 | * |
---|
| 21 | * SOCLIB_LGPL_HEADER_END |
---|
| 22 | * |
---|
| 23 | * Copyright (c) UPMC, Lip6, Asim |
---|
| 24 | * Cesar Fuguet <cesar.fuguet-tortolero@lip6.fr>, 2014 |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #include "vci_tsar_config.h" |
---|
| 29 | #include "tsar_config.h" |
---|
| 30 | |
---|
| 31 | namespace soclib { |
---|
| 32 | namespace caba { |
---|
| 33 | |
---|
| 34 | #define tmpl(x) template<typename vci_param> x VciTsarConfig<vci_param> |
---|
| 35 | |
---|
| 36 | ////////////////////////////////////////////////// |
---|
| 37 | tmpl(void)::transition() |
---|
| 38 | { |
---|
| 39 | p_blackhole_pos = r_blackhole_pos.read(); |
---|
| 40 | |
---|
| 41 | if (!p_resetn.read()) |
---|
| 42 | { |
---|
| 43 | r_fsm_state = IDLE; |
---|
| 44 | r_blackhole_pos = 0; |
---|
| 45 | return; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | switch (r_fsm_state.read()) |
---|
| 49 | { |
---|
| 50 | case IDLE: // waiting a VCI command |
---|
| 51 | { |
---|
| 52 | if (!p_vci.cmdval.read()) break; |
---|
| 53 | |
---|
| 54 | vci_addr_t address = p_vci.address.read(); |
---|
| 55 | std::list<soclib::common::Segment>::iterator seg; |
---|
| 56 | bool seg_error = true; |
---|
| 57 | for (seg = m_seglist.begin() ; seg != m_seglist.end() ; seg++) |
---|
| 58 | { |
---|
| 59 | if (seg->contains(address) and p_vci.eop.read()) |
---|
| 60 | { |
---|
| 61 | seg_error = false; |
---|
| 62 | break; |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | r_srcid = p_vci.srcid.read(); |
---|
| 67 | r_trdid = p_vci.trdid.read(); |
---|
| 68 | r_pktid = p_vci.pktid.read(); |
---|
| 69 | |
---|
| 70 | if (seg_error) |
---|
| 71 | { |
---|
| 72 | if (!p_vci.eop.read()) break; |
---|
| 73 | r_fsm_state = RSP_ERROR; |
---|
| 74 | break; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | int reg = (int)((address >> 2) & 0x1) % CONFIG_SPAN; |
---|
| 78 | |
---|
| 79 | if ((p_vci.cmd.read() == vci_param::CMD_WRITE) && |
---|
| 80 | (reg == CONFIG_BHPOS)) |
---|
| 81 | { |
---|
| 82 | r_blackhole_pos = (int)p_vci.wdata.read(); |
---|
| 83 | r_fsm_state = RSP_WRITE; |
---|
| 84 | break; |
---|
| 85 | } |
---|
| 86 | if ((p_vci.cmd.read() == vci_param::CMD_READ) && |
---|
| 87 | (reg == CONFIG_BHPOS)) |
---|
| 88 | { |
---|
| 89 | r_rdata = (vci_data_t)r_blackhole_pos.read(); |
---|
| 90 | r_fsm_state = RSP_READ; |
---|
| 91 | break; |
---|
| 92 | } |
---|
| 93 | if (p_vci.eop.read()) |
---|
| 94 | { |
---|
| 95 | r_fsm_state = RSP_ERROR; |
---|
| 96 | } |
---|
| 97 | break; |
---|
| 98 | } // end case IDLE |
---|
| 99 | case RSP_ERROR: // return an error response |
---|
| 100 | case RSP_READ: // return a valid read response |
---|
| 101 | case RSP_WRITE: // return a valid write response |
---|
| 102 | { |
---|
| 103 | if (p_vci.rspack.read()) |
---|
| 104 | { |
---|
| 105 | r_fsm_state = IDLE; |
---|
| 106 | } |
---|
| 107 | break; |
---|
| 108 | } |
---|
| 109 | } // end switch r_fsm_state |
---|
| 110 | } // end transition |
---|
| 111 | |
---|
| 112 | ////////////////////////////////////////////////// |
---|
| 113 | tmpl(void)::genMoore() |
---|
| 114 | { |
---|
| 115 | p_vci.rsrcid = r_srcid.read(); |
---|
| 116 | p_vci.rtrdid = r_trdid.read(); |
---|
| 117 | p_vci.rpktid = r_pktid.read(); |
---|
| 118 | p_vci.reop = true; |
---|
| 119 | |
---|
| 120 | switch(r_fsm_state.read()) |
---|
| 121 | { |
---|
| 122 | case IDLE: |
---|
| 123 | p_vci.cmdack = true; |
---|
| 124 | p_vci.rspval = false; |
---|
| 125 | p_vci.rdata = 0; |
---|
| 126 | p_vci.rerror = vci_param::ERR_NORMAL; |
---|
| 127 | break; |
---|
| 128 | |
---|
| 129 | case RSP_WRITE: |
---|
| 130 | p_vci.cmdack = false; |
---|
| 131 | p_vci.rspval = true; |
---|
| 132 | p_vci.rdata = 0; |
---|
| 133 | p_vci.rerror = vci_param::ERR_NORMAL; |
---|
| 134 | break; |
---|
| 135 | |
---|
| 136 | case RSP_READ: |
---|
| 137 | p_vci.cmdack = false; |
---|
| 138 | p_vci.rspval = true; |
---|
| 139 | p_vci.rdata = r_rdata.read(); |
---|
| 140 | p_vci.rerror = vci_param::ERR_NORMAL; |
---|
| 141 | break; |
---|
| 142 | |
---|
| 143 | case RSP_ERROR: |
---|
| 144 | p_vci.cmdack = false; |
---|
| 145 | p_vci.rspval = true; |
---|
| 146 | p_vci.rdata = 0; |
---|
| 147 | p_vci.rerror = vci_param::ERR_GENERAL_DATA_ERROR; |
---|
| 148 | break; |
---|
| 149 | } |
---|
| 150 | } // end genMoore() |
---|
| 151 | |
---|
| 152 | ////////////////////////////////////////////////// |
---|
| 153 | tmpl(/**/)::VciTsarConfig(sc_module_name name, |
---|
| 154 | const IntTab &index, |
---|
| 155 | const MappingTable &mt) |
---|
| 156 | : soclib::caba::BaseModule(name), |
---|
| 157 | p_clk("clk"), |
---|
| 158 | p_resetn("resetn"), |
---|
| 159 | p_vci("vci"), |
---|
| 160 | m_seglist(mt.getSegmentList(index)) |
---|
| 161 | { |
---|
| 162 | SC_METHOD(transition); |
---|
| 163 | dont_initialize(); |
---|
| 164 | sensitive << p_clk.pos(); |
---|
| 165 | |
---|
| 166 | SC_METHOD(genMoore); |
---|
| 167 | dont_initialize(); |
---|
| 168 | sensitive << p_clk.neg(); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | ////////////////////////////////////////////////// |
---|
| 172 | tmpl(/**/)::~VciTsarConfig() |
---|
| 173 | { |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | ////////////////////////////////////////////////// |
---|
| 177 | tmpl(void)::print_trace() |
---|
| 178 | { |
---|
| 179 | const char* state_str[] = {"IDLE", |
---|
| 180 | "RSP_WRITE", |
---|
| 181 | "RSP_READ", |
---|
| 182 | "RSP_ERROR"}; |
---|
| 183 | |
---|
| 184 | std::cout << "VCI_TSAR_CONFIG " << name() |
---|
| 185 | << " : state = " << state_str[r_fsm_state.read()] << std::endl; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | }} |
---|
| 189 | |
---|
| 190 | // Local Variables: |
---|
| 191 | // tab-width: 4 |
---|
| 192 | // c-basic-offset: 4 |
---|
| 193 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 194 | // indent-tabs-mode: nil |
---|
| 195 | // End: |
---|
| 196 | |
---|
| 197 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 198 | |
---|