3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
28 /******************************************************************************
29 * This project provides two demo applications. A simple blinky style project,
30 * and a more comprehensive test and demo application. The
31 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
32 * select between the two. The simply blinky demo is implemented and described
33 * in main_blinky.c. The more comprehensive test and demo application is
34 * implemented and described in main_full.c.
36 * This file implements the code that is not demo specific, including the
37 * hardware setup and FreeRTOS hook functions.
40 /* Kernel includes. */
44 /* Standard demo includes. */
47 /* Hardware specific includes. */
48 #include "ConfigPerformance.h"
50 /* Core configuratin fuse settings */
51 #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
52 #pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_2
53 #pragma config CP = OFF, BWP = OFF, PWP = OFF
55 /* Additional config fuse settings for other supported processors */
56 #if defined(__32MX460F512L__)
57 #pragma config UPLLEN = OFF
58 #elif defined(__32MX795F512L__)
59 #pragma config UPLLEN = OFF
60 #pragma config FSRSSEL = PRIORITY_7
63 /*-----------------------------------------------------------*/
65 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
66 or 0 to run the more comprehensive test and demo application. */
67 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
69 /*-----------------------------------------------------------*/
72 * Set up the hardware ready to run this demo.
74 static void prvSetupHardware( void );
77 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
78 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
80 extern void main_blinky( void );
81 extern void main_full( void );
83 /*-----------------------------------------------------------*/
86 * Create the demo tasks then start the scheduler.
90 /* Prepare the hardware to run this demo. */
93 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
95 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
107 /*-----------------------------------------------------------*/
109 static void prvSetupHardware( void )
111 /* Configure the hardware for maximum performance. */
112 vHardwareConfigurePerformance();
114 /* Setup to use the external interrupt controller. */
115 vHardwareUseMultiVectoredInterrupts();
117 portDISABLE_INTERRUPTS();
119 /* Setup the digital IO for the LED's. */
120 vParTestInitialise();
122 /*-----------------------------------------------------------*/
124 void vApplicationMallocFailedHook( void )
126 /* vApplicationMallocFailedHook() will only be called if
127 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
128 function that will get called if a call to pvPortMalloc() fails.
129 pvPortMalloc() is called internally by the kernel whenever a task, queue,
130 timer or semaphore is created. It is also called by various parts of the
131 demo application. If heap_1.c or heap_2.c are used, then the size of the
132 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
133 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
134 to query the size of free heap space that remains (although it does not
135 provide information on how the remaining heap might be fragmented). */
136 taskDISABLE_INTERRUPTS();
139 /*-----------------------------------------------------------*/
141 void vApplicationIdleHook( void )
143 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
144 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
145 task. It is essential that code added to this hook function never attempts
146 to block in any way (for example, call xQueueReceive() with a block time
147 specified, or call vTaskDelay()). If the application makes use of the
148 vTaskDelete() API function (as this demo application does) then it is also
149 important that vApplicationIdleHook() is permitted to return to its calling
150 function, because it is the responsibility of the idle task to clean up
151 memory allocated by the kernel to any task that has since been deleted. */
153 /*-----------------------------------------------------------*/
155 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
160 /* Run time task stack overflow checking is performed if
161 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
162 called if a task stack overflow is detected. Note the system/interrupt
163 stack is not checked. */
164 taskDISABLE_INTERRUPTS();
167 /*-----------------------------------------------------------*/
169 void vApplicationTickHook( void )
171 /* This function will be called by each tick interrupt if
172 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
173 added here, but the tick hook is called from an interrupt context, so
174 code must not attempt to block, and only the interrupt safe FreeRTOS API
175 functions can be used (those that end in FromISR()). */
177 /*-----------------------------------------------------------*/
179 void _general_exception_handler( unsigned long ulCause, unsigned long ulStatus )
181 /* This overrides the definition provided by the kernel. Other exceptions
182 should be handled here. */
185 /*-----------------------------------------------------------*/
187 void vAssertCalled( const char * pcFile, unsigned long ulLine )
189 volatile unsigned long ul = 0;
194 __asm volatile( "di" );
196 /* Set ul to a non-zero value using the debugger to step out of this
203 __asm volatile( "ei" );