1 |
22 |
zero_gravi |
/*
|
2 |
|
|
* FreeRTOS Kernel V10.3.0
|
3 |
|
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
4 |
|
|
*
|
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:
|
11 |
|
|
*
|
12 |
|
|
* The above copyright notice and this permission notice shall be included in all
|
13 |
|
|
* copies or substantial portions of the Software.
|
14 |
|
|
*
|
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.
|
21 |
|
|
*
|
22 |
|
|
* http://www.FreeRTOS.org
|
23 |
|
|
* http://aws.amazon.com/freertos
|
24 |
|
|
*
|
25 |
|
|
* 1 tab == 4 spaces!
|
26 |
|
|
*/
|
27 |
|
|
|
28 |
36 |
zero_gravi |
/******************************************************************************
|
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.
|
35 |
|
|
*
|
36 |
|
|
* This file implements the code that is not demo specific, including the
|
37 |
|
|
* hardware setup and standard FreeRTOS hook functions.
|
38 |
|
|
*
|
39 |
|
|
* ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
|
40 |
|
|
* THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
|
41 |
|
|
* APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
|
42 |
|
|
*
|
43 |
|
|
*/
|
44 |
|
|
|
45 |
22 |
zero_gravi |
/*
|
46 |
|
|
* Modified for the NEORV32 processor by Stephan Nolting.
|
47 |
|
|
*/
|
48 |
|
|
|
49 |
|
|
#ifdef RUN_FREERTOS_DEMO
|
50 |
|
|
|
51 |
36 |
zero_gravi |
#include <stdint.h>
|
52 |
22 |
zero_gravi |
|
53 |
|
|
/* FreeRTOS kernel includes. */
|
54 |
|
|
#include <FreeRTOS.h>
|
55 |
36 |
zero_gravi |
#include <semphr.h>
|
56 |
|
|
#include <queue.h>
|
57 |
22 |
zero_gravi |
#include <task.h>
|
58 |
|
|
|
59 |
|
|
/* NEORV32 includes. */
|
60 |
|
|
#include <neorv32.h>
|
61 |
|
|
|
62 |
36 |
zero_gravi |
/* misc */
|
63 |
|
|
//#include "driver_wrapper/uart_serial.h"
|
64 |
22 |
zero_gravi |
|
65 |
36 |
zero_gravi |
/* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
|
66 |
|
|
or 0 to run the more comprehensive test and demo application. */
|
67 |
|
|
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
|
68 |
|
|
|
69 |
|
|
/* UART hardware constants. */
|
70 |
22 |
zero_gravi |
#define BAUD_RATE 19200
|
71 |
|
|
|
72 |
36 |
zero_gravi |
/*-----------------------------------------------------------*/
|
73 |
22 |
zero_gravi |
|
74 |
36 |
zero_gravi |
/*
|
75 |
|
|
* main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
|
76 |
|
|
* main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
|
77 |
22 |
zero_gravi |
*/
|
78 |
36 |
zero_gravi |
#if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
|
79 |
|
|
extern void main_blinky( void );
|
80 |
|
|
#else
|
81 |
|
|
extern void main_full( void );
|
82 |
|
|
#endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
|
83 |
22 |
zero_gravi |
|
84 |
|
|
extern void freertos_risc_v_trap_handler( void );
|
85 |
|
|
|
86 |
36 |
zero_gravi |
/*
|
87 |
|
|
* Prototypes for the standard FreeRTOS callback/hook functions implemented
|
88 |
|
|
* within this file. See https://www.freertos.org/a00016.html
|
89 |
|
|
*/
|
90 |
22 |
zero_gravi |
void vApplicationMallocFailedHook( void );
|
91 |
|
|
void vApplicationIdleHook( void );
|
92 |
|
|
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
|
93 |
|
|
void vApplicationTickHook( void );
|
94 |
|
|
|
95 |
|
|
/* Prepare hardware to run the demo. */
|
96 |
|
|
static void prvSetupHardware( void );
|
97 |
|
|
|
98 |
36 |
zero_gravi |
/* System */
|
99 |
|
|
void vToggleLED( void );
|
100 |
|
|
void vSendString( const char * pcString );
|
101 |
22 |
zero_gravi |
|
102 |
|
|
/*-----------------------------------------------------------*/
|
103 |
|
|
|
104 |
|
|
int main( void )
|
105 |
|
|
{
|
106 |
|
|
prvSetupHardware();
|
107 |
|
|
|
108 |
36 |
zero_gravi |
/* say hi */
|
109 |
|
|
neorv32_uart_printf("FreeRTOS %s on NEORV32 Demo\n\n", tskKERNEL_VERSION_NUMBER);
|
110 |
22 |
zero_gravi |
|
111 |
36 |
zero_gravi |
/* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
|
112 |
|
|
of this file. */
|
113 |
|
|
#if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
|
114 |
|
|
main_blinky();
|
115 |
|
|
#else
|
116 |
|
|
main_full();
|
117 |
|
|
#endif
|
118 |
22 |
zero_gravi |
}
|
119 |
|
|
|
120 |
|
|
/*-----------------------------------------------------------*/
|
121 |
|
|
|
122 |
|
|
static void prvSetupHardware( void )
|
123 |
|
|
{
|
124 |
|
|
// configure trap handler entry point
|
125 |
|
|
neorv32_cpu_csr_write(CSR_MTVEC, (uint32_t)&freertos_risc_v_trap_handler);
|
126 |
|
|
|
127 |
36 |
zero_gravi |
// clear GPIO.out port
|
128 |
|
|
neorv32_gpio_port_set(0);
|
129 |
|
|
|
130 |
22 |
zero_gravi |
// configure UART for default baud rate, no rx interrupt, no tx interrupt
|
131 |
|
|
neorv32_uart_setup(BAUD_RATE, 0, 0);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
/*-----------------------------------------------------------*/
|
135 |
|
|
|
136 |
|
|
void vToggleLED( void )
|
137 |
|
|
{
|
138 |
|
|
neorv32_gpio_pin_toggle(0);
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
/*-----------------------------------------------------------*/
|
142 |
|
|
|
143 |
36 |
zero_gravi |
void vSendString( const char * pcString )
|
144 |
22 |
zero_gravi |
{
|
145 |
36 |
zero_gravi |
neorv32_uart_print( ( const char * ) pcString );
|
146 |
22 |
zero_gravi |
}
|
147 |
|
|
|
148 |
|
|
/*-----------------------------------------------------------*/
|
149 |
|
|
|
150 |
|
|
void vApplicationMallocFailedHook( void )
|
151 |
|
|
{
|
152 |
|
|
/* vApplicationMallocFailedHook() will only be called if
|
153 |
|
|
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
|
154 |
|
|
function that will get called if a call to pvPortMalloc() fails.
|
155 |
|
|
pvPortMalloc() is called internally by the kernel whenever a task, queue,
|
156 |
|
|
timer or semaphore is created. It is also called by various parts of the
|
157 |
|
|
demo application. If heap_1.c or heap_2.c are used, then the size of the
|
158 |
|
|
heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
|
159 |
|
|
FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
|
160 |
|
|
to query the size of free heap space that remains (although it does not
|
161 |
|
|
provide information on how the remaining heap might be fragmented). */
|
162 |
|
|
taskDISABLE_INTERRUPTS();
|
163 |
36 |
zero_gravi |
neorv32_uart_print("FreeRTOS_FAULT: vApplicationMallocFailedHook (solution: increase 'configTOTAL_HEAP_SIZE' in FreeRTOSConfig.h)\n");
|
164 |
22 |
zero_gravi |
__asm volatile( "ebreak" );
|
165 |
|
|
for( ;; );
|
166 |
|
|
}
|
167 |
|
|
/*-----------------------------------------------------------*/
|
168 |
|
|
|
169 |
|
|
void vApplicationIdleHook( void )
|
170 |
|
|
{
|
171 |
|
|
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
|
172 |
|
|
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
|
173 |
|
|
task. It is essential that code added to this hook function never attempts
|
174 |
|
|
to block in any way (for example, call xQueueReceive() with a block time
|
175 |
|
|
specified, or call vTaskDelay()). If the application makes use of the
|
176 |
|
|
vTaskDelete() API function (as this demo application does) then it is also
|
177 |
|
|
important that vApplicationIdleHook() is permitted to return to its calling
|
178 |
|
|
function, because it is the responsibility of the idle task to clean up
|
179 |
|
|
memory allocated by the kernel to any task that has since been deleted. */
|
180 |
|
|
neorv32_cpu_sleep();
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
/*-----------------------------------------------------------*/
|
184 |
|
|
|
185 |
|
|
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
|
186 |
|
|
{
|
187 |
|
|
( void ) pcTaskName;
|
188 |
|
|
( void ) pxTask;
|
189 |
|
|
|
190 |
|
|
/* Run time stack overflow checking is performed if
|
191 |
|
|
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
|
192 |
|
|
function is called if a stack overflow is detected. */
|
193 |
|
|
taskDISABLE_INTERRUPTS();
|
194 |
|
|
neorv32_uart_print("FreeRTOS_FAULT: vApplicationStackOverflowHook\n");
|
195 |
|
|
__asm volatile( "ebreak" );
|
196 |
|
|
for( ;; );
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
/*-----------------------------------------------------------*/
|
200 |
|
|
|
201 |
|
|
void vApplicationTickHook( void )
|
202 |
|
|
{
|
203 |
36 |
zero_gravi |
/* The tests in the full demo expect some interaction with interrupts. */
|
204 |
|
|
#if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )
|
205 |
|
|
{
|
206 |
|
|
extern void vFullDemoTickHook( void );
|
207 |
|
|
vFullDemoTickHook();
|
208 |
|
|
}
|
209 |
|
|
#endif
|
210 |
22 |
zero_gravi |
}
|
211 |
|
|
|
212 |
|
|
/*-----------------------------------------------------------*/
|
213 |
|
|
|
214 |
|
|
/* This handler is responsible for handling all interrupts. Only the machine timer interrupt is handled by the kernel. */
|
215 |
|
|
void SystemIrqHandler( uint32_t mcause )
|
216 |
|
|
{
|
217 |
|
|
neorv32_uart_printf("freeRTOS: Unknown interrupt (0x%x)\n", mcause);
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
// ---------- Primitive main in case this demo is not enabled (i.e. RUN_FREERTOS_DEMO is not defined) ----------
|
225 |
|
|
#else
|
226 |
|
|
#warning FREERTOS DEMO HAS NOT BEEN COMPILED! Use >>make USER_FLAGS+=-DRUN_FREERTOS_DEMO clean_all exe<< to compile it.
|
227 |
|
|
|
228 |
|
|
#include <neorv32.h>
|
229 |
|
|
int main() {
|
230 |
|
|
|
231 |
|
|
neorv32_uart_setup(19200, 0, 0);
|
232 |
|
|
neorv32_uart_print("ERROR! FreeRTOS has not been compiled. Use >>make USER_FLAGS+=-DRUN_FREERTOS_DEMO clean_all exe<< to compile it.\n");
|
233 |
|
|
return 0;
|
234 |
|
|
}
|
235 |
|
|
#endif
|