]> git.sur5r.net Git - freertos/blob - Source/portable/IAR/ARM_CM3/portasm.s
32e79796b7f18fc872cd3bc08b538034d399d50b
[freertos] / Source / portable / IAR / ARM_CM3 / portasm.s
1 /*\r
2         FreeRTOS.org V4.7.2 - Copyright (C) 2003-2008 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section\r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26         ***************************************************************************\r
27 \r
28         Please ensure to read the configuration and relevant port sections of the \r
29         online documentation.\r
30 \r
31         +++ http://www.FreeRTOS.org +++\r
32         Documentation, latest information, license and contact details.  \r
33 \r
34         +++ http://www.SafeRTOS.com +++\r
35         A version that is certified for use in safety critical systems.\r
36 \r
37         +++ http://www.OpenRTOS.com +++\r
38         Commercial support, development, porting, licensing and training services.\r
39 \r
40         ***************************************************************************\r
41 */\r
42 \r
43 /*\r
44         Change from V4.2.1:\r
45 \r
46         + Introduced usage of configKERNEL_INTERRUPT_PRIORITY macro to set the\r
47           interrupt priority used by the kernel.\r
48 */\r
49 \r
50 #include <FreeRTOSConfig.h>\r
51 \r
52 /* For backward compatibility, ensure configKERNEL_INTERRUPT_PRIORITY is\r
53 defined.  The value zero should also ensure backward compatibility.\r
54 FreeRTOS.org versions prior to V4.3.0 did not include this definition. */\r
55 #ifndef configKERNEL_INTERRUPT_PRIORITY\r
56         #define configKERNEL_INTERRUPT_PRIORITY 0\r
57 #endif\r
58 \r
59         \r
60         RSEG    CODE:CODE(2)\r
61         thumb\r
62 \r
63         EXTERN vPortYieldFromISR\r
64         EXTERN vPortSwitchContext\r
65         EXTERN vPortIncrementTick\r
66         EXTERN uxCriticalNesting\r
67         EXTERN pxCurrentTCB\r
68 \r
69         PUBLIC vSetPSP\r
70         PUBLIC vSetMSP\r
71         PUBLIC xPortPendSVHandler\r
72         PUBLIC xPortSysTickHandler\r
73         PUBLIC vPortSetInterruptMask\r
74         PUBLIC vPortClearInterruptMask\r
75 \r
76 \r
77 vSetPSP:\r
78         msr psp, r0\r
79         bx lr\r
80         \r
81 /*-----------------------------------------------------------*/\r
82 \r
83 vSetMSP\r
84         msr msp, r0\r
85         bx lr\r
86         \r
87 /*-----------------------------------------------------------*/\r
88 \r
89 xPortPendSVHandler:\r
90         mrs r0, psp                                             \r
91         cbz r0, no_save                                 \r
92         /* Save the context into the TCB. */\r
93         stmdb r0!, {r4-r11}                             \r
94         sub r0, r0, #0x04                                       \r
95         ldr r1, =uxCriticalNesting\r
96         ldr r2, =pxCurrentTCB           \r
97         ldr r1, [r1]                                    \r
98         ldr r2, [r2]                                    \r
99         str r1, [r0]                                    \r
100         str r0, [r2]                                    \r
101                                                                         \r
102 no_save:\r
103         push {r14}                                              \r
104         bl vPortSwitchContext                   \r
105         pop {r14}                                               \r
106         /* Restore the context. */              \r
107         ldr r1, =pxCurrentTCB\r
108         ldr r1, [r1]                                    \r
109         ldr r0, [r1]                                    \r
110         ldmia r0!, {r1, r4-r11}                 \r
111         ldr r2, =uxCriticalNesting\r
112         str r1, [r2]                                    \r
113         msr psp, r0                                             \r
114         orr r14, r14, #0xd                                      \r
115         /* Exit with interrupts in the state required by the task. */\r
116         cbnz r1, sv_disable_interrupts  \r
117         bx r14                                                  \r
118                                                                         \r
119 sv_disable_interrupts:                          \r
120         mov     r1, #configKERNEL_INTERRUPT_PRIORITY\r
121         msr     basepri, R1\r
122         bx r14                                                  \r
123 \r
124 \r
125 /*-----------------------------------------------------------*/\r
126 \r
127 xPortSysTickHandler:\r
128         /* Call the scheduler tick function. */\r
129         push {r14}\r
130         bl vPortIncrementTick\r
131         pop {r14}\r
132         \r
133         /* If using preemption, also force a context switch. */\r
134         #if configUSE_PREEMPTION == 1\r
135                 push {r14}\r
136                 bl vPortYieldFromISR\r
137                 pop {r14}\r
138         #endif\r
139 \r
140         /* Exit with interrupts in the correct state. */\r
141     ldr r2, =uxCriticalNesting\r
142         ldr r2, [r2]\r
143         cbnz r2, tick_disable_interrupts\r
144         bx r14\r
145 \r
146 tick_disable_interrupts:\r
147         mov     r1, #configKERNEL_INTERRUPT_PRIORITY\r
148         msr     basepri, R1\r
149         \r
150         bx r14\r
151 \r
152 /*-----------------------------------------------------------*/\r
153 \r
154 vPortSetInterruptMask:\r
155         push { r0 }\r
156         mov R0, #configKERNEL_INTERRUPT_PRIORITY\r
157         msr BASEPRI, R0\r
158         pop { R0 }\r
159 \r
160         bx r14\r
161         \r
162 /*-----------------------------------------------------------*/\r
163 \r
164 vPortClearInterruptMask:\r
165         PUSH { r0 }\r
166         MOV R0, #0\r
167         MSR BASEPRI, R0\r
168         POP      { R0 }\r
169 \r
170         bx r14\r
171 \r
172 /*-----------------------------------------------------------*/\r
173 \r
174         END\r
175