summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-05-24 15:05:49 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-05-24 15:05:49 +0200
commit6e43e8e9a59569b573628c84d68af26f284c8c4e (patch)
tree0b4f006e751823ec8448301162cc72b97921f129
parent50d32b105f25ac3e7a8290dfacd6ca9c87ed5f72 (diff)
MSP430: save & restore entire SRAM to/from FRAM
-rw-r--r--Makefile1
-rw-r--r--src/app/transactiontest/Makefile.inc5
-rw-r--r--src/app/transactiontest/main.cc64
-rw-r--r--src/app/transactiontest/util.S46
-rw-r--r--src/arch/msp430fr5969lp/Makefile.inc5
-rw-r--r--src/arch/msp430fr5994lp/Makefile.inc5
6 files changed, 124 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index cab89b1..f719c31 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,7 @@ COMMON_FLAGS = -g -Os -Wall -Wextra
CFLAGS = -std=c99
CXXFLAGS = -std=c++14 -fno-rtti -fno-threadsafe-statics
+ASM_TARGETS =
C_TARGETS =
CXX_TARGETS = src/app/${app}/main.cc src/os/object/cpp_helpers.cc src/os/object/outputstream.cc
diff --git a/src/app/transactiontest/Makefile.inc b/src/app/transactiontest/Makefile.inc
new file mode 100644
index 0000000..586a484
--- /dev/null
+++ b/src/app/transactiontest/Makefile.inc
@@ -0,0 +1,5 @@
+timer_cycles ?= 1
+timer_s ?= 1
+loop ?= 1
+
+ASM_TARGETS += src/app/transactiontest/util.S \ No newline at end of file
diff --git a/src/app/transactiontest/main.cc b/src/app/transactiontest/main.cc
new file mode 100644
index 0000000..e359e67
--- /dev/null
+++ b/src/app/transactiontest/main.cc
@@ -0,0 +1,64 @@
+#include "arch.h"
+#include "driver/gpio.h"
+#include "driver/stdout.h"
+#include "driver/uptime.h"
+
+#ifndef TIMER_CYCLES
+#error makeflag timer_cycles=1 required
+#endif
+
+extern "C" {
+ void asm_save_toc();
+ void asm_load_toc();
+}
+
+volatile bool __attribute__((section(".text"))) have_state = false;
+uint16_t i = 0;
+
+void restore_state()
+{
+ if (!have_state) {
+ return;
+ }
+ asm_load_toc();
+}
+
+void save_state()
+{
+ asm_save_toc();
+ have_state = true;
+}
+
+void loop(void)
+{
+ gpio.led_toggle(1);
+ kout << dec << i << endl;
+ i++;
+ if (i == 5) {
+ save_state();
+ }
+ if (i == 10) {
+ restore_state();
+ }
+}
+
+int main(void)
+{
+ arch.setup();
+ gpio.setup();
+ kout.setup();
+
+ restore_state();
+
+ gpio.led_on(0);
+ kout << "Hello, World!" << endl;
+ kout << "Test, World!" << endl;
+ kout << dec << uptime.get_cycles() << endl;
+ kout << dec << uptime.get_cycles() << endl;
+ kout << dec << uptime.get_cycles() << endl;
+ kout << dec << uptime.get_cycles() << endl;
+
+ arch.idle_loop();
+
+ return 0;
+}
diff --git a/src/app/transactiontest/util.S b/src/app/transactiontest/util.S
new file mode 100644
index 0000000..bf2530d
--- /dev/null
+++ b/src/app/transactiontest/util.S
@@ -0,0 +1,46 @@
+.global asm_save_toc
+.global asm_load_toc
+
+stack_backup:
+ .space 2048
+
+sp_backup:
+ .space 2
+
+asm_save_toc:
+ .irp reg,4,5,6,7,8,9,10,11
+ push r\reg
+ .endr
+
+ mov r1, &sp_backup
+
+ mov #1c00h, r10
+ mov #stack_backup, r11
+
+save_sram_word:
+ mov @r10+, 0(r11)
+ add #2, r11
+ cmp #1c00h+2048, r10
+ jlo save_sram_word
+
+ pop r11
+ pop r10
+ add #12, r1
+ ret
+
+asm_load_toc:
+ mov #stack_backup, r10
+ mov #1c00h, r11
+
+load_sram_word:
+ mov @r10+, 0(r11)
+ add #2, r11
+ cmp #1c00h+2048, r11
+ jlo load_sram_word
+
+ mov &sp_backup, r1
+ .irp reg,11,10,9,8,7,6,5,4
+ pop r\reg
+ .endr
+
+ ret \ No newline at end of file
diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc
index 557fa90..7e318ea 100644
--- a/src/arch/msp430fr5969lp/Makefile.inc
+++ b/src/arch/msp430fr5969lp/Makefile.inc
@@ -67,7 +67,7 @@ else
endif
-OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o}
+OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o} ${ASM_TARGETS:.S=.o}
.cc.o:
${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
@@ -75,6 +75,9 @@ OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o}
.c.o:
${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} ${CFLAGS} -c -o $@ ${@:.o=.c}
+.S.o:
+ ${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} -Wa,-gstabs,-ggdb -x assembler-with-cpp -c -o $@ ${@:.o=.S}
+
build/system.elf: ${OBJECTS}
${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} \
-Wl,--library-path=/opt/msp430/ti/gcc/include/ \
diff --git a/src/arch/msp430fr5994lp/Makefile.inc b/src/arch/msp430fr5994lp/Makefile.inc
index 0c82dfc..6498597 100644
--- a/src/arch/msp430fr5994lp/Makefile.inc
+++ b/src/arch/msp430fr5994lp/Makefile.inc
@@ -71,7 +71,7 @@ else
endif
-OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o}
+OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o} ${ASM_TARGETS:.S=.o}
.cc.o:
${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
@@ -79,6 +79,9 @@ OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o}
.c.o:
${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} ${CFLAGS} -c -o $@ ${@:.o=.c}
+.S.o:
+ ${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} -Wa,-gstabs,-ggdb -x assembler-with-cpp -c -o $@ ${@:.o=.S}
+
build/system.elf: ${OBJECTS}
${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} \
-Wl,--library-path=/opt/msp430/ti/msp430-gcc-full-linux-5.0.0.36/include/ \