Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | |
| 5 | namespace libhei |
| 6 | { |
| 7 | |
| 8 | class ReturnCode |
| 9 | { |
| 10 | public: |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 11 | /** |
| 12 | * @brief Constructor. |
| 13 | * @param i_rc The error code value. |
| 14 | */ |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 15 | explicit constexpr ReturnCode(uint32_t i_rc = 0) : iv_rc(i_rc) {} |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 16 | |
| 17 | /** @brief Default copy constructor. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 18 | ReturnCode(const ReturnCode&) = default; |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 19 | |
| 20 | /** @brief Default assignment operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 21 | ReturnCode& operator=(const ReturnCode&) = default; |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 22 | |
| 23 | /** @brief Default destructor. */ |
| 24 | ~ReturnCode() = default; |
| 25 | |
Zane Shelley | 83da245 | 2019-10-25 15:45:34 -0500 | [diff] [blame] | 26 | /** @brief Integral type conversion function. */ |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 27 | operator uint32_t() const |
| 28 | { |
| 29 | return iv_rc; |
| 30 | } |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 31 | |
| 32 | /** @brief Integral type conversion function. */ |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 33 | operator uint64_t() const |
| 34 | { |
| 35 | return iv_rc; |
| 36 | } |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 37 | |
| 38 | /** @brief Equals operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 39 | bool operator==(const ReturnCode& rhs) const |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 40 | { |
| 41 | return rhs.iv_rc == iv_rc; |
| 42 | } |
| 43 | |
| 44 | /** @brief Not equals operator. */ |
Zane Shelley | fe27b65 | 2019-10-28 11:33:07 -0500 | [diff] [blame] | 45 | bool operator!=(const ReturnCode& rhs) const |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 46 | { |
| 47 | return rhs.iv_rc != iv_rc; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @brief Returns the error code value. |
| 52 | * |
| 53 | * We'd prefer to use the integral type conversion functions above, but |
| 54 | * some compilers will throw warnings when passing this object into |
| 55 | * functions with variadic arguments, like printf(). |
| 56 | */ |
Zane Shelley | 7f7a42d | 2019-10-28 13:28:31 -0500 | [diff] [blame] | 57 | uint32_t get() const |
| 58 | { |
| 59 | return iv_rc; |
| 60 | } |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 61 | |
| 62 | private: |
Zane Shelley | ca4b2f4 | 2019-08-30 15:48:40 -0500 | [diff] [blame] | 63 | uint32_t iv_rc; ///< return code value |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 64 | }; |
| 65 | |
Zane Shelley | 7c8faa1 | 2019-10-28 22:26:28 -0500 | [diff] [blame] | 66 | // clang-format off |
| 67 | |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 68 | /** Function returned successfully. */ |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 69 | static constexpr ReturnCode RC_SUCCESS = ReturnCode(); |
Zane Shelley | 876bc2a | 2019-07-23 12:55:37 -0500 | [diff] [blame] | 70 | |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 71 | /** The given Chip Data File is malformed or unsupported. */ |
| 72 | static constexpr ReturnCode RC_CHIP_DATA_INVALID = ReturnCode(0x00000001); |
| 73 | |
| 74 | /** The given Chip Data File contains a chip type that has already been |
| 75 | * initialized. */ |
| 76 | static constexpr ReturnCode RC_CHIP_DATA_INITIALIZED = ReturnCode(0x00000002); |
| 77 | |
| 78 | /** The given chip type has not been initialized. */ |
| 79 | static constexpr ReturnCode RC_CHIP_DATA_MISSING = ReturnCode(0x00000003); |
| 80 | |
Zane Shelley | ca4b2f4 | 2019-08-30 15:48:40 -0500 | [diff] [blame] | 81 | /** Generic return code indicating something along the hardware register access |
| 82 | * path failed and the returned data is undefined and should not be used. */ |
| 83 | static constexpr ReturnCode RC_REG_ACCESS_FAILURE = ReturnCode(0x00000004); |
| 84 | |
Zane Shelley | 7c8faa1 | 2019-10-28 22:26:28 -0500 | [diff] [blame] | 85 | // clang-format on |
| 86 | |
Zane Shelley | a61f4c5 | 2019-08-01 13:58:49 -0500 | [diff] [blame] | 87 | } // end namespace libhei |