2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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 /* FreeRTOS kernel includes. */
\r
29 #include <FreeRTOS.h>
\r
32 /* Microsemi includes. */
\r
33 #include "core_uart_apb.h"
\r
34 #include "core_gpio.h"
\r
36 /******************************************************************************
\r
37 * This project provides two demo applications. A simple blinky style project,
\r
38 * and a more comprehensive test and demo application. The
\r
39 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
\r
40 * select between the two. The simply blinky demo is implemented and described
\r
41 * in main_blinky.c. The more comprehensive test and demo application is
\r
42 * implemented and described in main_full.c.
\r
44 * This file implements the code that is not demo specific, including the
\r
45 * hardware setup and standard FreeRTOS hook functions.
\r
47 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
\r
48 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
\r
49 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
\r
53 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
54 or 0 to run the more comprehensive test and demo application. */
\r
55 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
\r
58 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
59 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
61 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
\r
62 extern void main_blinky( void );
\r
64 extern void main_full( void );
\r
65 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\r
67 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
68 within this file. See https://www.freertos.org/a00016.html */
\r
69 void vApplicationMallocFailedHook( void );
\r
70 void vApplicationIdleHook( void );
\r
71 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
72 void vApplicationTickHook( void );
\r
74 /* Prepare hardware to run the demo. */
\r
75 static void prvSetupHardware( void );
\r
77 /* Send a message to the UART initialised in prvSetupHardware. */
\r
78 void vSendString( const char * const pcString );
\r
80 /*-----------------------------------------------------------*/
\r
82 /* The UART to which strings are output, and the GPIO used to toggle the LED. */
\r
83 static UART_instance_t g_uart;
\r
84 static gpio_instance_t g_gpio_out;
\r
86 /*-----------------------------------------------------------*/
\r
92 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
94 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
104 /*-----------------------------------------------------------*/
\r
106 static void prvSetupHardware( void )
\r
109 UART_init( &g_uart, COREUARTAPB0_BASE_ADDR, BAUD_VALUE_115200, ( DATA_8_BITS | NO_PARITY ) );
\r
111 /*-----------------------------------------------------------*/
\r
113 void vToggleLED( void )
\r
115 static uint32_t ulLEDState = 0;
\r
117 GPIO_set_outputs( &g_gpio_out, ulLEDState );
\r
118 ulLEDState = !ulLEDState;
\r
120 /*-----------------------------------------------------------*/
\r
122 void vSendString( const char * const pcString )
\r
124 UART_polled_tx_string( &g_uart, ( const uint8_t * ) pcString );
\r
126 /*-----------------------------------------------------------*/
\r
128 void vApplicationMallocFailedHook( void )
\r
130 /* vApplicationMallocFailedHook() will only be called if
\r
131 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
132 function that will get called if a call to pvPortMalloc() fails.
\r
133 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
134 timer or semaphore is created. It is also called by various parts of the
\r
135 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
136 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
137 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
138 to query the size of free heap space that remains (although it does not
\r
139 provide information on how the remaining heap might be fragmented). */
\r
140 taskDISABLE_INTERRUPTS();
\r
141 __asm volatile( "ebreak" );
\r
144 /*-----------------------------------------------------------*/
\r
146 void vApplicationIdleHook( void )
\r
148 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
149 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
150 task. It is essential that code added to this hook function never attempts
\r
151 to block in any way (for example, call xQueueReceive() with a block time
\r
152 specified, or call vTaskDelay()). If the application makes use of the
\r
153 vTaskDelete() API function (as this demo application does) then it is also
\r
154 important that vApplicationIdleHook() is permitted to return to its calling
\r
155 function, because it is the responsibility of the idle task to clean up
\r
156 memory allocated by the kernel to any task that has since been deleted. */
\r
158 /*-----------------------------------------------------------*/
\r
160 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
162 ( void ) pcTaskName;
\r
165 /* Run time stack overflow checking is performed if
\r
166 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
167 function is called if a stack overflow is detected. */
\r
168 taskDISABLE_INTERRUPTS();
\r
169 __asm volatile( "ebreak" );
\r
172 /*-----------------------------------------------------------*/
\r
174 void vApplicationTickHook( void )
\r
176 /* The tests in the full demo expect some interaction with interrupts. */
\r
177 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )
\r
179 extern void vFullDemoTickHook( void );
\r
180 vFullDemoTickHook();
\r
184 /*-----------------------------------------------------------*/
\r
186 void *_sbrk( ptrdiff_t incr )
\r
188 /* Required to link, but force an assert to ensure it is never actually
\r
190 configASSERT( ( void * ) incr == NULL );
\r