From 769f36d468735faf772a3f76211dfae6aff70b7c Mon Sep 17 00:00:00 2001 From: Sergiu Mosanu Date: Tue, 2 Mar 2021 01:28:21 -0500 Subject: [PATCH] extend demo with basic C and C++ examples --- litex/soc/software/demo/Makefile | 8 +++++++- litex/soc/software/demo/helloc.c | 5 +++++ litex/soc/software/demo/hellocpp.cpp | 7 +++++++ litex/soc/software/demo/main.c | 21 +++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 litex/soc/software/demo/helloc.c create mode 100644 litex/soc/software/demo/hellocpp.cpp diff --git a/litex/soc/software/demo/Makefile b/litex/soc/software/demo/Makefile index 5a2a47c3e..cc39cdebe 100644 --- a/litex/soc/software/demo/Makefile +++ b/litex/soc/software/demo/Makefile @@ -3,7 +3,7 @@ BUILD_DIR?=../build/ include $(BUILD_DIR)/software/include/generated/variables.mak include $(SOC_DIRECTORY)/software/common.mak -OBJECTS=isr.o donut.o main.o +OBJECTS=isr.o donut.o helloc.o hellocpp.o main.o all: demo.bin @@ -30,6 +30,12 @@ main.o: main.c donut.o: CFLAGS += -w +helloc.o: CFLAGS += -w + +hellocpp.o: CXXFLAGS += -w +%.o: %.cpp + $(compilexx) + %.o: %.c $(compile) diff --git a/litex/soc/software/demo/helloc.c b/litex/soc/software/demo/helloc.c new file mode 100644 index 000000000..6549e1262 --- /dev/null +++ b/litex/soc/software/demo/helloc.c @@ -0,0 +1,5 @@ +#include + +void helloc(void) { + printf("C: Hello, world!\n"); +} \ No newline at end of file diff --git a/litex/soc/software/demo/hellocpp.cpp b/litex/soc/software/demo/hellocpp.cpp new file mode 100644 index 000000000..fb9e3fe74 --- /dev/null +++ b/litex/soc/software/demo/hellocpp.cpp @@ -0,0 +1,7 @@ +#include + +extern "C" void hellocpp(void); +void hellocpp(void) +{ + printf("C++: Hello, world!\n"); +} \ No newline at end of file diff --git a/litex/soc/software/demo/main.c b/litex/soc/software/demo/main.c index aaca31174..be38cb521 100644 --- a/litex/soc/software/demo/main.c +++ b/litex/soc/software/demo/main.c @@ -87,6 +87,8 @@ static void help(void) puts("led - Led demo"); #endif puts("donut - Spinning Donut demo"); + puts("helloc - Hello C"); + puts("hellocpp - Hello C++"); } /*-----------------------------------------------------------------------*/ @@ -138,6 +140,21 @@ static void donut_cmd(void) donut(); } +extern void helloc(void); + +static void helloc_cmd(void) +{ + printf("Hello C demo...\n"); + helloc(); +} + +extern void hellocpp(void); + +static void hellocpp_cmd(void) +{ + printf("Hello C++ demo...\n"); + hellocpp(); +} /*-----------------------------------------------------------------------*/ /* Console service / Main */ /*-----------------------------------------------------------------------*/ @@ -160,6 +177,10 @@ static void console_service(void) #endif else if(strcmp(token, "donut") == 0) donut_cmd(); + else if(strcmp(token, "helloc") == 0) + helloc_cmd(); + else if(strcmp(token, "hellocpp") == 0) + hellocpp_cmd(); prompt(); }