2 * FreeRTOS Kernel V10.2.1
\r
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\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
36 * This file implements the code that is not demo specific, including the
\r
37 * hardware setup and FreeRTOS hook functions.
\r
40 /* Kernel includes. */
\r
41 #include "FreeRTOS.h"
\r
44 /* Standard demo includes. */
\r
45 #include "partest.h"
\r
46 #include "QueueOverwrite.h"
\r
47 #include "QueueSet.h"
\r
48 #include "EventGroupsDemo.h"
\r
50 /* Hardware specific includes. */
\r
51 #include "ConfigPerformance.h"
\r
53 /* Core configuration fuse settings */
\r
54 #if defined(__32MZ2048ECM144) || defined(__32MZ2048ECH144)
\r
55 #pragma config FMIIEN = OFF, FETHIO = OFF, PGL1WAY = OFF, PMDL1WAY = OFF, IOL1WAY = OFF, FUSBIDIO = OFF
\r
56 #pragma config FNOSC = SPLL, FSOSCEN = OFF, IESO = OFF, POSCMOD = EC
\r
57 #pragma config OSCIOFNC = OFF, FCKSM = CSECMD, FWDTEN = OFF, FDMTEN = OFF
\r
58 #pragma config DMTINTV = WIN_127_128, WDTSPGM = STOP, WINDIS= NORMAL
\r
59 #pragma config WDTPS = PS1048576, FWDTWINSZ = WINSZ_25, DMTCNT = DMT31
\r
60 #pragma config FPLLIDIV = DIV_3, FPLLRNG = RANGE_13_26_MHZ, FPLLICLK = PLL_POSC
\r
61 #pragma config FPLLMULT = MUL_50, FPLLODIV = DIV_2, UPLLFSEL = FREQ_12MHZ, UPLLEN = OFF
\r
62 #pragma config EJTAGBEN = NORMAL, DBGPER = PG_ALL, FSLEEP = OFF, FECCCON = OFF_UNLOCKED
\r
63 #pragma config BOOTISA = MIPS32, TRCEN = ON, ICESEL = ICS_PGx2, JTAGEN = OFF, DEBUG = ON
\r
64 #pragma config CP = OFF
\r
65 #elif defined(__32MZ2048EFM144) || defined(__32MZ2048EFH144)
\r
66 #pragma config FMIIEN = OFF, FETHIO = OFF, PGL1WAY = OFF, PMDL1WAY = OFF, IOL1WAY = OFF, FUSBIDIO = OFF
\r
67 #pragma config FNOSC = SPLL, FSOSCEN = OFF, IESO = OFF, POSCMOD = EC
\r
68 #pragma config OSCIOFNC = OFF, FCKSM = CSECMD, FWDTEN = OFF, FDMTEN = OFF
\r
69 #pragma config DMTINTV = WIN_127_128, WDTSPGM = STOP, WINDIS= NORMAL
\r
70 #pragma config WDTPS = PS1048576, FWDTWINSZ = WINSZ_25, DMTCNT = DMT31
\r
71 #pragma config FPLLIDIV = DIV_3, FPLLRNG = RANGE_13_26_MHZ, FPLLICLK = PLL_POSC
\r
72 #pragma config FPLLMULT = MUL_50, FPLLODIV = DIV_2, UPLLFSEL = FREQ_12MHZ
\r
73 #pragma config EJTAGBEN = NORMAL, DBGPER = PG_ALL, FSLEEP = OFF, FECCCON = OFF_UNLOCKED
\r
74 #pragma config BOOTISA = MIPS32, TRCEN = ON, ICESEL = ICS_PGx2, JTAGEN = OFF, DEBUG = ON
\r
75 #pragma config CP = OFF
\r
78 /*-----------------------------------------------------------*/
\r
80 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
81 or 0 to run the more comprehensive test and demo application. */
\r
82 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
\r
84 /*-----------------------------------------------------------*/
\r
87 * Set up the hardware ready to run this demo.
\r
89 static void prvSetupHardware( void );
\r
92 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
93 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
95 extern void main_blinky( void );
\r
96 extern void main_full( void );
\r
98 /*-----------------------------------------------------------*/
\r
101 * Create the demo tasks then start the scheduler.
\r
105 /* Prepare the hardware to run this demo. */
\r
106 prvSetupHardware();
\r
108 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
110 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
\r
122 /*-----------------------------------------------------------*/
\r
124 static void prvSetupHardware( void )
\r
126 /* Configure the hardware for maximum performance. */
\r
127 vHardwareConfigurePerformance();
\r
129 /* Setup to use the external interrupt controller. */
\r
130 vHardwareUseMultiVectoredInterrupts();
\r
132 portDISABLE_INTERRUPTS();
\r
134 /* Setup the digital IO for the LED's. */
\r
135 vParTestInitialise();
\r
137 /*-----------------------------------------------------------*/
\r
139 void vApplicationMallocFailedHook( void )
\r
141 /* vApplicationMallocFailedHook() will only be called if
\r
142 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
143 function that will get called if a call to pvPortMalloc() fails.
\r
144 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
145 timer or semaphore is created. It is also called by various parts of the
\r
146 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
147 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
148 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
149 to query the size of free heap space that remains (although it does not
\r
150 provide information on how the remaining heap might be fragmented). */
\r
151 taskDISABLE_INTERRUPTS();
\r
154 /*-----------------------------------------------------------*/
\r
156 void vApplicationIdleHook( void )
\r
158 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
159 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
160 task. It is essential that code added to this hook function never attempts
\r
161 to block in any way (for example, call xQueueReceive() with a block time
\r
162 specified, or call vTaskDelay()). If the application makes use of the
\r
163 vTaskDelete() API function (as this demo application does) then it is also
\r
164 important that vApplicationIdleHook() is permitted to return to its calling
\r
165 function, because it is the responsibility of the idle task to clean up
\r
166 memory allocated by the kernel to any task that has since been deleted. */
\r
168 /*-----------------------------------------------------------*/
\r
170 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
172 ( void ) pcTaskName;
\r
175 /* Run time task stack overflow checking is performed if
\r
176 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
\r
177 called if a task stack overflow is detected. Note the system/interrupt
\r
178 stack is not checked. */
\r
179 taskDISABLE_INTERRUPTS();
\r
182 /*-----------------------------------------------------------*/
\r
184 void vApplicationTickHook( void )
\r
186 /* This function will be called by each tick interrupt if
\r
187 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
\r
188 added here, but the tick hook is called from an interrupt context, so
\r
189 code must not attempt to block, and only the interrupt safe FreeRTOS API
\r
190 functions can be used (those that end in FromISR()). */
\r
192 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
\r
194 /* Call the periodic queue overwrite from ISR demo. */
\r
195 vQueueOverwritePeriodicISRDemo();
\r
197 /* Call the queue set ISR test function. */
\r
198 vQueueSetAccessQueueSetFromISR();
\r
200 /* Exercise event groups from interrupts. */
\r
201 vPeriodicEventGroupsProcessing();
\r
205 /*-----------------------------------------------------------*/
\r
207 extern void vAssertCalled( const char * pcFile, unsigned long ulLine )
\r
209 volatile char *pcFileName;
\r
210 volatile unsigned long ulLineNumber;
\r
212 /* Prevent things that are useful to view in the debugger from being
\r
214 pcFileName = ( char * ) pcFile;
\r
215 ( void ) pcFileName;
\r
216 ulLineNumber = ulLine;
\r
218 /* Set ulLineNumber to 0 in the debugger to break out of this loop and
\r
219 return to the line that triggered the assert. */
\r
220 while( ulLineNumber != 0 )
\r
222 __asm volatile( "NOP" );
\r
223 __asm volatile( "NOP" );
\r
224 __asm volatile( "NOP" );
\r
225 __asm volatile( "NOP" );
\r
226 __asm volatile( "NOP" );
\r
229 /*-----------------------------------------------------------*/
\r
231 /* This function overrides the normal _weak_ generic handler. */
\r
232 void _general_exception_handler(void)
\r
235 EXCEP_IRQ = 0, /* interrupt */
\r
236 EXCEP_AdEL = 4, /* address error exception (load or ifetch) */
\r
237 EXCEP_AdES, /* address error exception (store) */
\r
238 EXCEP_IBE, /* bus error (ifetch) */
\r
239 EXCEP_DBE, /* bus error (load/store) */
\r
240 EXCEP_Sys, /* syscall */
\r
241 EXCEP_Bp, /* breakpoint */
\r
242 EXCEP_RI, /* reserved instruction */
\r
243 EXCEP_CpU, /* coprocessor unusable */
\r
244 EXCEP_Overflow, /* arithmetic overflow */
\r
245 EXCEP_Trap, /* trap (possible divide by zero) */
\r
246 EXCEP_FPE = 15, /* floating point exception */
\r
247 EXCEP_IS1 = 16, /* implementation specfic 1 */
\r
248 EXCEP_CEU, /* CorExtend Unuseable */
\r
249 EXCEP_C2E, /* coprocessor 2 */
\r
250 EXCEP_DSPDis = 26 /* DSP module disabled */
\r
253 static unsigned long _epc_code;
\r
254 static unsigned long _excep_addr;
\r
256 asm volatile( "mfc0 %0,$13" : "=r" (_epc_code) );
\r
257 asm volatile( "mfc0 %0,$14" : "=r" (_excep_addr) );
\r
259 _excep_code = ( _epc_code & 0x0000007C ) >> 2;
\r
263 /* prevent compiler warning */
\r
264 (void) _excep_code;
\r
266 /* Examine _excep_code to identify the type of exception. Examine
\r
267 _excep_addr to find the address that caused the exception */
\r
274 /*-----------------------------------------------------------*/
\r