Summary:
used AVR stacksize =2048 is:
min < avr < typical
min < avr < typical
1120 < 2048 < 2400
So 2048 is probably ok.
2048/size(int) = 2048/32 = 75 int variables would be allowed.
Since minimum is 1120, then 2048-1120=928 ==> 928/32= 29 automatic variables could be used by receiveThread function.
. 2048/size(int) = 2048/32 = 75 int variables would be allowed.
Since minimum is 1120, then 2048-1120=928 ==> 928/32= 29 automatic variables could be used by receiveThread function.
Background: AVR control code was written in C. Updating it from C to C++, it needed the most care due to its direct HW communication between the ARM and AVR. There may still be improvements, but changes need to be made carefully to not break working code.
.
Studying the code during the code review update.
1. Why the stack size of 2048 was chosen?
Answer: Value used in sample code in eCos Book:: Embedded SW Dev with eCos p.111 Code Listing 6.1: Thread Initialization Example
.
2. Is it really the best stacksize for the avr communication thread?
Still unknown, but the min stacksize and typical stacksize suggested via the eCos include comments and other references are:
.
p.117 ecos reference explains the constants used for CYGNUM_HAL_STACK_SIZE_MINIMUM and CYGNUM_HAL_STACK_SIZE_TYPICAL stacksizes and were found in hal_arch.h. The caclulated values are:
CYGNUM_HAL_STACK_FRAME_SIZE = (4 * 20) = 80
.
.
CYGNUM_HAL_STACK_INTERRUPT_SIZE=
((4 * 20) + 2 * CYGNUM_HAL_STACK_FRAME_SIZE) =
((4 * 20) + 2 * (4*20) = 240
.
.
CYGNUM_HAL_MAX_INTERRUPT_NESTING = 4
.
CYGNUM_HAL_STACK_SIZE_MINIMUM =
(CYGNUM_HAL_MAX_INTERRUPT_NESTING * CYGNUM_HAL_STACK_INTERRUPT_SIZE
4 * 240
+ 2 * CYGNUM_HAL_STACK_FRAME_SIZE) + 2 * 80
= 4* 240 + 2*80 = 1120
.
CYGNUM_HAL_STACK_SIZE_TYPICAL = (CYGNUM_HAL_STACK_SIZE_MINIMUM
+ 16 * CYGNUM_HAL_STACK_FRAME_SIZE)
= 1120 +16*(4*20) =2400
.
Info from comments;
// ...Idle thread stack should be this big.
.
// THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
// THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
.
// This is not a config option because it should not be adjusted except
// under "enough rope" sort of disclaimers.
.
This leads to the Summary at the top of this post.
This leads to the Summary at the top of this post.
No comments:
Post a Comment