1 /**
2  * @file These are the implementations of the user interfaces declared
3  *       in hei_user_interface.hpp
4  */
5 
6 #include <assert.h>
7 #include <inttypes.h>
8 #include <libpdbg.h>
9 #include <stdarg.h>
10 #include <stdio.h>
11 
12 #include <hei_user_interface.hpp>
13 #include <util/trace.hpp>
14 
15 namespace libhei
16 {
17 
18 //------------------------------------------------------------------------------
19 
20 bool registerRead(const Chip& i_chip, RegisterType_t i_regType,
21                   uint64_t i_address, uint64_t& o_value)
22 {
23     bool accessFailure = false;
24 
25     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;
33 
34         default:
35             assert(0); // an unsupported register type
36     }
37 
38     if (accessFailure)
39     {
40         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);
43         o_value = 0; // just in case
44     }
45 
46     return accessFailure;
47 }
48 
49 //------------------------------------------------------------------------------
50 
51 // prints a single line to stdout
52 void hei_inf(char* format, ...)
53 {
54     va_list args;
55     va_start(args, format);
56     trace::inf(format, args);
57     va_end(args);
58 }
59 
60 //------------------------------------------------------------------------------
61 
62 // prints a single line to stderr
63 void hei_err(char* format, ...)
64 {
65     va_list args;
66     va_start(args, format);
67     trace::err(format, args);
68     va_end(args);
69 }
70 
71 } // namespace libhei
72