ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
platform.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file platform.h
6 * @brief The platform contract: what the library asks of a target, in the library's own words.
7 *
8 * Nothing here names a vendor. The axis itself is resolved in vendor/vendor_detect.h, which then
9 * pulls in exactly one vendor/<vendor>/ header; this file states the questions that header has to
10 * answer and refuses the build, by name, for any it did not.
11 *
12 * Two kinds of thing live here:
13 * - the capability questions (PROTOCORE_HAS_*): does this part carry the thing at all. Each is
14 * `#ifndef`, so a build states what it has by defining it, and an unanswered one is an #error
15 * rather than a silent 0.
16 * - the seams (protocore_platform_*): declared under the capability that answers whether the part
17 * carries the thing, so reaching for an absent one is a compile error, not a link-time surprise.
18 *
19 * It is also the assembly point: the vendor axis, the board profile, the widths, the types built
20 * from them, the capability floors and questions, and the seams - in the one order each depends on
21 * the last. Nothing here includes a standard header; config/platform/types.h is the only file that
22 * does.
23 *
24 * @author Douglas Quigg (dstroy0)
25 * @date 2026
26 */
27
28#ifndef PROTOCORE_PLATFORM_H
29#define PROTOCORE_PLATFORM_H
30
31// PROTOCORE_INLINE, settled before any body is parsed - the vendor header below defines its seams
32// with it, so the linkage comes first.
34// The vendor axis, then the one vendor header that answers the capability questions below.
35#include "vendor/vendor_detect.h"
36// What a namespace is: PROTOCORE_NS, PROTOCORE_NS_LAYOUT, PROTOCORE_CALL. Beside the linkage and
37// for the same reason - every module's dispatch table is written with these, so they are settled
38// before any of them is parsed.
40// Per-variant default sizing (chip / PSRAM / flash profiles). Reached before the widths so a board
41// profile can state PROTOCORE_HW_WORD_BITS; a -D override still wins (every default is #ifndef).
42#include "vendor/board_profiles/board_profile.h"
43
44// ---------------------------------------------------------------------------
45// Platform widths
46// ---------------------------------------------------------------------------
47// The three numbers every primitive type and every lane mask is derived from
48// (protocore_types.h, mmgr/swar.h). They are `#define`s rather than typedefs
49// so they participate in preprocessor arithmetic, can be tested by `#if`, and can be overridden
50// from build_opt.h or -D like every other knob. Each is checked below, so a bad value stops the
51// build here, naming itself, instead of at the first expression that assumed it.
52
53/**
54 * @brief The target's natural register width, in bits.
55 *
56 * What a value is carried in while it is being worked on. Arithmetic narrower than the register is
57 * not cheaper on any part in the target list - it costs the mask or sign-extend that keeps the
58 * unused half correct - so the library states the register once and narrows only at a boundary.
59 */
60// The die states its register width in vendor/board_profiles/ (PROTOCORE_HW_WORD_BITS, floored at
61// 32 for every part in the target list); this only names it. It is NOT read off the toolchain: the
62// host toolchain is 64-bit, so inferring would give the host build 8-byte lane math, an 8-byte move
63// ladder and 64-bit index arithmetic - a shape no target executes, measured on a machine that does
64// not ship. A -D override still wins, which is how a 64-bit port or a width experiment is done.
65#ifndef PROTO_WORD_BITS
66#define PROTO_WORD_BITS PROTOCORE_HW_WORD_BITS
67#endif
68
69/**
70 * @brief Bits in every offset, length and capacity the library declares (protocore_idx).
71 *
72 * Replaces `size_t`, whose width is inherited from the target's pointer and therefore differs
73 * between a device build and the host test that proves it - the same source emitting different
74 * index arithmetic in the two places it has to agree. 32 addresses far more than any pool reserved
75 * here; a target whose every buffer is under 64 KB may set 16.
76 */
77#ifndef PROTO_INDEX_BITS
78#define PROTO_INDEX_BITS 32
79#endif
80
81/**
82 * @brief Bits in the lane carrier the byte-parallel scans and compares work in.
83 *
84 * Defaults to the register width, which is what makes the lane algebra worth doing: one word test
85 * answers for PROTO_SWAR_BITS/8 bytes at once. Set it lower only to model a narrower machine - a
86 * carrier WIDER than the register is synthesized from halves and is measurably slower than the
87 * width it decomposes into. 8 is legal and degenerates to one lane per word, which is the honest
88 * setting for a part with no wider register.
89 */
90#ifndef PROTO_SWAR_BITS
91#define PROTO_SWAR_BITS PROTO_WORD_BITS
92#endif
93
94// The widths are settled above, so the types built from them come next. types.h is the one file in
95// the library that includes a standard header.
97
98// What seams exist to call at all, then the capability questions the vendor had to answer.
101
102// The library's own constants, and the seams each capability promises.
106
107// Every width and ordering rule the above had to satisfy.
108// The accelerator HALs the selected arm answers with, in the types settled above.
109#include "vendor/vendor_hal.h"
110
112
113#endif // PROTOCORE_PLATFORM_H
Compiler-specific directives for the ProtoCore library.
Whether a seam exists to call at all: the floor under every hardware capability.
Every hardware capability the build must state, and the refusal when it did not.
The seams each hardware capability promises, declared only where the capability is 1.
What a namespace IS: how its table is stored, how its slots are pinned, and how a call with several o...
Platform defines for the ProtoCore library.
The platform's compile-time rules: a bad width stops the build here, naming itself,...
Platform prototypes for the ProtoCore library.
The primitive types every other file is written in, and the one place <stdint.h> and <stddef....