34#define DOMAIN "Interrupt"
37extern uint32_t *
intc0;
39static bool gpio_initialized =
false;
42 if (gpio_initialized ==
false) {
43 pynq_error(
"Interrupts have not been initialized. Call gpio_interupt_init() first.\n");
48 int fd = open(
"/dev/uio1", O_RDWR, O_CLOEXEC);
54 gpio_initialized =
true;
60 int pin_bank =
pin % 32;
61 int bank =
pin < 32 ? 0 : 1;
63 printf(
"interrupt set 0: %08X %08X\r\n",
pin, pin_bank);
64 intc0[0] |= (1 << pin_bank);
66 printf(
"interrupt set 1: %08X %08X\r\n",
pin, pin_bank);
67 intc0[1] |= (1 << (pin_bank));
84 uint64_t retv =
intc0[3];
98 uint64_t retv =
intc0[1];
102 uint64_t bitMask = 1ULL <<
pin;
103 if (!(bitMask & retv)) {
104 pynq_error(
"Pin %d is not enabled. Enable by using "
105 "gpio_enable_interrupt(pin). \n",
110 pynq_error(
"No interrupts enabled. Enable by using "
111 "gpio_enable_interrupt(pin). \n");
121 printf(
"interrupt 0: %08X %08X\r\n",
intc0[0],
intc0[2]);
122 printf(
"interrupt 1: %08X %08X\r\n",
intc0[1],
intc0[3]);
130 positions[count++] = index;
143 if (interrupt != 0) {
150 uint64_t bitMask = 1ULL <<
pin;
151 if (bitMask & interrupt) {
163 uint64_t
pin = (uint64_t)((uint64_t)(
intc0[3]) << 32 |
intc0[2]);
167 for (
int i = 0; i < 64; i++) {
168 if (positions[i] != 0) {
175 printf(
"WARNING: gpio_get_interrupt_pins: No pins interrupted. ");
void gpio_disable_all_interrupts(void)
Disables all interrupts from being raised.
void gpio_enable_interrupt(const gpio_t pin)
enables a specific pin to raise interrupts.
uint8_t * gpio_get_interrupt_pins(uint8_t *positions)
Gets all pins on which an interrupt occurred.
int gpio_interrupt_init(void)
Enables interrupts to be set and read.
uint64_t gpio_get_interrupt(void)
void gpio_disable_interrupt(const gpio_t pin)
Disables interrupts from occuring on the specific pin. Hereafter, the pin will not trigger an interru...
void gpio_print_interrupt(void)
prints the current interrupt word
void gpio_wait_for_interrupt(const gpio_t pin)
Waits untill an interrupt occurs on the specified pin or if the value of pin is larger than 63,...
void verify_interrupt_request(const gpio_t pin)
Checks for error in enabled pin. Terminates the process if the pin is not enabled.
void gpio_ack_interrupt(void)
acknowledges the raised interrupts and resets the interrupt word. Allows new interrupts to occur on t...
void sleep_msec(int msec)
Wait for msec milliseconds.
void check_initialization(void)
void findSetBitPositions(uint64_t word, uint8_t *positions)