2 * Copyright 2016-2019 NXP
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without modification,
\r
6 * are permitted provided that the following conditions are met:
\r
8 * o Redistributions of source code must retain the above copyright notice, this list
\r
9 * of conditions and the following disclaimer.
\r
11 * o Redistributions in binary form must reproduce the above copyright notice, this
\r
12 * list of conditions and the following disclaimer in the documentation and/or
\r
13 * other materials provided with the distribution.
\r
15 * o Neither the name of NXP Semiconductor, Inc. nor the names of its
\r
16 * contributors may be used to endorse or promote products derived from this
\r
17 * software without specific prior written permission.
\r
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
\r
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
\r
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
\r
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
33 * @brief Application entry point.
\r
37 /* Board specific includes. */
\r
39 #include "peripherals.h"
\r
40 #include "pin_mux.h"
\r
41 #include "clock_config.h"
\r
42 #include "LPC51U68.h"
\r
43 #include "fsl_debug_console.h"
\r
45 /* FreeRTOS includes. */
\r
46 #include "FreeRTOS.h"
\r
49 #include "compiler_attributes.h"
\r
51 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to
\r
52 * 0 -- to run the more comprehensive test and demo application,
\r
53 * 1 -- to run the simple blinky demo.
\r
55 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
\r
57 /*-----------------------------------------------------------*/
\r
58 typedef enum LED_STATE {
\r
59 LED_RED_BLINK_ON = 1,
\r
62 LED_GREEN_BLINK_OFF,
\r
67 /* Static variable to keep track of LED color.
\r
68 * red -> green -> blue -> red -> ...
\r
69 * This variable is not intended for multi-threaded application.
\r
71 static E_LED_STATE eLedState = LED_RED_BLINK_ON;
\r
73 /* Show iteration number in UART.
\r
74 * This variable is not intended for multi-threaded application.
\r
78 /* Track how many times tick interrupt has occurred. */
\r
79 static unsigned int uTickInterruptCounter = 0;
\r
82 * Perform any application specific hardware configuration. The clocks,
\r
83 * memory, etc. are configured before main() is called.
\r
85 static void prvSetupHardware( void );
\r
88 * Heap_5 is being used because the RAM is not contiguous, therefore the heap
\r
89 * needs to be initialized. See http://www.freertos.org/a00111.html
\r
91 static void prvInitializeHeap( void );
\r
94 * The hardware only has a single LED. Simply toggle it.
\r
96 void vMainToggleLED( void );
\r
98 /* main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
99 main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0. */
\r
100 void main_blinky( void );
\r
101 void main_full( void );
\r
104 * @brief Application entry point.
\r
109 /* Prepare the hardware to run this demo. */
\r
110 prvSetupHardware();
\r
112 /* Initialize heap regions. */
\r
113 prvInitializeHeap();
\r
115 /* Show something on UART.
\r
116 Serial port setup as baudrate: 115200, data: 8-bit, parity: none, stop bits: 1, flow control: none.
\r
117 sTerminal setup as receive: auto, transmit: CR+LF.*/
\r
118 PRINTF("FreeRTOS demo.\r\n");
\r
120 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
122 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
\r
135 /*-----------------------------------------------------------*/
\r
136 void vMainToggleLED( void )
\r
140 case LED_RED_BLINK_ON:
\r
141 PRINTF("Iteration %d -- tick interrupt count %d.\r\n", i, uTickInterruptCounter);
\r
145 eLedState = LED_RED_BLINK_OFF;
\r
147 case LED_RED_BLINK_OFF:
\r
149 eLedState = LED_GREEN_BLINK_ON;
\r
151 case LED_GREEN_BLINK_ON:
\r
153 eLedState = LED_GREEN_BLINK_OFF;
\r
155 case LED_GREEN_BLINK_OFF:
\r
157 eLedState = LED_BLUE_BLINK_ON;
\r
159 case LED_BLUE_BLINK_ON:
\r
161 eLedState = LED_BLUE_BLINK_OFF;
\r
163 case LED_BLUE_BLINK_OFF:
\r
165 eLedState = LED_RED_BLINK_ON;
\r
168 /* Unexpected state. Let's reset to default color. */
\r
169 eLedState = LED_RED_BLINK_ON;
\r
175 /*-----------------------------------------------------------*/
\r
177 static void prvSetupHardware( void )
\r
179 /* Initialize board hardware. */
\r
180 BOARD_InitBootPins();
\r
181 BOARD_InitBootClocks();
\r
182 BOARD_InitBootPeripherals();
\r
184 /* Enable clock for GPIO. */
\r
185 CLOCK_EnableClock(kCLOCK_Gpio0);
\r
186 CLOCK_EnableClock(kCLOCK_Gpio1);
\r
188 /* Initialize FSL debug console. */
\r
189 BOARD_InitDebugConsole();
\r
191 /* Initialize tri-color LED. */
\r
192 LED_RED_INIT(LOGIC_LED_OFF);
\r
193 LED_GREEN_INIT(LOGIC_LED_OFF);
\r
194 LED_BLUE_INIT(LOGIC_LED_OFF);
\r
199 /*-----------------------------------------------------------*/
\r
201 static void prvInitializeHeap( void )
\r
203 /* Place the first block of the heap memory in the first bank of RAM. */
\r
204 static uint8_t ucHeap1[ configTOTAL_HEAP_SIZE ];
\r
206 /* Place the second block of the heap memory in the second bank of RAM. */
\r
207 static uint8_t ucHeap2[ 16 * 1024 ] COMPILER_ATTRIBUTE_PLACE_IN_2ND_MEMORY_BANK;
\r
209 /* Memory regions are defined in address order, and terminate with NULL. */
\r
210 static HeapRegion_t xHeapRegions[] =
\r
212 { ( unsigned char * ) ucHeap1, sizeof( ucHeap1 ) },
\r
213 { ( unsigned char * ) ucHeap2, sizeof( ucHeap2 ) },
\r
217 vPortDefineHeapRegions( xHeapRegions );
\r
222 /*-----------------------------------------------------------*/
\r
224 void vApplicationMallocFailedHook( void )
\r
226 /* vApplicationMallocFailedHook() will only be called if
\r
227 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
228 function that will get called if a call to pvPortMalloc() fails.
\r
229 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
230 timer or semaphore is created. It is also called by various parts of the
\r
231 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
232 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
233 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
234 to query the size of free heap space that remains (although it does not
\r
235 provide information on how the remaining heap might be fragmented). */
\r
236 taskDISABLE_INTERRUPTS();
\r
240 /*-----------------------------------------------------------*/
\r
242 void vApplicationIdleHook( void )
\r
244 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
245 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
246 task. It is essential that code added to this hook function never attempts
\r
247 to block in any way (for example, call xQueueReceive() with a block time
\r
248 specified, or call vTaskDelay()). If the application makes use of the
\r
249 vTaskDelete() API function (as this demo application does) then it is also
\r
250 important that vApplicationIdleHook() is permitted to return to its calling
\r
251 function, because it is the responsibility of the idle task to clean up
\r
252 memory allocated by the kernel to any task that has since been deleted. */
\r
255 /*-----------------------------------------------------------*/
\r
257 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
259 ( void ) pcTaskName;
\r
262 /* Run time stack overflow checking is performed if
\r
263 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
264 function is called if a stack overflow is detected. */
\r
265 taskDISABLE_INTERRUPTS();
\r
269 /*-----------------------------------------------------------*/
\r
271 void vApplicationTickHook( void )
\r
273 #if mainCHECK_INTERRUPT_STACK == 1
\r
274 extern unsigned long _pvHeapStart[];
\r
276 /* This function will be called by each tick interrupt if
\r
277 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
\r
278 added here, but the tick hook is called from an interrupt context, so
\r
279 code must not attempt to block, and only the interrupt safe FreeRTOS API
\r
280 functions can be used (those that end in FromISR()). */
\r
282 /* Manually check the last few bytes of the interrupt stack to check they
\r
283 have not been overwritten. Note - the task stacks are automatically
\r
284 checked for overflow if configCHECK_FOR_STACK_OVERFLOW is set to 1 or 2
\r
285 in FreeRTOSConifg.h, but the interrupt stack is not. */
\r
286 configASSERT( memcmp( ( void * ) _pvHeapStart, ucExpectedInterruptStackValues, sizeof( ucExpectedInterruptStackValues ) ) == 0U );
\r
287 #endif /* mainCHECK_INTERRUPT_STACK */
\r
289 uTickInterruptCounter++;
\r