]> begriffs open source - cmsis-freertos/blob - Demo/PIC32MX_MPLAB/main.c
Update cmsis_os2.c
[cmsis-freertos] / Demo / PIC32MX_MPLAB / main.c
1 /*
2     FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70 /******************************************************************************
71  * This project provides two demo applications.  A simple blinky style project,
72  * and a more comprehensive test and demo application.  The
73  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
74  * select between the two.  The simply blinky demo is implemented and described
75  * in main_blinky.c.  The more comprehensive test and demo application is
76  * implemented and described in main_full.c.
77  *
78  * This file implements the code that is not demo specific, including the
79  * hardware setup and FreeRTOS hook functions.
80  */
81
82 /* Kernel includes. */
83 #include "FreeRTOS.h"
84 #include "task.h"
85
86 /* Standard demo includes. */
87 #include "partest.h"
88
89 /* Hardware specific includes. */
90 #include "ConfigPerformance.h"
91
92 /* Core configuratin fuse settings */
93 #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
94 #pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_2
95 #pragma config CP = OFF, BWP = OFF, PWP = OFF
96
97 /* Additional config fuse settings for other supported processors */
98 #if defined(__32MX460F512L__)
99         #pragma config UPLLEN = OFF
100 #elif defined(__32MX795F512L__)
101         #pragma config UPLLEN = OFF
102         #pragma config FSRSSEL = PRIORITY_7
103 #endif
104
105 /*-----------------------------------------------------------*/
106
107 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
108 or 0 to run the more comprehensive test and demo application. */
109 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0
110
111 /*-----------------------------------------------------------*/
112
113 /*
114  * Set up the hardware ready to run this demo.
115  */
116 static void prvSetupHardware( void );
117
118 /*
119  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
120  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
121  */
122 extern void main_blinky( void );
123 extern void main_full( void );
124
125 /*-----------------------------------------------------------*/
126
127 /*
128  * Create the demo tasks then start the scheduler.
129  */
130 int main( void )
131 {
132         /* Prepare the hardware to run this demo. */
133         prvSetupHardware();
134
135         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
136         of this file. */
137         #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
138         {
139                 main_blinky();
140         }
141         #else
142         {
143                 main_full();
144         }
145         #endif
146
147         return 0;
148 }
149 /*-----------------------------------------------------------*/
150
151 static void prvSetupHardware( void )
152 {
153         /* Configure the hardware for maximum performance. */
154         vHardwareConfigurePerformance();
155
156         /* Setup to use the external interrupt controller. */
157         vHardwareUseMultiVectoredInterrupts();
158
159         portDISABLE_INTERRUPTS();
160
161         /* Setup the digital IO for the LED's. */
162         vParTestInitialise();
163 }
164 /*-----------------------------------------------------------*/
165
166 void vApplicationMallocFailedHook( void )
167 {
168         /* vApplicationMallocFailedHook() will only be called if
169         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
170         function that will get called if a call to pvPortMalloc() fails.
171         pvPortMalloc() is called internally by the kernel whenever a task, queue,
172         timer or semaphore is created.  It is also called by various parts of the
173         demo application.  If heap_1.c or heap_2.c are used, then the size of the
174         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
175         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
176         to query the size of free heap space that remains (although it does not
177         provide information on how the remaining heap might be fragmented). */
178         taskDISABLE_INTERRUPTS();
179         for( ;; );
180 }
181 /*-----------------------------------------------------------*/
182
183 void vApplicationIdleHook( void )
184 {
185         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
186         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle
187         task.  It is essential that code added to this hook function never attempts
188         to block in any way (for example, call xQueueReceive() with a block time
189         specified, or call vTaskDelay()).  If the application makes use of the
190         vTaskDelete() API function (as this demo application does) then it is also
191         important that vApplicationIdleHook() is permitted to return to its calling
192         function, because it is the responsibility of the idle task to clean up
193         memory allocated by the kernel to any task that has since been deleted. */
194 }
195 /*-----------------------------------------------------------*/
196
197 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
198 {
199         ( void ) pcTaskName;
200         ( void ) pxTask;
201
202         /* Run time task stack overflow checking is performed if
203         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook function is 
204         called if a task stack overflow is detected.  Note the system/interrupt
205         stack is not checked. */
206         taskDISABLE_INTERRUPTS();
207         for( ;; );
208 }
209 /*-----------------------------------------------------------*/
210
211 void vApplicationTickHook( void )
212 {
213         /* This function will be called by each tick interrupt if
214         configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be
215         added here, but the tick hook is called from an interrupt context, so
216         code must not attempt to block, and only the interrupt safe FreeRTOS API
217         functions can be used (those that end in FromISR()). */
218 }
219 /*-----------------------------------------------------------*/
220
221 void _general_exception_handler( unsigned long ulCause, unsigned long ulStatus )
222 {
223         /* This overrides the definition provided by the kernel.  Other exceptions 
224         should be handled here. */
225         for( ;; );
226 }
227 /*-----------------------------------------------------------*/
228
229 void vAssertCalled( const char * pcFile, unsigned long ulLine )
230 {
231 volatile unsigned long ul = 0;
232
233         ( void ) pcFile;
234         ( void ) ulLine;
235
236         __asm volatile( "di" );
237         {
238                 /* Set ul to a non-zero value using the debugger to step out of this
239                 function. */
240                 while( ul == 0 )
241                 {
242                         portNOP();
243                 }
244         }
245         __asm volatile( "ei" );
246 }