Dawn Framework 1.0
Universal data acquisition framework for embedded systems
descriptor.hxx
1// dawn/include/dawn/dev/descriptor.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <array>
9#include <cstddef>
10#include <cstdint>
11
12#include "dawn/porting/config.hxx"
13
14namespace dawn
15{
19{
20public:
23 constexpr static int MAX_DESCRIPTORS = CONFIG_DAWN_DESC_SLOTS;
24#if CONFIG_DAWN_DESC_SLOTS > 1
25 constexpr static size_t SLOT_SIZE = CONFIG_DAWN_DESC_SLOT_SIZE;
26#else
27 constexpr static size_t SLOT_SIZE = 0;
28#endif
29
32 struct descriptor_reg_s
33 {
34 void *ptr;
35 size_t len;
36 } typedef SDescriptorReg;
37
45 {
46 if (CDevDescriptor::singleton == nullptr)
47 {
48 CDevDescriptor::singleton = new CDevDescriptor();
49 }
50
51 return CDevDescriptor::singleton;
52 }
53
56 static void destroy()
57 {
58 delete CDevDescriptor::singleton;
59 CDevDescriptor::singleton = nullptr;
60 }
61
70 int regDescriptor(int inst, const SDescriptorReg &reg);
71
80 int getDescriptor(int inst, SDescriptorReg &reg);
81
92 int writeSlotData(int inst, const void *data, size_t offset, size_t len);
93
101 size_t getSlotWritten(int inst) const;
102
112 int resetSlot(int inst);
113
114private:
117 static CDevDescriptor *singleton;
118
121 SDescriptorReg regDesc[MAX_DESCRIPTORS] = {};
122
123#if CONFIG_DAWN_DESC_SLOTS > 1
126 std::array<std::array<uint8_t, SLOT_SIZE>, CONFIG_DAWN_DESC_SLOTS - 1> slotBuf = {};
127
130 std::array<size_t, CONFIG_DAWN_DESC_SLOTS - 1> slotWritten = {};
131#endif
132
135 CDevDescriptor() = default;
136};
137
138} // Namespace dawn
Descriptor interface available for IO.
static void destroy()
Destroy singleton instance.
int resetSlot(int inst)
Reset a RAM slot.
int getDescriptor(int inst, SDescriptorReg &reg)
Get registered descriptor data for an instance.
static CDevDescriptor * getInst()
Get singleton instance.
int regDescriptor(int inst, const SDescriptorReg &reg)
Register descriptor data for an instance.
int writeSlotData(int inst, const void *data, size_t offset, size_t len)
Write descriptor bytes into a RAM slot.
static int MAX_DESCRIPTORS
Maximum number of descriptors that can be registered.
size_t getSlotWritten(int inst) const
Get valid byte count currently stored in a RAM slot.
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Registered descriptor information.
size_t len
Descriptor length in bytes.
void * ptr
Pointer to descriptor data.