MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
praet_praefinitum.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 praet_praefinitum.h
9 * @brief Every knob this module reads, what it takes when the caller did not set it, and the warning
10 * that says so.
11 * @author dstroy0 (Douglas Quigg) <dquigg123@gmail.com>
12 * @date 2026-09-01
13 *
14 * @note A knob that quietly takes a default is how a build breaks in a way nobody traces back. Three
15 * knobs get set, two do not, the part misbehaves, and the compiler said nothing.
16 * @note Nothing here stops the build. Every unset knob takes its default, raises a warning that names
17 * itself and the value it took, and leaves a flag behind. praet_iudex.h reads those
18 * flags at the end and stops once, with a list of what to go fix.
19 * @note That order is essential. An #error halts its translation unit where it is. A
20 * build with four knobs unset reports one, gets a fix, and reports the next. That is four
21 * rounds to learn four facts that were all known on the first. A warning here and a stop at
22 * the end passes the whole basket over at once.
23 * @note Nothing about it needs a build system. It is preprocessor directives. A bare gcc or clang
24 * on one file behaves the same way as any tree that drives them. A build that continues past
25 * an error reaches across translation units on top of this. That is a separate half of the
26 * same idea and not something this depends on.
27 * @note #warning is a GNU and clang directive and is standard from C23. This library targets those
28 * two compilers and no others, and so it is available everywhere this builds.
29 * @note Every message is a #warning directive, with no macro over _Pragma. GCC's warning pragma
30 * retains only the first string literal after it. A message written as adjacent literals
31 * arrives cut off at the first one. That still reads as a finished sentence and still passes a
32 * check written against its first words. A #warning takes the rest of the line and arrives
33 * whole.
34 * @warning A directive cannot come out of a macro expansion, and so this only works where the report sits
35 * at file scope. Every knob here does. The one report that fires from inside a macro is the
36 * boundary word answer at a declaration, and praet_ordo.h reaches that a different way.
37 * @warning No message interpolates a macro. Neither #warning nor the pragma expands one. A name in
38 * the middle of a message arrives as the name of the macro, and its value never appears.
39 */
40#ifndef MMGR_PRAET_PRAEFINITUM_H
41#define MMGR_PRAET_PRAEFINITUM_H
42
43/** @addtogroup mod_praet
44 * @{ */
45
46/**
47 * @brief Logical channels one context carries.
48 *
49 * @note Per part, and the caller is the single one who knows which part. There is no number here that is
50 * right for everyone.
51 */
52#ifndef PRAET_CHANNELS
53#define PRAET_CHANNELS 8u
54#define PRAET_UNSET_CHANNELS 1
55#warning \
56 "PRAET_CHANNELS was not set and took the library default of 8. Set it to the channels your part gives one engine."
57#endif
58
59/**
60 * @brief Microseconds the engine spends in its settle before it will take a transfer.
61 *
62 * @note Microseconds and not milliseconds. DMA timing is tight enough that a millisecond is not a unit
63 * anything here fits in.
64 * @warning At EMBED_WORD_BITS=16 a microsecond count wraps at 65535, about 65 milliseconds. No
65 * engine takes that long to come up, and so this knob is safe at every width.
66 */
67#ifndef PRAET_SETTLE_MICROS
68#define PRAET_SETTLE_MICROS 0u
69#define PRAET_UNSET_SETTLE_MICROS 1
70#warning \
71 "PRAET_SETTLE_MICROS was not set and took the library default of 0, so this build waits for nothing after an attach. Set it to what your engine takes to come up."
72#endif
73
74/**
75 * @brief Microseconds an active channel may go with no kick from the port before it reads stalled.
76 *
77 * @note A watchdog window and not a transfer length. The port kicks this whenever the engine shows a
78 * sign of life. A window that goes unkicked says the channel stopped, and it never
79 * says the transfer finished. Completion arrives from the port, because how long a transfer
80 * takes is not something this library can know.
81 * @note That is also why the width is not a problem. A watchdog window is short deliberately. So the
82 * 65 millisecond ceiling a 16-bit word puts on a microsecond count is far above any value
83 * worth a place here. A transfer's runtime has no bound at all.
84 */
85#ifndef PRAET_KEEPALIVE_MICROS
86#define PRAET_KEEPALIVE_MICROS 1000u
87#define PRAET_UNSET_KEEPALIVE_MICROS 1
88#warning \
89 "PRAET_KEEPALIVE_MICROS was not set and took the library default of 1000. Set it to how long a moving channel may go unkicked on your part before it has stopped."
90#endif
91
92/**
93 * @brief Whether a stalled transfer can go back or come out scrubbed.
94 *
95 * @note The capability switch. Off is what a caller gets with no answer. Recovery costs
96 * three arrays per channel and a caller who never said where the bytes were cannot back
97 * anything out of them.
98 * @note With it on, submit takes the start and the length, kick reports how far the engine got, and
99 * praet_ordo_resolve exists. With it off none of those members are in the context and none
100 * of those entries exist. A call site that wanted them fails to compile and does not
101 * link against a version that records nothing.
102 */
103#ifndef PRAET_RECOVERY
104#define PRAET_RECOVERY 0
105#define PRAET_UNSET_RECOVERY 1
106#warning \
107 "PRAET_RECOVERY was not set and took the library default of 0. A stalled transfer cannot be backed out or scrubbed in this build. Set it to 1 to have that machinery, 0 to say you meant to leave it out."
108#endif
109
110// A capability switch is on or off, and a third value is somebody reading it as a count or a channel
111// number. Every test on it below would take the on arm silently. This one stops where it is
112// and stays out of the basket. Every gate after it would answer a question about a
113// value nobody can read
114#if (PRAET_RECOVERY != 0) && (PRAET_RECOVERY != 1)
115#error "PRAET_RECOVERY must be 0 or 1. It is a capability switch, not a count."
116#endif
117
118// The boundary word check is not a build knob and has no default. Each context answers it once, in
119// the declaration, with a token nobody writes by accident. See PraetOrdoContext in
120// praet_ordo.h. A -D that sets it here reads as a build-wide switch, which it is not
121#ifdef PRAET_RECOVERY_CRC
122#error \
123 "PRAET_RECOVERY_CRC is not a build knob. The boundary word check is answered per context, in the declaration: PraetOrdoContext(name, AD_VERBI_CONFINIUM_RESTITUE_PAULATIM_CRC_ENABLE) or the DISABLE token."
124#endif
125
126/** @} */
127
128#endif