3 * Copyright (C) 2020 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 standard FreeRTOS hook functions.
39 * When running on the PolarFire SoC hardware:
40 * When executing correctly the yellow LED will toggle every three seconds. If
41 * the yellow LED toggles every 500ms then one of the self-monitoring test tasks
42 * discovered a potential issue. If the red led toggles rapidly then a hardware
45 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
46 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
47 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
51 /* FreeRTOS kernel includes. */
55 /* PolarFire HAL includes. */
56 #include "mpfs_hal/mss_hal.h"
57 #include "drivers/mss/mss_gpio/mss_gpio.h"
58 #include "drivers/mss/mss_mmuart/mss_uart.h"
60 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
61 or 0 to run the more comprehensive test and demo application. */
62 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
64 /*-----------------------------------------------------------*/
67 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
68 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
70 #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
71 extern void main_blinky( void );
73 extern void main_full( void );
74 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
77 * Prototypes for the standard FreeRTOS callback/hook functions implemented
78 * within this file. See https://www.freertos.org/a00016.html
80 void vApplicationMallocFailedHook( void );
81 void vApplicationIdleHook( void );
82 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
83 void vApplicationTickHook( void );
86 * Setup the hardware to run this demo.
88 static void prvSetupHardware( void );
90 /*-----------------------------------------------------------*/
92 /* Main function for the HART0(E51 processor). Application code running on
93 * HART0 is placed here. */
98 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
100 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
110 /*-----------------------------------------------------------*/
112 static void prvSetupHardware( void )
114 /* Configure UART0. */
115 SYSREG->SUBBLK_CLOCK_CR |= SUBBLK_CLOCK_CR_MMUART0_MASK;
116 SYSREG->SOFT_RESET_CR &= ~SOFT_RESET_CR_MMUART0_MASK;
117 MSS_UART_init( &( g_mss_uart0_lo ),
118 MSS_UART_115200_BAUD,
119 MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT );
121 /* Configure the LED. */
122 mss_config_clk_rst( MSS_PERIPH_GPIO2, ( uint8_t )MPFS_HAL_FIRST_HART, PERIPHERAL_ON );
123 MSS_GPIO_config( GPIO2_LO, MSS_GPIO_16, MSS_GPIO_OUTPUT_MODE ); /* Red Led (LED1). */
124 MSS_GPIO_config( GPIO2_LO, MSS_GPIO_18, MSS_GPIO_OUTPUT_MODE ); /* Yellow Led (LED3). */
126 /*-----------------------------------------------------------*/
128 void vApplicationMallocFailedHook( void )
130 /* vApplicationMallocFailedHook() will only be called if
131 * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
132 * function that will get called if a call to pvPortMalloc() fails.
133 * pvPortMalloc() is called internally by the kernel whenever a task, queue,
134 * timer or semaphore is created. It is also called by various parts of the
135 * demo application. If heap_1.c or heap_2.c are used, then the size of the
136 * heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
137 * FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
138 * to query the size of free heap space that remains (although it does not
139 * provide information on how the remaining heap might be fragmented). */
140 taskDISABLE_INTERRUPTS();
143 /*-----------------------------------------------------------*/
145 void vApplicationIdleHook( void )
147 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
148 * to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
149 * task. It is essential that code added to this hook function never attempts
150 * to block in any way (for example, call xQueueReceive() with a block time
151 * specified, or call vTaskDelay()). If the application makes use of the
152 * vTaskDelete() API function (as this demo application does) then it is also
153 * important that vApplicationIdleHook() is permitted to return to its calling
154 * function, because it is the responsibility of the idle task to clean up
155 * memory allocated by the kernel to any task that has since been deleted. */
157 /*-----------------------------------------------------------*/
159 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
164 /* Run time stack overflow checking is performed if
165 * configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
166 * function is called if a stack overflow is detected. */
167 taskDISABLE_INTERRUPTS();
170 /*-----------------------------------------------------------*/
172 void vApplicationTickHook( void )
174 /* The tests in the full demo expect some interaction with interrupts. */
175 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )
177 extern void vFullDemoTickHook( void );
182 /*-----------------------------------------------------------*/
184 void vToggleLED( void )
186 static volatile uint8_t value = 0u;
188 value = ( value == 0u ) ? 1u : 0u;
189 MSS_GPIO_set_output( GPIO2_LO, MSS_GPIO_18, value );
191 /*-----------------------------------------------------------*/
193 void vAssertCalled( void )
195 volatile uint32_t ul;
196 const uint32_t ulNullLoopDelay = 0x1ffffUL;
197 static volatile uint8_t value = 0u;
199 taskDISABLE_INTERRUPTS();
201 /* Flash the red LED to indicate that assert was hit - interrupts are off
202 * here to prevent any further tick interrupts or context switches, so the
203 * delay is implemented as a crude loop instead of a peripheral timer. */
206 for( ul = 0; ul < ulNullLoopDelay; ul++ )
208 __asm volatile( "nop" );
211 value = ( value == 0u ) ? 1u : 0u;
212 MSS_GPIO_set_output( GPIO2_LO, MSS_GPIO_16, value );
215 /*-----------------------------------------------------------*/