summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/soc/gpio.c
blob: 4fa93ddd7ff6414ee8aaa477593f0ca42d539cd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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);
}