111818SChristian.Menard@tu-dresden.de/*
211818SChristian.Menard@tu-dresden.de * Copyright (c) 2015, University of Kaiserslautern
311818SChristian.Menard@tu-dresden.de * All rights reserved.
411818SChristian.Menard@tu-dresden.de *
511818SChristian.Menard@tu-dresden.de * Redistribution and use in source and binary forms, with or without
611818SChristian.Menard@tu-dresden.de * modification, are permitted provided that the following conditions are
711818SChristian.Menard@tu-dresden.de * met:
811818SChristian.Menard@tu-dresden.de *
911818SChristian.Menard@tu-dresden.de * 1. Redistributions of source code must retain the above copyright notice,
1011818SChristian.Menard@tu-dresden.de *    this list of conditions and the following disclaimer.
1111818SChristian.Menard@tu-dresden.de *
1211818SChristian.Menard@tu-dresden.de * 2. Redistributions in binary form must reproduce the above copyright
1311818SChristian.Menard@tu-dresden.de *    notice, this list of conditions and the following disclaimer in the
1411818SChristian.Menard@tu-dresden.de *    documentation and/or other materials provided with the distribution.
1511818SChristian.Menard@tu-dresden.de *
1611818SChristian.Menard@tu-dresden.de * 3. Neither the name of the copyright holder nor the names of its
1711818SChristian.Menard@tu-dresden.de *    contributors may be used to endorse or promote products derived from
1811818SChristian.Menard@tu-dresden.de *    this software without specific prior written permission.
1911818SChristian.Menard@tu-dresden.de *
2011818SChristian.Menard@tu-dresden.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2111818SChristian.Menard@tu-dresden.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2211818SChristian.Menard@tu-dresden.de * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2311818SChristian.Menard@tu-dresden.de * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
2411818SChristian.Menard@tu-dresden.de * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2511818SChristian.Menard@tu-dresden.de * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2611818SChristian.Menard@tu-dresden.de * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2711818SChristian.Menard@tu-dresden.de * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2811818SChristian.Menard@tu-dresden.de * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2911818SChristian.Menard@tu-dresden.de * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3011818SChristian.Menard@tu-dresden.de * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3111818SChristian.Menard@tu-dresden.de *
3211818SChristian.Menard@tu-dresden.de * Authors: Matthias Jung
3311818SChristian.Menard@tu-dresden.de */
3411818SChristian.Menard@tu-dresden.de
3511818SChristian.Menard@tu-dresden.de#ifndef __SIM_SC_TARGET_HH__
3611818SChristian.Menard@tu-dresden.de#define __SIM_SC_TARGET_HH__
3711818SChristian.Menard@tu-dresden.de
3811818SChristian.Menard@tu-dresden.de#include <tlm_utils/peq_with_cb_and_phase.h>
3911818SChristian.Menard@tu-dresden.de#include <tlm_utils/simple_target_socket.h>
4011818SChristian.Menard@tu-dresden.de
4111818SChristian.Menard@tu-dresden.de#include <iostream>
4211818SChristian.Menard@tu-dresden.de#include <systemc>
4311818SChristian.Menard@tu-dresden.de#include <tlm>
4411818SChristian.Menard@tu-dresden.de
4511818SChristian.Menard@tu-dresden.deusing namespace sc_core;
4611818SChristian.Menard@tu-dresden.deusing namespace std;
4711818SChristian.Menard@tu-dresden.de
4811818SChristian.Menard@tu-dresden.destruct Target: sc_module
4911818SChristian.Menard@tu-dresden.de{
5011818SChristian.Menard@tu-dresden.de    /** TLM interface socket: */
5111818SChristian.Menard@tu-dresden.de    tlm_utils::simple_target_socket<Target> socket;
5211818SChristian.Menard@tu-dresden.de
5311818SChristian.Menard@tu-dresden.de    /** TLM related member variables: */
5411818SChristian.Menard@tu-dresden.de    tlm::tlm_generic_payload*  transaction_in_progress;
5511818SChristian.Menard@tu-dresden.de    sc_event                   target_done_event;
5611818SChristian.Menard@tu-dresden.de    bool                       response_in_progress;
5711818SChristian.Menard@tu-dresden.de    bool                       debug;
5811818SChristian.Menard@tu-dresden.de    tlm::tlm_generic_payload*  next_response_pending;
5911818SChristian.Menard@tu-dresden.de    tlm::tlm_generic_payload*  end_req_pending;
6011818SChristian.Menard@tu-dresden.de    tlm_utils::peq_with_cb_and_phase<Target> m_peq;
6111818SChristian.Menard@tu-dresden.de
6211818SChristian.Menard@tu-dresden.de    /** Storage, may be implemented with a map for large devices */
6311818SChristian.Menard@tu-dresden.de    unsigned char *mem;
6411818SChristian.Menard@tu-dresden.de
6511818SChristian.Menard@tu-dresden.de    Target(sc_core::sc_module_name name,
6611818SChristian.Menard@tu-dresden.de        bool debug,
6711818SChristian.Menard@tu-dresden.de        unsigned long long int size,
6811818SChristian.Menard@tu-dresden.de        unsigned int offset);
6911818SChristian.Menard@tu-dresden.de    SC_HAS_PROCESS(Target);
7011818SChristian.Menard@tu-dresden.de
7111818SChristian.Menard@tu-dresden.de    /** TLM interface functions */
7211818SChristian.Menard@tu-dresden.de    virtual void b_transport(tlm::tlm_generic_payload& trans,
7311818SChristian.Menard@tu-dresden.de                             sc_time& delay);
7411818SChristian.Menard@tu-dresden.de    virtual unsigned int transport_dbg(tlm::tlm_generic_payload& trans);
7511818SChristian.Menard@tu-dresden.de    virtual tlm::tlm_sync_enum nb_transport_fw(
7611818SChristian.Menard@tu-dresden.de                tlm::tlm_generic_payload& trans,
7711818SChristian.Menard@tu-dresden.de                tlm::tlm_phase& phase,
7811818SChristian.Menard@tu-dresden.de                sc_time& delay);
7911818SChristian.Menard@tu-dresden.de
8011818SChristian.Menard@tu-dresden.de    /** Callback of Payload Event Queue: */
8111818SChristian.Menard@tu-dresden.de    void peq_cb(tlm::tlm_generic_payload& trans,
8211818SChristian.Menard@tu-dresden.de                const tlm::tlm_phase& phase);
8311818SChristian.Menard@tu-dresden.de
8411818SChristian.Menard@tu-dresden.de    /** Helping function common to b_transport and nb_transport */
8511818SChristian.Menard@tu-dresden.de    void execute_transaction(tlm::tlm_generic_payload& trans);
8611818SChristian.Menard@tu-dresden.de
8711818SChristian.Menard@tu-dresden.de    /** Helping functions and processes: */
8811818SChristian.Menard@tu-dresden.de    void send_end_req(tlm::tlm_generic_payload& trans);
8911818SChristian.Menard@tu-dresden.de    void send_response(tlm::tlm_generic_payload& trans);
9011818SChristian.Menard@tu-dresden.de
9111818SChristian.Menard@tu-dresden.de    /** Method process that runs on target_done_event */
9211818SChristian.Menard@tu-dresden.de    void execute_transaction_process();
9311818SChristian.Menard@tu-dresden.de
9412048Schristian.menard@tu-dresden.de    /** Helping function that checks if a requested address is with range */
9512048Schristian.menard@tu-dresden.de    void check_address(unsigned long long int addr);
9612048Schristian.menard@tu-dresden.de
9711818SChristian.Menard@tu-dresden.de    /** Helping Variables **/
9811818SChristian.Menard@tu-dresden.de    unsigned long long int size;
9911818SChristian.Menard@tu-dresden.de    unsigned offset;
10011818SChristian.Menard@tu-dresden.de};
10111818SChristian.Menard@tu-dresden.de
10211818SChristian.Menard@tu-dresden.de#endif //__SIM_SC_TARGET_HH__
10311818SChristian.Menard@tu-dresden.de
104