A SystemC productivity library for virtual platform development utilizing SCV and TLM2.0 https://www.minres.com/#opensource

resource_access_if.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*******************************************************************************
  2. * Copyright 2016, 2018 MINRES Technologies GmbH
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *******************************************************************************/
  16. #ifndef _SYSC_RESOURCE_ACCESS_IF_H_
  17. #define _SYSC_RESOURCE_ACCESS_IF_H_
  18. #include <cstddef>
  19. #include <cstdint>
  20. #include <sysc/kernel/sc_time.h>
  21. namespace scc {
  22. /**
  23. * interface defining access to a resource
  24. */
  25. class resource_access_if {
  26. public:
  27. /**
  28. * the destructor
  29. */
  30. virtual ~resource_access_if() = default;
  31. /**
  32. * return the size of the resource
  33. *
  34. * @return the size
  35. */
  36. virtual std::size_t size() const = 0;
  37. /**
  38. * reset the resource
  39. */
  40. virtual void reset() = 0;
  41. // functional accesses
  42. /**
  43. * write to the resource
  44. *
  45. * @param data data to write
  46. * @param length length of data to write
  47. * @param offset offset of the data to write
  48. * @param d the annotated delay
  49. * @return true it the access is successful
  50. */
  51. virtual bool write(const uint8_t *data, std::size_t length, uint64_t offset = 0,
  52. sc_core::sc_time d = sc_core::SC_ZERO_TIME) = 0;
  53. /**
  54. * read the data from the resource
  55. *
  56. * @param data buffer to read the data into
  57. * @param length length of data to read
  58. * @param offset offset of the data to read
  59. * @param d the annotated delay
  60. * @return true it the access is successful
  61. */
  62. virtual bool read(uint8_t *data, std::size_t length, uint64_t offset = 0,
  63. sc_core::sc_time d = sc_core::SC_ZERO_TIME) const = 0;
  64. // non-functional/debug accesses
  65. /**
  66. * debug write to the resource
  67. *
  68. * @param data data to write
  69. * @param length length of data to write
  70. * @param offset offset of the data to write
  71. * @return true it the access is successful
  72. */
  73. virtual bool write_dbg(const uint8_t *data, std::size_t length, uint64_t offset = 0) = 0;
  74. /**
  75. * debug read the data from the resource
  76. *
  77. * @param data buffer to read the data into
  78. * @param length length of data to read
  79. * @param offset offset of the data to read
  80. * @return true it the access is successful
  81. */
  82. virtual bool read_dbg(uint8_t *data, std::size_t length, uint64_t offset = 0) const = 0;
  83. };
  84. /**
  85. * interface defining access to an indexed resource
  86. */
  87. class indexed_resource_access_if {
  88. public:
  89. using value_type = resource_access_if;
  90. using pointer = value_type *;
  91. using const_pointer = const value_type *;
  92. using reference = value_type &;
  93. using const_reference = const value_type &;
  94. using iterator = resource_access_if *;
  95. using const_iterator = const resource_access_if *;
  96. /**
  97. * the destructor
  98. */
  99. virtual ~indexed_resource_access_if() = default;
  100. /**
  101. * get the size of the resource
  102. * @return
  103. */
  104. virtual std::size_t size() = 0;
  105. /**
  106. * Element access.
  107. *
  108. * @param idx
  109. * @return the data
  110. */
  111. virtual reference operator[](std::size_t idx) noexcept = 0;
  112. /**
  113. * const element access.
  114. *
  115. * @param idx
  116. * @return the data
  117. */
  118. virtual const_reference operator[](std::size_t idx) const noexcept = 0;
  119. /**
  120. * Element access.
  121. *
  122. * @param idx
  123. * @return the data
  124. */
  125. virtual reference at(std::size_t idx) = 0;
  126. /**
  127. * const element access.
  128. *
  129. * @param idx
  130. * @return the data
  131. */
  132. virtual const_reference at(std::size_t idx) const = 0;
  133. };
  134. }
  135. #endif /* _SYSC_RESOURCE_ACCESS_IF_H_ */