MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
memoriam_praetereo.h
Go to the documentation of this file.
1/* MMgr - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2 * SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Commercial OR LicenseRef-Educational
3 *
4 * Every use falls under AGPL-3.0-or-later unless you hold explicit permission, which is either a
5 * negotiated commercial licensing contract or an educator's license issued to you personally.
6 */
7/**
8 * @file memoriam_praetereo.h
9 * @brief DMA channels: the completion event, the port hooks, the praet dispatch table, and the
10 * schedule and descriptors under them.
11 * @author dstroy0 (Douglas Quigg) <dquigg123@gmail.com>
12 * @date 2026-08-29
13 *
14 * @note The one header a caller includes. praet_ordo.h and praet_descriptor.h come in at the end,
15 * and the knobs they read come from the build line, before the include reaches this.
16 * @warning Everything below exists only when MMGR_ENABLE_DMA holds.
17 */
18#ifndef MMGR_MEMORIAM_PRAETEREO_H
19#define MMGR_MEMORIAM_PRAETEREO_H
20
21/** @addtogroup mod_praet
22 * @{ */
23
24#include "mmgr.h"
25
26#if MMGR_ENABLE_DMA
27
28EMBED_BEGIN_DECLS
29
30/**
31 * @brief What the port layer reports when a transfer finishes.
32 *
33 * @warning data points at the port layer's buffer. It is valid only for the callback's duration [BORROWS].
34 */
35typedef struct
36{
37 const uint8_t *data; /**< Bytes the transfer moved [BORROWS]. */
38 uint32_t completion_ms; /**< Completion time, whole milliseconds. */
39 uint32_t completion_us; /**< Completion time, microseconds within that millisecond. */
40 uint16_t bytes; /**< Bytes in data. */
41 uint16_t sequence; /**< Sequence number the port layer assigns. */
42 uint8_t channel; /**< Channel the transfer ran on. */
43 uint8_t peripheral; /**< Peripheral the channel serves. */
44 uint8_t direction; /**< Direction of the transfer. */
46
47/**
48 * @brief Reports a finished transfer to whatever registered this callback.
49 *
50 * @param[in] event The completion event [BORROWS].
51 * @param[in] user The pointer registered alongside this callback [BORROWS].
52 * @note Runs in whatever context the port layer finishes a transfer in. No mmgr_praet_ entry point
53 * calls it.
54 * @warning event and event->data belong to the port layer and last only until this returns. Copy
55 * anything retained [BORROWS].
56 */
57typedef void (*mmgr_praet_callback)(const mmgr_praet_event *event, void *user);
58
59/**
60 * @brief A completion callback and the pointer passed back to it.
61 *
62 * @warning mmgr_praet_open forwards the pointer to this struct unchanged and retains no copy. So it
63 * must stay valid for as long as the channel is open [BORROWS].
64 */
65typedef struct
66{
67 const mmgr_praet_callback callback; /**< Function to call [BORROWS]. */
68 void *const user; /**< Passed back to callback unexamined [BORROWS]. */
70
71/**
72 * @brief Arguments for a channel open, and for a poll of one.
73 *
74 * @note mmgr_praet_open reads all four members. mmgr_praet_poll passes the whole struct to the port
75 * layer.
76 */
77typedef struct
78{
79 const uint8_t channel; /**< Channel to act on. */
80 const uint8_t peripheral; /**< Peripheral the channel serves. */
81 const embed_bool loopback; /**< Open the channel looped back on itself. */
82 const PraetCallbackCfg *const on_complete; /**< Called when a transfer finishes [BORROWS]. */
83} PraetCfg;
84
85/**
86 * @brief Arguments for a transfer submit, and for a channel close.
87 *
88 * @note mmgr_praet_tx_submit reads all three. mmgr_praet_close reads channel alone.
89 */
90typedef struct
91{
92 const uint8_t channel; /**< Channel to act on. */
93 const uint8_t *const buf; /**< Bytes to send [BORROWS]. */
94 const uint16_t bytes; /**< Bytes in buf. */
96
97/**
98 * @brief Type of the praet dispatch table.
99 *
100 * @note EMBED_TABLE_LAYOUT asserts the four members sit at consecutive EMBED_FUNCTION_POINTER_BYTES offsets, with
101 * nothing else.
102 */
103typedef struct
104{
105 embed_bool (*open)(const PraetCfg *args); /**< Opens a channel. */
106 embed_bool (*tx_submit)(const PraetTransferCfg *args); /**< Submits a transfer. */
107 void (*close)(const PraetTransferCfg *args); /**< Closes a channel. */
108 void (*poll)(const PraetCfg *args); /**< Drives the port layer's poll hook. */
110EMBED_TABLE_LAYOUT(MemoriamPraetereoNs, open, tx_submit, close, poll);
111
112/**
113 * @brief Opens args->channel and registers args->on_complete against it.
114 *
115 * @param[in] args Channel, peripheral, loopback flag and completion callback [BORROWS].
116 * @return EMBED_TRUE when the port layer accepted the request.
117 * @note The default mmgr_praet_hw_open refuses, and so this returns EMBED_FALSE until a port replaces it.
118 * @warning args->channel must be below PRAET_CHANNELS, and args->on_complete must not be NULL.
119 */
120EMBED_HOST_DEVICE embed_bool mmgr_praet_open(const PraetCfg *args);
121
122/**
123 * @brief Submits args->bytes of args->buf on args->channel.
124 *
125 * @param[in] args Channel, buffer and byte count [BORROWS].
126 * @return EMBED_TRUE when the port layer accepted the transfer.
127 * @note The default mmgr_praet_hw_tx_submit refuses, and so this returns EMBED_FALSE until a port replaces it.
128 * @warning args->buf must stay valid until the completion callback runs [BORROWS].
129 * @warning args->channel must be below PRAET_CHANNELS.
130 */
131EMBED_HOST_DEVICE embed_bool mmgr_praet_tx_submit(const PraetTransferCfg *args);
132
133/**
134 * @brief Closes args->channel.
135 *
136 * @param[in] args Channel to close [BORROWS].
137 * @note It reads only args->channel. buf and bytes take no part.
138 * @warning args->channel must be below PRAET_CHANNELS.
139 */
140EMBED_HOST_DEVICE void mmgr_praet_close(const PraetTransferCfg *args);
141
142/**
143 * @brief Drives the port layer's poll hook.
144 *
145 * @param[in] args Channel to poll [BORROWS].
146 * @note Passes args straight to mmgr_praet_hw_poll, unlike the other three entries, which assert first.
147 * @warning No assertion runs here. args and args->channel reach the port layer exactly as the caller gave them.
148 */
149EMBED_HOST_DEVICE void mmgr_praet_poll(const PraetCfg *args);
150
151/**
152 * @brief Opens a DMA channel on real hardware.
153 *
154 * @param[in] args Channel, peripheral, loopback flag and completion callback, as mmgr_praet_open
155 * forwards them [BORROWS].
156 * @return EMBED_TRUE when the hardware accepted the request.
157 * @note The default in memoriam_praetereo.c refuses every request. A build links without a port.
158 * @note An application definition of this name replaces that default where EMBED_HAS_ATTRIBUTE(weak)
159 * is non-zero.
160 * @note A program that opens a channel from a kernel defines this for the device, as EMBED_WEAK_NAME states.
161 * @warning Reached through mmgr_praet_open, which asserts the channel and the callback first.
162 */
163EMBED_HOST_DEVICE embed_bool mmgr_praet_hw_open(const PraetCfg *args);
164
165/**
166 * @brief Submits a transfer on real hardware.
167 *
168 * @param[in] args Channel, buffer and byte count, as mmgr_praet_tx_submit forwards them [BORROWS].
169 * @return EMBED_TRUE when the hardware accepted the transfer.
170 * @note The default in memoriam_praetereo.c refuses every transfer. A build links without a port.
171 * @note An application definition of this name replaces that default where EMBED_HAS_ATTRIBUTE(weak)
172 * is non-zero.
173 * @warning Reached through mmgr_praet_tx_submit, which asserts the channel first.
174 * @warning args->buf must stay valid until this reports completion through the registered callback [BORROWS].
175 */
176EMBED_HOST_DEVICE embed_bool mmgr_praet_hw_tx_submit(const PraetTransferCfg *args);
177
178/**
179 * @brief Closes a DMA channel on real hardware.
180 *
181 * @param[in] args Channel to close, as mmgr_praet_close forwards it [BORROWS].
182 * @note The default in memoriam_praetereo.c does nothing. A build links without a port.
183 * @note An application definition of this name replaces that default where EMBED_HAS_ATTRIBUTE(weak)
184 * is non-zero.
185 * @note It forwards only args->channel. buf and bytes take no part.
186 * @warning Reached through mmgr_praet_close, which asserts the channel first.
187 */
188EMBED_HOST_DEVICE void mmgr_praet_hw_close(const PraetTransferCfg *args);
189
190/**
191 * @brief Advances whatever poll work the port layer needs.
192 *
193 * @param[in] args Channel to poll, exactly as the caller gave it [BORROWS].
194 * @note The default in memoriam_praetereo.c does nothing. A build links without a port.
195 * @note An application definition of this name replaces that default where EMBED_HAS_ATTRIBUTE(weak)
196 * is non-zero.
197 * @warning mmgr_praet_poll calls this directly, with no check call in between. args and
198 * args->channel arrive exactly as the caller wrote them, unasserted.
199 */
200EMBED_HOST_DEVICE void mmgr_praet_hw_poll(const PraetCfg *args);
201
202/**
203 * @brief Dispatch table instance named praet.
204 *
205 * @note Each member calls the mmgr_praet_ function of the same name, one to one. No member points at
206 * another's function, which is where this differs from the memor table.
207 */
208EMBED_TABLE_STORAGE MemoriamPraetereoNs praet EMBED_UNUSED = {
209 .open = mmgr_praet_open,
210 .tx_submit = mmgr_praet_tx_submit,
211 .close = mmgr_praet_close,
212 .poll = mmgr_praet_poll,
213};
214
215EMBED_END_DECLS
216
217// The descriptors, and the schedule they ride on with its knobs and its flag word. Both need the
218// knobs this build set, and neither comes in where MMGR_ENABLE_DMA is off
221
222#endif
223
224/** @} */
225
226#endif
static const MemoriamPraetereoNs praet
Dispatch table instance named praet.
EMBED_HOST_DEVICE embed_bool mmgr_praet_open(const PraetCfg *args)
Opens args->channel and registers args->on_complete against it.
EMBED_HOST_DEVICE embed_bool mmgr_praet_hw_open(const PraetCfg *args)
Opens a DMA channel on real hardware.
EMBED_HOST_DEVICE embed_bool mmgr_praet_tx_submit(const PraetTransferCfg *args)
Submits args->bytes of args->buf on args->channel.
EMBED_HOST_DEVICE void mmgr_praet_hw_close(const PraetTransferCfg *args)
Closes a DMA channel on real hardware.
EMBED_HOST_DEVICE void mmgr_praet_hw_poll(const PraetCfg *args)
Advances whatever poll work the port layer needs.
EMBED_HOST_DEVICE void mmgr_praet_poll(const PraetCfg *args)
Drives the port layer's poll hook.
EMBED_HOST_DEVICE void mmgr_praet_close(const PraetTransferCfg *args)
Closes args->channel.
EMBED_HOST_DEVICE embed_bool mmgr_praet_hw_tx_submit(const PraetTransferCfg *args)
Submits a transfer on real hardware.
void(*) mmgr_praet_callback(const mmgr_praet_event *event, void *user)
Reports a finished transfer to whatever registered this callback.
The embedded_types headers every module builds on.
A transfer written down: where from, where to, how many bytes, how each address moves,...
The schedule context: one flag word per channel, the two volatiles that coordinate the interrupt,...
Type of the praet dispatch table.
embed_bool(*) tx_submit(const PraetTransferCfg *args)
void(*) poll(const PraetCfg *args)
void(*) close(const PraetTransferCfg *args)
embed_bool(*) open(const PraetCfg *args)
A completion callback and the pointer passed back to it.
const mmgr_praet_callback callback
Arguments for a channel open, and for a poll of one.
const embed_bool loopback
const uint8_t channel
const uint8_t peripheral
const PraetCallbackCfg *const on_complete
Arguments for a transfer submit, and for a channel close.
const uint8_t channel
const uint8_t *const buf
const uint16_t bytes
What the port layer reports when a transfer finishes.
const uint8_t * data