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