API Reference
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32.h
Go to the documentation of this file.
1// ================================================================================ //
2// The NEORV32 RISC-V Processor - https://github.com/stnolting/neorv32 //
3// Copyright (c) NEORV32 contributors. //
4// Copyright (c) 2020 - 2026 Stephan Nolting. All rights reserved. //
5// Licensed under the BSD-3-Clause license, see LICENSE for details. //
6// SPDX-License-Identifier: BSD-3-Clause //
7// ================================================================================ //
8
14#ifndef NEORV32_H
15#define NEORV32_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21// Standard libraries
22#include <stdint.h>
23#include <inttypes.h>
24#include <stdlib.h>
25
26// required for semihosting
27#if defined(STDIO_SEMIHOSTING)
28#include <stdio.h>
29#include <string.h>
30#include <fcntl.h> // for open()
31#include <unistd.h> // for close()
32#endif
33
34/**********************************************************************/
38#define IO_BASE_ADDRESS (0XFFE00000U)
39#define NEORV32_BOOTROM_BASE (0xFFE00000U)
40//#define NEORV32_???_BASE (0xFFE10000U) /**< reserved */
41//#define NEORV32_???_BASE (0xFFE20000U) /**< reserved */
42//#define NEORV32_???_BASE (0xFFE30000U) /**< reserved */
43//#define NEORV32_???_BASE (0xFFE40000U) /**< reserved */
44//#define NEORV32_???_BASE (0xFFE50000U) /**< reserved */
45//#define NEORV32_???_BASE (0xFFE60000U) /**< reserved */
46//#define NEORV32_???_BASE (0xFFE70000U) /**< reserved */
47//#define NEORV32_???_BASE (0xFFE80000U) /**< reserved */
48//#define NEORV32_???_BASE (0xFFE90000U) /**< reserved */
49#define NEORV32_TWD_BASE (0xFFEA0000U)
50#define NEORV32_CFS_BASE (0xFFEB0000U)
51#define NEORV32_SLINK_BASE (0xFFEC0000U)
52#define NEORV32_DMA_BASE (0xFFED0000U)
53//#define NEORV32_???_BASE (0xFFEE0000U) /**< reserved */
54#define NEORV32_SMC_BASE (0xFFEF0000U)
55#define NEORV32_PWM_BASE (0xFFF00000U)
56#define NEORV32_GPTMR_BASE (0xFFF10000U)
57#define NEORV32_ONEWIRE_BASE (0xFFF20000U)
58#define NEORV32_TRACEBUF_BASE (0xFFF30000U)
59#define NEORV32_CLINT_BASE (0xFFF40000U)
60#define NEORV32_UART0_BASE (0xFFF50000U)
61#define NEORV32_UART1_BASE (0xFFF60000U)
62#define NEORV32_SDI_BASE (0xFFF70000U)
63#define NEORV32_SPI_BASE (0xFFF80000U)
64#define NEORV32_TWI_BASE (0xFFF90000U)
65#define NEORV32_TRNG_BASE (0xFFFA0000U)
66#define NEORV32_WDT_BASE (0xFFFB0000U)
67#define NEORV32_GPIO_BASE (0xFFFC0000U)
68#define NEORV32_NEOLED_BASE (0xFFFD0000U)
69#define NEORV32_SYSINFO_BASE (0xFFFE0000U)
70#define NEORV32_DM_BASE (0xFFFF0000U)
73/**********************************************************************/
79#define CFS_FIRQ_ENABLE CSR_MIE_FIRQ1E
80#define CFS_FIRQ_PENDING CSR_MIP_FIRQ1P
81#define CFS_TRAP_CODE TRAP_CODE_FIRQ_1
85#define UART0_FIRQ_ENABLE CSR_MIE_FIRQ2E
86#define UART0_FIRQ_PENDING CSR_MIP_FIRQ2P
87#define UART0_TRAP_CODE TRAP_CODE_FIRQ_2
91#define UART1_FIRQ_ENABLE CSR_MIE_FIRQ3E
92#define UART1_FIRQ_PENDING CSR_MIP_FIRQ3P
93#define UART1_TRAP_CODE TRAP_CODE_FIRQ_3
97#define TWD_FIRQ_ENABLE CSR_MIE_FIRQ4E
98#define TWD_FIRQ_PENDING CSR_MIP_FIRQ4P
99#define TWD_TRAP_CODE TRAP_CODE_FIRQ_4
103#define TRACEBUF_FIRQ_ENABLE CSR_MIE_FIRQ5E
104#define TRACEBUF_FIRQ_PENDING CSR_MIP_FIRQ5P
105#define TRACEBUF_TRAP_CODE TRAP_CODE_FIRQ_5
109#define SPI_FIRQ_ENABLE CSR_MIE_FIRQ6E
110#define SPI_FIRQ_PENDING CSR_MIP_FIRQ6P
111#define SPI_TRAP_CODE TRAP_CODE_FIRQ_6
115#define TWI_FIRQ_ENABLE CSR_MIE_FIRQ7E
116#define TWI_FIRQ_PENDING CSR_MIP_FIRQ7P
117#define TWI_TRAP_CODE TRAP_CODE_FIRQ_7
121#define GPIO_FIRQ_ENABLE CSR_MIE_FIRQ8E
122#define GPIO_FIRQ_PENDING CSR_MIP_FIRQ8P
123#define GPIO_TRAP_CODE TRAP_CODE_FIRQ_8
127#define NEOLED_FIRQ_ENABLE CSR_MIE_FIRQ9E
128#define NEOLED_FIRQ_PENDING CSR_MIP_FIRQ9P
129#define NEOLED_TRAP_CODE TRAP_CODE_FIRQ_9
133#define DMA_FIRQ_ENABLE CSR_MIE_FIRQ10E
134#define DMA_FIRQ_PENDING CSR_MIP_FIRQ10P
135#define DMA_TRAP_CODE TRAP_CODE_FIRQ_10
139#define SDI_FIRQ_ENABLE CSR_MIE_FIRQ11E
140#define SDI_FIRQ_PENDING CSR_MIP_FIRQ11P
141#define SDI_TRAP_CODE TRAP_CODE_FIRQ_11
145#define GPTMR_FIRQ_ENABLE CSR_MIE_FIRQ12E
146#define GPTMR_FIRQ_PENDING CSR_MIP_FIRQ12P
147#define GPTMR_TRAP_CODE TRAP_CODE_FIRQ_12
151#define ONEWIRE_FIRQ_ENABLE CSR_MIE_FIRQ13E
152#define ONEWIRE_FIRQ_PENDING CSR_MIP_FIRQ13P
153#define ONEWIRE_TRAP_CODE TRAP_CODE_FIRQ_13
157#define SLINK_FIRQ_ENABLE CSR_MIE_FIRQ14E
158#define SLINK_FIRQ_PENDING CSR_MIP_FIRQ14P
159#define SLINK_TRAP_CODE TRAP_CODE_FIRQ_14
163#define TRNG_FIRQ_ENABLE CSR_MIE_FIRQ15E
164#define TRNG_FIRQ_PENDING CSR_MIP_FIRQ15P
165#define TRNG_TRAP_CODE TRAP_CODE_FIRQ_15
169/**********************************************************************/
173extern char __heap_start[];
174extern char __heap_end[];
175extern char __crt0_max_heap[];
176extern char __crt0_entry[];
177extern char __crt0_rom_base[];
178extern char __crt0_rom_size[];
179extern char __crt0_ram_base[];
180extern char __crt0_ram_size[];
181// aliases
182#define NEORV32_HEAP_BEGIN ((uint32_t)&__heap_start[0])
183#define NEORV32_HEAP_END ((uint32_t)&__heap_end[0])
184#define NEORV32_HEAP_SIZE ((uint32_t)&__crt0_max_heap[0])
185#define NEORV32_CRT0_ENTRY ((uint32_t)&__crt0_entry[0])
186#define NEORV32_ROM_BASE ((uint32_t)&__crt0_rom_base[0])
187#define NEORV32_ROM_SIZE ((uint32_t)&__crt0_rom_size[0])
188#define NEORV32_RAM_BASE ((uint32_t)&__crt0_ram_base[0])
189#define NEORV32_RAM_SIZE ((uint32_t)&__crt0_ram_size[0])
192/**********************************************************************/
208/**********************************************************************/
213typedef union {
214 uint64_t uint64;
215 uint32_t uint32[2];
216 uint16_t uint16[4];
217 uint8_t uint8[8];
219
221typedef union {
222 uint32_t uint32;
223 uint16_t uint16[2];
224 uint8_t uint8[4];
226
228typedef union {
229 uint16_t uint16;
230 uint8_t uint8[2];
234/**********************************************************************/
238// generic
239#define __MMREG_BSET(r, m) ((r) |= (m))
240#define __MMREG_BCLR(r, m) ((r) &= ~(m))
241#define __MMREG_BINV(r, m) ((r) ^= (m))
242// 32-bit access
243#if defined(__riscv_a) || defined(__riscv_zaamo) // use atomic RMW instructions
244#define __MMREG32_BSET(r, m) (neorv32_cpu_amoor( (uint32_t)(&r), (uint32_t)(m)))
245#define __MMREG32_BCLR(r, m) (neorv32_cpu_amoand((uint32_t)(&r), ~(uint32_t)(m)))
246#define __MMREG32_BINV(r, m) (neorv32_cpu_amoxor((uint32_t)(&r), (uint32_t)(m)))
247#else // use individual load + modify + write instructions
248#define __MMREG32_BSET(r, m) __MMREG_BSET(r, (uint32_t)(m))
249#define __MMREG32_BCLR(r, m) __MMREG_BCLR(r, (uint32_t)(m))
250#define __MMREG32_BINV(r, m) __MMREG_BINV(r, (uint32_t)(m))
251#endif
252// 16-bit access
253#define __MMREG16_BSET(r, m) __MMREG_BSET(r, (uint16_t)(m))
254#define __MMREG16_BCLR(r, m) __MMREG_BCLR(r, (uint16_t)(m))
255#define __MMREG16_BINV(r, m) __MMREG_BINV(r, (uint16_t)(m))
256// 8-bit access
257#define __MMREG8_BSET(r, m) __MMREG_BSET(r, (uint8_t)(m))
258#define __MMREG8_BCLR(r, m) __MMREG_BCLR(r, (uint8_t)(m))
259#define __MMREG8_BINV(r, m) __MMREG_BINV(r, (uint8_t)(m))
262/**********************************************************************/
266#include "neorv32_aux.h"
267#include "neorv32_cfs.h"
268#include "neorv32_clint.h"
269#include "neorv32_cpu.h"
270#include "neorv32_csr.h"
271#include "neorv32_dma.h"
272#include "neorv32_gpio.h"
273#include "neorv32_gptmr.h"
274#include "neorv32_intrinsics.h"
275#include "neorv32_neoled.h"
276#include "neorv32_onewire.h"
277#include "neorv32_pwm.h"
278#include "neorv32_rte.h"
279#include "neorv32_semihosting.h"
280#include "neorv32_sdi.h"
281#include "neorv32_slink.h"
282#include "neorv32_smc.h"
283#include "neorv32_smp.h"
284#include "neorv32_spi.h"
285#include "neorv32_sysinfo.h"
286#include "neorv32_tracebuf.h"
287#include "neorv32_trng.h"
288#include "neorv32_twd.h"
289#include "neorv32_twi.h"
290#include "neorv32_uart.h"
291#include "neorv32_wdt.h"
294#ifdef __cplusplus
295}
296#endif
297
298#endif // NEORV32_H
char __crt0_entry[]
char __heap_start[]
NEORV32_CLOCK_PRSC_enum
Definition neorv32.h:196
@ CLK_PRSC_4096
Definition neorv32.h:204
@ CLK_PRSC_1024
Definition neorv32.h:202
@ CLK_PRSC_64
Definition neorv32.h:200
@ CLK_PRSC_4
Definition neorv32.h:198
@ CLK_PRSC_128
Definition neorv32.h:201
@ CLK_PRSC_2048
Definition neorv32.h:203
@ CLK_PRSC_8
Definition neorv32.h:199
@ CLK_PRSC_2
Definition neorv32.h:197
char __crt0_rom_size[]
char __crt0_rom_base[]
char __crt0_ram_size[]
char __crt0_max_heap[]
char __crt0_ram_base[]
char __heap_end[]
General auxiliary functions header file.
Custom Functions Subsystem (CFS) HW driver header file.
Core-Local Interruptor (CLINT) HW driver header file.
CPU Core Functions HW driver header file.
Control and Status Registers (CSR) definitions.
Direct Memory Access Controller (DMA) HW driver header file.
General purpose input/output port unit (GPIO) HW driver header file.
General purpose timer (GPTMR) HW driver header file.
Prototypes for custom RISC-V instructions ("intrinsics"). Based on the ".insn" pseudo directive: http...
Smart LED Interface (NEOLED) HW driver header file.
1-Wire Interface Controller (ONEWIRE) HW driver header file.
Pulse-Width Modulation Controller (PWM) HW driver header file.
NEORV32 Runtime Environment.
Serial data interface controller (SDI) HW driver header file.
RISC-V semihosting header file.
Serial memory controller (SMC) HW driver header file.
Symmetric multiprocessing (SMP) library header file.
Serial peripheral interface controller (SPI) HW driver header file.
System Information Memory (SYSINFO) HW driver header file.
Execution trace buffer (TRACEBUF) HW driver header file.
True Random Number Generator (TRNG) HW driver header file.
Two-Wire Device Controller (TWD) HW driver header file.
Two-Wire Interface Controller (TWI) HW driver header file.
Universal asynchronous receiver/transmitter (UART0/UART1) HW driver header file.
Watchdog Timer (WDT) HW driver header file.
Definition neorv32.h:228
Definition neorv32.h:221
Definition neorv32.h:213