blob: a0b3ba6930062d555b7693a2536949d892a2f8f8 [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
Zane Shelley2f263182020-07-10 21:41:21 -050025 auto trgt = (pdbg_target*)(i_chip.getChip());
26
Ben Tyner0523f8a2020-05-14 16:01:53 -050027 switch (i_regType)
28 {
29 case REG_TYPE_SCOM:
30 case REG_TYPE_ID_SCOM:
31 // Read the 64-bit SCOM register.
Zane Shelley2f263182020-07-10 21:41:21 -050032 accessFailure = (0 != pib_read(trgt, i_address, &o_value));
Ben Tyner0523f8a2020-05-14 16:01:53 -050033 break;
Ben Tynerb859d792020-05-06 21:29:47 -050034
Ben Tyner0523f8a2020-05-14 16:01:53 -050035 default:
36 assert(0); // an unsupported register type
37 }
38
39 if (accessFailure)
40 {
Zane Shelley2f263182020-07-10 21:41:21 -050041 trace::err("Register read failed: chip=%s type=0x%0" PRIx8
42 "addr=0x%0" PRIx64,
43 pdbg_target_path(trgt), i_regType, i_address);
Ben Tyner0523f8a2020-05-14 16:01:53 -050044 o_value = 0; // just in case
45 }
Ben Tyner92e39fd2020-02-05 18:11:02 -060046
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050047 return accessFailure;
Ben Tyner92e39fd2020-02-05 18:11:02 -060048}
49
50//------------------------------------------------------------------------------
51
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050052// prints a single line to stdout
53void hei_inf(char* format, ...)
54{
55 va_list args;
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050056 va_start(args, format);
Zane Shelley0c44c2f2020-06-05 17:14:31 -050057 trace::inf(format, args);
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050058 va_end(args);
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050059}
60
61//------------------------------------------------------------------------------
62
63// prints a single line to stderr
64void hei_err(char* format, ...)
65{
66 va_list args;
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050067 va_start(args, format);
Zane Shelley0c44c2f2020-06-05 17:14:31 -050068 trace::err(format, args);
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050069 va_end(args);
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050070}
71
Ben Tyner92e39fd2020-02-05 18:11:02 -060072} // namespace libhei