]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_IGLOO2_Creative_SoftConsole/main.c
c1582b7cb9be5b2f1428256a0827e99c70a6c181
[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 "riscv_hal.h"\r
8 #include "hal.h"\r
9 #include "core_gpio.h"\r
10 #include "core_timer.h"\r
11 #include "core_uart_apb.h"\r
12 \r
13 const char * g_hello_msg = "\r\nFreeRTOS Example\r\n";\r
14 \r
15 \r
16 /*\r
17  * Notes:\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
23  */\r
24 \r
25 \r
26 /* A block time of zero simply means "don't block". */\r
27 #define mainDONT_BLOCK                                          ( 0UL )\r
28 \r
29 /******************************************************************************\r
30  * CoreUARTapb instance data.\r
31  *****************************************************************************/\r
32 UART_instance_t g_uart;\r
33 /*-----------------------------------------------------------*/\r
34 \r
35 static void vUartTestTask1( void *pvParameters );\r
36 static void vUartTestTask2( void *pvParameters );\r
37 \r
38 /*\r
39  * FreeRTOS hook for when malloc fails, enable in FreeRTOSConfig.\r
40  */\r
41 void vApplicationMallocFailedHook( void );\r
42 \r
43 /*\r
44  * FreeRTOS hook for when FreeRtos is idling, enable in FreeRTOSConfig.\r
45  */\r
46 void vApplicationIdleHook( void );\r
47 \r
48 /*\r
49  * FreeRTOS hook for when a stack overflow occurs, enable in FreeRTOSConfig.\r
50  */\r
51 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
52 \r
53 /*_RB_\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
58 \r
59 \r
60 /*-----------------------------------------------------------*/\r
61 extern uint32_t SysTick_Config(uint32_t ticks);\r
62 extern void __enable_irq(void);\r
63 \r
64 int main( void )\r
65 {\r
66     PLIC_init();\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
69 \r
70     /**************************************************************************\r
71     * Initialize CoreUART with its base address, baud value, and line\r
72     * configuration.\r
73     *************************************************************************/\r
74     UART_init(&g_uart, COREUARTAPB0_BASE_ADDR, BAUD_VALUE_115200,\r
75              (DATA_8_BITS | NO_PARITY) );\r
76 \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
79 \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
83 \r
84         /* Start the kernel.  From here on, only tasks and interrupts will run. */\r
85         vTaskStartScheduler();\r
86 \r
87         /* Exit FreeRTOS */\r
88         return 0;\r
89 }\r
90 \r
91 /*-----------------------------------------------------------*/\r
92 \r
93 void vApplicationMallocFailedHook( void )\r
94 {\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
106         for( ;; );\r
107 }\r
108 /*-----------------------------------------------------------*/\r
109 \r
110 void vApplicationIdleHook( void )\r
111 {\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
121 }\r
122 /*-----------------------------------------------------------*/\r
123 \r
124 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
125 {\r
126         ( void ) pcTaskName;\r
127         ( void ) pxTask;\r
128 \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
133         for( ;; );\r
134 }\r
135 /*-----------------------------------------------------------*/\r
136 \r
137 static void vUartTestTask1( void *pvParameters )\r
138 {\r
139         ( void ) pvParameters;\r
140 \r
141         for( ;; )\r
142         {\r
143                 UART_polled_tx_string( &g_uart, (const uint8_t *)"Task - 1\r\n" );\r
144             vTaskDelay( pdMS_TO_TICKS( 100 ) );\r
145         }\r
146 }\r
147 \r
148 \r
149 /*-----------------------------------------------------------*/\r
150 \r
151 static void vUartTestTask2( void *pvParameters )\r
152 {\r
153         ( void ) pvParameters;\r
154 \r
155         for( ;; )\r
156         {\r
157 //              UART_polled_tx_string( &g_uart, (const uint8_t *)"Task - 2\r\n" );\r
158             vTaskDelay(5);\r
159         }\r
160 }\r