aboutsummaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-03-30 16:22:09 -0700
committerChristian Cunningham <cc@localhost>2022-03-30 16:22:09 -0700
commit72a403ce29627ad6fb603c366b239ba8c9e5131e (patch)
treef8b0e6cc520b64ccee98f8c852da12ea318aab1c /usr
parent16348742989a94b63f278fb4c43e09ef994353f8 (diff)
Allow C++ user code
Diffstat (limited to 'usr')
-rw-r--r--usr/cxx.cpp24
-rw-r--r--usr/main.c4
2 files changed, 27 insertions, 1 deletions
diff --git a/usr/cxx.cpp b/usr/cxx.cpp
new file mode 100644
index 0000000..0c41cca
--- /dev/null
+++ b/usr/cxx.cpp
@@ -0,0 +1,24 @@
+extern "C" {
+#include <drivers/uart.h>
+};
+
+class TestClass {
+ public:
+ unsigned long value;
+ TestClass(unsigned long v) {
+ value = v;
+ }
+ void increment() {
+ value++;
+ }
+ void increment(unsigned long v) {
+ value += v;
+ }
+};
+
+extern "C" void cpp_demo(unsigned long v)
+{
+ TestClass tc = TestClass(v);
+ tc.increment();
+ uart_hexn(tc.value);
+}
diff --git a/usr/main.c b/usr/main.c
index a4c6048..0308d4b 100644
--- a/usr/main.c
+++ b/usr/main.c
@@ -4,10 +4,11 @@
#include <graphics/lfb.h>
#include <symbols.h>
#include <sys/schedule.h>
+#include <usr/cxx.h>
+#include <usr/math.h>
#include <usr/string.h>
#include <usr/timed.h>
#include <usr/uart.h>
-#include <usr/math.h>
static struct SysTimerInfo stime_0 = {
.tick_rate = 5000000,
@@ -99,4 +100,5 @@ void main(void)
//add_thread(consumer, 0, 3);
//add_thread(test_super, 0, 4);
//subscribe_irq(SYS_TIMER_3_IRQ, gptest, &stime_3);
+ cpp_demo(53);
}