Merge pull request #1 from hplp/cppdemo

demo with basic C and C++ examples
This commit is contained in:
Sergiu Mosanu 2021-03-02 01:31:46 -05:00 committed by GitHub
commit 7fd39235af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 1 deletions

View File

@ -3,7 +3,7 @@ BUILD_DIR?=../build/
include $(BUILD_DIR)/software/include/generated/variables.mak include $(BUILD_DIR)/software/include/generated/variables.mak
include $(SOC_DIRECTORY)/software/common.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 all: demo.bin
@ -30,6 +30,12 @@ main.o: main.c
donut.o: CFLAGS += -w donut.o: CFLAGS += -w
helloc.o: CFLAGS += -w
hellocpp.o: CXXFLAGS += -w
%.o: %.cpp
$(compilexx)
%.o: %.c %.o: %.c
$(compile) $(compile)

View File

@ -0,0 +1,5 @@
#include <stdio.h>
void helloc(void) {
printf("C: Hello, world!\n");
}

View File

@ -0,0 +1,7 @@
#include <stdio.h>
extern "C" void hellocpp(void);
void hellocpp(void)
{
printf("C++: Hello, world!\n");
}

View File

@ -87,6 +87,8 @@ static void help(void)
puts("led - Led demo"); puts("led - Led demo");
#endif #endif
puts("donut - Spinning Donut demo"); puts("donut - Spinning Donut demo");
puts("helloc - Hello C");
puts("hellocpp - Hello C++");
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
@ -138,6 +140,21 @@ static void donut_cmd(void)
donut(); 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 */ /* Console service / Main */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
@ -160,6 +177,10 @@ static void console_service(void)
#endif #endif
else if(strcmp(token, "donut") == 0) else if(strcmp(token, "donut") == 0)
donut_cmd(); donut_cmd();
else if(strcmp(token, "helloc") == 0)
helloc_cmd();
else if(strcmp(token, "hellocpp") == 0)
hellocpp_cmd();
prompt(); prompt();
} }