]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/main.c
Update copyright date ready for tagging V10.1.0.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / main.c
1 /*\r
2  * FreeRTOS Kernel V10.1.0\r
3  * Copyright (C) 2018 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.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /******************************************************************************\r
29  * This project provides two demo applications.  A simple blinky style project,\r
30  * and a more comprehensive test and demo application.  The\r
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
32  * select between the two.  The simply blinky demo is implemented and described\r
33  * in main_blinky.c.  The more comprehensive test and demo application is\r
34  * implemented and described in main_full.c.\r
35  *\r
36  * This file implements the code that is not demo specific, including the\r
37  * hardware setup, standard FreeRTOS hook functions, and the ISR hander called\r
38  * by the RTOS after interrupt entry (including nesting) has been taken care of.\r
39  *\r
40  * NOTE on LEDS:\r
41  *\r
42  *     This demo is NOT configured to use the LED built onto the SAMA6D2\r
43  *     XPLained board!\r
44  *\r
45  *     The LED driver PIN_LED definitions have been altered in\r
46  *     board_sama5d2-xplained.h to remap them to GPIOs terminating on pins 30,\r
47  *     32 and 34 of J17. (This change is conditional on the preprocessor\r
48  *     #define "LEDS_ON_J17".) These GPIOs are configured to be "high drive"\r
49  *     push-pull outputs; they can source up to 18mA at 1.8v. Low\r
50  *     forward-voltage LEDs may be connected via 100 ohm resistors to pins\r
51  *     30, 32 and 34 with their cathodes to pin 35/36 (GND).\r
52  *\r
53  */\r
54 \r
55 /*\r
56  * Procedure to download and execute code from RAM\r
57  * -----------------------------------------------\r
58  *\r
59  * 1. Close jumper JP9(BOOT_DIS) and JP2(DEBUG_DIS).\r
60  * 2. Open jumper JP1(EDBG_DIS).\r
61  * 3. Power on the board by USB connection on J14(EDBG_JTAG).\r
62  * 4. Open \93EDBG Virtual COM Port\94 with setting \9357600,8,N,1\94.\r
63  * 5. Type \93#\94 on HyperTerminal and get \93>\94 as a reply.\r
64  * 6. Don\92t reset the board during debugging. For IAR, set the Debugger to CMSIS\r
65  *    DAP, with the "Disabled(no reset)" option.\r
66  */\r
67 \r
68 /* Scheduler include files. */\r
69 #include "FreeRTOS.h"\r
70 #include "task.h"\r
71 #include "semphr.h"\r
72 \r
73 /* Standard demo includes. */\r
74 #include "partest.h"\r
75 #include "TimerDemo.h"\r
76 #include "QueueOverwrite.h"\r
77 #include "EventGroupsDemo.h"\r
78 \r
79 /* Library includes. */\r
80 #include "board_sama5d2-xplained.h"\r
81 #include "peripherals/wdt.h"\r
82 #include "peripherals/pio.h"\r
83 #include "chip.h"\r
84 \r
85 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
86 or 0 to run the more comprehensive test and demo application. */\r
87 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1\r
88 \r
89 /*-----------------------------------------------------------*/\r
90 \r
91 /*\r
92  * Configure the hardware as necessary to run this demo.\r
93  */\r
94 static void prvSetupHardware( void );\r
95 \r
96 /*\r
97  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
98  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
99  */\r
100 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
101         extern void main_blinky( void );\r
102 #else\r
103         extern void main_full( void );\r
104 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
105 \r
106 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
107 within this file. */\r
108 void vApplicationMallocFailedHook( void );\r
109 void vApplicationIdleHook( void );\r
110 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
111 void vApplicationTickHook( void );\r
112 \r
113 /* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port\r
114 layer. */\r
115 void vApplicationIRQHandler( void );\r
116 \r
117 /*-----------------------------------------------------------*/\r
118 \r
119 int main( void )\r
120 {\r
121         /* Configure the hardware ready to run the demo. */\r
122         prvSetupHardware();\r
123 \r
124         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
125         of this file. */\r
126         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
127         {\r
128                 main_blinky();\r
129         }\r
130         #else\r
131         {\r
132                 main_full();\r
133         }\r
134         #endif\r
135 \r
136         return 0;\r
137 }\r
138 /*-----------------------------------------------------------*/\r
139 \r
140 static void prvSetupHardware( void )\r
141 {\r
142         /* Disable watchdog */\r
143         wdt_disable( );\r
144 \r
145         /* Set protect mode in the AIC for easier debugging. */\r
146         AIC->AIC_DCR |= AIC_DCR_PROT;\r
147 \r
148         /* Configure ports used by LEDs. */\r
149         vParTestInitialise();\r
150 \r
151         #if defined (ddram)\r
152                 MMU_Initialize( ( uint32_t * ) 0x30C000 );\r
153                 CP15_EnableMMU();\r
154                 CP15_EnableDcache();\r
155                 CP15_EnableIcache();\r
156         #endif\r
157 }\r
158 /*-----------------------------------------------------------*/\r
159 \r
160 void vApplicationMallocFailedHook( void )\r
161 {\r
162         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
163         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
164         internally by FreeRTOS API functions that create tasks, queues, software\r
165         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
166         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
167 \r
168         /* Force an assert. */\r
169         configASSERT( ( volatile void * ) NULL );\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
174 {\r
175         ( void ) pcTaskName;\r
176         ( void ) pxTask;\r
177 \r
178         /* Run time stack overflow checking is performed if\r
179         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
180         function is called if a stack overflow is detected. */\r
181 \r
182         /* Force an assert. */\r
183         configASSERT( ( volatile void * ) NULL );\r
184 }\r
185 /*-----------------------------------------------------------*/\r
186 \r
187 void vApplicationIdleHook( void )\r
188 {\r
189 volatile size_t xFreeHeapSpace;\r
190 \r
191         /* This is just a trivial example of an idle hook.  It is called on each\r
192         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
193         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
194         memory management section on the http://www.FreeRTOS.org web site for memory\r
195         management options.  If there is a lot of heap memory free then the\r
196         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
197         RAM. */\r
198         xFreeHeapSpace = xPortGetFreeHeapSize();\r
199 \r
200         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
201         ( void ) xFreeHeapSpace;\r
202 }\r
203 /*-----------------------------------------------------------*/\r
204 \r
205 void vAssertCalled( const char * pcFile, unsigned long ulLine )\r
206 {\r
207 volatile unsigned long ul = 0;\r
208 \r
209         ( void ) pcFile;\r
210         ( void ) ulLine;\r
211 \r
212         taskENTER_CRITICAL();\r
213         {\r
214                 /* Set ul to a non-zero value using the debugger to step out of this\r
215                 function. */\r
216                 while( ul == 0 )\r
217                 {\r
218                         portNOP();\r
219                 }\r
220         }\r
221         taskEXIT_CRITICAL();\r
222 }\r
223 /*-----------------------------------------------------------*/\r
224 \r
225 void vApplicationTickHook( void )\r
226 {\r
227         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
228         {\r
229                 /* The full demo includes a software timer demo/test that requires\r
230                 prodding periodically from the tick interrupt. */\r
231                 vTimerPeriodicISRTests();\r
232 \r
233                 /* Call the periodic queue overwrite from ISR demo. */\r
234                 vQueueOverwritePeriodicISRDemo();\r
235 \r
236                 /* Call the periodic event group from ISR demo. */\r
237                 vPeriodicEventGroupsProcessing();\r
238         }\r
239         #endif\r
240 }\r
241 /*-----------------------------------------------------------*/\r
242 \r
243 /* The function called by the RTOS port layer after it has managed interrupt\r
244 entry. */\r
245 void vApplicationIRQHandler( void )\r
246 {\r
247 typedef void (*ISRFunction_t)( void );\r
248 ISRFunction_t pxISRFunction;\r
249 volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;\r
250 \r
251         /* Obtain the address of the interrupt handler from the AIR. */\r
252         pxISRFunction = ( ISRFunction_t ) *pulAIC_IVR;\r
253 \r
254         /* Write back to the SAMA5's interrupt controller's IVR register in case the\r
255         CPU is in protect mode.  If the interrupt controller is not in protect mode\r
256         then this write is not necessary. */\r
257         *pulAIC_IVR = ( uint32_t ) pxISRFunction;\r
258 \r
259         /* Ensure the write takes before re-enabling interrupts. */\r
260         __DSB();\r
261         __ISB();\r
262         __enable_irq();\r
263 \r
264         /* Call the installed ISR. */\r
265         pxISRFunction();\r
266 }\r
267 \r
268 /* Keep the linker quiet. */\r
269 size_t __write(int, const unsigned char *, size_t);\r
270 size_t __write(int f, const unsigned char *p, size_t s)\r
271 {\r
272   (void) f;\r
273   (void) p;\r
274   (void) s;\r
275   return 0;\r
276 }\r
277 \r
278 \r
279 \r