Chapter 5
As a reminder, the location of the .StkLimitPtr is determined by the “ stk_limit ”
argument passed to OSTaskCreate() , when the task is created as shown below:
OS_TCB
MtTaskTCB;
CPU_STK MyTaskStk[1000];
OSTaskCreate(&MyTaskTCB,
“MyTaskName”,
MyTask,
&MyTaskArg,
MyPrio,
&MyTaskStk[0], /* Stack base address */
100 , /* Set .StkLimitPtr to trigger exception at stack usage > 90% */
1000, /* Total stack size (in CPU_STK elements) */
MyTaskQSize,
MyTaskTimeQuanta,
(void *)0,
MY_TASK_OPT,
&err);
Of course, the value of .StkLimitPtr used by the CPU’s stack overflow detection hardware
needs to be changed whenever μC/OS-III performs a context switch. This can be tricky
because the value of this register may need to be changed so that it first points to NULL ,
then change the CPU’s stack pointer, and finally set the value of the stack checking register
to the value saved in the TCB’s .StkLimitPtr . Why? Because if the sequence is not
followed, the exception could be generated as soon as the stack pointer or the stack
overflow detection register is changed. One can avoid this problem by first changing the
stack overflow detection register to point to a location that ensures the stack pointer is
never invalid (thus the NULL as described above). Note that I assumed here that the stack
grows from high memory to low memory but the concept works in a similar fashion if the
stack grows in the opposite direction.
3) Software-based stack overflow detection
Whenever μC/OS-III switches from one task to another, it calls a “hook” function
( OSTaskSwHook() ), which allows the μC/OS-III port programmer to extend the capabilities
of the context switch function. So, if the processor doesn’t have hardware stack pointer
overflow detection, it’s still possible to “simulate” this feature by adding code in the context
switch hook function and, perform the overflow detection in software. Specifically, before a
task is switched in, the code should ensure that the stack pointer to load into the CPU does
not exceed the “limit” placed in .StkLimitPtr . Because the software implementation
88
相关PDF资料
AD-UCUSBD-SPRD PRD LIC UCUSB DEV CORE CCES SGL
AD637-EVALZ BOARD EVALUATION FOR AD637
AD736-EVALZ BOARD EVALUATION FOR AD736
AD737-EVALZ BOARD EVALUATION FOR AD737
AD8007AKS-EBZ BOARD EVAL FOR AD8007AKS
AD8018ARU-EVAL BOARD EVAL FOR AD8018
AD8034ART-EBZ BOARD EVAL FOR AD8034ART
AD8040AR-EBZ BOARD EVAL FOR AD8040AR
相关代理商/技术参数
ADUCOSC100 制造商:Analog Devices 功能描述:ADC - Rail/Tube
ADUCOSC100-REEL 功能描述:DAC MICROCONVERTER DUAL TSSOP 制造商:analog devices inc. 系列:* 零件状态:上次购买时间 标准包装:1
ADUCOSC100-REEL7 功能描述:DAC MICROCONVERTER DUAL TSSOP 制造商:analog devices inc. 系列:* 零件状态:上次购买时间 标准包装:1
ADUCOSCZ100 制造商:Analog Devices 功能描述:
ADUCOSCZ100-REEL7 制造商:Analog Devices 功能描述:ANAADUCOSCZ100-REEL7 12 BIT ADC WITH EMB
ADuC-P7026 功能描述:开发板和工具包 - ARM PROTOTYPE BRD FOR ADUC7026 ARM7 RoHS:否 制造商:Arduino 产品:Development Boards 工具用于评估:ATSAM3X8EA-AU 核心:ARM Cortex M3 接口类型:DAC, ICSP, JTAG, UART, USB 工作电源电压:3.3 V
ADUCRF101 制造商:Analog Devices 功能描述:PRECISION ANALOG MICRCONTROLLER - Tape and Reel
ADUCRF101BCPZ128 制造商:Analog Devices 功能描述:PRECISION ANALOG MICROCONTROLLER WITH RF TRANSCEIVER, ARM CO - Trays