]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4_ATSAM4S_Atmel_Studio/src/main.c
7f76ad50165f7226949fe7efa78c4305ebeac471
[freertos] / FreeRTOS / Demo / CORTEX_M4_ATSAM4S_Atmel_Studio / src / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 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 and FreeRTOS hook functions.\r
38  *\r
39  */\r
40 \r
41 /* Standard includes. */\r
42 #include <stdio.h>\r
43 \r
44 /* Kernel includes. */\r
45 #include "FreeRTOS.h"\r
46 #include "task.h"\r
47 \r
48 /* Standard demo includes. */\r
49 #include "partest.h"\r
50 \r
51 /* Atmel library includes. */\r
52 #include <asf.h>\r
53 \r
54 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
55 or 0 to run the more comprehensive test and demo application. */\r
56 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
57 \r
58 /*-----------------------------------------------------------*/\r
59 \r
60 /*\r
61  * Set up the hardware ready to run this demo.\r
62  */\r
63 static void prvSetupHardware( void );\r
64 \r
65 /*\r
66  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
67  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
68  */\r
69 extern void main_blinky( void );\r
70 extern void main_full( void );\r
71 \r
72 /*-----------------------------------------------------------*/\r
73 \r
74 /* See the documentation page for this demo on the FreeRTOS.org web site for\r
75 full information - including hardware setup requirements. */\r
76 \r
77 int main( void )\r
78 {\r
79         /* Prepare the hardware to run this demo. */\r
80         prvSetupHardware();\r
81 \r
82         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
83         of this file. */\r
84         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
85         {\r
86                 main_blinky();\r
87         }\r
88         #else\r
89         {\r
90                 main_full();\r
91         }\r
92         #endif\r
93 \r
94         return 0;\r
95 }\r
96 /*-----------------------------------------------------------*/\r
97 \r
98 static void prvSetupHardware( void )\r
99 {\r
100 extern void SystemCoreClockUpdate( void );\r
101 \r
102         /* ASF function to setup clocking. */\r
103         sysclk_init();\r
104 \r
105         /* Ensure all priority bits are assigned as preemption priority bits. */\r
106         NVIC_SetPriorityGrouping( 0 );\r
107 \r
108         /* Atmel library function to setup for the evaluation kit being used. */\r
109         board_init();\r
110 \r
111         /* Perform any configuration necessary to use the ParTest LED output\r
112         functions. */\r
113         vParTestInitialise();\r
114 }\r
115 /*-----------------------------------------------------------*/\r
116 \r
117 void vApplicationMallocFailedHook( void )\r
118 {\r
119         /* vApplicationMallocFailedHook() will only be called if\r
120         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
121         function that will get called if a call to pvPortMalloc() fails.\r
122         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
123         timer or semaphore is created.  It is also called by various parts of the\r
124         demo application.  If heap_1.c or heap_2.c are used, then the size of the\r
125         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
126         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
127         to query the size of free heap space that remains (although it does not\r
128         provide information on how the remaining heap might be fragmented). */\r
129         taskDISABLE_INTERRUPTS();\r
130         for( ;; );\r
131 }\r
132 /*-----------------------------------------------------------*/\r
133 \r
134 void vApplicationIdleHook( void )\r
135 {\r
136         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set\r
137         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle\r
138         task.  It is essential that code added to this hook function never attempts\r
139         to block in any way (for example, call xQueueReceive() with a block time\r
140         specified, or call vTaskDelay()).  If the application makes use of the\r
141         vTaskDelete() API function (as this demo application does) then it is also\r
142         important that vApplicationIdleHook() is permitted to return to its calling\r
143         function, because it is the responsibility of the idle task to clean up\r
144         memory allocated by the kernel to any task that has since been deleted. */\r
145         \r
146         #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )\r
147         {\r
148         extern void vFullDemoIdleHook( void );\r
149         \r
150                 vFullDemoIdleHook();\r
151         }\r
152         #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */\r
153 }\r
154 /*-----------------------------------------------------------*/\r
155 \r
156 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
157 {\r
158         ( void ) pcTaskName;\r
159         ( void ) pxTask;\r
160 \r
161         /* Run time stack overflow checking is performed if\r
162         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
163         function is called if a stack overflow is detected. */\r
164         taskDISABLE_INTERRUPTS();\r
165         for( ;; );\r
166 }\r
167 /*-----------------------------------------------------------*/\r
168 \r
169 void vApplicationTickHook( void )\r
170 {\r
171         /* This function will be called by each tick interrupt if\r
172         configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be\r
173         added here, but the tick hook is called from an interrupt context, so\r
174         code must not attempt to block, and only the interrupt safe FreeRTOS API\r
175         functions can be used (those that end in FromISR()).  */\r
176 \r
177         #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )\r
178         {\r
179         extern void vFullDemoTickHook( void );\r
180         \r
181                 vFullDemoTickHook();\r
182         }\r
183         #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */\r
184 }\r
185 /*-----------------------------------------------------------*/\r
186 \r