Nrk-api-stack

Version 2 (Anthony Rowe, 03/03/2007 09:15 pm)

1 1 Anthony Rowe
= Stack =
2 1 Anthony Rowe
3 1 Anthony Rowe
The stack for each task is separate and defined by the user. The kernel stack is located
4 1 Anthony Rowe
at the end of RAM and is not included in the BSS section of the code. On Atmel
5 1 Anthony Rowe
processors, the stack grows down. A Nano-RK stack is defined with the NRKSTK
6 1 Anthony Rowe
type. When a context swap occurs, each task stores its current state (32 registers + 1
7 1 Anthony Rowe
status register) on its own stack. This means that each application stack must be at least
8 1 Anthony Rowe
33 bytes longer than what the task locally requires.
9 1 Anthony Rowe
10 1 Anthony Rowe
11 1 Anthony Rowe
{{{
12 1 Anthony Rowe
// defined globally...
13 1 Anthony Rowe
NRK_STK Stack1[NRK_APP_STACKSIZE];
14 1 Anthony Rowe
nrk_task_type TaskOne;
15 1 Anthony Rowe
void Task1(void);
16 1 Anthony Rowe
...
17 1 Anthony Rowe
// Pass the task structure the stack upon creation
18 1 Anthony Rowe
TaskOne.task = Task1;
19 1 Anthony Rowe
TaskOne.Ptos = (void *) &Stack1[NRK_APP_STACKSIZE-1];
20 1 Anthony Rowe
TaskOne.Pbos = (void *) &Stack1[0];
21 1 Anthony Rowe
TaskOne.prio = 2;
22 1 Anthony Rowe
TaskOne.FirstActivation = TRUE;
23 1 Anthony Rowe
TaskOne.Type = BASIC_TASK;
24 1 Anthony Rowe
TaskOne.SchType = PREEMPTIVE;
25 1 Anthony Rowe
TaskOne.period.secs = 0;
26 1 Anthony Rowe
TaskOne.period.nano_secs = 500*NANOS_PER_MS;
27 1 Anthony Rowe
TaskOne.cpu_reserve.secs = 0;
28 1 Anthony Rowe
TaskOne.cpu_reserve.nano_secs = 100*NANOS_PER_MS;
29 1 Anthony Rowe
TaskOne.offset.secs = 0;
30 1 Anthony Rowe
TaskOne.offset.nano_secs= 0;
31 1 Anthony Rowe
nrk_activate_task (&TaskOne);
32 1 Anthony Rowe
}}}
33 1 Anthony Rowe
34 1 Anthony Rowe
Example of setting up an applications stack.
35 1 Anthony Rowe
36 1 Anthony Rowe
37 1 Anthony Rowe
When you compile, make sure that the .data section, .bss section and the kernel
38 1 Anthony Rowe
stack size combined is less than the total memory in the system. Application stacks
39 1 Anthony Rowe
will appear in the .bss region.
40 1 Anthony Rowe
Given that the atmel is a Harvard architecture, special instructions must be used to
41 1 Anthony Rowe
access addresses in ROM. This causes issues when you try to printf constant strings
42 1 Anthony Rowe
from ROM. GCC works around this problem by copying your string into RAM. This
43 1 Anthony Rowe
will use LOTS of RAM. If you have constant strings, use nrk_kprintf.
44 1 Anthony Rowe
45 1 Anthony Rowe
'''void nrk_stack_check( )'''
46 2 Anthony Rowe
47 1 Anthony Rowe
This function will check the canary value of the stack. This is a number stored at
48 1 Anthony Rowe
the bottom of the stack that can flag an error if over written due to a stack overflow.
49 1 Anthony Rowe
This function is automatically called when NRK_STACK_CHECK is defined in
50 1 Anthony Rowe
nrk_cfg.h on any suspend system calls.
51 1 Anthony Rowe
52 1 Anthony Rowe
53 1 Anthony Rowe
| [wiki:nrk-api Contents] | [wiki:nrk-api-signals-semaphores Signals and Semaphores] |