Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual

Page 71

Advertising
background image

KTD-S0057-I

Page 67 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide

else
{

if (write (fd_tmp, EDGE_FALL, sizeof(EDGE_FALL)-1) != sizeof(EDGE_FALL)-1)

{

close

(fd_tmp);

return

-1;

}

}

close

(fd_tmp);

return

0;

}

int main (void)
{

int i, ret, value;

struct pollfd poll_fd;

printf ("\nGPIO IRQ test program\n");

if ((! gpio_export (GP2_17)) && (! gpio_set_direction (GP2_17, GPIO_IN)))

{

if ((! gpio_set_edge (GP2_17, IRQ_RISE)) && (! gpio_open_read (GP2_17)))

{

poll_fd.fd

= fd [GP2_17];

poll_fd.events = POLLPRI;

poll_fd.revents = 0;

printf ("Waiting for interrupt ...\n");

/* Read before Poll is necessary */

gpio_read (GP2_17, &value);

ret = poll (&poll_fd, 1, POLL_TIMEOUT);

switch

(ret)

{

case -1: printf ("Interrupt routine fails !\n"); break;

case

0: printf ("Timeout has occured !\n"); break;

case

1: if (poll_fd.revents & POLLPRI)

printf ("IRQ successfully detected.\n");

else

printf ("Unexpected problem !\n");

break;

default : printf ("Unexpected problem !\n"); break;

}

gpio_close_read

(GP2_17);

}

else

{

printf ("\nCannot set edge or open GPIO !\n");

gpio_unexport

(GP2_17);

return

-1;

}

gpio_unexport

(GP2_17);

}

Advertising
This manual is related to the following products: