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// for vsf_systimer_tick_t
34#include "kernel/vsf_kernel.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/*============================ TYPES =========================================*/
41
42typedef long BaseType_t;
43typedef unsigned long UBaseType_t;
44
46#ifndef portMAX_DELAY
47# define portMAX_DELAY ((TickType_t)-1)
48#endif
49
50// StackType_t is documented as "the type used by the stack". FreeRTOS
51// applications pass stack budgets in units of StackType_t. We define it as
52// a byte so budgets are expressed in bytes, which matches how the VSF
53// thread API actually consumes them.
55
56/*============================ MACROS ========================================*/
57
58#ifndef pdFALSE
59# define pdFALSE ((BaseType_t)0)
60#endif
61#ifndef pdTRUE
62# define pdTRUE ((BaseType_t)1)
63#endif
64#ifndef pdPASS
65# define pdPASS pdTRUE
66#endif
67#ifndef pdFAIL
68# define pdFAIL pdFALSE
69#endif
70
71// Scheduler-level critical sections. Under the hood these call
72// vTaskEnterCritical / vTaskExitCritical (see task.h), which wrap
73// vsf_sched_lock with a nested-counter so pairs can safely nest.
74// The FromISR variants return/accept the saved scheduler state.
75//
76// ESP-IDF's FreeRTOS variant passes a portMUX_TYPE spinlock to the
77// macro -- we accept but ignore the argument on single-core targets.
78// Users that genuinely need IRQ-off sections should still call
79// vsf_protect_interrupt() directly.
80#define portENTER_CRITICAL(...) vTaskEnterCritical()
81#define portEXIT_CRITICAL(...) vTaskExitCritical()
82#define portENTER_CRITICAL_ISR(...) vTaskEnterCritical()
83#define portEXIT_CRITICAL_ISR(...) vTaskExitCritical()
84#define portDISABLE_INTERRUPTS() ((void)0)
85#define portENABLE_INTERRUPTS() ((void)0)
86
87// ESP-IDF portMUX_TYPE spinlock compatibility shim. On single-core VSF
88// targets there is no real spinlock to acquire; the type and its
89// initialiser are provided purely so code written for ESP-IDF compiles.
90typedef struct {
93#define portMUX_INITIALIZER_UNLOCKED { 0 }
94#define portMUX_FREE_VAL 0
95#define vPortCPUInitializeMutex(mux) do { (void)(mux); } while(0)
96
97// Entry points (defined in port/freertos_critical_port.c). Exposed
98// through portmacro.h so anything that includes FreeRTOS.h picks them up.
99extern void vTaskEnterCritical(void);
100extern void vTaskExitCritical(void);
102extern void vTaskExitCriticalFromISR(UBaseType_t uxSavedInterruptState);
103
104#define taskENTER_CRITICAL(...) vTaskEnterCritical()
105#define taskEXIT_CRITICAL(...) vTaskExitCritical()
106#define taskENTER_CRITICAL_ISR(...) vTaskEnterCriticalFromISR()
107#define taskEXIT_CRITICAL_ISR(x) vTaskExitCriticalFromISR((UBaseType_t)(x))
108#define taskENTER_CRITICAL_FROM_ISR(...) vTaskEnterCriticalFromISR()
109#define taskEXIT_CRITICAL_FROM_ISR(x) vTaskExitCriticalFromISR((UBaseType_t)(x))
110
111// Stack budget unit. FreeRTOS defines configMINIMAL_STACK_SIZE in units of
112// StackType_t. In this shim one unit == one byte.
113#define portSTACK_TYPE StackType_t
114#define portBASE_TYPE BaseType_t
115
116// portTICK_PERIOD_MS is the number of milliseconds per kernel tick. The VSF
117// shim maps FreeRTOS ticks 1:1 to milliseconds so that pdMS_TO_TICKS is the
118// identity. The underlying sleep still uses systimer ticks internally.
119#ifndef portTICK_PERIOD_MS
120# define portTICK_PERIOD_MS ((TickType_t)1)
121#endif
122#ifndef portTICK_RATE_MS
123# define portTICK_RATE_MS portTICK_PERIOD_MS
124#endif
125
126// Placeholder: real ISR yield must be deferred to the scheduler on the
127// caller side. Documented as a best-effort no-op.
128#define portYIELD_FROM_ISR(x) ((void)(x))
129
130#ifdef __cplusplus
131}
132#endif
133
134#endif // __VSF_FREERTOS_PORTMACRO_H__
uint64_t vsf_systimer_tick_t
Definition cortex_a_generic.h:70
uint8_t StackType_t
Definition portmacro.h:54
UBaseType_t vTaskEnterCriticalFromISR(void)
Definition freertos_critical_port.c:134
long BaseType_t
Definition portmacro.h:42
unsigned long UBaseType_t
Definition portmacro.h:43
void vTaskExitCritical(void)
Definition freertos_critical_port.c:95
vsf_systimer_tick_t TickType_t
Definition portmacro.h:45
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:90
uint32_t _placeholder
Definition portmacro.h:91
Generated from commit: vsfteam/vsf@c3767bf