1 #include "FreeRTOS.h"
\r
6 #include "hw_platform.h"
\r
7 #include "riscv_hal.h"
\r
9 #include "core_gpio.h"
\r
10 #include "core_timer.h"
\r
11 #include "core_uart_apb.h"
\r
13 const char * g_hello_msg = "\r\nFreeRTOS Example\r\n";
\r
18 * + Program the device using the flash project in
\r
19 * MS-RISC-V\M2GL025-Creative-Board\Programming_The_Target_Device\PROC_SUBSYSTEM_MIV_RV32IMA_BaseDesign.
\r
20 * See https://github.com/RISCV-on-Microsemi-FPGA/M2GL025-Creative-Board.
\r
21 * + Above referenced image sets the clock to 50MHz. *
\r
22 * + Debug configuration is critical.
\r
26 /* A block time of zero simply means "don't block". */
\r
27 #define mainDONT_BLOCK ( 0UL )
\r
29 /******************************************************************************
\r
30 * CoreUARTapb instance data.
\r
31 *****************************************************************************/
\r
32 UART_instance_t g_uart;
\r
33 /*-----------------------------------------------------------*/
\r
35 static void vUartTestTask1( void *pvParameters );
\r
36 static void vUartTestTask2( void *pvParameters );
\r
39 * FreeRTOS hook for when malloc fails, enable in FreeRTOSConfig.
\r
41 void vApplicationMallocFailedHook( void );
\r
44 * FreeRTOS hook for when FreeRtos is idling, enable in FreeRTOSConfig.
\r
46 void vApplicationIdleHook( void );
\r
49 * FreeRTOS hook for when a stack overflow occurs, enable in FreeRTOSConfig.
\r
51 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
54 gpio_instance_t g_gpio0;
\r
55 gpio_instance_t g_gpio1;
\r
56 timer_instance_t g_timer0;
\r
57 timer_instance_t g_timer1;
\r
60 /*-----------------------------------------------------------*/
\r
61 extern uint32_t SysTick_Config(uint32_t ticks);
\r
62 extern void __enable_irq(void);
\r
67 //_RB_ GPIO_init(&g_gpio0, COREGPIO_IN_BASE_ADDR, GPIO_APB_32_BITS_BUS);
\r
68 //_RB_ GPIO_init(&g_gpio1, COREGPIO_OUT_BASE_ADDR, GPIO_APB_32_BITS_BUS);
\r
70 /**************************************************************************
\r
71 * Initialize CoreUART with its base address, baud value, and line
\r
73 *************************************************************************/
\r
74 UART_init(&g_uart, COREUARTAPB0_BASE_ADDR, BAUD_VALUE_115200,
\r
75 (DATA_8_BITS | NO_PARITY) );
\r
77 UART_polled_tx_string( &g_uart, (const uint8_t *)"\r\n\r\n Sample Demonstration of FreeRTOS port for Mi-V processor.\r\n\r\n" );
\r
78 UART_polled_tx_string( &g_uart, (const uint8_t *)" This project creates two tasks and runs them at regular intervals.\r\n" );
\r
80 /* Create the two test tasks. */
\r
81 xTaskCreate( vUartTestTask1, "UArt1", 1000, NULL, uartPRIMARY_PRIORITY, NULL );
\r
82 // xTaskCreate( vUartTestTask2, "UArt2", 1000, NULL, uartPRIMARY_PRIORITY, NULL );
\r
84 /* Start the kernel. From here on, only tasks and interrupts will run. */
\r
85 vTaskStartScheduler();
\r
91 /*-----------------------------------------------------------*/
\r
93 void vApplicationMallocFailedHook( void )
\r
95 /* vApplicationMallocFailedHook() will only be called if
\r
96 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
97 function that will get called if a call to pvPortMalloc() fails.
\r
98 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
99 timer or semaphore is created. It is also called by various parts of the
\r
100 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
101 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
102 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
103 to query the size of free heap space that remains (although it does not
\r
104 provide information on how the remaining heap might be fragmented). */
\r
105 taskDISABLE_INTERRUPTS();
\r
108 /*-----------------------------------------------------------*/
\r
110 void vApplicationIdleHook( void )
\r
112 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
113 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
114 task. It is essential that code added to this hook function never attempts
\r
115 to block in any way (for example, call xQueueReceive() with a block time
\r
116 specified, or call vTaskDelay()). If the application makes use of the
\r
117 vTaskDelete() API function (as this demo application does) then it is also
\r
118 important that vApplicationIdleHook() is permitted to return to its calling
\r
119 function, because it is the responsibility of the idle task to clean up
\r
120 memory allocated by the kernel to any task that has since been deleted. */
\r
122 /*-----------------------------------------------------------*/
\r
124 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
126 ( void ) pcTaskName;
\r
129 /* Run time stack overflow checking is performed if
\r
130 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
131 function is called if a stack overflow is detected. */
\r
132 taskDISABLE_INTERRUPTS();
\r
135 /*-----------------------------------------------------------*/
\r
137 static void vUartTestTask1( void *pvParameters )
\r
139 ( void ) pvParameters;
\r
143 UART_polled_tx_string( &g_uart, (const uint8_t *)"Task - 1\r\n" );
\r
144 vTaskDelay( pdMS_TO_TICKS( 100 ) );
\r
149 /*-----------------------------------------------------------*/
\r
151 static void vUartTestTask2( void *pvParameters )
\r
153 ( void ) pvParameters;
\r
157 // UART_polled_tx_string( &g_uart, (const uint8_t *)"Task - 2\r\n" );
\r