summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/soc/gpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos/soc/gpio.c')
-rw-r--r--fw/fe310/eos/soc/gpio.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/fw/fe310/eos/soc/gpio.c b/fw/fe310/eos/soc/gpio.c
new file mode 100644
index 0000000..4fa93dd
--- /dev/null
+++ b/fw/fe310/eos/soc/gpio.c
@@ -0,0 +1,20 @@
+#include <stdint.h>
+
+#include "encoding.h"
+#include "platform.h"
+
+int eos_gpio_get(uint32_t reg, int pin) {
+ return !!(GPIO_REG(reg) & (1 << pin));
+}
+
+void eos_gpio_set(uint32_t reg, int pin) {
+ if ((reg == GPIO_OUTPUT_VAL) || (reg == GPIO_LOW_IE)) clear_csr(mstatus, MSTATUS_MIE);
+ GPIO_REG(reg) |= (1 << pin);
+ if ((reg == GPIO_OUTPUT_VAL) || (reg == GPIO_LOW_IE)) set_csr(mstatus, MSTATUS_MIE);
+}
+
+void eos_gpio_clear(uint32_t reg, int pin) {
+ if ((reg == GPIO_OUTPUT_VAL) || (reg == GPIO_LOW_IE)) clear_csr(mstatus, MSTATUS_MIE);
+ GPIO_REG(reg) &= ~(1 << pin);
+ if ((reg == GPIO_OUTPUT_VAL) || (reg == GPIO_LOW_IE)) set_csr(mstatus, MSTATUS_MIE);
+}