1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* [AMENDMENT] This module provides the Rust equivalents of FreeRTOS base types.
* These are typically defined in portmacro.h for each port. Here we provide
* generic definitions controlled by Cargo features.
*/
//! FreeRTOS Base Types
//!
//! This module defines the fundamental types used throughout FreeRTOS:
//! - `BaseType_t` - Signed type, architecture word size
//! - `UBaseType_t` - Unsigned type, architecture word size
//! - `StackType_t` - Stack element type
//! - `TickType_t` - Tick counter type
//!
//! ## Architecture Width
//! - `arch-32bit` feature: 32-bit types
//! - `arch-64bit` feature: 64-bit types
//!
//! ## Tick Width
//! - `tick-16bit` feature: 16-bit tick counter
//! - `tick-32bit` feature: 32-bit tick counter
//! - `tick-64bit` feature: 64-bit tick counter
//!
//! Exactly one of each category must be enabled.
// =============================================================================
// Feature validation (compile-time checks)
// =============================================================================
// Ensure exactly one arch is selected
compile_error!;
compile_error!;
// Ensure exactly one tick width is selected
compile_error!;
compile_error!;
// =============================================================================
// Architecture-dependent types (BaseType_t, UBaseType_t, StackType_t)
// =============================================================================
/// Signed base type - architecture word size
/// Used for boolean returns, error codes, and small signed values.
pub type BaseType_t = i32;
pub type BaseType_t = i64;
/// Unsigned base type - architecture word size
/// Used for counts, indices, and priority values.
pub type UBaseType_t = u32;
pub type UBaseType_t = u64;
/// Stack element type
/// Each stack "slot" is this size.
pub type StackType_t = u32;
pub type StackType_t = u64;
// =============================================================================
// Tick type (configurable width independent of architecture)
// =============================================================================
/// Tick counter type - 16-bit variant
/// Suitable for very resource-constrained systems.
pub type TickType_t = u16;
/// Maximum tick value for 16-bit ticks
pub const portMAX_DELAY: TickType_t = 0xFFFF;
/// Tick counter type - 32-bit variant (most common)
pub type TickType_t = u32;
/// Maximum tick value for 32-bit ticks
pub const portMAX_DELAY: TickType_t = 0xFFFF_FFFF;
/// Tick counter type - 64-bit variant
/// For systems needing very long delays without overflow.
pub type TickType_t = u64;
/// Maximum tick value for 64-bit ticks
pub const portMAX_DELAY: TickType_t = 0xFFFF_FFFF_FFFF_FFFF;
// =============================================================================
// Tick type width constants (for conditional compilation in kernel code)
// =============================================================================
/// Tick type width indicator - 16-bit
pub const TICK_TYPE_WIDTH_16_BITS: u8 = 0;
/// Tick type width indicator - 32-bit
pub const TICK_TYPE_WIDTH_32_BITS: u8 = 1;
/// Tick type width indicator - 64-bit
pub const TICK_TYPE_WIDTH_64_BITS: u8 = 2;
/// Current tick type width (for runtime checks if needed)
pub const configTICK_TYPE_WIDTH_IN_BITS: u8 = TICK_TYPE_WIDTH_16_BITS;
pub const configTICK_TYPE_WIDTH_IN_BITS: u8 = TICK_TYPE_WIDTH_32_BITS;
pub const configTICK_TYPE_WIDTH_IN_BITS: u8 = TICK_TYPE_WIDTH_64_BITS;
// =============================================================================
// Boolean-like constants (from projdefs.h)
// =============================================================================
/// Boolean false as BaseType_t
pub const pdFALSE: BaseType_t = 0;
/// Boolean true as BaseType_t
pub const pdTRUE: BaseType_t = 1;
/// Pass/success return value
pub const pdPASS: BaseType_t = pdTRUE;
/// Fail return value
pub const pdFAIL: BaseType_t = pdFALSE;
/// Queue empty indicator
pub const errQUEUE_EMPTY: BaseType_t = 0;
/// Queue full indicator
pub const errQUEUE_FULL: BaseType_t = 0;
// =============================================================================
// Error codes (from projdefs.h)
// =============================================================================
/// Could not allocate required memory
pub const errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY: BaseType_t = -1;
/// Queue blocked
pub const errQUEUE_BLOCKED: BaseType_t = -4;
/// Queue yield
pub const errQUEUE_YIELD: BaseType_t = -5;
// =============================================================================
// Integrity check value (from projdefs.h)
// =============================================================================
/// Integrity check magic value - 16-bit ticks
pub const pdINTEGRITY_CHECK_VALUE: TickType_t = 0x5A5A;
/// Integrity check magic value - 32-bit ticks
pub const pdINTEGRITY_CHECK_VALUE: TickType_t = 0x5A5A_5A5A;
/// Integrity check magic value - 64-bit ticks
pub const pdINTEGRITY_CHECK_VALUE: TickType_t = 0x5A5A_5A5A_5A5A_5A5A;
// =============================================================================
// Task function type (from projdefs.h)
// =============================================================================
/// Task function prototype
/// `void vTaskFunction(void *pvParameters)`
///
/// [AMENDMENT] In Rust, we use a function pointer type. The `extern "C"` ensures
/// C-compatible calling convention for potential interop.
pub type TaskFunction_t = extern "C" fn;
// =============================================================================
// Utility macros as functions (from projdefs.h)
// =============================================================================
/// Convert milliseconds to ticks
/// Equivalent to pdMS_TO_TICKS macro
pub const
/// Convert ticks to milliseconds
/// Equivalent to pdTICKS_TO_MS macro
pub const
// =============================================================================
// Handle types (opaque pointers to kernel objects)
// =============================================================================
/// Task handle - opaque pointer to a task control block
pub type TaskHandle_t = *mut c_void;
// NOTE: QueueHandle_t, SemaphoreHandle_t, MutexHandle_t are defined in queue.rs
// to avoid circular dependencies
/// Timer handle - opaque pointer to a timer
pub type TimerHandle_t = *mut c_void;
/// Event group handle
pub type EventGroupHandle_t = *mut c_void;
/// Stream buffer handle
pub type StreamBufferHandle_t = *mut c_void;
/// Message buffer handle (same as stream buffer)
pub type MessageBufferHandle_t = StreamBufferHandle_t;
// =============================================================================
// Sleep Mode Status (for tickless idle)
// =============================================================================
/// Return type for eTaskConfirmSleepModeStatus
///
/// Used by the port layer to determine whether to enter a sleep mode.
// =============================================================================
// Null handle constant
// =============================================================================
/// Null handle value
pub const NULL_HANDLE: *mut c_void = null_mut;
// =============================================================================
// Task Status Structure (for vTaskGetInfo / uxTaskGetSystemState)
// =============================================================================
// Forward declare eTaskState - the actual enum is in tasks.rs
// We re-export it here for the TaskStatus_t struct
// [AMENDMENT] In C, eTaskState is defined in task.h. In Rust, the enum
// is in tasks.rs, so TaskStatus_t references it via the kernel module.
/// Task status information structure
///
/// Used by `vTaskGetInfo` and `uxTaskGetSystemState` to return detailed
/// information about a task.