]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D4x_EK_IAR/main.c
b2f34b4c7f589da8efcd2cdc7c0393d20792b760
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D4x_EK_IAR / main.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /******************************************************************************\r
30  * This project provides two demo applications.  A simple blinky style project,\r
31  * and a more comprehensive test and demo application.  The\r
32  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
33  * select between the two.  The simply blinky demo is implemented and described\r
34  * in main_blinky.c.  The more comprehensive test and demo application is\r
35  * implemented and described in main_full.c.\r
36  *\r
37  * This file implements the code that is not demo specific, including the\r
38  * hardware setup, standard FreeRTOS hook functions, and the ISR hander called\r
39  * by the RTOS after interrupt entry (including nesting) has been taken care of.\r
40  *\r
41  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
42  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
43  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
44  *\r
45  */\r
46 \r
47 /* Scheduler include files. */\r
48 #include "FreeRTOS.h"\r
49 #include "task.h"\r
50 #include "semphr.h"\r
51 \r
52 /* Standard demo includes. */\r
53 #include "partest.h"\r
54 #include "TimerDemo.h"\r
55 #include "QueueOverwrite.h"\r
56 #include "EventGroupsDemo.h"\r
57 \r
58 /* Library includes. */\r
59 #include "chip.h"\r
60 \r
61 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
62 or 0 to run the more comprehensive test and demo application. */\r
63 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1\r
64 \r
65 /*-----------------------------------------------------------*/\r
66 \r
67 /*\r
68  * Configure the hardware as necessary to run this demo.\r
69  */\r
70 static void prvSetupHardware( void );\r
71 \r
72 /*\r
73  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
74  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
75  */\r
76 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
77         extern void main_blinky( void );\r
78 #else\r
79         extern void main_full( void );\r
80 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
81 \r
82 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
83 within this file. */\r
84 void vApplicationMallocFailedHook( void );\r
85 void vApplicationIdleHook( void );\r
86 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
87 void vApplicationTickHook( void );\r
88 \r
89 /* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port\r
90 layer. */\r
91 void vApplicationIRQHandler( void );\r
92 \r
93 /*-----------------------------------------------------------*/\r
94 \r
95 int main( void )\r
96 {\r
97         /* Configure the hardware ready to run the demo. */\r
98         prvSetupHardware();\r
99 \r
100         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
101         of this file. */\r
102         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
103         {\r
104                 main_blinky();\r
105         }\r
106         #else\r
107         {\r
108                 main_full();\r
109         }\r
110         #endif\r
111 \r
112         return 0;\r
113 }\r
114 /*-----------------------------------------------------------*/\r
115 \r
116 static void prvSetupHardware( void )\r
117 {\r
118     /* Disable watchdog */\r
119     WDT_Disable( WDT );\r
120 \r
121         /* Set protect mode in the AIC for easier debugging.  THIS IS COMMENTED OUT\r
122         AS IT RESULTS IN SPURIOUS INTERRUPTS.\r
123         AIC->AIC_DCR |= AIC_DCR_PROT; */\r
124 \r
125         /* Configure ports used by LEDs. */\r
126         vParTestInitialise();\r
127 \r
128         #if defined (ddram)\r
129         {\r
130                 MMU_Initialize( ( uint32_t * ) 0x20C000 );\r
131                 CP15_EnableMMU();\r
132                 CP15_EnableDcache();\r
133                 CP15_EnableIcache();\r
134         }\r
135         #endif\r
136 }\r
137 /*-----------------------------------------------------------*/\r
138 \r
139 void vApplicationMallocFailedHook( void )\r
140 {\r
141         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
142         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
143         internally by FreeRTOS API functions that create tasks, queues, software\r
144         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
145         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
146 \r
147         /* Force an assert. */\r
148         configASSERT( ( volatile void * ) NULL );\r
149 }\r
150 /*-----------------------------------------------------------*/\r
151 \r
152 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
153 {\r
154         ( void ) pcTaskName;\r
155         ( void ) pxTask;\r
156 \r
157         /* Run time stack overflow checking is performed if\r
158         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
159         function is called if a stack overflow is detected. */\r
160 \r
161         /* Force an assert. */\r
162         configASSERT( ( volatile void * ) NULL );\r
163 }\r
164 /*-----------------------------------------------------------*/\r
165 \r
166 void vApplicationIdleHook( void )\r
167 {\r
168 volatile size_t xFreeHeapSpace;\r
169 \r
170         /* This is just a trivial example of an idle hook.  It is called on each\r
171         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
172         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
173         memory management section on the http://www.FreeRTOS.org web site for memory\r
174         management options.  If there is a lot of heap memory free then the\r
175         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
176         RAM. */\r
177         xFreeHeapSpace = xPortGetFreeHeapSize();\r
178 \r
179         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
180         ( void ) xFreeHeapSpace;\r
181 }\r
182 /*-----------------------------------------------------------*/\r
183 \r
184 void vAssertCalled( const char * pcFile, unsigned long ulLine )\r
185 {\r
186 volatile unsigned long ul = 0;\r
187 \r
188         ( void ) pcFile;\r
189         ( void ) ulLine;\r
190 \r
191         taskENTER_CRITICAL();\r
192         {\r
193                 /* Set ul to a non-zero value using the debugger to step out of this\r
194                 function. */\r
195                 while( ul == 0 )\r
196                 {\r
197                         portNOP();\r
198                 }\r
199         }\r
200         taskEXIT_CRITICAL();\r
201 }\r
202 /*-----------------------------------------------------------*/\r
203 \r
204 void vApplicationTickHook( void )\r
205 {\r
206         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
207         {\r
208                 /* The full demo includes a software timer demo/test that requires\r
209                 prodding periodically from the tick interrupt. */\r
210                 vTimerPeriodicISRTests();\r
211 \r
212                 /* Call the periodic queue overwrite from ISR demo. */\r
213                 vQueueOverwritePeriodicISRDemo();\r
214 \r
215                 /* Call the periodic event group from ISR demo. */\r
216                 vPeriodicEventGroupsProcessing();\r
217         }\r
218         #endif\r
219 }\r
220 /*-----------------------------------------------------------*/\r
221 \r
222 /* The function called by the RTOS port layer after it has managed interrupt\r
223 entry. */\r
224 void vApplicationIRQHandler( void )\r
225 {\r
226 typedef void (*ISRFunction_t)( void );\r
227 ISRFunction_t pxISRFunction;\r
228 volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;\r
229 \r
230         /* Obtain the address of the interrupt handler from the AIR. */\r
231         pxISRFunction = ( ISRFunction_t ) *pulAIC_IVR;\r
232 \r
233         /* Write back to the SAMA5's interrupt controller's IVR register in case the\r
234         CPU is in protect mode.  If the interrupt controller is not in protect mode\r
235         then this write is not necessary. */\r
236         *pulAIC_IVR = ( uint32_t ) pxISRFunction;\r
237 \r
238         /* Ensure the write takes before re-enabling interrupts. */\r
239         __DSB();\r
240         __ISB();\r
241     __enable_irq();\r
242 \r
243         /* Call the installed ISR. */\r
244         pxISRFunction();\r
245 }\r
246 \r