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

Subversion Repositories neorv32

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

Go to most recent revision | 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
/*
29
 * Modified for the NEORV32 processor by Stephan Nolting.
30
 */
31
 
32
#ifdef RUN_FREERTOS_DEMO
33
 
34
 
35
/* FreeRTOS kernel includes. */
36
#include <FreeRTOS.h>
37
#include <task.h>
38
 
39
/* NEORV32 includes. */
40
#include <neorv32.h>
41
 
42
 
43
#define BAUD_RATE 19200
44
 
45
 
46
/******************************************************************************
47
 * This project provides two demo applications.  A simple blinky style project,
48
 * and a more comprehensive test and demo application.  The
49
 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
50
 * select between the two.  The simply blinky demo is implemented and described
51
 * in main_blinky.c.  The more comprehensive test and demo application is
52
 * implemented and described in main_full.c.
53
 *
54
 * This file implements the code that is not demo specific, including the
55
 * hardware setup and standard FreeRTOS hook functions.
56
 *
57
 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
58
 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
59
 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
60
 *
61
 */
62
 
63
extern void main_blinky( void );
64
extern void freertos_risc_v_trap_handler( void );
65
 
66
/* Prototypes for the standard FreeRTOS callback/hook functions implemented
67
within this file.  See https://www.freertos.org/a00016.html */
68
void vApplicationMallocFailedHook( void );
69
void vApplicationIdleHook( void );
70
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
71
void vApplicationTickHook( void );
72
 
73
/* Prepare hardware to run the demo. */
74
static void prvSetupHardware( void );
75
 
76
/* Send a message to the UART initialised in prvSetupHardware. */
77
void vSendString( const char * const pcString );
78
 
79
/*-----------------------------------------------------------*/
80
 
81
int main( void )
82
{
83
        prvSetupHardware();
84
 
85
  neorv32_uart_printf("FreeRTOS %s\n", tskKERNEL_VERSION_NUMBER);
86
 
87
        main_blinky();
88
}
89
 
90
/*-----------------------------------------------------------*/
91
 
92
static void prvSetupHardware( void )
93
{
94
  // configure trap handler entry point
95
  neorv32_cpu_csr_write(CSR_MTVEC, (uint32_t)&freertos_risc_v_trap_handler);
96
 
97
  // configure UART for default baud rate, no rx interrupt, no tx interrupt
98
  neorv32_uart_setup(BAUD_RATE, 0, 0);
99
}
100
 
101
/*-----------------------------------------------------------*/
102
 
103
void vToggleLED( void )
104
{
105
        neorv32_gpio_pin_toggle(0);
106
}
107
 
108
/*-----------------------------------------------------------*/
109
 
110
void vSendString( const char * const pcString )
111
{
112
        neorv32_uart_print( (char *)pcString );
113
}
114
 
115
/*-----------------------------------------------------------*/
116
 
117
void vApplicationMallocFailedHook( void )
118
{
119
        /* vApplicationMallocFailedHook() will only be called if
120
        configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
121
        function that will get called if a call to pvPortMalloc() fails.
122
        pvPortMalloc() is called internally by the kernel whenever a task, queue,
123
        timer or semaphore is created.  It is also called by various parts of the
124
        demo application.  If heap_1.c or heap_2.c are used, then the size of the
125
        heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
126
        FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
127
        to query the size of free heap space that remains (although it does not
128
        provide information on how the remaining heap might be fragmented). */
129
        taskDISABLE_INTERRUPTS();
130
  neorv32_uart_print("FreeRTOS_FAULT: vApplicationMallocFailedHook\n");
131
        __asm volatile( "ebreak" );
132
        for( ;; );
133
}
134
/*-----------------------------------------------------------*/
135
 
136
void vApplicationIdleHook( void )
137
{
138
        /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
139
        to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle
140
        task.  It is essential that code added to this hook function never attempts
141
        to block in any way (for example, call xQueueReceive() with a block time
142
        specified, or call vTaskDelay()).  If the application makes use of the
143
        vTaskDelete() API function (as this demo application does) then it is also
144
        important that vApplicationIdleHook() is permitted to return to its calling
145
        function, because it is the responsibility of the idle task to clean up
146
        memory allocated by the kernel to any task that has since been deleted. */
147
  neorv32_cpu_sleep();
148
}
149
 
150
/*-----------------------------------------------------------*/
151
 
152
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
153
{
154
        ( void ) pcTaskName;
155
        ( void ) pxTask;
156
 
157
        /* Run time stack overflow checking is performed if
158
        configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
159
        function is called if a stack overflow is detected. */
160
        taskDISABLE_INTERRUPTS();
161
  neorv32_uart_print("FreeRTOS_FAULT: vApplicationStackOverflowHook\n");
162
        __asm volatile( "ebreak" );
163
        for( ;; );
164
}
165
 
166
/*-----------------------------------------------------------*/
167
 
168
void vApplicationTickHook( void )
169
{
170
 
171
}
172
 
173
/*-----------------------------------------------------------*/
174
 
175
/* This handler is responsible for handling all interrupts. Only the machine timer interrupt is handled by the kernel. */
176
void SystemIrqHandler( uint32_t mcause )
177
{
178
  neorv32_uart_printf("freeRTOS: Unknown interrupt (0x%x)\n", mcause);
179
}
180
 
181
 
182
 
183
 
184
 
185
// ---------- Primitive main in case this demo is not enabled (i.e. RUN_FREERTOS_DEMO is not defined) ----------
186
#else
187
  #warning FREERTOS DEMO HAS NOT BEEN COMPILED! Use >>make USER_FLAGS+=-DRUN_FREERTOS_DEMO clean_all exe<< to compile it.
188
 
189
#include <neorv32.h>
190
int main() {
191
 
192
  neorv32_uart_setup(19200, 0, 0);
193
  neorv32_uart_print("ERROR! FreeRTOS has not been compiled. Use >>make USER_FLAGS+=-DRUN_FREERTOS_DEMO clean_all exe<< to compile it.\n");
194
  return 0;
195
}
196
#endif

powered by: WebSVN 2.1.0

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