| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#import <os/log.h> |
| 34 |
|
| 35 |
#import <functional> |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
constexpr uint32_t MAX_DYNAMIC_BUFFERS = 8; |
| 41 |
|
| 42 |
|
| 43 |
static constexpr uint32_t MAX_FRAME_COUNT = 3; |
| 44 |
|
| 45 |
#pragma mark - Boolean flags |
| 46 |
|
| 47 |
namespace flags { |
| 48 |
|
| 49 |
|
| 50 |
template <typename Tv, typename Tm> |
| 51 |
void set(Tv &p_value, Tm p_mask) { |
| 52 |
using T = std::underlying_type_t<Tv>; |
| 53 |
p_value = static_cast<Tv>(static_cast<T>(p_value) | static_cast<T>(p_mask)); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
template <typename Tv, typename Tm> |
| 58 |
void clear(Tv &p_value, Tm p_mask) { |
| 59 |
using T = std::underlying_type_t<Tv>; |
| 60 |
p_value = static_cast<Tv>(static_cast<T>(p_value) & ~static_cast<T>(p_mask)); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
template <typename Tv, typename Tm> |
| 65 |
static constexpr bool any(Tv p_value, const Tm p_mask) { |
| 66 |
return ((p_value & p_mask) != 0); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
template <typename Tv, typename Tm> |
| 71 |
static constexpr bool all(Tv p_value, const Tm p_mask) { |
| 72 |
return ((p_value & p_mask) == p_mask); |
| 73 |
} |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
#pragma mark - Alignment and Offsets |
| 78 |
|
| 79 |
static constexpr bool is_power_of_two(uint64_t p_value) { |
| 80 |
return p_value && ((p_value & (p_value - 1)) == 0); |
| 81 |
} |
| 82 |
|
| 83 |
static constexpr uint64_t round_up_to_alignment(uint64_t p_value, uint64_t p_alignment) { |
| 84 |
DEV_ASSERT(is_power_of_two(p_alignment)); |
| 85 |
|
| 86 |
if (p_alignment == 0) { |
| 87 |
return p_value; |
| 88 |
} |
| 89 |
|
| 90 |
uint64_t mask = p_alignment - 1; |
| 91 |
uint64_t aligned_value = (p_value + mask) & ~mask; |
| 92 |
|
| 93 |
return aligned_value; |
| 94 |
} |
| 95 |
|
| 96 |
class Defer { |
| 97 |
public: |
| 98 |
Defer(std::function<void()> func) : |
| 99 |
func_(func) {} |
| 100 |
~Defer() { func_(); } |
| 101 |
|
| 102 |
private: |
| 103 |
std::function<void()> func_; |
| 104 |
}; |
| 105 |
|
| 106 |
#define CONCAT_INTERNAL(x, y) x##y |
| 107 |
#define CONCAT(x, y) CONCAT_INTERNAL(x, y) |
| 108 |
#define DEFER const Defer &CONCAT(defer__, __LINE__) = Defer |
| 109 |
|
| 110 |
extern os_log_t LOG_DRIVER; |
| 111 |
|
| 112 |
extern os_log_t LOG_INTERVALS; |
| 113 |
|
| 114 |
_FORCE_INLINE_ static constexpr uint32_t make_msl_version(uint32_t p_major, uint32_t p_minor = 0, uint32_t p_patch = 0) { |
| 115 |
return (p_major * 10000) + (p_minor * 100) + p_patch; |
| 116 |
} |
| 117 |
|
| 118 |
_FORCE_INLINE_ static constexpr void parse_msl_version(uint32_t p_version, uint32_t &r_major, uint32_t &r_minor) { |
| 119 |
r_major = p_version / 10000; |
| 120 |
r_minor = (p_version % 10000) / 100; |
| 121 |
} |
| 122 |
|
| 123 |
constexpr uint32_t MSL_VERSION_23 = make_msl_version(2, 3); |
| 124 |
constexpr uint32_t MSL_VERSION_24 = make_msl_version(2, 4); |
| 125 |
constexpr uint32_t MSL_VERSION_30 = make_msl_version(3, 0); |
| 126 |
constexpr uint32_t MSL_VERSION_31 = make_msl_version(3, 1); |
| 127 |
constexpr uint32_t MSL_VERSION_32 = make_msl_version(3, 2); |
| 128 |
constexpr uint32_t MSL_VERSION_40 = make_msl_version(4, 0); |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|