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> |
| 13 | |
| 14 | namespace libhei |
| 15 | { |
| 16 | |
| 17 | //------------------------------------------------------------------------------ |
| 18 | |
Ben Tyner | 0523f8a | 2020-05-14 16:01:53 -0500 | [diff] [blame] | 19 | bool registerRead(const Chip& i_chip, RegisterType_t i_regType, |
| 20 | uint64_t i_address, uint64_t& o_value) |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 21 | { |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 22 | bool accessFailure = false; |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 23 | |
Ben Tyner | 0523f8a | 2020-05-14 16:01:53 -0500 | [diff] [blame] | 24 | 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 Tyner | b859d79 | 2020-05-06 21:29:47 -0500 | [diff] [blame] | 32 | |
Ben Tyner | 0523f8a | 2020-05-14 16:01:53 -0500 | [diff] [blame] | 33 | 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 Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 44 | |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 45 | return accessFailure; |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | //------------------------------------------------------------------------------ |
| 49 | |
Zane Shelley | b78dd0c | 2020-05-08 14:35:15 -0500 | [diff] [blame] | 50 | // prints a single line to stdout |
| 51 | void 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 |
| 64 | void 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 Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 74 | } // namespace libhei |