blob: ce6fa87ba35aa64e040cb793a1e3e5b6acade699 [file] [log] [blame]
Ben Tyner92e39fd2020-02-05 18:11:02 -06001/**
Ben Tynerb859d792020-05-06 21:29:47 -05002 * @file These are the implementations of the user interfaces declared
3 * in hei_user_interface.hpp
Ben Tyner92e39fd2020-02-05 18:11:02 -06004 */
5
Ben Tynerb859d792020-05-06 21:29:47 -05006#include <assert.h>
Ben Tyner0523f8a2020-05-14 16:01:53 -05007#include <inttypes.h>
8#include <libpdbg.h>
Zane Shelleyb78dd0c2020-05-08 14:35:15 -05009#include <stdarg.h>
10#include <stdio.h>
11
Ben Tyner92e39fd2020-02-05 18:11:02 -060012#include <hei_user_interface.hpp>
Zane Shelley0c44c2f2020-06-05 17:14:31 -050013#include <util/trace.hpp>
Ben Tyner92e39fd2020-02-05 18:11:02 -060014
15namespace libhei
16{
17
18//------------------------------------------------------------------------------
19
Ben Tyner0523f8a2020-05-14 16:01:53 -050020bool registerRead(const Chip& i_chip, RegisterType_t i_regType,
21 uint64_t i_address, uint64_t& o_value)
Ben Tyner92e39fd2020-02-05 18:11:02 -060022{
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050023 bool accessFailure = false;
Ben Tyner92e39fd2020-02-05 18:11:02 -060024
Ben Tyner0523f8a2020-05-14 16:01:53 -050025 switch (i_regType)
26 {
27 case REG_TYPE_SCOM:
28 case REG_TYPE_ID_SCOM:
29 // Read the 64-bit SCOM register.
30 accessFailure = (0 != pib_read((pdbg_target*)i_chip.getChip(),
31 i_address, &o_value));
32 break;
Ben Tynerb859d792020-05-06 21:29:47 -050033
Ben Tyner0523f8a2020-05-14 16:01:53 -050034 default:
35 assert(0); // an unsupported register type
36 }
37
38 if (accessFailure)
39 {
Zane Shelley0c44c2f2020-06-05 17:14:31 -050040 trace::err("Register read failed: chip=%p type=0x%0" PRIx8
41 "addr=0x%0" PRIx64 "\n",
42 i_chip.getChip(), i_regType, i_address);
Ben Tyner0523f8a2020-05-14 16:01:53 -050043 o_value = 0; // just in case
44 }
Ben Tyner92e39fd2020-02-05 18:11:02 -060045
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050046 return accessFailure;
Ben Tyner92e39fd2020-02-05 18:11:02 -060047}
48
49//------------------------------------------------------------------------------
50
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050051// prints a single line to stdout
52void hei_inf(char* format, ...)
53{
54 va_list args;
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050055 va_start(args, format);
Zane Shelley0c44c2f2020-06-05 17:14:31 -050056 trace::inf(format, args);
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050057 va_end(args);
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050058}
59
60//------------------------------------------------------------------------------
61
62// prints a single line to stderr
63void hei_err(char* format, ...)
64{
65 va_list args;
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050066 va_start(args, format);
Zane Shelley0c44c2f2020-06-05 17:14:31 -050067 trace::err(format, args);
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050068 va_end(args);
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050069}
70
Ben Tyner92e39fd2020-02-05 18:11:02 -060071} // namespace libhei