diff --git a/sw/example/hello_cpp/main.cpp b/sw/example/hello_cpp/main.cpp index e74700af0..a2b471cd5 100644 --- a/sw/example/hello_cpp/main.cpp +++ b/sw/example/hello_cpp/main.cpp @@ -68,7 +68,7 @@ int main() { neorv32_rte_print_logo(); // say hello - neorv32_uart0_puts("Hello world! :)\n"); + neorv32_uart0_printf("Hello C++! :)\n"); // print the IDs of the two statically declared instances of DemoClass demo1.print_id(); diff --git a/sw/example/hello_cpp/makefile b/sw/example/hello_cpp/makefile index 8f9e2fdc0..e303f51e0 100644 --- a/sw/example/hello_cpp/makefile +++ b/sw/example/hello_cpp/makefile @@ -1,4 +1,7 @@ # Modify this variable to fit your NEORV32 setup (neorv32 home folder) NEORV32_HOME ?= ../../.. - include $(NEORV32_HOME)/sw/common/common.mk + +# Use c++ compiler and define c++ standard +override CC = $(RISCV_PREFIX)g++ +override USER_FLAGS += -std=c++11 diff --git a/sw/lib/include/neorv32.h b/sw/lib/include/neorv32.h index 100b46411..fd4303e9a 100644 --- a/sw/lib/include/neorv32.h +++ b/sw/lib/include/neorv32.h @@ -273,6 +273,7 @@ typedef union { #include "neorv32_xip.h" #include "neorv32_xirq.h" + #ifdef __cplusplus } #endif diff --git a/sw/lib/include/neorv32_cpu_amo.h b/sw/lib/include/neorv32_cpu_amo.h index f0419e73c..4812024b1 100644 --- a/sw/lib/include/neorv32_cpu_amo.h +++ b/sw/lib/include/neorv32_cpu_amo.h @@ -74,7 +74,10 @@ inline uint32_t __attribute__ ((always_inline)) neorv32_cpu_amosc(uint32_t addr, } -// prototypes +/**********************************************************************//** + * @name Prototypes + **************************************************************************/ +/**@{*/ uint32_t neorv32_cpu_amoswapw(uint32_t addr, uint32_t wdata); uint32_t neorv32_cpu_amoaddw(uint32_t addr, uint32_t wdata); uint32_t neorv32_cpu_amoandw(uint32_t addr, uint32_t wdata); @@ -84,5 +87,7 @@ int32_t neorv32_cpu_amomaxw(uint32_t addr, int32_t wdata); uint32_t neorv32_cpu_amomaxuw(uint32_t addr, uint32_t wdata); int32_t neorv32_cpu_amominw(uint32_t addr, int32_t wdata); uint32_t neorv32_cpu_amominuw(uint32_t addr, uint32_t wdata); +/**@}*/ + #endif // neorv32_cpu_amo_h diff --git a/sw/lib/include/neorv32_legacy.h b/sw/lib/include/neorv32_legacy.h index 8bf98bf9b..db5a0e1aa 100644 --- a/sw/lib/include/neorv32_legacy.h +++ b/sw/lib/include/neorv32_legacy.h @@ -19,54 +19,6 @@ #include -/**********************************************************************//** - * @name UART0 legacy compatibility wrappers - **************************************************************************/ -/**@{*/ -#define neorv32_uart0_available() neorv32_uart_available(NEORV32_UART0) -#define neorv32_uart0_get_rx_fifo_depth() neorv32_uart_get_rx_fifo_depth(NEORV32_UART0) -#define neorv32_uart0_get_tx_fifo_depth() neorv32_uart_get_tx_fifo_depth(NEORV32_UART0) -#define neorv32_uart0_setup(baudrate, irq_mask) neorv32_uart_setup(NEORV32_UART0, baudrate, irq_mask) -#define neorv32_uart0_disable() neorv32_uart_disable(NEORV32_UART0) -#define neorv32_uart0_enable() neorv32_uart_enable(NEORV32_UART0) -#define neorv32_uart0_rtscts_disable() neorv32_uart_rtscts_disable(NEORV32_UART0) -#define neorv32_uart0_rtscts_enable() neorv32_uart_rtscts_enable(NEORV32_UART0) -#define neorv32_uart0_putc(c) neorv32_uart_putc(NEORV32_UART0, c) -#define neorv32_uart0_rx_clear() neorv32_uart_rx_clear(NEORV32_UART0) -#define neorv32_uart0_tx_clear() neorv32_uart_tx_clear(NEORV32_UART0) -#define neorv32_uart0_tx_busy() neorv32_uart_tx_busy(NEORV32_UART0) -#define neorv32_uart0_getc() neorv32_uart_getc(NEORV32_UART0) -#define neorv32_uart0_char_received() neorv32_uart_char_received(NEORV32_UART0) -#define neorv32_uart0_char_received_get() neorv32_uart_char_received_get(NEORV32_UART0) -#define neorv32_uart0_puts(s) neorv32_uart_puts(NEORV32_UART0, s) -#define neorv32_uart0_printf(...) neorv32_uart_printf(NEORV32_UART0, __VA_ARGS__) -#define neorv32_uart0_scan(buffer, max_size, echo) neorv32_uart_scan(NEORV32_UART0, buffer, max_size, echo) -/**@}*/ - -/**********************************************************************//** - * @name UART1 legacy compatibility wrappers - **************************************************************************/ -/**@{*/ -#define neorv32_uart1_available() neorv32_uart_available(NEORV32_UART1) -#define neorv32_uart1_get_rx_fifo_depth() neorv32_uart_get_rx_fifo_depth(NEORV32_UART1) -#define neorv32_uart1_get_tx_fifo_depth() neorv32_uart_get_tx_fifo_depth(NEORV32_UART1) -#define neorv32_uart1_setup(baudrate, irq_mask) neorv32_uart_setup(NEORV32_UART1, baudrate, irq_mask) -#define neorv32_uart1_disable() neorv32_uart_disable(NEORV32_UART1) -#define neorv32_uart1_enable() neorv32_uart_enable(NEORV32_UART1) -#define neorv32_uart1_rtscts_disable() neorv32_uart_rtscts_disable(NEORV32_UART1) -#define neorv32_uart1_rtscts_enable() neorv32_uart_rtscts_enable(NEORV32_UART1) -#define neorv32_uart1_putc(c) neorv32_uart_putc(NEORV32_UART1, c) -#define neorv32_uart1_rx_clear() neorv32_uart_rx_clear(NEORV32_UART1) -#define neorv32_uart1_tx_clear() neorv32_uart_tx_clear(NEORV32_UART1) -#define neorv32_uart1_tx_busy() neorv32_uart_tx_busy(NEORV32_UART1) -#define neorv32_uart1_getc() neorv32_uart_getc(NEORV32_UART1) -#define neorv32_uart1_char_received() neorv32_uart_char_received(NEORV32_UART1) -#define neorv32_uart1_char_received_get() neorv32_uart_char_received_get(NEORV32_UART1) -#define neorv32_uart1_puts(s) neorv32_uart_puts(NEORV32_UART1, s) -#define neorv32_uart1_printf(...) neorv32_uart_printf(NEORV32_UART1, __VA_ARGS__) -#define neorv32_uart1_scan(buffer, max_size, echo) neorv32_uart_scan(NEORV32_UART1, buffer, max_size, echo) -/**@}*/ - /**********************************************************************//** * @name GPIO aliases **************************************************************************/ @@ -77,8 +29,9 @@ #define OUTPUT_HI OUTPUT[1] /**@}*/ + /**********************************************************************//** - * @name Atomic LR/SC aliases + * @name Atomic LR/SC instructions **************************************************************************/ /**@{*/ #define neorv32_cpu_load_reservate_word(addr, wdata) neorv32_cpu_amolr(addr, wdata) diff --git a/sw/lib/include/neorv32_uart.h b/sw/lib/include/neorv32_uart.h index 5fc2b616f..f9f645b1e 100644 --- a/sw/lib/include/neorv32_uart.h +++ b/sw/lib/include/neorv32_uart.h @@ -114,4 +114,48 @@ int neorv32_uart_scan(neorv32_uart_t *UARTx, char *buffer, int max_size, int ec /**@}*/ +/**********************************************************************//** + * @name UART wrappers for easy access + **************************************************************************/ +/**@{*/ +#define neorv32_uart0_available() neorv32_uart_available(NEORV32_UART0) +#define neorv32_uart0_get_rx_fifo_depth() neorv32_uart_get_rx_fifo_depth(NEORV32_UART0) +#define neorv32_uart0_get_tx_fifo_depth() neorv32_uart_get_tx_fifo_depth(NEORV32_UART0) +#define neorv32_uart0_setup(baudrate, irq_mask) neorv32_uart_setup(NEORV32_UART0, baudrate, irq_mask) +#define neorv32_uart0_disable() neorv32_uart_disable(NEORV32_UART0) +#define neorv32_uart0_enable() neorv32_uart_enable(NEORV32_UART0) +#define neorv32_uart0_rtscts_disable() neorv32_uart_rtscts_disable(NEORV32_UART0) +#define neorv32_uart0_rtscts_enable() neorv32_uart_rtscts_enable(NEORV32_UART0) +#define neorv32_uart0_putc(c) neorv32_uart_putc(NEORV32_UART0, c) +#define neorv32_uart0_rx_clear() neorv32_uart_rx_clear(NEORV32_UART0) +#define neorv32_uart0_tx_clear() neorv32_uart_tx_clear(NEORV32_UART0) +#define neorv32_uart0_tx_busy() neorv32_uart_tx_busy(NEORV32_UART0) +#define neorv32_uart0_getc() neorv32_uart_getc(NEORV32_UART0) +#define neorv32_uart0_char_received() neorv32_uart_char_received(NEORV32_UART0) +#define neorv32_uart0_char_received_get() neorv32_uart_char_received_get(NEORV32_UART0) +#define neorv32_uart0_puts(s) neorv32_uart_puts(NEORV32_UART0, s) +#define neorv32_uart0_printf(...) neorv32_uart_printf(NEORV32_UART0, __VA_ARGS__) +#define neorv32_uart0_scan(buffer, max_size, echo) neorv32_uart_scan(NEORV32_UART0, buffer, max_size, echo) + +#define neorv32_uart1_available() neorv32_uart_available(NEORV32_UART1) +#define neorv32_uart1_get_rx_fifo_depth() neorv32_uart_get_rx_fifo_depth(NEORV32_UART1) +#define neorv32_uart1_get_tx_fifo_depth() neorv32_uart_get_tx_fifo_depth(NEORV32_UART1) +#define neorv32_uart1_setup(baudrate, irq_mask) neorv32_uart_setup(NEORV32_UART1, baudrate, irq_mask) +#define neorv32_uart1_disable() neorv32_uart_disable(NEORV32_UART1) +#define neorv32_uart1_enable() neorv32_uart_enable(NEORV32_UART1) +#define neorv32_uart1_rtscts_disable() neorv32_uart_rtscts_disable(NEORV32_UART1) +#define neorv32_uart1_rtscts_enable() neorv32_uart_rtscts_enable(NEORV32_UART1) +#define neorv32_uart1_putc(c) neorv32_uart_putc(NEORV32_UART1, c) +#define neorv32_uart1_rx_clear() neorv32_uart_rx_clear(NEORV32_UART1) +#define neorv32_uart1_tx_clear() neorv32_uart_tx_clear(NEORV32_UART1) +#define neorv32_uart1_tx_busy() neorv32_uart_tx_busy(NEORV32_UART1) +#define neorv32_uart1_getc() neorv32_uart_getc(NEORV32_UART1) +#define neorv32_uart1_char_received() neorv32_uart_char_received(NEORV32_UART1) +#define neorv32_uart1_char_received_get() neorv32_uart_char_received_get(NEORV32_UART1) +#define neorv32_uart1_puts(s) neorv32_uart_puts(NEORV32_UART1, s) +#define neorv32_uart1_printf(...) neorv32_uart_printf(NEORV32_UART1, __VA_ARGS__) +#define neorv32_uart1_scan(buffer, max_size, echo) neorv32_uart_scan(NEORV32_UART1, buffer, max_size, echo) +/**@}*/ + + #endif // neorv32_uart_h diff --git a/sw/lib/source/neorv32_aux.c b/sw/lib/source/neorv32_aux.c index 67d4a4743..5dc59da6e 100644 --- a/sw/lib/source/neorv32_aux.c +++ b/sw/lib/source/neorv32_aux.c @@ -12,7 +12,7 @@ * @see https://stnolting.github.io/neorv32/sw/files.html */ -#include +#include "neorv32.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_cfs.c b/sw/lib/source/neorv32_cfs.c index ae0feee58..9219fb038 100644 --- a/sw/lib/source/neorv32_cfs.c +++ b/sw/lib/source/neorv32_cfs.c @@ -19,7 +19,6 @@ */ #include "neorv32.h" -#include "neorv32_cfs.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_cpu.c b/sw/lib/source/neorv32_cpu.c index d1e2eed46..e92c6ae8f 100644 --- a/sw/lib/source/neorv32_cpu.c +++ b/sw/lib/source/neorv32_cpu.c @@ -14,7 +14,6 @@ */ #include "neorv32.h" -#include "neorv32_cpu.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_cpu_amo.c b/sw/lib/source/neorv32_cpu_amo.c index 941bcf527..3c9a850d2 100644 --- a/sw/lib/source/neorv32_cpu_amo.c +++ b/sw/lib/source/neorv32_cpu_amo.c @@ -14,7 +14,6 @@ */ #include "neorv32.h" -#include "neorv32_cpu_amo.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_cpu_cfu.c b/sw/lib/source/neorv32_cpu_cfu.c index f7aebdd89..0e6b10225 100644 --- a/sw/lib/source/neorv32_cpu_cfu.c +++ b/sw/lib/source/neorv32_cpu_cfu.c @@ -14,7 +14,6 @@ */ #include "neorv32.h" -#include "neorv32_cpu_cfu.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_crc.c b/sw/lib/source/neorv32_crc.c index a4b59b429..8f73282f6 100644 --- a/sw/lib/source/neorv32_crc.c +++ b/sw/lib/source/neorv32_crc.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_crc.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_dma.c b/sw/lib/source/neorv32_dma.c index 990dcbcb7..f1912c4a2 100644 --- a/sw/lib/source/neorv32_dma.c +++ b/sw/lib/source/neorv32_dma.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_dma.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_gpio.c b/sw/lib/source/neorv32_gpio.c index 6ba539912..72b6c9466 100644 --- a/sw/lib/source/neorv32_gpio.c +++ b/sw/lib/source/neorv32_gpio.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_gpio.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_gptmr.c b/sw/lib/source/neorv32_gptmr.c index 9015f3345..7826e15a8 100644 --- a/sw/lib/source/neorv32_gptmr.c +++ b/sw/lib/source/neorv32_gptmr.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_gptmr.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_mtime.c b/sw/lib/source/neorv32_mtime.c index a65a1a2b2..0783c170a 100644 --- a/sw/lib/source/neorv32_mtime.c +++ b/sw/lib/source/neorv32_mtime.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_mtime.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_neoled.c b/sw/lib/source/neorv32_neoled.c index cd92c55db..53d4e674d 100644 --- a/sw/lib/source/neorv32_neoled.c +++ b/sw/lib/source/neorv32_neoled.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_neoled.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_onewire.c b/sw/lib/source/neorv32_onewire.c index 3ea235833..434e5751a 100644 --- a/sw/lib/source/neorv32_onewire.c +++ b/sw/lib/source/neorv32_onewire.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_onewire.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_pwm.c b/sw/lib/source/neorv32_pwm.c index ccf1baa33..bf6efa284 100644 --- a/sw/lib/source/neorv32_pwm.c +++ b/sw/lib/source/neorv32_pwm.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_pwm.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_rte.c b/sw/lib/source/neorv32_rte.c index aaf4a127c..69e231372 100644 --- a/sw/lib/source/neorv32_rte.c +++ b/sw/lib/source/neorv32_rte.c @@ -14,7 +14,6 @@ */ #include "neorv32.h" -#include "neorv32_rte.h" /**********************************************************************//** @@ -186,7 +185,9 @@ static void __attribute__((__naked__,aligned(4))) __neorv32_rte_core(void) { } // call handler - asm volatile ("jalr ra, 0(%[dst])" : : [dst] "r" (handler_base)); + typedef void handler_t(); + handler_t* handler = (handler_t*)handler_base; + handler(); // compute return address (for exceptions only) // do not alter return address if instruction access exception (fatal?) @@ -251,14 +252,14 @@ static void __attribute__((__naked__,aligned(4))) __neorv32_rte_core(void) { /**********************************************************************//** * NEORV32 runtime environment (RTE): - * Read register from application context. + * Read register from application context (on stack). * * @param[in] x Register number (0..31, corresponds to register x0..x31). * @return Content of register x. **************************************************************************/ uint32_t neorv32_rte_context_get(int x) { - // MSCRATCH CSR contain the stack pointer of the interrupted program + // MSCRATCH CSR contains the stack pointer of the interrupted program uint32_t tmp = neorv32_cpu_csr_read(CSR_MSCRATCH); #ifdef __riscv_32e tmp += (x & 15) << 2; @@ -271,14 +272,14 @@ uint32_t neorv32_rte_context_get(int x) { /**********************************************************************//** * NEORV32 runtime environment (RTE): - * Write register in application context. + * Write register to application context (on stack). * * @param[in] x Register number (0..31, corresponds to register x0..x31). * @param[in] data Data to be written to register x. **************************************************************************/ void neorv32_rte_context_put(int x, uint32_t data) { - // MSCRATCH CSR contain the stack pointer of the interrupted program + // MSCRATCH CSR contains the stack pointer of the interrupted program uint32_t tmp = neorv32_cpu_csr_read(CSR_MSCRATCH); #ifdef __riscv_32e tmp += (x & 15) << 2; @@ -641,7 +642,7 @@ void neorv32_rte_print_hw_config(void) { void __neorv32_rte_print_hex_word(uint32_t num) { int i; - static const char hex_symbols[16] = "0123456789ABCDEF"; + static const char hex_symbols[] = "0123456789ABCDEF"; if (neorv32_uart0_available() != 0) { // cannot output anything if UART0 is not implemented neorv32_uart0_putc('0'); @@ -721,7 +722,7 @@ void neorv32_rte_print_logo(void) { {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0300, 0xc630} }; - int x, y, z; + unsigned int x, y, z; uint16_t tmp; char c; diff --git a/sw/lib/source/neorv32_sdi.c b/sw/lib/source/neorv32_sdi.c index e53d87eff..a54200e08 100644 --- a/sw/lib/source/neorv32_sdi.c +++ b/sw/lib/source/neorv32_sdi.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_sdi.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_slink.c b/sw/lib/source/neorv32_slink.c index 49e1f92fb..6e9478599 100644 --- a/sw/lib/source/neorv32_slink.c +++ b/sw/lib/source/neorv32_slink.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_slink.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_spi.c b/sw/lib/source/neorv32_spi.c index a9ad18a6d..443ebf040 100644 --- a/sw/lib/source/neorv32_spi.c +++ b/sw/lib/source/neorv32_spi.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_spi.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_trng.c b/sw/lib/source/neorv32_trng.c index b44bb0c05..7570e2e0e 100644 --- a/sw/lib/source/neorv32_trng.c +++ b/sw/lib/source/neorv32_trng.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_trng.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_twi.c b/sw/lib/source/neorv32_twi.c index 17a92d6f7..8ff4a7d6a 100644 --- a/sw/lib/source/neorv32_twi.c +++ b/sw/lib/source/neorv32_twi.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_twi.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_uart.c b/sw/lib/source/neorv32_uart.c index 31fc9ca74..a8038d031 100644 --- a/sw/lib/source/neorv32_uart.c +++ b/sw/lib/source/neorv32_uart.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_uart.h" #include #include diff --git a/sw/lib/source/neorv32_wdt.c b/sw/lib/source/neorv32_wdt.c index ab49d3507..f76d796f3 100644 --- a/sw/lib/source/neorv32_wdt.c +++ b/sw/lib/source/neorv32_wdt.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_wdt.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_xip.c b/sw/lib/source/neorv32_xip.c index 0d20a9824..735052745 100644 --- a/sw/lib/source/neorv32_xip.c +++ b/sw/lib/source/neorv32_xip.c @@ -16,7 +16,6 @@ */ #include "neorv32.h" -#include "neorv32_xip.h" /**********************************************************************//** diff --git a/sw/lib/source/neorv32_xirq.c b/sw/lib/source/neorv32_xirq.c index 8f8acff84..e71f0fd53 100644 --- a/sw/lib/source/neorv32_xirq.c +++ b/sw/lib/source/neorv32_xirq.c @@ -32,14 +32,16 @@ // # The NEORV32 Processor - https://github.com/stnolting/neorv32 (c) Stephan Nolting # // ################################################################################################# - -/**********************************************************************//** +/** * @file neorv32_xirq.c * @brief External Interrupt controller HW driver source file. - **************************************************************************/ + * + * @note These functions should only be used if the XIRQ controller was synthesized. + * + * @see https://stnolting.github.io/neorv32/sw/files.html + */ #include "neorv32.h" -#include "neorv32_xirq.h" /**********************************************************************//** @@ -263,10 +265,9 @@ static void __neorv32_xirq_core(void) { NEORV32_XIRQ->EIP = ~(1 << src); // execute handler - uint32_t xirq_handler = __neorv32_xirq_vector_lut[src]; - void (*handler_pnt)(void); - handler_pnt = (void*)xirq_handler; - (*handler_pnt)(); + typedef void handler_t(); + handler_t* handler = (handler_t*)__neorv32_xirq_vector_lut[src]; + handler(); NEORV32_XIRQ->ESC = 0; // acknowledge the current XIRQ interrupt } diff --git a/sw/lib/source/syscalls.c b/sw/lib/source/syscalls.c index 68874b504..f83b14fa5 100644 --- a/sw/lib/source/syscalls.c +++ b/sw/lib/source/syscalls.c @@ -18,14 +18,15 @@ * @see https://stnolting.github.io/neorv32/sw/files.html */ +#include "neorv32.h" #include #include #include #include -#include +#include +#include #include #include -#include #undef errno extern int errno;