diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-05-24 15:05:49 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-05-24 15:05:49 +0200 |
commit | 6e43e8e9a59569b573628c84d68af26f284c8c4e (patch) | |
tree | 0b4f006e751823ec8448301162cc72b97921f129 /src/app/transactiontest | |
parent | 50d32b105f25ac3e7a8290dfacd6ca9c87ed5f72 (diff) |
MSP430: save & restore entire SRAM to/from FRAM
Diffstat (limited to 'src/app/transactiontest')
-rw-r--r-- | src/app/transactiontest/Makefile.inc | 5 | ||||
-rw-r--r-- | src/app/transactiontest/main.cc | 64 | ||||
-rw-r--r-- | src/app/transactiontest/util.S | 46 |
3 files changed, 115 insertions, 0 deletions
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 |