summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/soc/aon.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos/soc/aon.c')
-rw-r--r--fw/fe310/eos/soc/aon.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/fw/fe310/eos/soc/aon.c b/fw/fe310/eos/soc/aon.c
new file mode 100644
index 0000000..a11259e
--- /dev/null
+++ b/fw/fe310/eos/soc/aon.c
@@ -0,0 +1,46 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "encoding.h"
+#include "platform.h"
+
+#include "eos.h"
+#include "pwr.h"
+
+#include "aon.h"
+
+#define AON_MAX_BACKUP 16
+
+int eos_aon_init(void) {
+ uint8_t wakeup_cause;
+ int i, rst;
+
+ wakeup_cause = eos_pwr_wakeup_cause();
+ rst = (wakeup_cause == EOS_PWR_WAKE_RST);
+ if (rst) {
+ for (i=0; i<AON_MAX_BACKUP; i++) {
+ eos_aon_set_reg(i, 0);
+ }
+ }
+
+ return EOS_OK;
+}
+
+uint32_t eos_aon_get_reg(int idx) {
+ uint32_t addr;
+
+ if ((idx < 0) || (idx >= AON_MAX_BACKUP)) return -1;
+
+ addr = AON_BACKUP0 + sizeof(uint32_t) * idx;
+ return AON_REG(addr);
+}
+
+void eos_aon_set_reg(int idx, uint32_t reg) {
+ uint32_t addr;
+
+ if ((idx < 0) || (idx > 15)) return;
+
+ addr = AON_BACKUP0 + sizeof(uint32_t) * idx;
+ AON_REG(addr) = reg;
+}
+