blob: 2bcc2af31456de9eecd47162bdbc3a1196b37806 [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;
53 HEI_ERR("registerRead(%p,%p,%lx,%lx,%lx)", i_chip.getChip(),
54 o_buffer, io_bufSize, i_regType, i_address);
55 }
56
57 return rc;
58}
59
60//------------------------------------------------------------------------------
61
62#ifndef __HEI_READ_ONLY
63
64ReturnCode registerWrite(const Chip& i_chip, void* i_buffer, size_t& io_bufSize,
65 uint64_t i_regType, uint64_t i_address)
66{
67 ReturnCode rc{};
68
69 HEI_ASSERT(nullptr != i_buffer);
70 HEI_ASSERT(0 != io_bufSize);
71
72 switch (i_regType)
73 {
74 // TODO: add cases for REG_TYPE_SCOM and REG_TYPE_ID_SCOM
75 default:
76 rc = RC_REG_ACCESS_FAILURE;
77 HEI_ERR("registerWrite(%p,%p,%lx,%lx,%lx)", i_chip.getChip(),
78 i_buffer, io_bufSize, i_regType, i_address);
79 }
80
81 return rc;
82}
83
84#endif
85
86//------------------------------------------------------------------------------
87
88} // namespace libhei