]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_IGLOO2_Creative_SoftConsole/main.c
Add starting point for IGLOO2 RISV-V demo project.
[freertos] / FreeRTOS / Demo / RISC-V_IGLOO2_Creative_SoftConsole / main.c
1 #include "FreeRTOS.h"\r
2 #include "task.h"\r
3 #include "queue.h"\r
4 #include "timers.h"\r
5 \r
6 #include "hw_platform.h"\r
7 #include "core_uart_apb.h"\r
8 #include "task.h"\r
9 \r
10 const char * g_hello_msg = "\r\nFreeRTOS Example\r\n";\r
11 \r
12 \r
13 /* A block time of zero simply means "don't block". */\r
14 #define mainDONT_BLOCK                                          ( 0UL )\r
15 \r
16 /******************************************************************************\r
17  * CoreUARTapb instance data.\r
18  *****************************************************************************/\r
19 UART_instance_t g_uart;\r
20 /*-----------------------------------------------------------*/\r
21 \r
22 static void vUartTestTask1( void *pvParameters );\r
23 static void vUartTestTask2( void *pvParameters );\r
24 \r
25 /*\r
26  * FreeRTOS hook for when malloc fails, enable in FreeRTOSConfig.\r
27  */\r
28 void vApplicationMallocFailedHook( void );\r
29 \r
30 /*\r
31  * FreeRTOS hook for when FreeRtos is idling, enable in FreeRTOSConfig.\r
32  */\r
33 void vApplicationIdleHook( void );\r
34 \r
35 /*\r
36  * FreeRTOS hook for when a stack overflow occurs, enable in FreeRTOSConfig.\r
37  */\r
38 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
39 \r
40 /*-----------------------------------------------------------*/\r
41 \r
42 int main( void )\r
43 {\r
44     PLIC_init();\r
45 \r
46     /**************************************************************************\r
47     * Initialize CoreUART with its base address, baud value, and line\r
48     * configuration.\r
49     *************************************************************************/\r
50     UART_init(&g_uart, COREUARTAPB0_BASE_ADDR, BAUD_VALUE_115200,\r
51              (DATA_8_BITS | NO_PARITY) );\r
52 \r
53     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
54     UART_polled_tx_string( &g_uart, (const uint8_t *)"          This project creates  two tasks and runs them at regular intervals.\r\n" );\r
55 \r
56     /* Create the two test tasks. */\r
57         xTaskCreate( vUartTestTask1, "UArt1", 1000, NULL, uartPRIMARY_PRIORITY, NULL );\r
58         xTaskCreate( vUartTestTask2, "UArt2", 1000, NULL, uartPRIMARY_PRIORITY, NULL );\r
59 \r
60         /* Start the kernel.  From here on, only tasks and interrupts will run. */\r
61         vTaskStartScheduler();\r
62 \r
63         /* Exit FreeRTOS */\r
64         return 0;\r
65 }\r
66 \r
67 /*-----------------------------------------------------------*/\r
68 \r
69 void vApplicationMallocFailedHook( void )\r
70 {\r
71         /* vApplicationMallocFailedHook() will only be called if\r
72         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
73         function that will get called if a call to pvPortMalloc() fails.\r
74         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
75         timer or semaphore is created.  It is also called by various parts of the\r
76         demo application.  If heap_1.c or heap_2.c are used, then the size of the\r
77         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
78         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
79         to query the size of free heap space that remains (although it does not\r
80         provide information on how the remaining heap might be fragmented). */\r
81         taskDISABLE_INTERRUPTS();\r
82         for( ;; );\r
83 }\r
84 /*-----------------------------------------------------------*/\r
85 \r
86 void vApplicationIdleHook( void )\r
87 {\r
88         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set\r
89         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle\r
90         task.  It is essential that code added to this hook function never attempts\r
91         to block in any way (for example, call xQueueReceive() with a block time\r
92         specified, or call vTaskDelay()).  If the application makes use of the\r
93         vTaskDelete() API function (as this demo application does) then it is also\r
94         important that vApplicationIdleHook() is permitted to return to its calling\r
95         function, because it is the responsibility of the idle task to clean up\r
96         memory allocated by the kernel to any task that has since been deleted. */\r
97 }\r
98 /*-----------------------------------------------------------*/\r
99 \r
100 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
101 {\r
102         ( void ) pcTaskName;\r
103         ( void ) pxTask;\r
104 \r
105         /* Run time stack overflow checking is performed if\r
106         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
107         function is called if a stack overflow is detected. */\r
108         taskDISABLE_INTERRUPTS();\r
109         for( ;; );\r
110 }\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 static void vUartTestTask1( void *pvParameters )\r
114 {\r
115         ( void ) pvParameters;\r
116 \r
117         for( ;; )\r
118         {\r
119                 UART_polled_tx_string( &g_uart, (const uint8_t *)"Task - 1\r\n" );\r
120             vTaskDelay(10);\r
121         }\r
122 }\r
123 \r
124 \r
125 /*-----------------------------------------------------------*/\r
126 \r
127 static void vUartTestTask2( void *pvParameters )\r
128 {\r
129         ( void ) pvParameters;\r
130 \r
131         for( ;; )\r
132         {\r
133                 UART_polled_tx_string( &g_uart, (const uint8_t *)"Task - 2\r\n" );\r
134             vTaskDelay(5);\r
135         }\r
136 }\r