tl_uh_bfm.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*******************************************************************************
  2. * Copyright (C) 2018 MINRES Technologies GmbH
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * 3. Neither the name of the copyright holder nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. *******************************************************************************/
  32. #include "sysc/rtl/tl_uh_bfm.h"
  33. #include <scc/report.h>
  34. #include <scc/utilities.h>
  35. namespace sysc {
  36. using namespace sc_core;
  37. tl_uh_bfm::tl_uh_bfm(sc_module_name nm, int64_t offset)
  38. : sc_module(nm)
  39. , offset(offset)
  40. , NAMED(socket)
  41. , NAMED(clock)
  42. , NAMED(reset)
  43. , NAMED(a_bits_address)
  44. , NAMED(a_bits_data)
  45. , NAMED(a_ready)
  46. , NAMED(a_valid)
  47. , NAMED(a_bits_opcode)
  48. , NAMED(a_bits_param)
  49. , NAMED(a_bits_size)
  50. , NAMED(a_bits_source)
  51. , NAMED(a_bits_mask)
  52. , NAMED(a_bits_corrupt)
  53. , NAMED(d_bits_data)
  54. , NAMED(d_ready)
  55. , NAMED(d_valid)
  56. , NAMED(d_bits_opcode)
  57. , NAMED(d_bits_size)
  58. , NAMED(d_bits_source)
  59. , NAMED(fw_queue) {
  60. socket.register_nb_transport_fw(
  61. [this](tlm::tlm_generic_payload &gp, tlm::tlm_phase &phase, sc_core::sc_time &delay) -> tlm::tlm_sync_enum {
  62. if (phase == tlm::BEGIN_REQ && gp.get_command() != tlm::TLM_IGNORE_COMMAND) {
  63. gp.acquire();
  64. fw_queue.notify(gp, delay);
  65. return tlm::TLM_ACCEPTED;
  66. } else if (phase == tlm::END_RESP) {
  67. gp.release();
  68. d_ready = true;
  69. }
  70. });
  71. SC_METHOD(tl_response_method);
  72. sensitive << clock.pos();
  73. SC_THREAD(fw_thread);
  74. }
  75. tl_uh_bfm::~tl_uh_bfm() = default;
  76. void tl_uh_bfm::fw_thread() {
  77. d_ready = true;
  78. while (true) {
  79. a_valid = false;
  80. wait(fw_queue.get_event());
  81. auto gp = fw_queue.get_next_transaction();
  82. if (gp->get_data_length() == 4) {
  83. auto addr = gp->get_address() + offset;
  84. a_bits_address = addr;
  85. a_valid = true;
  86. a_bits_param = 0;
  87. a_bits_size = 2; // 2^2 bytes
  88. a_bits_source = 0x55;
  89. a_bits_mask = 0xf;
  90. a_bits_corrupt = false;
  91. if (gp->get_command() == tlm::TLM_WRITE_COMMAND) {
  92. a_bits_opcode = PutFullData;
  93. a_bits_data = *(uint32_t *)gp->get_data_ptr();
  94. } else {
  95. a_bits_opcode = Get;
  96. a_bits_data = 0;
  97. }
  98. tl_in_progress.push_back(gp);
  99. do {
  100. wait(clock.posedge_event());
  101. } while (a_ready == false);
  102. } else
  103. SCERR("tlbfm") << "Got transaction with unequal length";
  104. }
  105. }
  106. void tl_uh_bfm::tl_response_method() {
  107. if (d_valid && d_ready) {
  108. // if(d_bits_source==0x55){ // this is ours
  109. auto gp = tl_in_progress.front();
  110. sc_assert(gp && "Got TL response without a request in queue");
  111. tl_in_progress.pop_front();
  112. if (gp->get_command() == tlm::TLM_WRITE_COMMAND) {
  113. sc_assert(d_bits_opcode == AccessAck &&
  114. "TL did not respond with AccessAck to write request");
  115. } else {
  116. sc_assert(d_bits_opcode == AccessAckData &&
  117. "TL did not respond with AccessAckData to read request");
  118. *(uint32_t *)(gp->get_data_ptr()) = d_bits_data;
  119. }
  120. gp->set_response_status(tlm::TLM_OK_RESPONSE);
  121. sc_core::sc_time delay;
  122. tlm::tlm_phase phase{tlm::BEGIN_RESP};
  123. auto ret = socket->nb_transport_bw(*gp, phase, delay);
  124. if (ret == tlm::TLM_COMPLETED || (ret == tlm::TLM_UPDATED && phase == tlm::END_RESP)) {
  125. d_ready = true;
  126. gp->release();
  127. } else
  128. d_ready = false;
  129. // }
  130. }
  131. }
  132. } /* namespace sysc */