From 6e43e8e9a59569b573628c84d68af26f284c8c4e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 24 May 2019 15:05:49 +0200 Subject: MSP430: save & restore entire SRAM to/from FRAM --- src/app/transactiontest/main.cc | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/app/transactiontest/main.cc (limited to 'src/app/transactiontest/main.cc') 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; +} -- cgit v1.2.3