VSF Documented
portmacro.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18// Clean-room FreeRTOS portmacro.h shim for VSF.
19//
20// Only the primitive types FreeRTOS applications rely on are exposed here.
21// Architecture-specific primitives (portYIELD_FROM_ISR, portENTER_CRITICAL,
22// etc.) are mapped to VSF kernel operations where a sensible equivalent
23// exists; the rest become no-ops so that code written against FreeRTOS
24// compiles but the semantics are explicit in this header.
25
26#ifndef __VSF_FREERTOS_PORTMACRO_H__
27#define __VSF_FREERTOS_PORTMACRO_H__
28
29#include <stdint.h>
30#include <stddef.h>
31#include <stdbool.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/*============================ TYPES =========================================*/
38
39typedef long BaseType_t;
40typedef unsigned long UBaseType_t;
41
42// A tick is a systimer tick in the VSF shim. 32-bit matches FreeRTOS with
43// configUSE_16_BIT_TICKS == 0.
45#ifndef portMAX_DELAY
46# define portMAX_DELAY ((TickType_t)0xFFFFFFFFUL)
47#endif
48
49// StackType_t is documented as "the type used by the stack". FreeRTOS
50// applications pass stack budgets in units of StackType_t. We define it as
51// a byte so budgets are expressed in bytes, which matches how the VSF
52// thread API actually consumes them.
54
55/*============================ MACROS ========================================*/
56
57#ifndef pdFALSE
58# define pdFALSE ((BaseType_t)0)
59#endif
60#ifndef pdTRUE
61# define pdTRUE ((BaseType_t)1)
62#endif
63#ifndef pdPASS
64# define pdPASS pdTRUE
65#endif
66#ifndef pdFAIL
67# define pdFAIL pdFALSE
68#endif
69
70// Scheduler-level critical sections. Under the hood these call
71// vTaskEnterCritical / vTaskExitCritical (see task.h), which wrap
72// vsf_sched_lock with a nested-counter so pairs can safely nest.
73// The FromISR variants return/accept the saved scheduler state.
74//
75// ESP-IDF's FreeRTOS variant passes a portMUX_TYPE spinlock to the
76// macro -- we accept but ignore the argument on single-core targets.
77// Users that genuinely need IRQ-off sections should still call
78// vsf_protect_interrupt() directly.
79#define portENTER_CRITICAL(...) vTaskEnterCritical()
80#define portEXIT_CRITICAL(...) vTaskExitCritical()
81#define portENTER_CRITICAL_ISR(...) vTaskEnterCritical()
82#define portEXIT_CRITICAL_ISR(...) vTaskExitCritical()
83#define portDISABLE_INTERRUPTS() ((void)0)
84#define portENABLE_INTERRUPTS() ((void)0)
85
86// ESP-IDF portMUX_TYPE spinlock compatibility shim. On single-core VSF
87// targets there is no real spinlock to acquire; the type and its
88// initialiser are provided purely so code written for ESP-IDF compiles.
89typedef struct {
92#define portMUX_INITIALIZER_UNLOCKED { 0 }
93#define portMUX_FREE_VAL 0
94#define vPortCPUInitializeMutex(mux) do { (void)(mux); } while(0)
95
96// Entry points (defined in port/freertos_critical_port.c). Exposed
97// through portmacro.h so anything that includes FreeRTOS.h picks them up.
98extern void vTaskEnterCritical(void);
99extern void vTaskExitCritical(void);
101extern void vTaskExitCriticalFromISR(UBaseType_t uxSavedInterruptState);
102
103#define taskENTER_CRITICAL(...) vTaskEnterCritical()
104#define taskEXIT_CRITICAL(...) vTaskExitCritical()
105#define taskENTER_CRITICAL_ISR(...) vTaskEnterCriticalFromISR()
106#define taskEXIT_CRITICAL_ISR(x) vTaskExitCriticalFromISR((UBaseType_t)(x))
107#define taskENTER_CRITICAL_FROM_ISR(...) vTaskEnterCriticalFromISR()
108#define taskEXIT_CRITICAL_FROM_ISR(x) vTaskExitCriticalFromISR((UBaseType_t)(x))
109
110// Stack budget unit. FreeRTOS defines configMINIMAL_STACK_SIZE in units of
111// StackType_t. In this shim one unit == one byte.
112#define portSTACK_TYPE StackType_t
113#define portBASE_TYPE BaseType_t
114
115// portTICK_PERIOD_MS is the number of milliseconds per kernel tick. The VSF
116// shim maps FreeRTOS ticks 1:1 to milliseconds so that pdMS_TO_TICKS is the
117// identity. The underlying sleep still uses systimer ticks internally.
118#ifndef portTICK_PERIOD_MS
119# define portTICK_PERIOD_MS ((TickType_t)1)
120#endif
121#ifndef portTICK_RATE_MS
122# define portTICK_RATE_MS portTICK_PERIOD_MS
123#endif
124
125// Placeholder: real ISR yield must be deferred to the scheduler on the
126// caller side. Documented as a best-effort no-op.
127#define portYIELD_FROM_ISR(x) ((void)(x))
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif // __VSF_FREERTOS_PORTMACRO_H__
uint8_t StackType_t
Definition portmacro.h:53
UBaseType_t vTaskEnterCriticalFromISR(void)
Definition freertos_critical_port.c:134
long BaseType_t
Definition portmacro.h:39
unsigned long UBaseType_t
Definition portmacro.h:40
uint32_t TickType_t
Definition portmacro.h:44
void vTaskExitCritical(void)
Definition freertos_critical_port.c:95
void vTaskExitCriticalFromISR(UBaseType_t uxSavedInterruptState)
Definition freertos_critical_port.c:139
void vTaskEnterCritical(void)
Definition freertos_critical_port.c:84
uint32_t UBaseType_t
Definition rtos_al.h:60
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
Definition portmacro.h:89
uint32_t _placeholder
Definition portmacro.h:90
Generated from commit: vsfteam/vsf@015f4d1