blob: 5ec9953e3c7196570302c48f40d877224da1eb2b [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:
11
12 /**
13 * @brief Constructor.
14 * @param i_rc The error code value.
15 */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050016 explicit constexpr ReturnCode(uint32_t i_rc = 0) : iv_rc(i_rc) {}
Zane Shelley876bc2a2019-07-23 12:55:37 -050017
18 /** @brief Default copy constructor. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050019 ReturnCode(const ReturnCode&) = default;
Zane Shelley876bc2a2019-07-23 12:55:37 -050020
21 /** @brief Default assignment operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050022 ReturnCode& operator=(const ReturnCode&) = default;
Zane Shelley876bc2a2019-07-23 12:55:37 -050023
24 /** @brief Default destructor. */
25 ~ReturnCode() = default;
26
Zane Shelley83da2452019-10-25 15:45:34 -050027 /** @brief Integral type conversion function. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050028 operator uint32_t() const
29 {
30 return iv_rc;
31 }
Zane Shelley876bc2a2019-07-23 12:55:37 -050032
33 /** @brief Integral type conversion function. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050034 operator uint64_t() const
35 {
36 return iv_rc;
37 }
Zane Shelley876bc2a2019-07-23 12:55:37 -050038
39 /** @brief Equals operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050040 bool operator==(const ReturnCode& rhs) const
Zane Shelley876bc2a2019-07-23 12:55:37 -050041 {
42 return rhs.iv_rc == iv_rc;
43 }
44
45 /** @brief Not equals operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -050046 bool operator!=(const ReturnCode& rhs) const
Zane Shelley876bc2a2019-07-23 12:55:37 -050047 {
48 return rhs.iv_rc != iv_rc;
49 }
50
51 /**
52 * @brief Returns the error code value.
53 *
54 * We'd prefer to use the integral type conversion functions above, but
55 * some compilers will throw warnings when passing this object into
56 * functions with variadic arguments, like printf().
57 */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050058 uint32_t get() const
59 {
60 return iv_rc;
61 }
Zane Shelley876bc2a2019-07-23 12:55:37 -050062
63 private:
64
Zane Shelleyca4b2f42019-08-30 15:48:40 -050065 uint32_t iv_rc; ///< return code value
Zane Shelley876bc2a2019-07-23 12:55:37 -050066};
67
68/** 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 Shelleya61f4c52019-08-01 13:58:49 -050085} // end namespace libhei