summaryrefslogtreecommitdiff
path: root/src/app/transactiontest/main.cc
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 /src/app/transactiontest/main.cc
parent50d32b105f25ac3e7a8290dfacd6ca9c87ed5f72 (diff)
MSP430: save & restore entire SRAM to/from FRAM
Diffstat (limited to 'src/app/transactiontest/main.cc')
-rw-r--r--src/app/transactiontest/main.cc64
1 files changed, 64 insertions, 0 deletions
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;
+}