Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 1 | /** |
| 2 | * @file These are the simulated implementations of the user interfaces declared |
| 3 | * in hei_user_interface.hpp |
| 4 | */ |
| 5 | |
| 6 | #include "simulator.hpp" |
| 7 | |
| 8 | #include <endian.h> |
| 9 | |
| 10 | #include <hei_user_interface.hpp> |
| 11 | |
| 12 | namespace libhei |
| 13 | { |
| 14 | |
| 15 | //------------------------------------------------------------------------------ |
| 16 | |
| 17 | ReturnCode registerRead(const Chip& i_chip, void* o_buffer, size_t& io_bufSize, |
| 18 | uint64_t i_regType, uint64_t i_address) |
| 19 | { |
| 20 | ReturnCode rc{}; |
| 21 | |
| 22 | HEI_ASSERT(nullptr != o_buffer); |
| 23 | HEI_ASSERT(0 != io_bufSize); |
| 24 | |
Paul Greenwood | c091934 | 2019-12-10 15:36:17 -0600 | [diff] [blame] | 25 | // Get access to data through the singleton |
| 26 | SimulatorData& theSimData = SimulatorData::getSingleton(); |
| 27 | |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 28 | switch (i_regType) |
| 29 | { |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 30 | case REG_TYPE_SCOM: |
| 31 | { |
Paul Greenwood | c091934 | 2019-12-10 15:36:17 -0600 | [diff] [blame] | 32 | // Get the register value and change its endianness |
| 33 | uint64_t regValue = |
| 34 | htobe64(theSimData.getScomReg(i_chip, (uint32_t)i_address)); |
| 35 | // Get size of register value for calling code and memcopy |
| 36 | io_bufSize = sizeof(regValue); |
| 37 | memcpy(o_buffer, ®Value, io_bufSize); |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 38 | break; |
| 39 | } |
| 40 | case REG_TYPE_ID_SCOM: |
| 41 | { |
Paul Greenwood | c091934 | 2019-12-10 15:36:17 -0600 | [diff] [blame] | 42 | // Get the register value and change its endianness |
| 43 | uint64_t regValue = |
| 44 | htobe64(theSimData.getIdScomReg(i_chip, i_address)); |
| 45 | // Get size of register value for calling code and memcopy |
| 46 | io_bufSize = sizeof(regValue); |
| 47 | memcpy(o_buffer, ®Value, io_bufSize); |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 48 | break; |
| 49 | } |
| 50 | // END temporary code |
| 51 | default: |
| 52 | rc = RC_REG_ACCESS_FAILURE; |
Ben Tyner | 7c79605 | 2020-02-03 19:00:37 -0600 | [diff] [blame] | 53 | HEI_ERR("registerRead(%p,%p,%" PRIu64 ",%" PRIx64 ",%" PRIx64 ")", |
| 54 | i_chip.getChip(), o_buffer, (uint64_t)io_bufSize, i_regType, |
| 55 | i_address); |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | return rc; |
| 59 | } |
| 60 | |
| 61 | //------------------------------------------------------------------------------ |
| 62 | |
| 63 | #ifndef __HEI_READ_ONLY |
| 64 | |
| 65 | ReturnCode registerWrite(const Chip& i_chip, void* i_buffer, size_t& io_bufSize, |
| 66 | uint64_t i_regType, uint64_t i_address) |
| 67 | { |
| 68 | ReturnCode rc{}; |
| 69 | |
| 70 | HEI_ASSERT(nullptr != i_buffer); |
| 71 | HEI_ASSERT(0 != io_bufSize); |
| 72 | |
| 73 | switch (i_regType) |
| 74 | { |
| 75 | // TODO: add cases for REG_TYPE_SCOM and REG_TYPE_ID_SCOM |
| 76 | default: |
| 77 | rc = RC_REG_ACCESS_FAILURE; |
Ben Tyner | 7c79605 | 2020-02-03 19:00:37 -0600 | [diff] [blame] | 78 | HEI_ERR("registerWrite(%p,%p,%" PRIu64 ",%" PRIx64 ",%" PRIx64 ")", |
| 79 | i_chip.getChip(), i_buffer, (uint64_t)io_bufSize, i_regType, |
| 80 | i_address); |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | return rc; |
| 84 | } |
| 85 | |
| 86 | #endif |
| 87 | |
| 88 | //------------------------------------------------------------------------------ |
| 89 | |
| 90 | } // namespace libhei |