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 | |
Zane Shelley | 01e590b | 2020-05-08 21:11:46 -0500 | [diff] [blame^] | 10 | #include <hei_includes.hpp> |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 11 | #include <hei_user_interface.hpp> |
| 12 | |
| 13 | namespace libhei |
| 14 | { |
| 15 | |
| 16 | //------------------------------------------------------------------------------ |
| 17 | |
Zane Shelley | 2f4aa91 | 2020-05-08 14:28:18 -0500 | [diff] [blame] | 18 | bool registerRead(const Chip& i_chip, void* o_buffer, size_t& io_bufSize, |
| 19 | uint64_t i_regType, uint64_t i_address) |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 20 | { |
Zane Shelley | 2f4aa91 | 2020-05-08 14:28:18 -0500 | [diff] [blame] | 21 | bool accessFailure = false; |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 22 | |
| 23 | HEI_ASSERT(nullptr != o_buffer); |
| 24 | HEI_ASSERT(0 != io_bufSize); |
| 25 | |
Paul Greenwood | c091934 | 2019-12-10 15:36:17 -0600 | [diff] [blame] | 26 | // Get access to data through the singleton |
| 27 | SimulatorData& theSimData = SimulatorData::getSingleton(); |
| 28 | |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 29 | switch (i_regType) |
| 30 | { |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 31 | case REG_TYPE_SCOM: |
| 32 | { |
Paul Greenwood | c091934 | 2019-12-10 15:36:17 -0600 | [diff] [blame] | 33 | // Get the register value and change its endianness |
| 34 | uint64_t regValue = |
| 35 | htobe64(theSimData.getScomReg(i_chip, (uint32_t)i_address)); |
| 36 | // Get size of register value for calling code and memcopy |
| 37 | io_bufSize = sizeof(regValue); |
| 38 | memcpy(o_buffer, ®Value, io_bufSize); |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 39 | break; |
| 40 | } |
| 41 | case REG_TYPE_ID_SCOM: |
| 42 | { |
Paul Greenwood | c091934 | 2019-12-10 15:36:17 -0600 | [diff] [blame] | 43 | // Get the register value and change its endianness |
| 44 | uint64_t regValue = |
| 45 | htobe64(theSimData.getIdScomReg(i_chip, i_address)); |
| 46 | // Get size of register value for calling code and memcopy |
| 47 | io_bufSize = sizeof(regValue); |
| 48 | memcpy(o_buffer, ®Value, io_bufSize); |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 49 | break; |
| 50 | } |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 51 | default: |
Zane Shelley | 2f4aa91 | 2020-05-08 14:28:18 -0500 | [diff] [blame] | 52 | accessFailure = true; |
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 | |
Zane Shelley | 2f4aa91 | 2020-05-08 14:28:18 -0500 | [diff] [blame] | 58 | return accessFailure; |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | //------------------------------------------------------------------------------ |
| 62 | |
| 63 | #ifndef __HEI_READ_ONLY |
| 64 | |
Zane Shelley | 2f4aa91 | 2020-05-08 14:28:18 -0500 | [diff] [blame] | 65 | bool registerWrite(const Chip& i_chip, void* i_buffer, size_t& io_bufSize, |
| 66 | uint64_t i_regType, uint64_t i_address) |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 67 | { |
Zane Shelley | 2f4aa91 | 2020-05-08 14:28:18 -0500 | [diff] [blame] | 68 | bool accessFailure = false; |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 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: |
Zane Shelley | 2f4aa91 | 2020-05-08 14:28:18 -0500 | [diff] [blame] | 77 | accessFailure = true; |
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 | |
Zane Shelley | 2f4aa91 | 2020-05-08 14:28:18 -0500 | [diff] [blame] | 83 | return accessFailure; |
Zane Shelley | 11b8994 | 2019-11-07 11:07:28 -0600 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | #endif |
| 87 | |
| 88 | //------------------------------------------------------------------------------ |
| 89 | |
| 90 | } // namespace libhei |