]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/CORTUS_APS3/port.c
Make Cortex-M0 set/clear interrupt flag from ISR functions nestable.
[freertos] / FreeRTOS / Source / portable / GCC / CORTUS_APS3 / port.c
1 /*\r
2     FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
5 \r
6     ***************************************************************************\r
7      *                                                                       *\r
8      *    FreeRTOS provides completely free yet professionally developed,    *\r
9      *    robust, strictly quality controlled, supported, and cross          *\r
10      *    platform software that has become a de facto standard.             *\r
11      *                                                                       *\r
12      *    Help yourself get started quickly and support the FreeRTOS         *\r
13      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
14      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
15      *                                                                       *\r
16      *    Thank you!                                                         *\r
17      *                                                                       *\r
18     ***************************************************************************\r
19 \r
20     This file is part of the FreeRTOS distribution.\r
21 \r
22     FreeRTOS is free software; you can redistribute it and/or modify it under\r
23     the terms of the GNU General Public License (version 2) as published by the\r
24     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
25 \r
26     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
27     >>! a combined work that includes FreeRTOS without being obliged to provide\r
28     >>! the source code for proprietary components outside of the FreeRTOS\r
29     >>! kernel.\r
30 \r
31     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
32     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
33     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
34     link: http://www.freertos.org/a00114.html\r
35 \r
36     1 tab == 4 spaces!\r
37 \r
38     ***************************************************************************\r
39      *                                                                       *\r
40      *    Having a problem?  Start by reading the FAQ "My application does   *\r
41      *    not run, what could be wrong?"                                     *\r
42      *                                                                       *\r
43      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
44      *                                                                       *\r
45     ***************************************************************************\r
46 \r
47     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
48     license and Real Time Engineers Ltd. contact details.\r
49 \r
50     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
51     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
52     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
53 \r
54     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
55     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
56     licenses offer ticketed support, indemnification and middleware.\r
57 \r
58     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
59     engineered and independently SIL3 certified version for use in safety and\r
60     mission critical applications that require provable dependability.\r
61 \r
62     1 tab == 4 spaces!\r
63 */\r
64 \r
65 /* Standard includes. */\r
66 #include <stdlib.h>\r
67 \r
68 /* Kernel includes. */\r
69 #include "FreeRTOS.h"\r
70 #include "task.h"\r
71 \r
72 /* Machine includes */\r
73 #include <machine/counter.h>\r
74 #include <machine/ic.h>\r
75 /*-----------------------------------------------------------*/\r
76 \r
77 /* The initial PSR has the Previous Interrupt Enabled (PIEN) flag set. */\r
78 #define portINITIAL_PSR                 ( 0x00020000 )\r
79 \r
80 /*-----------------------------------------------------------*/\r
81 \r
82 /*\r
83  * Perform any hardware configuration necessary to generate the tick interrupt.\r
84  */\r
85 static void prvSetupTimerInterrupt( void );\r
86 /*-----------------------------------------------------------*/\r
87 \r
88 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
89 {\r
90         /* Make space on the stack for the context - this leaves a couple of spaces\r
91         empty.  */\r
92         pxTopOfStack -= 20;\r
93 \r
94         /* Fill the registers with known values to assist debugging. */\r
95         pxTopOfStack[ 16 ] = 0;\r
96         pxTopOfStack[ 15 ] = portINITIAL_PSR;\r
97         pxTopOfStack[ 14 ] = ( unsigned long ) pxCode;\r
98         pxTopOfStack[ 13 ] = 0x00000000UL; /* R15. */\r
99         pxTopOfStack[ 12 ] = 0x00000000UL; /* R14. */\r
100         pxTopOfStack[ 11 ] = 0x0d0d0d0dUL;\r
101         pxTopOfStack[ 10 ] = 0x0c0c0c0cUL;\r
102         pxTopOfStack[ 9 ] = 0x0b0b0b0bUL;\r
103         pxTopOfStack[ 8 ] = 0x0a0a0a0aUL;\r
104         pxTopOfStack[ 7 ] = 0x09090909UL;\r
105         pxTopOfStack[ 6 ] = 0x08080808UL;\r
106         pxTopOfStack[ 5 ] = 0x07070707UL;\r
107         pxTopOfStack[ 4 ] = 0x06060606UL;\r
108         pxTopOfStack[ 3 ] = 0x05050505UL;\r
109         pxTopOfStack[ 2 ] = 0x04040404UL;\r
110         pxTopOfStack[ 1 ] = 0x03030303UL;\r
111         pxTopOfStack[ 0 ] = ( unsigned long ) pvParameters;\r
112 \r
113         return pxTopOfStack;\r
114 }\r
115 /*-----------------------------------------------------------*/\r
116 \r
117 portBASE_TYPE xPortStartScheduler( void )\r
118 {\r
119         /* Set-up the timer interrupt. */\r
120         prvSetupTimerInterrupt();\r
121 \r
122         /* Integrated Interrupt Controller: Enable all interrupts. */\r
123         ic->ien = 1;\r
124 \r
125         /* Restore callee saved registers. */\r
126         portRESTORE_CONTEXT();\r
127 \r
128         /* Should not get here. */\r
129         return 0;\r
130 }\r
131 /*-----------------------------------------------------------*/\r
132 \r
133 static void prvSetupTimerInterrupt( void )\r
134 {\r
135         /* Enable timer interrupts */\r
136         counter1->reload = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1;\r
137         counter1->value = counter1->reload;\r
138         counter1->mask = 1;\r
139 \r
140         /* Set the IRQ Handler priority and enable it. */\r
141         irq[ IRQ_COUNTER1 ].ien = 1;\r
142 }\r
143 /*-----------------------------------------------------------*/\r
144 \r
145 /* Trap 31 handler. */\r
146 void interrupt31_handler( void ) __attribute__((naked));\r
147 void interrupt31_handler( void )\r
148 {\r
149         portSAVE_CONTEXT();\r
150         __asm volatile ( "call vTaskSwitchContext" );\r
151         portRESTORE_CONTEXT();\r
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 static void prvProcessTick( void ) __attribute__((noinline));\r
156 static void prvProcessTick( void )\r
157 {\r
158         if( xTaskIncrementTick() != pdFALSE )\r
159         {\r
160                 vTaskSwitchContext();\r
161         }\r
162                 \r
163         /* Clear the Tick Interrupt. */\r
164         counter1->expired = 0;\r
165 }\r
166 /*-----------------------------------------------------------*/\r
167 \r
168 /* Timer 1 interrupt handler, used for tick interrupt. */\r
169 void interrupt7_handler( void ) __attribute__((naked));\r
170 void interrupt7_handler( void )\r
171 {\r
172         portSAVE_CONTEXT();\r
173         prvProcessTick();\r
174         portRESTORE_CONTEXT();\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 void vPortEndScheduler( void )\r
179 {\r
180         /* Nothing to do. Unlikely to want to end. */\r
181 }\r
182 /*-----------------------------------------------------------*/\r