arch_task.h 源码
2026/7/20大约 2 分钟源码参考架构层任务管理头文件
arch_task.h — 任务栈架构层接口头文件
源文件路径: arch/arm/armv7m/include/arch_task.h
引用章节: 4.2 任务管理
完整源码
/**
***********************************************************************************************************************
* Copyright (c) 2020, China Mobile Communications Group Co.,Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* @file arch_task.h
*
* @brief Header file for task stack functions.
*
* @revision
* Date Author Notes
* 2021-10-22 OneOS Team First version.
***********************************************************************************************************************
*/
#ifndef __ARCH_TASK_H__
#define __ARCH_TASK_H__
#include <os_types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define OS_ARCH_STACK_ALIGN_SIZE 8
struct cpu_stack_frame
{
uint32_t r0;
uint32_t r1;
uint32_t r2;
uint32_t r3;
uint32_t r12;
uint32_t lr;
uint32_t pc;
uint32_t psr;
};
struct cpu_stack_frame_fpu
{
uint32_t r0;
uint32_t r1;
uint32_t r2;
uint32_t r3;
uint32_t r12;
uint32_t lr;
uint32_t pc;
uint32_t psr;
/* FPU registers */
uint32_t S0;
uint32_t S1;
uint32_t S2;
uint32_t S3;
uint32_t S4;
uint32_t S5;
uint32_t S6;
uint32_t S7;
uint32_t S8;
uint32_t S9;
uint32_t S10;
uint32_t S11;
uint32_t S12;
uint32_t S13;
uint32_t S14;
uint32_t S15;
uint32_t FPSCR;
uint32_t NO_NAME;
};
struct stack_frame_common
{
uint32_t r4;
uint32_t r5;
uint32_t r6;
uint32_t r7;
uint32_t r8;
uint32_t r9;
uint32_t r10;
uint32_t r11;
uint32_t exc_return;
};
struct stack_frame_nofpu
{
/* Push or pop stack manually */
uint32_t r4;
uint32_t r5;
uint32_t r6;
uint32_t r7;
uint32_t r8;
uint32_t r9;
uint32_t r10;
uint32_t r11;
uint32_t exc_return;
/* Push or pop stack automatically */
uint32_t r0;
uint32_t r1;
uint32_t r2;
uint32_t r3;
uint32_t r12;
uint32_t lr;
uint32_t pc;
uint32_t psr;
};
struct stack_frame_fpu
{
/* begin: Push or pop stack manually */
uint32_t r4;
uint32_t r5;
uint32_t r6;
uint32_t r7;
uint32_t r8;
uint32_t r9;
uint32_t r10;
uint32_t r11;
uint32_t exc_return;
/* FPU registers */
uint32_t s16;
uint32_t s17;
uint32_t s18;
uint32_t s19;
uint32_t s20;
uint32_t s21;
uint32_t s22;
uint32_t s23;
uint32_t s24;
uint32_t s25;
uint32_t s26;
uint32_t s27;
uint32_t s28;
uint32_t s29;
uint32_t s30;
uint32_t s31;
/* end: Push or pop stack manually */
/* begin: Push or pop stack automatically */
uint32_t r0;
uint32_t r1;
uint32_t r2;
uint32_t r3;
uint32_t r12;
uint32_t lr;
uint32_t pc;
uint32_t psr;
/* FPU registers */
uint32_t S0;
uint32_t S1;
uint32_t S2;
uint32_t S3;
uint32_t S4;
uint32_t S5;
uint32_t S6;
uint32_t S7;
uint32_t S8;
uint32_t S9;
uint32_t S10;
uint32_t S11;
uint32_t S12;
uint32_t S13;
uint32_t S14;
uint32_t S15;
uint32_t FPSCR;
uint32_t NO_NAME;
/* end: Push or pop stack automatically */
};
extern void *os_hw_stack_init(void (*task_entry)(void *arg),
void *arg,
void *stack_begin,
uint32_t stack_size,
void (*task_exit)(void));
extern uint32_t os_hw_stack_max_used(void *stack_begin, uint32_t stack_size);
extern void os_first_task_start(void);
extern void os_task_switch(void);
#ifdef OS_USING_OVERFLOW_CHECK
extern os_bool_t os_task_stack_is_overflow(void *stack_top, void *stack_begin, void *stack_end);
#endif
#ifdef __cplusplus
}
#endif
#endif /* __ARCH_TASK_H__ */关键说明
| 模块 | 说明 |
|---|---|
| 栈对齐 | OS_ARCH_STACK_ALIGN_SIZE = 8,ARM Cortex-M 要求 8 字节对齐 |
| 栈帧结构 | 定义了 4 种栈帧结构:cpu_stack_frame(异常自动入栈)、cpu_stack_frame_fpu(含 FPU)、stack_frame_nofpu(完整无 FPU 栈帧)、stack_frame_fpu(完整含 FPU 栈帧) |
| 栈初始化 | os_hw_stack_init 初始化任务栈,填充 EXC_RETURN(0xFFFFFFFD),返回栈顶指针 |
| 栈检测 | os_hw_stack_max_used 从栈底扫描 $ 标记计算最大使用量 |
| 任务切换 | os_first_task_start(启动第一个任务)和 os_task_switch |