embOS实时操作系统 - 堆栈 < Cortex M >

 

The stack has the same function as in a single-task system:

storage of return addresses of function calls,
parameters and local variables,
and temporary storage of intermediate calculation results and register values.

 

Task stack for Cortex M

All embOS tasks execute in thread mode using the process stack pointer. <PSP>

Each embOS task has a separate stack. The location and size of this stack is defined when creating the task

The stack itself is located in any RAM location.
Each task uses its individual stack.
The stack poiter is initialized and set every time a task is activated by the scheduler.
The stacksize required for a task is the sum of the stack-size of all routines
plus a basic stack size plus size used by exceptions.

The basic stack size is the size of memory required to store the registers of the CPU
plus the stack size required by calling embOS-routines.

For the Cortex M CPUs, this minimum basic task stack size is about 72 bytes.
Because any function call uses some amount of stack and
every exception also pushes at least 32 bytes onto the current stack,
the task stack size has to be large enough to handle one exception too.

We recommend at least 256 bytes stack as a start.

When Cortex M4F CPUs with VFPv4 are used,
keep in mind that the VFP registers may be pushed onto the stack
and will require additional 136 bytes of stack.

 

System stack for Cortex M

The embOS system executes in thread mode, the scheduler executes in handler mode.

The scheduler and OS_Idle() execute using the main stack pointer. <MSP>

The minimum system stack size required by embOS is about 136 bytes (stack check & profiling build)
However, since the system stack is also used by the application before the start of multitasking (the call to OS_Start()),
and because software-timers and .C.-level interrupt handlers also use the system-stack,
the actual stack requirements depend on the application.

The size of the system stack can be changed by modifying the CSTACK size in your *.icf file.

We recommend a minimum stack size of 256 bytes for the CSTACK.

Using a Cortex M4F CPU with floating point unit may require more stack,
because the floating point registers might be saved on the system stack also.

Interrupt stack for Cortex M

If a normal hardware exception occurs, the Cortex M core switches to handler mode which uses the main stack pointer.<MSP>

With embOS, the main stack pointer is initialized to use the CSTACK which is defined in the linker command file.
The main stack is also used as stack by the embOS scheduler and during idle times, when no task is ready to run and OS_Idle() is executed

 

<PSP>  initialized and set every time a task is activated by the scheduler <Task Stack>

<MSP> initialized from vector_table[0] < CSTACK >

            for the embOS system<Software Timers(and callback)>the embOS scheduler, OS_Idle(),  and hardware exception 

 

由于RTOS需占用一定的系统资源(尤其是RAM资源),只有μC/OS-II、embOS、salvo、FreeRTOS等少数实时操作系统能在小RAM单片机上运行。相对于C/OS-II、 embOS等商业操作系统,FreeRTOS操作系统是完全免费的操作系统,具有源码公开、可移植、可裁减、调度策略灵活的特点,可以方便地移植到各种单片机上运行,其最新版本为6.0版。 作为一个轻量级的操作系统,FreeRTOS提供的功能包括:任务管理、时间管理、信号量、消息队列、内存管理、记录功能等,可基本满足较小系统的需要。 FreeRTOS内核支持优先级调度算法,每个任务可根据重要程度的不同被赋予一定的优先级,CPU总是让处于就绪态的、优先级最高的任务先运行。 FreeRT0S内核同时支持轮换调度算法,系统允许不同的任务使用相同的优先级,在没有更高优先级任务就绪的情况下,同一优先级的任务共享CPU的使用 时间。 FreeRTOS的内核可根据用户需要设置为可剥夺型内核或不可剥夺型内核。当 FreeRTOS被设置为可剥夺型内核时,处于就绪态的高优先级任务能剥夺低优先级任务的CPU使用权,这样可保证系统满足实时性的要求;当 FreeRTOS被设置为不可剥夺型内核时,处于就绪态的高优先级任务只有等当前运行任务主动释放CPU的使用权后才能获得运行,这样可提高CPU的运行 效率。 FreeRTOS的移植:FreeRTOS操作系统可以被方便地移植到不同处理器上工作,现已提供了ARM、MSP430、 AVR、PIC、C8051F等多款处理器的移植。FrceRTOS在不同处理器上的移植类似于μC/0S一II,故本文不再详述FreeRTOS的移 植。此外,TCP/IP协议栈μIP已被移植到FreeRTOS上,具体代码可见FreeRTOS网站 相对于常见的μC/OS—II操作系统,FreeRTOS操作系统既有优点也存在不足。其不足之处, 一方面体现在系统的服务功能上,如FreeRTOS只提供了消息队列和信号量的实现,无法以后进先出的顺序向消息队列发送消息;另一方 面,FreeRTOS只是一个操作系统内核,需外扩第三方的GUI(图形用户界面)、TCP/IP协议栈、FS(文件系统)等才能实现一个较复杂的系统, 不像μC/OS-II可以和μC/GUI、μC/FS、μC/TCP-IP等无缝结合。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值