]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_CEC1302_Keil_GCC/main.c
Update demo project for Tensilita - work in progres..
[freertos] / FreeRTOS / Demo / CORTEX_M4F_CEC1302_Keil_GCC / main.c
1 /*\r
2  * FreeRTOS Kernel V10.0.1\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.\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  * See http://www.freertos.org/Microchip_CEC1302_ARM_Cortex-M4F_Low_Power_Demo.html\r
30  *\r
31  * This project provides two demo applications.  A simple blinky style project\r
32  * that demonstrates low power tickless functionality, and a more comprehensive\r
33  * test and demo application.  The configCREATE_LOW_POWER_DEMO setting, which is\r
34  * defined in FreeRTOSConfig.h, is used to select between the two.  The simply\r
35  * blinky low power demo is implemented and described in main_low_power.c.  The\r
36  * more comprehensive test and demo application is implemented and described in\r
37  * main_full.c.\r
38  *\r
39  * The simple blinky demo uses aggregated interrupts.  The full demo uses\r
40  * disaggregated interrupts.\r
41  *\r
42  * This file implements the code that is not demo specific, including the\r
43  * hardware setup and standard FreeRTOS hook functions.\r
44  *\r
45  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
46  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
47  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
48  *\r
49  */\r
50 \r
51 /* Scheduler include files. */\r
52 #include "FreeRTOS.h"\r
53 #include "task.h"\r
54 \r
55 /* Hardware register addresses. */\r
56 #define mainVTOR                                        ( * ( uint32_t * ) 0xE000ED08 )\r
57 #define mainNVIC_AUX_ACTLR                      ( * ( uint32_t * ) 0xE000E008 )\r
58 #define mainEC_INTERRUPT_CONTROL        ( * ( volatile uint32_t * ) 0x4000FC18 )\r
59 \r
60 /*-----------------------------------------------------------*/\r
61 \r
62 /*\r
63  * Configure the hardware as necessary to run this demo.\r
64  */\r
65 static void prvSetupHardware( void );\r
66 \r
67 /*\r
68  * main_low_power() is used when configCREATE_LOW_POWER_DEMO is set to 1.\r
69  * main_full() is used when configCREATE_LOW_POWER_DEMO is set to 0.\r
70  */\r
71 #if( configCREATE_LOW_POWER_DEMO == 1 )\r
72 \r
73         extern void main_low_power( void );\r
74 \r
75 #else\r
76 \r
77         extern void main_full( void );\r
78 \r
79         /* Some of the tests and examples executed as part of the full demo make use\r
80         of the tick hook to call API functions from an interrupt context. */\r
81         extern void vFullDemoTickHook( void );\r
82 \r
83 #endif /* #if configCREATE_LOW_POWER_DEMO == 1 */\r
84 \r
85 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
86 within this file. */\r
87 void vApplicationMallocFailedHook( void );\r
88 void vApplicationIdleHook( void );\r
89 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
90 void vApplicationTickHook( void );\r
91 \r
92 /*-----------------------------------------------------------*/\r
93 \r
94 /* The variable that is incremented to represent each LED toggle.  On the\r
95 clicker hardware the LED state is set to the value of the least significant bit\r
96 of this variable.  On other hardware, where an LED is not used, the LED just\r
97 keeps a count of the number of times the LED would otherwise have been toggled.\r
98 See the comments in main_low_power.c and main_full.c for information on the\r
99 expected LED toggle rate). */\r
100 volatile uint32_t ulLED = 0;\r
101 \r
102 /*-----------------------------------------------------------*/\r
103 \r
104 int main( void )\r
105 {\r
106         /* See http://www.freertos.org/Microchip_CEC1302_ARM_Cortex-M4F_Low_Power_Demo.html */\r
107 \r
108         /* Configure the hardware ready to run the demo. */\r
109         prvSetupHardware();\r
110 \r
111         /* The configCREATE_LOW_POWER_DEMO setting is described at the top\r
112         of this file. */\r
113         #if( configCREATE_LOW_POWER_DEMO == 1 )\r
114         {\r
115                 /* The low power demo also demonstrated aggregated interrupts, so clear\r
116                 the interrupt control register to disable the alternative NVIC vectors. */\r
117                 mainEC_INTERRUPT_CONTROL = pdFALSE;\r
118 \r
119                 main_low_power();\r
120         }\r
121         #else\r
122         {\r
123                 /* The full demo also demonstrated disaggregated interrupts, so set the\r
124                 interrupt control register to enable the alternative NVIC vectors. */\r
125                 mainEC_INTERRUPT_CONTROL = pdTRUE;\r
126 \r
127                 main_full();\r
128         }\r
129         #endif\r
130 \r
131         /* Should not get here. */\r
132         return 0;\r
133 }\r
134 /*-----------------------------------------------------------*/\r
135 \r
136 static void prvSetupHardware( void )\r
137 {\r
138 extern void system_set_ec_clock( void );\r
139 extern unsigned long __Vectors[];\r
140 \r
141         /* Disable M4 write buffer: fix CEC1302 hardware bug. */\r
142         mainNVIC_AUX_ACTLR |= 0x07;\r
143 \r
144         system_set_ec_clock();\r
145 \r
146         /* Assuming downloading code via the debugger - so ensure the hardware\r
147         is using the vector table downloaded with the application. */\r
148         mainVTOR = ( uint32_t ) __Vectors;\r
149 }\r
150 /*-----------------------------------------------------------*/\r
151 \r
152 void vApplicationMallocFailedHook( void )\r
153 {\r
154         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
155         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
156         internally by FreeRTOS API functions that create tasks, queues, software\r
157         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
158         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
159 \r
160         /* Force an assert. */\r
161         configASSERT( ( volatile void * ) NULL );\r
162 }\r
163 /*-----------------------------------------------------------*/\r
164 \r
165 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
166 {\r
167         ( void ) pcTaskName;\r
168         ( void ) pxTask;\r
169 \r
170         /* Run time stack overflow checking is performed if\r
171         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
172         function is called if a stack overflow is detected. */\r
173 \r
174         /* Force an assert. */\r
175         configASSERT( ( volatile void * ) NULL );\r
176 }\r
177 /*-----------------------------------------------------------*/\r
178 \r
179 void vApplicationIdleHook( void )\r
180 {\r
181 volatile size_t xFreeHeapSpace;\r
182 \r
183         /* This is just a trivial example of an idle hook.  It is called on each\r
184         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
185         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
186         memory management section on the http://www.FreeRTOS.org web site for memory\r
187         management options.  If there is a lot of heap memory free then the\r
188         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
189         RAM. */\r
190         xFreeHeapSpace = xPortGetFreeHeapSize();\r
191 \r
192         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
193         ( void ) xFreeHeapSpace;\r
194 }\r
195 /*-----------------------------------------------------------*/\r
196 \r
197 void vApplicationTickHook( void )\r
198 {\r
199         /* The full demo includes tests that run from the tick hook. */\r
200         #if( configCREATE_LOW_POWER_DEMO == 0 )\r
201         {\r
202                 /* Some of the tests and demo tasks executed by the full demo include\r
203                 interaction from an interrupt - for which the tick interrupt is used\r
204                 via the tick hook function. */\r
205                 vFullDemoTickHook();\r
206         }\r
207         #endif\r
208 }\r
209 /*-----------------------------------------------------------*/\r
210 \r
211 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an\r
212 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is\r
213 used by the Idle task. */\r
214 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )\r
215 {\r
216 /* If the buffers to be provided to the Idle task are declared inside this\r
217 function then they must be declared static - otherwise they will be allocated on\r
218 the stack and so not exists after this function exits. */\r
219 static StaticTask_t xIdleTaskTCB;\r
220 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];\r
221 \r
222         /* Pass out a pointer to the StaticTask_t structure in which the Idle task's\r
223         state will be stored. */\r
224         *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
225 \r
226         /* Pass out the array that will be used as the Idle task's stack. */\r
227         *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
228 \r
229         /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\r
230         Note that, as the array is necessarily of type StackType_t,\r
231         configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
232         *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
233 }\r
234 /*-----------------------------------------------------------*/\r
235 \r
236 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the\r
237 application must provide an implementation of vApplicationGetTimerTaskMemory()\r
238 to provide the memory that is used by the Timer service task. */\r
239 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )\r
240 {\r
241 /* If the buffers to be provided to the Timer task are declared inside this\r
242 function then they must be declared static - otherwise they will be allocated on\r
243 the stack and so not exists after this function exits. */\r
244 static StaticTask_t xTimerTaskTCB;\r
245 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];\r
246 \r
247         /* Pass out a pointer to the StaticTask_t structure in which the Timer\r
248         task's state will be stored. */\r
249         *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
250 \r
251         /* Pass out the array that will be used as the Timer task's stack. */\r
252         *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
253 \r
254         /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.\r
255         Note that, as the array is necessarily of type StackType_t,\r
256         configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
257         *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
258 }\r
259 \r
260 \r