blob: 5d0526e6999c2bec8076589801fb705a77c6b16f [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 */
16 explicit constexpr ReturnCode( uint32_t i_rc = 0 ) :
17 iv_rc( i_rc )
18 {}
19
20 /** @brief Default copy constructor. */
21 ReturnCode( const ReturnCode & ) = default;
22
23 /** @brief Default assignment operator. */
24 ReturnCode& operator=( const ReturnCode & ) = default;
25
26 /** @brief Default destructor. */
27 ~ReturnCode() = default;
28
29 /** @brief Integral type conversion function. */
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. */
36 bool operator==( const ReturnCode & rhs ) const
37 {
38 return rhs.iv_rc == iv_rc;
39 }
40
41 /** @brief Not equals operator. */
42 bool operator!=( const ReturnCode & rhs ) const
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 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
Zane Shelley876bc2a2019-07-23 12:55:37 -050079