blob: 0b8b6efa11550b7cfc6c1aa496b23b234bd216bf [file] [log] [blame]
Zane Shelley11b89942019-11-07 11:07:28 -06001/**
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
12namespace libhei
13{
14
15//------------------------------------------------------------------------------
16
17ReturnCode 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 Greenwoodc0919342019-12-10 15:36:17 -060025 // Get access to data through the singleton
26 SimulatorData& theSimData = SimulatorData::getSingleton();
27
Zane Shelley11b89942019-11-07 11:07:28 -060028 switch (i_regType)
29 {
Zane Shelley11b89942019-11-07 11:07:28 -060030 case REG_TYPE_SCOM:
31 {
Paul Greenwoodc0919342019-12-10 15:36:17 -060032 // 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, &regValue, io_bufSize);
Zane Shelley11b89942019-11-07 11:07:28 -060038 break;
39 }
40 case REG_TYPE_ID_SCOM:
41 {
Paul Greenwoodc0919342019-12-10 15:36:17 -060042 // 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, &regValue, io_bufSize);
Zane Shelley11b89942019-11-07 11:07:28 -060048 break;
49 }
50 // END temporary code
51 default:
52 rc = RC_REG_ACCESS_FAILURE;
Ben Tyner7c796052020-02-03 19:00:37 -060053 HEI_ERR("registerRead(%p,%p,%" PRIu64 ",%" PRIx64 ",%" PRIx64 ")",
54 i_chip.getChip(), o_buffer, (uint64_t)io_bufSize, i_regType,
55 i_address);
Zane Shelley11b89942019-11-07 11:07:28 -060056 }
57
58 return rc;
59}
60
61//------------------------------------------------------------------------------
62
63#ifndef __HEI_READ_ONLY
64
65ReturnCode 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 Tyner7c796052020-02-03 19:00:37 -060078 HEI_ERR("registerWrite(%p,%p,%" PRIu64 ",%" PRIx64 ",%" PRIx64 ")",
79 i_chip.getChip(), i_buffer, (uint64_t)io_bufSize, i_regType,
80 i_address);
Zane Shelley11b89942019-11-07 11:07:28 -060081 }
82
83 return rc;
84}
85
86#endif
87
88//------------------------------------------------------------------------------
89
90} // namespace libhei