Nut/OS  4.10.3
API Reference
gpioc_at91.c
Go to the documentation of this file.
00001 
00037 #include <arch/arm.h>
00038 
00039 #include <stdlib.h>
00040 #include <string.h>
00041 
00042 #include <dev/gpio.h>
00043 
00044 #if defined(PIOC_ISR)
00045 
00049 static void PioIsrC(void *arg)
00050 {
00051     GPIO_VECTOR *vct = (GPIO_VECTOR *)arg;
00052     unsigned int isr;
00053 
00054     for (isr = inr(PIOC_ISR); isr; isr >>= 1, vct++) {
00055         if ((isr & 1) != 0 && vct->iov_handler) {
00056             (vct->iov_handler) (vct->iov_arg);
00057         }
00058     }
00059 }
00060 
00064 static int PioCtlC(int cmd, void *param, int bit)
00065 {
00066     int rc = 0;
00067     unsigned int *ival = (unsigned int *) param;
00068     uint32_t enabled = inr(PIOC_IMR) & _BV(bit);
00069 
00070     /* Disable interrupt. */
00071     if (enabled) {
00072         outr(PIOC_IDR, _BV(bit));
00073     }
00074     switch (cmd) {
00075     case NUT_IRQCTL_STATUS:
00076         if (enabled) {
00077             *ival |= 1;
00078         } else {
00079             *ival &= ~1;
00080         }
00081         break;
00082     case NUT_IRQCTL_ENABLE:
00083         enabled = 1;
00084         break;
00085     case NUT_IRQCTL_DISABLE:
00086         enabled = 0;
00087         break;
00088     default:
00089         rc = -1;
00090         break;
00091     }
00092 
00093     /* Enable interrupt. */
00094     if (enabled) {
00095         outr(PIOC_IER, _BV(bit));
00096     }
00097     return rc;
00098 }
00099 
00100 GPIO_SIGNAL sig_GPIO3 = {
00101     &sig_PIOC,   /* ios_sig */
00102     PioIsrC,    /* ios_handler */
00103     PioCtlC,    /* ios_ctl */
00104     NULL        /* ios_vector */
00105 };
00106 
00107 #endif /* PIOC_ISR */