blob: 86137f7679fda3375d114eedda1de914b9e02305 [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>
13
14namespace libhei
15{
16
17//------------------------------------------------------------------------------
18
Ben Tyner0523f8a2020-05-14 16:01:53 -050019bool registerRead(const Chip& i_chip, RegisterType_t i_regType,
20 uint64_t i_address, uint64_t& o_value)
Ben Tyner92e39fd2020-02-05 18:11:02 -060021{
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050022 bool accessFailure = false;
Ben Tyner92e39fd2020-02-05 18:11:02 -060023
Ben Tyner0523f8a2020-05-14 16:01:53 -050024 switch (i_regType)
25 {
26 case REG_TYPE_SCOM:
27 case REG_TYPE_ID_SCOM:
28 // Read the 64-bit SCOM register.
29 accessFailure = (0 != pib_read((pdbg_target*)i_chip.getChip(),
30 i_address, &o_value));
31 break;
Ben Tynerb859d792020-05-06 21:29:47 -050032
Ben Tyner0523f8a2020-05-14 16:01:53 -050033 default:
34 assert(0); // an unsupported register type
35 }
36
37 if (accessFailure)
38 {
39 printf("Register read failed: chip=%p type=0x%0" PRIx8
40 "addr=0x%0" PRIx64 "\n",
41 i_chip.getChip(), i_regType, i_address);
42 o_value = 0; // just in case
43 }
Ben Tyner92e39fd2020-02-05 18:11:02 -060044
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050045 return accessFailure;
Ben Tyner92e39fd2020-02-05 18:11:02 -060046}
47
48//------------------------------------------------------------------------------
49
Zane Shelleyb78dd0c2020-05-08 14:35:15 -050050// prints a single line to stdout
51void hei_inf(char* format, ...)
52{
53 va_list args;
54 fprintf(stdout, "I> ");
55 va_start(args, format);
56 vfprintf(stdout, format, args);
57 va_end(args);
58 fprintf(stdout, "\n");
59}
60
61//------------------------------------------------------------------------------
62
63// prints a single line to stderr
64void hei_err(char* format, ...)
65{
66 va_list args;
67 fprintf(stderr, "E> ");
68 va_start(args, format);
69 vfprintf(stderr, format, args);
70 va_end(args);
71 fprintf(stderr, "\n");
72}
73
Ben Tyner92e39fd2020-02-05 18:11:02 -060074} // namespace libhei