blob: c9ebc8a6404b9d1c84b7453d00e54d9f07968066 [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 Shelley83da2452019-10-25 15:45:34 -050016 explicit constexpr ReturnCode(uint32_t i_rc = 0) :
17 iv_rc(i_rc)
Zane Shelley876bc2a2019-07-23 12:55:37 -050018 {}
19
20 /** @brief Default copy constructor. */
Zane Shelley83da2452019-10-25 15:45:34 -050021 ReturnCode(const ReturnCode &) = default;
Zane Shelley876bc2a2019-07-23 12:55:37 -050022
23 /** @brief Default assignment operator. */
Zane Shelley83da2452019-10-25 15:45:34 -050024 ReturnCode& operator=(const ReturnCode &) = default;
Zane Shelley876bc2a2019-07-23 12:55:37 -050025
26 /** @brief Default destructor. */
27 ~ReturnCode() = default;
28
Zane Shelley83da2452019-10-25 15:45:34 -050029 /** @brief Integral type conversion function. */
Zane Shelley876bc2a2019-07-23 12:55:37 -050030 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 Shelley83da2452019-10-25 15:45:34 -050036 bool operator==(const ReturnCode & rhs) const
Zane Shelley876bc2a2019-07-23 12:55:37 -050037 {
38 return rhs.iv_rc == iv_rc;
39 }
40
41 /** @brief Not equals operator. */
Zane Shelley83da2452019-10-25 15:45:34 -050042 bool operator!=(const ReturnCode & rhs) const
Zane Shelley876bc2a2019-07-23 12:55:37 -050043 {
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 Shelleyca4b2f42019-08-30 15:48:40 -050058 uint32_t iv_rc; ///< return code value
Zane Shelley876bc2a2019-07-23 12:55:37 -050059};
60
61/** Function returned successfully. */
Zane Shelleya61f4c52019-08-01 13:58:49 -050062static constexpr ReturnCode RC_SUCCESS = ReturnCode();
Zane Shelley876bc2a2019-07-23 12:55:37 -050063
Zane Shelleya61f4c52019-08-01 13:58:49 -050064/** The given Chip Data File is malformed or unsupported. */
65static 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. */
69static constexpr ReturnCode RC_CHIP_DATA_INITIALIZED = ReturnCode(0x00000002);
70
71/** The given chip type has not been initialized. */
72static constexpr ReturnCode RC_CHIP_DATA_MISSING = ReturnCode(0x00000003);
73
Zane Shelleyca4b2f42019-08-30 15:48:40 -050074/** Generic return code indicating something along the hardware register access
75 * path failed and the returned data is undefined and should not be used. */
76static constexpr ReturnCode RC_REG_ACCESS_FAILURE = ReturnCode(0x00000004);
77
Zane Shelleya61f4c52019-08-01 13:58:49 -050078} // end namespace libhei