CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
TropicSlotMap.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
5namespace cdc::core {
6
7class TropicSlotMap {
8public:
9 enum class SlotType : uint8_t {
12 };
13
14 struct SlotRange {
15 bool valid = false;
17 const char* moduleName = nullptr;
18 uint8_t moduleId = 0;
19 uint16_t start = 0;
20 uint16_t end = 0;
21 };
22
23 static TropicSlotMap& instance();
24
25 bool isValid() const { return valid_; }
26 const char* errorMessage() const { return errorMessage_; }
27
28 bool getRangeByName(const char* moduleName, SlotType type, SlotRange* out) const;
29 bool getRangeByModuleId(uint8_t moduleId, SlotType type, SlotRange* out) const;
30 bool isRmemAllowedForModuleId(uint16_t slot, uint8_t moduleId) const;
31
32 using RangeCallback = void (*)(const SlotRange& range, void* user);
33 void forEachRange(SlotType type, RangeCallback cb, void* user) const;
34
35 uint16_t rmemMax() const;
36
37 uint32_t computeMapSignature() const;
38
39private:
40 TropicSlotMap();
41
42 void validateOnce();
43 void setError(const char* message);
44
45 bool valid_ = true;
46 const char* errorMessage_ = nullptr;
47};
48
49} // namespace cdc::core
uint8_t moduleId
void(*)(const SlotRange &range, void *user) RangeCallback
static TropicSlotMap & instance()
Returns singleton Tropic slot-map instance.
uint16_t rmemMax() const
Returns maximum RMEM slot index.
void forEachRange(SlotType type, RangeCallback cb, void *user) const
Iterates configured slot ranges of the given type in declaration order.
bool isRmemAllowedForModuleId(uint16_t slot, uint8_t moduleId) const
Checks whether RMEM slot is allowed for given module id.
bool getRangeByModuleId(uint8_t moduleId, SlotType type, SlotRange *out) const
Retrieves slot range by module id and slot type.
uint32_t computeMapSignature() const
Computes deterministic signature over static map constants and ranges.
bool getRangeByName(const char *moduleName, SlotType type, SlotRange *out) const
Retrieves slot range by module name and slot type.
const char * errorMessage() const