blob: 370b92f61b2acc51163a840e1df2d125c22d7168 [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>
Zane Shelleyd5073512021-01-14 12:51:18 -060011#include <util/hei_includes.hpp>
Zane Shelley11b89942019-11-07 11:07:28 -060012
13namespace libhei
14{
15
16//------------------------------------------------------------------------------
17
Zane Shelley2d4981a2020-06-04 14:32:45 -050018bool registerRead(const Chip& i_chip, RegisterType_t i_regType,
19 uint64_t i_address, uint64_t& o_value)
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
Zane Shelley2d4981a2020-06-04 14:32:45 -050023 // Get access to data through the singleton.
Paul Greenwoodc0919342019-12-10 15:36:17 -060024 SimulatorData& theSimData = SimulatorData::getSingleton();
25
Zane Shelley11b89942019-11-07 11:07:28 -060026 switch (i_regType)
27 {
Zane Shelley11b89942019-11-07 11:07:28 -060028 case REG_TYPE_SCOM:
Zane Shelley2d4981a2020-06-04 14:32:45 -050029 o_value = theSimData.getScomReg(i_chip, (uint32_t)i_address);
Zane Shelley11b89942019-11-07 11:07:28 -060030 break;
Zane Shelley11b89942019-11-07 11:07:28 -060031 case REG_TYPE_ID_SCOM:
Zane Shelley2d4981a2020-06-04 14:32:45 -050032 o_value = theSimData.getIdScomReg(i_chip, i_address);
Zane Shelley11b89942019-11-07 11:07:28 -060033 break;
Zane Shelley11b89942019-11-07 11:07:28 -060034 default:
Zane Shelley2f4aa912020-05-08 14:28:18 -050035 accessFailure = true;
Zane Shelley2d4981a2020-06-04 14:32:45 -050036 HEI_ERR("registerRead(%p,%" PRIu8 ",%" PRIx64 ")", i_chip.getChip(),
37 i_regType, i_address);
Zane Shelley11b89942019-11-07 11:07:28 -060038 }
39
Zane Shelley2f4aa912020-05-08 14:28:18 -050040 return accessFailure;
Zane Shelley11b89942019-11-07 11:07:28 -060041}
42
43//------------------------------------------------------------------------------
44
Ben Tyner7b3420b2020-05-11 10:52:07 -050045#ifdef __HEI_ENABLE_HW_WRITE
Zane Shelley11b89942019-11-07 11:07:28 -060046
Zane Shelley2d4981a2020-06-04 14:32:45 -050047bool registerWrite(const Chip& i_chip, RegisterType_t i_regType,
48 uint64_t i_address, uint64_t i_value)
Zane Shelley11b89942019-11-07 11:07:28 -060049{
Zane Shelley2f4aa912020-05-08 14:28:18 -050050 bool accessFailure = false;
Zane Shelley11b89942019-11-07 11:07:28 -060051
Zane Shelley11b89942019-11-07 11:07:28 -060052 switch (i_regType)
53 {
54 // TODO: add cases for REG_TYPE_SCOM and REG_TYPE_ID_SCOM
55 default:
Zane Shelley2f4aa912020-05-08 14:28:18 -050056 accessFailure = true;
Zane Shelley2d4981a2020-06-04 14:32:45 -050057 HEI_ERR("registerWrite(%p,%" PRIu8 ",%" PRIx64 ",%" PRIx64 ")",
58 i_chip.getChip(), i_regType, i_address, i_value);
Zane Shelley11b89942019-11-07 11:07:28 -060059 }
60
Zane Shelley2f4aa912020-05-08 14:28:18 -050061 return accessFailure;
Zane Shelley11b89942019-11-07 11:07:28 -060062}
63
Ben Tyner7b3420b2020-05-11 10:52:07 -050064#endif // __HEI_ENABLE_HW_WRITE
Zane Shelley11b89942019-11-07 11:07:28 -060065
66//------------------------------------------------------------------------------
67
68} // namespace libhei