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