summaryrefslogtreecommitdiff
path: root/src/arch/posix
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-12-04 15:19:25 +0100
committerDaniel Friesel <derf@finalrewind.org>2017-12-04 15:19:25 +0100
commit7b5284023070b841293d0c5a6be0c6c345372cde (patch)
tree5f2c70451cf61ef6744813cac3a221cef210b213 /src/arch/posix
Add basic system: LED GPIO on MSP430FR5969 Launchpad and faked GPIO on POSIX
Diffstat (limited to 'src/arch/posix')
-rw-r--r--src/arch/posix/Makefile.inc24
-rw-r--r--src/arch/posix/arch.cc13
-rw-r--r--src/arch/posix/driver/gpio.cc31
3 files changed, 68 insertions, 0 deletions
diff --git a/src/arch/posix/Makefile.inc b/src/arch/posix/Makefile.inc
new file mode 100644
index 0000000..caf16a7
--- /dev/null
+++ b/src/arch/posix/Makefile.inc
@@ -0,0 +1,24 @@
+# vim:ft=make
+
+CC = gcc
+CXX = g++
+
+INCLUDES += -Iinclude/posix
+TARGETS += src/arch/posix/arch.cc src/arch/posix/driver/gpio.cc
+
+OBJECTS = ${TARGETS:.cc=.o}
+
+.cc.o:
+ ${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
+
+build/system.elf: ${OBJECTS}
+ ${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} \
+ -o $@ ${OBJECTS}
+
+run: build/system.elf
+ build/system.elf
+
+arch_clean:
+ rm -f ${OBJECTS}
+
+.PHONY: arch_clean program
diff --git a/src/arch/posix/arch.cc b/src/arch/posix/arch.cc
new file mode 100644
index 0000000..efcf90e
--- /dev/null
+++ b/src/arch/posix/arch.cc
@@ -0,0 +1,13 @@
+#include "arch.h"
+#include <unistd.h>
+
+void Arch::setup(void) { }
+
+void Arch::idle_loop(void)
+{
+ while (1) {
+ sleep(1);
+ }
+}
+
+Arch arch;
diff --git a/src/arch/posix/driver/gpio.cc b/src/arch/posix/driver/gpio.cc
new file mode 100644
index 0000000..25eed39
--- /dev/null
+++ b/src/arch/posix/driver/gpio.cc
@@ -0,0 +1,31 @@
+#include "driver/gpio.h"
+#include <stdio.h>
+
+void GPIO::led_on(unsigned char id)
+{
+ if (id < 8) {
+ printf("▶ LED %3d on\n", id);
+ ledstate |= (1 << id);
+ }
+}
+
+void GPIO::led_off(unsigned char id)
+{
+ if (id < 8) {
+ printf("▶ LED %3d off\n", id);
+ ledstate &= ~(1 << id);
+ }
+}
+
+void GPIO::led_toggle(unsigned char id)
+{
+ if (id < 8) {
+ if (ledstate & (1 << id)) {
+ led_off(id);
+ } else {
+ led_on(id);
+ }
+ }
+}
+
+GPIO gpio;