blob: 25cc8bdc176a773d364b864a1288f7be6ce73ab4 [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
Zane Shelley01e590b2020-05-08 21:11:46 -050010#include <hei_includes.hpp>
Zane Shelley11b89942019-11-07 11:07:28 -060011#include <hei_user_interface.hpp>
12
13namespace libhei
14{
15
16//------------------------------------------------------------------------------
17
Zane Shelley2f4aa912020-05-08 14:28:18 -050018bool registerRead(const Chip& i_chip, void* o_buffer, size_t& io_bufSize,
19 uint64_t i_regType, uint64_t i_address)
Zane Shelley11b89942019-11-07 11:07:28 -060020{
Zane Shelley2f4aa912020-05-08 14:28:18 -050021 bool accessFailure = false;
Zane Shelley11b89942019-11-07 11:07:28 -060022
23 HEI_ASSERT(nullptr != o_buffer);
24 HEI_ASSERT(0 != io_bufSize);
25
Paul Greenwoodc0919342019-12-10 15:36:17 -060026 // Get access to data through the singleton
27 SimulatorData& theSimData = SimulatorData::getSingleton();
28
Zane Shelley11b89942019-11-07 11:07:28 -060029 switch (i_regType)
30 {
Zane Shelley11b89942019-11-07 11:07:28 -060031 case REG_TYPE_SCOM:
32 {
Paul Greenwoodc0919342019-12-10 15:36:17 -060033 // 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, &regValue, io_bufSize);
Zane Shelley11b89942019-11-07 11:07:28 -060039 break;
40 }
41 case REG_TYPE_ID_SCOM:
42 {
Paul Greenwoodc0919342019-12-10 15:36:17 -060043 // 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, &regValue, io_bufSize);
Zane Shelley11b89942019-11-07 11:07:28 -060049 break;
50 }
Zane Shelley11b89942019-11-07 11:07:28 -060051 default:
Zane Shelley2f4aa912020-05-08 14:28:18 -050052 accessFailure = true;
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
Zane Shelley2f4aa912020-05-08 14:28:18 -050058 return accessFailure;
Zane Shelley11b89942019-11-07 11:07:28 -060059}
60
61//------------------------------------------------------------------------------
62
63#ifndef __HEI_READ_ONLY
64
Zane Shelley2f4aa912020-05-08 14:28:18 -050065bool registerWrite(const Chip& i_chip, void* i_buffer, size_t& io_bufSize,
66 uint64_t i_regType, uint64_t i_address)
Zane Shelley11b89942019-11-07 11:07:28 -060067{
Zane Shelley2f4aa912020-05-08 14:28:18 -050068 bool accessFailure = false;
Zane Shelley11b89942019-11-07 11:07:28 -060069
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 Shelley2f4aa912020-05-08 14:28:18 -050077 accessFailure = true;
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
Zane Shelley2f4aa912020-05-08 14:28:18 -050083 return accessFailure;
Zane Shelley11b89942019-11-07 11:07:28 -060084}
85
86#endif
87
88//------------------------------------------------------------------------------
89
90} // namespace libhei