2 * FreeRTOS Kernel V10.2.0
\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
30 * Create implementation of vPortSetupTimerInterrupt() if the CLINT is not
\r
31 * available, but make sure the configCLINT_BASE_ADDRESS constant is still
\r
34 * Define vPortHandleInterrupt to whatever the interrupt handler is called. In
\r
35 * this case done by defining vPortHandleInterrupt=SystemIrqHandler on the
\r
36 * assembler command line as SystemIrqHandler is referenced from both FreeRTOS
\r
37 * code and the libraries that come with the Vega board.
\r
40 /* FreeRTOS kernel includes. */
\r
41 #include <FreeRTOS.h>
\r
44 /* Vega includes. */
\r
45 #include "fsl_device_registers.h"
\r
46 #include "fsl_debug_console.h"
\r
48 #include "pin_mux.h"
\r
49 #include "clock_config.h"
\r
52 /******************************************************************************
\r
53 * This project provides two demo applications. A simple blinky style project,
\r
54 * and a more comprehensive test and demo application. The
\r
55 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
\r
56 * select between the two. The simply blinky demo is implemented and described
\r
57 * in main_blinky.c. The more comprehensive test and demo application is
\r
58 * implemented and described in main_full.c.
\r
60 * This file implements the code that is not demo specific, including the
\r
61 * hardware setup and standard FreeRTOS hook functions.
\r
63 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
\r
64 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
\r
65 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
\r
69 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
70 or 0 to run the more comprehensive test and demo application. */
\r
71 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
\r
74 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
75 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
77 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
\r
78 extern void main_blinky( void );
\r
80 extern void main_full( void );
\r
81 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\r
83 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
84 within this file. See https://www.freertos.org/a00016.html */
\r
85 void vApplicationMallocFailedHook( void );
\r
86 void vApplicationIdleHook( void );
\r
87 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
88 void vApplicationTickHook( void );
\r
90 /* Prepare haredware to run the demo. */
\r
91 static void prvSetupHardware( void );
\r
93 /* Send a messaage to the UART initialised in prvSetupHardware. */
\r
94 void vSendString( const char * const pcString );
\r
96 /*-----------------------------------------------------------*/
\r
100 prvSetupHardware();
\r
102 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
104 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
114 /*-----------------------------------------------------------*/
\r
116 static void prvSetupHardware( void )
\r
118 gpio_pin_config_t mGpioPinConfigStruct;
\r
120 /* Init board hardware. */
\r
122 BOARD_BootClockRUN();
\r
123 BOARD_InitDebugConsole();
\r
126 mGpioPinConfigStruct.outputLogic = 1U; /* High. */
\r
127 mGpioPinConfigStruct.pinDirection = kGPIO_DigitalOutput;
\r
128 GPIO_PinInit( BOARD_LED1_GPIO, BOARD_LED1_GPIO_PIN, &mGpioPinConfigStruct );
\r
130 /*-----------------------------------------------------------*/
\r
132 void vToggleLED( void )
\r
134 GPIO_TogglePinsOutput( BOARD_LED1_GPIO, 1U << BOARD_LED1_GPIO_PIN );
\r
136 /*-----------------------------------------------------------*/
\r
138 void vSendString( const char * const pcString )
\r
140 PRINTF( pcString );
\r
142 /*-----------------------------------------------------------*/
\r
144 void vApplicationMallocFailedHook( void )
\r
146 /* vApplicationMallocFailedHook() will only be called if
\r
147 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
148 function that will get called if a call to pvPortMalloc() fails.
\r
149 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
150 timer or semaphore is created. It is also called by various parts of the
\r
151 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
152 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
153 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
154 to query the size of free heap space that remains (although it does not
\r
155 provide information on how the remaining heap might be fragmented). */
\r
156 taskDISABLE_INTERRUPTS();
\r
157 __asm volatile( "ebreak" );
\r
160 /*-----------------------------------------------------------*/
\r
162 void vApplicationIdleHook( void )
\r
164 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
165 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
166 task. It is essential that code added to this hook function never attempts
\r
167 to block in any way (for example, call xQueueReceive() with a block time
\r
168 specified, or call vTaskDelay()). If the application makes use of the
\r
169 vTaskDelete() API function (as this demo application does) then it is also
\r
170 important that vApplicationIdleHook() is permitted to return to its calling
\r
171 function, because it is the responsibility of the idle task to clean up
\r
172 memory allocated by the kernel to any task that has since been deleted. */
\r
174 /*-----------------------------------------------------------*/
\r
176 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
178 ( void ) pcTaskName;
\r
181 /* Run time stack overflow checking is performed if
\r
182 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
183 function is called if a stack overflow is detected. */
\r
184 taskDISABLE_INTERRUPTS();
\r
185 __asm volatile( "ebreak" );
\r
188 /*-----------------------------------------------------------*/
\r
190 void vApplicationTickHook( void )
\r
192 /* The tests in the full demo expect some interaction with interrupts. */
\r
193 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )
\r
195 extern void vFullDemoTickHook( void );
\r
196 vFullDemoTickHook();
\r
200 /*-----------------------------------------------------------*/
\r
202 void vPortSetupTimerInterrupt( void )
\r
204 extern void SystemSetupSystick(uint32_t tickRateHz, uint32_t intPriority );
\r
206 /* No CLINT so use the LPIT (Low Power Interrupt Timer) to generate the tick
\r
208 CLOCK_SetIpSrc( kCLOCK_Lpit0, kCLOCK_IpSrcFircAsync );
\r
209 SystemSetupSystick( configTICK_RATE_HZ, configKERNEL_INTERRUPT_PRIORITY - 1 );
\r
211 /*-----------------------------------------------------------*/
\r
213 void LPIT0_IRQHandler( void )
\r
215 BaseType_t xTaskIncrementTick( void );
\r
216 void vTaskSwitchContext( void );
\r
218 #warning requires critical section if interrpt nesting is used.
\r
220 /* vPortSetupTimerInterrupt() uses LPIT0 to generate the tick interrupt. */
\r
221 if( xTaskIncrementTick() != 0 )
\r
223 vTaskSwitchContext();
\r
226 /* Clear LPIT0 interrupt. */
\r
229 /*-----------------------------------------------------------*/
\r
231 /* At the time of writing, interrupt nesting is not supported, so do not use
\r
232 the default SystemIrqHandler() implementation as that enables interrupts. A
\r
233 version that does not enable interrupts is provided below. THIS INTERRUPT
\r
234 HANDLER IS SPECIFIC TO THE VEGA BOARD WHICH DOES NOT INCLUDE A CLINT! */
\r
235 void SystemIrqHandler( uint32_t mcause )
\r
237 uint32_t ulInterruptNumber;
\r
238 typedef void ( * irq_handler_t )( void );
\r
239 extern const irq_handler_t isrTable[];
\r
241 ulInterruptNumber = mcause & 0x1FUL;
\r
243 /* Clear pending flag in EVENT unit .*/
\r
244 EVENT_UNIT->INTPTPENDCLEAR = ( 1U << ulInterruptNumber );
\r
246 /* Read back to make sure write finished. */
\r
247 (void)(EVENT_UNIT->INTPTPENDCLEAR);
\r
249 /* Now call the real irq handler for ulInterruptNumber */
\r
250 isrTable[ ulInterruptNumber ]();
\r