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 /*-----------------------------------------------------------*/
\r
52 typedef enum LED_STATE {
\r
53 LED_RED_BLINK_ON = 1,
\r
56 LED_GREEN_BLINK_OFF,
\r
61 /* Static variable to keep track of LED color.
\r
62 * red -> green -> blue -> red -> ...
\r
63 * This variable is not intended for multi-threaded application.
\r
65 static E_LED_STATE eLedState = LED_RED_BLINK_ON;
\r
67 /* Show iteration number in UART.
\r
68 * This variable is not intended for multi-threaded application.
\r
72 /* Track how many times tick interrupt has occurred. */
\r
73 static unsigned int uTickInterruptCounter = 0;
\r
76 * Perform any application specific hardware configuration. The clocks,
\r
77 * memory, etc. are configured before main() is called.
\r
79 static void prvSetupHardware( void );
\r
82 * Heap_5 is being used because the RAM is not contiguous, therefore the heap
\r
83 * needs to be initialized. See http://www.freertos.org/a00111.html
\r
85 static void prvInitializeHeap( void );
\r
88 * The hardware only has a single LED. Simply toggle it.
\r
90 void vMainToggleLED( 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
94 void main_blinky( void );
\r
95 void main_full( void );
\r
98 * @brief Application entry point.
\r
103 /* Prepare the hardware to run this demo. */
\r
104 prvSetupHardware();
\r
106 /* Initialize heap regions. */
\r
107 prvInitializeHeap();
\r
109 /* Show something on UART.
\r
110 Serial port setup as baudrate: 115200, data: 8-bit, parity: none, stop bits: 1, flow control: none.
\r
111 sTerminal setup as receive: auto, transmit: CR+LF.*/
\r
112 PRINTF("FreeRTOS demo.\r\n");
\r
114 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
116 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
\r
129 /*-----------------------------------------------------------*/
\r
130 void vMainToggleLED( void )
\r
134 case LED_RED_BLINK_ON:
\r
135 PRINTF("Iteration %d -- tick interrupt count %d.\r\n", i, uTickInterruptCounter);
\r
139 eLedState = LED_RED_BLINK_OFF;
\r
141 case LED_RED_BLINK_OFF:
\r
143 eLedState = LED_GREEN_BLINK_ON;
\r
145 case LED_GREEN_BLINK_ON:
\r
147 eLedState = LED_GREEN_BLINK_OFF;
\r
149 case LED_GREEN_BLINK_OFF:
\r
151 eLedState = LED_BLUE_BLINK_ON;
\r
153 case LED_BLUE_BLINK_ON:
\r
155 eLedState = LED_BLUE_BLINK_OFF;
\r
157 case LED_BLUE_BLINK_OFF:
\r
159 eLedState = LED_RED_BLINK_ON;
\r
162 /* Unexpected state. Let's reset to default color. */
\r
163 eLedState = LED_RED_BLINK_ON;
\r
169 /*-----------------------------------------------------------*/
\r
171 static void prvSetupHardware( void )
\r
173 /* Initialize board hardware. */
\r
174 BOARD_InitBootPins();
\r
175 BOARD_InitBootClocks();
\r
176 BOARD_InitBootPeripherals();
\r
178 /* Enable clock for GPIO. */
\r
179 CLOCK_EnableClock(kCLOCK_Gpio0);
\r
180 CLOCK_EnableClock(kCLOCK_Gpio1);
\r
182 /* Initialize FSL debug console. */
\r
183 BOARD_InitDebugConsole();
\r
185 /* Initialize tri-color LED. */
\r
186 LED_RED_INIT(LOGIC_LED_OFF);
\r
187 LED_GREEN_INIT(LOGIC_LED_OFF);
\r
188 LED_BLUE_INIT(LOGIC_LED_OFF);
\r
193 /*-----------------------------------------------------------*/
\r
195 static void prvInitializeHeap( void )
\r
197 /* Place the first block of the heap memory in the first bank of RAM. */
\r
198 static uint8_t ucHeap1[ configTOTAL_HEAP_SIZE ];
\r
200 /* Place the second block of the heap memory in the second bank of RAM. */
\r
201 static uint8_t ucHeap2[ 16 * 1024 ] COMPILER_ATTRIBUTE_PLACE_IN_2ND_MEMORY_BANK;
\r
203 /* Memory regions are defined in address order, and terminate with NULL. */
\r
204 static HeapRegion_t xHeapRegions[] =
\r
206 { ( unsigned char * ) ucHeap1, sizeof( ucHeap1 ) },
\r
207 { ( unsigned char * ) ucHeap2, sizeof( ucHeap2 ) },
\r
211 vPortDefineHeapRegions( xHeapRegions );
\r
216 /*-----------------------------------------------------------*/
\r
218 void vApplicationMallocFailedHook( void )
\r
220 /* vApplicationMallocFailedHook() will only be called if
\r
221 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
222 function that will get called if a call to pvPortMalloc() fails.
\r
223 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
224 timer or semaphore is created. It is also called by various parts of the
\r
225 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
226 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
227 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
228 to query the size of free heap space that remains (although it does not
\r
229 provide information on how the remaining heap might be fragmented). */
\r
230 taskDISABLE_INTERRUPTS();
\r
234 /*-----------------------------------------------------------*/
\r
236 void vApplicationIdleHook( void )
\r
238 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
239 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
240 task. It is essential that code added to this hook function never attempts
\r
241 to block in any way (for example, call xQueueReceive() with a block time
\r
242 specified, or call vTaskDelay()). If the application makes use of the
\r
243 vTaskDelete() API function (as this demo application does) then it is also
\r
244 important that vApplicationIdleHook() is permitted to return to its calling
\r
245 function, because it is the responsibility of the idle task to clean up
\r
246 memory allocated by the kernel to any task that has since been deleted. */
\r
249 /*-----------------------------------------------------------*/
\r
251 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
253 ( void ) pcTaskName;
\r
256 /* Run time stack overflow checking is performed if
\r
257 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
258 function is called if a stack overflow is detected. */
\r
259 taskDISABLE_INTERRUPTS();
\r
263 /*-----------------------------------------------------------*/
\r
265 void vApplicationTickHook( void )
\r
267 #if mainCHECK_INTERRUPT_STACK == 1
\r
268 extern unsigned long _pvHeapStart[];
\r
270 /* This function will be called by each tick interrupt if
\r
271 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
\r
272 added here, but the tick hook is called from an interrupt context, so
\r
273 code must not attempt to block, and only the interrupt safe FreeRTOS API
\r
274 functions can be used (those that end in FromISR()). */
\r
276 /* Manually check the last few bytes of the interrupt stack to check they
\r
277 have not been overwritten. Note - the task stacks are automatically
\r
278 checked for overflow if configCHECK_FOR_STACK_OVERFLOW is set to 1 or 2
\r
279 in FreeRTOSConifg.h, but the interrupt stack is not. */
\r
280 configASSERT( memcmp( ( void * ) _pvHeapStart, ucExpectedInterruptStackValues, sizeof( ucExpectedInterruptStackValues ) ) == 0U );
\r
281 #endif /* mainCHECK_INTERRUPT_STACK */
\r
283 uTickInterruptCounter++;
\r