blob: 4be07136a096cede2c9bdc783c3611892bf731c3 [file] [log] [blame]
Zane Shelley876bc2a2019-07-23 12:55:37 -05001#pragma once
2
3#include <stdint.h>
4
5namespace libhei
6{
7
8class ReturnCode
9{
10 public:
Zane Shelley876bc2a2019-07-23 12:55:37 -050011 /**
12 * @brief Constructor.
13 * @param i_rc The error code value.
14 */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050015 explicit constexpr ReturnCode(uint32_t i_rc = 0) : iv_rc(i_rc) {}
Zane Shelley876bc2a2019-07-23 12:55:37 -050016
17 /** @brief Default copy constructor. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050018 ReturnCode(const ReturnCode&) = default;
Zane Shelley876bc2a2019-07-23 12:55:37 -050019
20 /** @brief Default assignment operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050021 ReturnCode& operator=(const ReturnCode&) = default;
Zane Shelley876bc2a2019-07-23 12:55:37 -050022
23 /** @brief Default destructor. */
24 ~ReturnCode() = default;
25
Zane Shelley83da2452019-10-25 15:45:34 -050026 /** @brief Integral type conversion function. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050027 operator uint32_t() const
28 {
29 return iv_rc;
30 }
Zane Shelley876bc2a2019-07-23 12:55:37 -050031
32 /** @brief Integral type conversion function. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050033 operator uint64_t() const
34 {
35 return iv_rc;
36 }
Zane Shelley876bc2a2019-07-23 12:55:37 -050037
38 /** @brief Equals operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050039 bool operator==(const ReturnCode& rhs) const
Zane Shelley876bc2a2019-07-23 12:55:37 -050040 {
41 return rhs.iv_rc == iv_rc;
42 }
43
44 /** @brief Not equals operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050045 bool operator!=(const ReturnCode& rhs) const
Zane Shelley876bc2a2019-07-23 12:55:37 -050046 {
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 Shelley7f7a42d2019-10-28 13:28:31 -050057 uint32_t get() const
58 {
59 return iv_rc;
60 }
Zane Shelley876bc2a2019-07-23 12:55:37 -050061
62 private:
Zane Shelleyca4b2f42019-08-30 15:48:40 -050063 uint32_t iv_rc; ///< return code value
Zane Shelley876bc2a2019-07-23 12:55:37 -050064};
65
Zane Shelley7c8faa12019-10-28 22:26:28 -050066// clang-format off
67
Zane Shelley876bc2a2019-07-23 12:55:37 -050068/** Function returned successfully. */
Zane Shelleya61f4c52019-08-01 13:58:49 -050069static constexpr ReturnCode RC_SUCCESS = ReturnCode();
Zane Shelley876bc2a2019-07-23 12:55:37 -050070
Zane Shelleya61f4c52019-08-01 13:58:49 -050071/** The given Chip Data File is malformed or unsupported. */
72static 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. */
76static constexpr ReturnCode RC_CHIP_DATA_INITIALIZED = ReturnCode(0x00000002);
77
78/** The given chip type has not been initialized. */
79static constexpr ReturnCode RC_CHIP_DATA_MISSING = ReturnCode(0x00000003);
80
Zane Shelleyca4b2f42019-08-30 15:48:40 -050081/** Generic return code indicating something along the hardware register access
82 * path failed and the returned data is undefined and should not be used. */
83static constexpr ReturnCode RC_REG_ACCESS_FAILURE = ReturnCode(0x00000004);
84
Zane Shelley7c8faa12019-10-28 22:26:28 -050085// clang-format on
86
Zane Shelleya61f4c52019-08-01 13:58:49 -050087} // end namespace libhei