]> git.sur5r.net Git - freertos/blob - Source/portable/IAR/AtmelSAM7S64/ISR_Support.h
First version under SVN is V4.0.1
[freertos] / Source / portable / IAR / AtmelSAM7S64 / ISR_Support.h
1         EXTERN pxCurrentTCB\r
2         EXTERN ulCriticalNesting\r
3 \r
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
5 ; Context save and restore macro definitions\r
6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
7 \r
8 portSAVE_CONTEXT MACRO\r
9 \r
10         ; Push R0 as we are going to use the register.                                  \r
11         STMDB   SP!, {R0}\r
12 \r
13         ; Set R0 to point to the task stack pointer.                                    \r
14         STMDB   SP, {SP}^\r
15         NOP\r
16         SUB             SP, SP, #4\r
17         LDMIA   SP!, {R0}\r
18 \r
19         ; Push the return address onto the stack.                                               \r
20         STMDB   R0!, {LR}\r
21 \r
22         ; Now we have saved LR we can use it instead of R0.                             \r
23         MOV             LR, R0\r
24 \r
25         ; Pop R0 so we can save it onto the system mode stack.                  \r
26         LDMIA   SP!, {R0}\r
27 \r
28         ; Push all the system mode registers onto the task stack.               \r
29         STMDB   LR, {R0-LR}^\r
30         NOP\r
31         SUB             LR, LR, #60\r
32 \r
33         ; Push the SPSR onto the task stack.                                                    \r
34         MRS             R0, SPSR\r
35         STMDB   LR!, {R0}\r
36 \r
37         LDR             R0, =ulCriticalNesting \r
38         LDR             R0, [R0]\r
39         STMDB   LR!, {R0}\r
40 \r
41         ; Store the new top of stack for the task.                                              \r
42         LDR             R1, =pxCurrentTCB\r
43         LDR             R0, [R1]\r
44         STR             LR, [R0]\r
45 \r
46         ENDM\r
47 \r
48 \r
49 portRESTORE_CONTEXT MACRO\r
50 \r
51         ; Set the LR to the task stack.                                                                         \r
52         LDR             R1, =pxCurrentTCB\r
53         LDR             R0, [R1]\r
54         LDR             LR, [R0]\r
55 \r
56         ; The critical nesting depth is the first item on the stack.    \r
57         ; Load it into the ulCriticalNesting variable.                                  \r
58         LDR             R0, =ulCriticalNesting\r
59         LDMFD   LR!, {R1}\r
60         STR             R1, [R0]\r
61 \r
62         ; Get the SPSR from the stack.                                                                  \r
63         LDMFD   LR!, {R0}\r
64         MSR             SPSR_cxsf, R0\r
65 \r
66         ; Restore all system mode registers for the task.                               \r
67         LDMFD   LR, {R0-R14}^\r
68         NOP\r
69 \r
70         ; Restore the return address.                                                                   \r
71         LDR             LR, [LR, #+60]\r
72 \r
73         ; And return - correcting the offset in the LR to obtain the    \r
74         ; correct address.                                                                                              \r
75         SUBS    PC, LR, #4\r
76 \r
77         ENDM\r
78 \r