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