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