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