OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [demo_freeRTOS/] [main.c] - Blame information for rev 65

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 42 zero_gravi
/* UART hardware constants. */
50
#define BAUD_RATE 19200
51
 
52 22 zero_gravi
#ifdef RUN_FREERTOS_DEMO
53
 
54 36 zero_gravi
#include <stdint.h>
55 22 zero_gravi
 
56
/* FreeRTOS kernel includes. */
57
#include <FreeRTOS.h>
58 36 zero_gravi
#include <semphr.h>
59
#include <queue.h>
60 22 zero_gravi
#include <task.h>
61
 
62
/* NEORV32 includes. */
63
#include <neorv32.h>
64
 
65 36 zero_gravi
/* misc */
66
//#include "driver_wrapper/uart_serial.h"
67 22 zero_gravi
 
68 36 zero_gravi
/* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
69
or 0 to run the more comprehensive test and demo application. */
70
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      1
71
 
72
/*-----------------------------------------------------------*/
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 65 zero_gravi
  neorv32_uart0_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 51 zero_gravi
  // init UART at default baud rate, no parity bits, ho hw flow control
131 65 zero_gravi
  neorv32_uart0_setup(BAUD_RATE, PARITY_NONE, FLOW_CONTROL_NONE);
132 44 zero_gravi
 
133
  // check available hardware extensions and compare with compiler flags
134
  neorv32_rte_check_isa(0); // silent = 0 -> show message if isa mismatch
135 22 zero_gravi
}
136
 
137
/*-----------------------------------------------------------*/
138
 
139
void vToggleLED( void )
140
{
141
        neorv32_gpio_pin_toggle(0);
142
}
143
 
144
/*-----------------------------------------------------------*/
145
 
146 36 zero_gravi
void vSendString( const char * pcString )
147 22 zero_gravi
{
148 65 zero_gravi
        neorv32_uart0_print( ( const char * ) pcString );
149 22 zero_gravi
}
150
 
151
/*-----------------------------------------------------------*/
152
 
153
void vApplicationMallocFailedHook( void )
154
{
155
        /* vApplicationMallocFailedHook() will only be called if
156
        configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
157
        function that will get called if a call to pvPortMalloc() fails.
158
        pvPortMalloc() is called internally by the kernel whenever a task, queue,
159
        timer or semaphore is created.  It is also called by various parts of the
160
        demo application.  If heap_1.c or heap_2.c are used, then the size of the
161
        heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
162
        FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
163
        to query the size of free heap space that remains (although it does not
164
        provide information on how the remaining heap might be fragmented). */
165
        taskDISABLE_INTERRUPTS();
166 65 zero_gravi
  neorv32_uart0_print("FreeRTOS_FAULT: vApplicationMallocFailedHook (solution: increase 'configTOTAL_HEAP_SIZE' in FreeRTOSConfig.h)\n");
167 22 zero_gravi
        __asm volatile( "ebreak" );
168
        for( ;; );
169
}
170
/*-----------------------------------------------------------*/
171
 
172
void vApplicationIdleHook( void )
173
{
174
        /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
175
        to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle
176
        task.  It is essential that code added to this hook function never attempts
177
        to block in any way (for example, call xQueueReceive() with a block time
178
        specified, or call vTaskDelay()).  If the application makes use of the
179
        vTaskDelete() API function (as this demo application does) then it is also
180
        important that vApplicationIdleHook() is permitted to return to its calling
181
        function, because it is the responsibility of the idle task to clean up
182
        memory allocated by the kernel to any task that has since been deleted. */
183
  neorv32_cpu_sleep();
184
}
185
 
186
/*-----------------------------------------------------------*/
187
 
188
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
189
{
190
        ( void ) pcTaskName;
191
        ( void ) pxTask;
192
 
193
        /* Run time stack overflow checking is performed if
194
        configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
195
        function is called if a stack overflow is detected. */
196
        taskDISABLE_INTERRUPTS();
197 65 zero_gravi
  neorv32_uart0_print("FreeRTOS_FAULT: vApplicationStackOverflowHook\n");
198 22 zero_gravi
        __asm volatile( "ebreak" );
199
        for( ;; );
200
}
201
 
202
/*-----------------------------------------------------------*/
203
 
204
void vApplicationTickHook( void )
205
{
206 36 zero_gravi
  /* The tests in the full demo expect some interaction with interrupts. */
207
#if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )
208
  {
209
  extern void vFullDemoTickHook( void );
210
  vFullDemoTickHook();
211
  }
212
#endif
213 22 zero_gravi
}
214
 
215
/*-----------------------------------------------------------*/
216
 
217
/* This handler is responsible for handling all interrupts. Only the machine timer interrupt is handled by the kernel. */
218
void SystemIrqHandler( uint32_t mcause )
219
{
220 65 zero_gravi
  neorv32_uart0_printf("freeRTOS: Unknown interrupt (0x%x)\n", mcause);
221 22 zero_gravi
}
222
 
223
 
224
 
225
 
226
 
227
// ---------- Primitive main in case this demo is not enabled (i.e. RUN_FREERTOS_DEMO is not defined) ----------
228
#else
229
  #warning FREERTOS DEMO HAS NOT BEEN COMPILED! Use >>make USER_FLAGS+=-DRUN_FREERTOS_DEMO clean_all exe<< to compile it.
230
 
231
#include <neorv32.h>
232
int main() {
233
 
234 51 zero_gravi
  // init UART at default baud rate, no parity bits, ho hw flow control
235 65 zero_gravi
  neorv32_uart0_setup(BAUD_RATE, PARITY_NONE, FLOW_CONTROL_NONE);
236
  neorv32_uart0_print("ERROR! FreeRTOS has not been compiled. Use >>make USER_FLAGS+=-DRUN_FREERTOS_DEMO clean_all exe<< to compile it.\n");
237 60 zero_gravi
  return 1;
238 22 zero_gravi
}
239
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.