]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D3x_Xplained_IAR/main.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D3x_Xplained_IAR / main.c
1 /*\r
2     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95 \r
96 /******************************************************************************\r
97  * This project provides two demo applications.  A simple blinky style project,\r
98  * and a more comprehensive test and demo application.  The\r
99  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
100  * select between the two.  The simply blinky demo is implemented and described\r
101  * in main_blinky.c.  The more comprehensive test and demo application is\r
102  * implemented and described in main_full.c.\r
103  *\r
104  * This file implements the code that is not demo specific, including the\r
105  * hardware setup, standard FreeRTOS hook functions, and the ISR hander called\r
106  * by the RTOS after interrupt entry (including nesting) has been taken care of.\r
107  *\r
108  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
109  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
110  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
111  *\r
112  */\r
113 \r
114 /* Scheduler include files. */\r
115 #include "FreeRTOS.h"\r
116 #include "task.h"\r
117 #include "semphr.h"\r
118 \r
119 /* Standard demo includes. */\r
120 #include "partest.h"\r
121 #include "TimerDemo.h"\r
122 #include "QueueOverwrite.h"\r
123 #include "EventGroupsDemo.h"\r
124 \r
125 /* Library includes. */\r
126 #include "chip.h"\r
127 \r
128 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
129 or 0 to run the more comprehensive test and demo application. */\r
130 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1\r
131 \r
132 /*-----------------------------------------------------------*/\r
133 \r
134 /*\r
135  * Configure the hardware as necessary to run this demo.\r
136  */\r
137 static void prvSetupHardware( void );\r
138 \r
139 /*\r
140  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
141  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
142  */\r
143 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
144         extern void main_blinky( void );\r
145 #else\r
146         extern void main_full( void );\r
147 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
148 \r
149 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
150 within this file. */\r
151 void vApplicationMallocFailedHook( void );\r
152 void vApplicationIdleHook( void );\r
153 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
154 void vApplicationTickHook( void );\r
155 \r
156 /* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port\r
157 layer. */\r
158 void vApplicationIRQHandler( void );\r
159 \r
160 /*-----------------------------------------------------------*/\r
161 \r
162 int main( void )\r
163 {\r
164         /* Configure the hardware ready to run the demo. */\r
165         prvSetupHardware();\r
166 \r
167         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
168         of this file. */\r
169         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
170         {\r
171                 main_blinky();\r
172         }\r
173         #else\r
174         {\r
175                 main_full();\r
176         }\r
177         #endif\r
178 \r
179         return 0;\r
180 }\r
181 /*-----------------------------------------------------------*/\r
182 \r
183 static void prvSetupHardware( void )\r
184 {\r
185     /* Disable watchdog */\r
186     WDT_Disable( WDT );\r
187 \r
188         /* Set protect mode in the AIC for easier debugging. */\r
189         AIC->AIC_DCR |= AIC_DCR_PROT;\r
190 \r
191         /* Configure ports used by LEDs. */\r
192         vParTestInitialise();\r
193 \r
194         #if defined (ddram)\r
195                 MMU_Initialize( ( uint32_t * ) 0x30C000 );\r
196                 CP15_EnableMMU();\r
197                 CP15_EnableDcache();\r
198                 CP15_EnableIcache();\r
199         #endif\r
200 }\r
201 /*-----------------------------------------------------------*/\r
202 \r
203 void vApplicationMallocFailedHook( void )\r
204 {\r
205         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
206         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
207         internally by FreeRTOS API functions that create tasks, queues, software\r
208         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
209         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
210 \r
211         /* Force an assert. */\r
212         configASSERT( ( volatile void * ) NULL );\r
213 }\r
214 /*-----------------------------------------------------------*/\r
215 \r
216 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
217 {\r
218         ( void ) pcTaskName;\r
219         ( void ) pxTask;\r
220 \r
221         /* Run time stack overflow checking is performed if\r
222         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
223         function is called if a stack overflow is detected. */\r
224 \r
225         /* Force an assert. */\r
226         configASSERT( ( volatile void * ) NULL );\r
227 }\r
228 /*-----------------------------------------------------------*/\r
229 \r
230 void vApplicationIdleHook( void )\r
231 {\r
232 volatile size_t xFreeHeapSpace;\r
233 \r
234         /* This is just a trivial example of an idle hook.  It is called on each\r
235         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
236         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
237         memory management section on the http://www.FreeRTOS.org web site for memory\r
238         management options.  If there is a lot of heap memory free then the\r
239         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
240         RAM. */\r
241         xFreeHeapSpace = xPortGetFreeHeapSize();\r
242 \r
243         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
244         ( void ) xFreeHeapSpace;\r
245 }\r
246 /*-----------------------------------------------------------*/\r
247 \r
248 void vAssertCalled( const char * pcFile, unsigned long ulLine )\r
249 {\r
250 volatile unsigned long ul = 0;\r
251 \r
252         ( void ) pcFile;\r
253         ( void ) ulLine;\r
254 \r
255         taskENTER_CRITICAL();\r
256         {\r
257                 /* Set ul to a non-zero value using the debugger to step out of this\r
258                 function. */\r
259                 while( ul == 0 )\r
260                 {\r
261                         portNOP();\r
262                 }\r
263         }\r
264         taskEXIT_CRITICAL();\r
265 }\r
266 /*-----------------------------------------------------------*/\r
267 \r
268 void vApplicationTickHook( void )\r
269 {\r
270         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
271         {\r
272                 /* The full demo includes a software timer demo/test that requires\r
273                 prodding periodically from the tick interrupt. */\r
274                 vTimerPeriodicISRTests();\r
275 \r
276                 /* Call the periodic queue overwrite from ISR demo. */\r
277                 vQueueOverwritePeriodicISRDemo();\r
278 \r
279                 /* Call the periodic event group from ISR demo. */\r
280                 vPeriodicEventGroupsProcessing();\r
281         }\r
282         #endif\r
283 }\r
284 /*-----------------------------------------------------------*/\r
285 \r
286 /* The function called by the RTOS port layer after it has managed interrupt\r
287 entry. */\r
288 void vApplicationIRQHandler( void )\r
289 {\r
290 typedef void (*ISRFunction_t)( void );\r
291 ISRFunction_t pxISRFunction;\r
292 volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;\r
293 \r
294         /* Obtain the address of the interrupt handler from the AIR. */\r
295         pxISRFunction = ( ISRFunction_t ) *pulAIC_IVR;\r
296 \r
297         /* Write back to the SAMA5's interrupt controller's IVR register in case the\r
298         CPU is in protect mode.  If the interrupt controller is not in protect mode\r
299         then this write is not necessary. */\r
300         *pulAIC_IVR = ( uint32_t ) pxISRFunction;\r
301 \r
302         /* Ensure the write takes before re-enabling interrupts. */\r
303         __DSB();\r
304         __ISB();\r
305     __enable_irq();\r
306 \r
307         /* Call the installed ISR. */\r
308         pxISRFunction();\r
309 }\r
310 \r
311 \r