diff --git a/arch/arm/src/kl/kl_gpioirq.c b/arch/arm/src/kl/kl_gpioirq.c index f7c3c2ae57c..38f30c0870f 100644 --- a/arch/arm/src/kl/kl_gpioirq.c +++ b/arch/arm/src/kl/kl_gpioirq.c @@ -68,7 +68,7 @@ #endif #if defined(CONFIG_KL_PORTBINTS) || defined(CONFIG_KL_PORTCINTS) || \ - defined(CONFIG_KL_PORTEINTS) + defined(CONFIG_KL_PORTEINTS) # error Kinetis KL25 only supports interrupt on PORTA or PORTD #endif @@ -78,7 +78,7 @@ struct g_portisrs_s { - xcpt_t handler; /* Entery hander entry point */ + xcpt_t handler; /* Interrupt handler entry point */ void *arg; /* The argument that accompanies the interrupt handler */ }; diff --git a/arch/mips/src/pic32mx/pic32mx-gpioirq.c b/arch/mips/src/pic32mx/pic32mx-gpioirq.c index 2565c1bf375..9000618c7f6 100644 --- a/arch/mips/src/pic32mx/pic32mx-gpioirq.c +++ b/arch/mips/src/pic32mx/pic32mx-gpioirq.c @@ -58,7 +58,7 @@ struct g_cnisrs_s { - xcpt_t handler; /* Entery hander entry point */ + xcpt_t handler; /* Interrupt handler entry point */ void *arg; /* The argument that accompanies the interrupt handler */ }; diff --git a/arch/mips/src/pic32mx/pic32mx.h b/arch/mips/src/pic32mx/pic32mx.h index 69f3d18653a..a2de82ed5aa 100644 --- a/arch/mips/src/pic32mx/pic32mx.h +++ b/arch/mips/src/pic32mx/pic32mx.h @@ -340,7 +340,7 @@ void pic32mx_gpioirqinitialize(void); int pic32mx_gpioattach(uint32_t pinset, unsigned int cn, xcpt_t handler, void *arg); #else -# define pic32mx_gpioattach(p,c,h,a) (NULL) +# define pic32mx_gpioattach(p,c,h,a) (0) #endif /************************************************************************************ diff --git a/arch/mips/src/pic32mz/pic32mz-gpio.h b/arch/mips/src/pic32mz/pic32mz-gpio.h index d2c6389a992..17e6e6add61 100644 --- a/arch/mips/src/pic32mz/pic32mz-gpio.h +++ b/arch/mips/src/pic32mz/pic32mz-gpio.h @@ -199,22 +199,20 @@ void pic32mz_gpioirqinitialize(void); * case, all attached handlers will be called. Each handler must maintain state * and determine if the underlying GPIO input value changed. * - * Parameters: - * - pinset: GPIO pin configuration - * - cn: The change notification number associated with the pin - * - handler: Interrupt handler (may be NULL to detach) + * pinset - GPIO pin configuration + * handler - Interrupt handler (may be NULL to detach) + * arg - The argument that accompanies the interrupt * - * Returns: - * The previous value of the interrupt handler function pointer. This value may, - * for example, be used to restore the previous handler when multiple handlers are - * used. + * Returned Value: + * Zero (OK) is returned on success. A negated error value is returned on + * any failure to indicate the nature of the failure. * - ************************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_PIC32MZ_GPIOIRQ -xcpt_t pic32mz_gpioattach(pinset_t pinset, xcpt_t handler); +int pic32mz_gpioattach(uint32_t pinset, xcpt_t handler, void *arg); #else -# define pic32mz_gpioattach(p,f) (NULL) +# define pic32mz_gpioattach(p,h,a) (0) #endif /************************************************************************************ diff --git a/arch/mips/src/pic32mz/pic32mz-gpioirq.c b/arch/mips/src/pic32mz/pic32mz-gpioirq.c index 8e3106cc206..ed6d3cdf459 100644 --- a/arch/mips/src/pic32mz/pic32mz-gpioirq.c +++ b/arch/mips/src/pic32mz/pic32mz-gpioirq.c @@ -78,9 +78,15 @@ static int pic32mz_cninterrupt(int irq, FAR void *context, FAR void *arg); * Public Data ****************************************************************************/ +struct ioport_handler_s +{ + xcpt_t entry; /* Interrupt handler entry point */ + void *arg; /* The argument that accompanies the interrupt handler */ +}; + struct ioport_level2_s { - xcpt_t handler[16]; + struct ioport_handler_s handler[16]; }; /**************************************************************************** @@ -260,12 +266,12 @@ static int pic32mz_cninterrupt(int irq, FAR void *context, FAR void *arg) { /* Yes.. Has the user attached a handler? */ - handler = handlers->handler[i]; + handler = handlers->handler[i].entry; if (handler) { /* Yes.. call the attached handler */ - status = handler(irq, context); + status = handler(irq, context, handlers->handler[i].arg); /* Keep track of the status of the last handler that * failed. @@ -365,22 +371,21 @@ void pic32mz_gpioirqinitialize(void) * In that case, all attached handlers will be called. Each handler must * maintain state and determine if the underlying GPIO input value changed. * - * Parameters: - * - pinset: GPIO pin configuration - * - pin: The change notification number associated with the pin. - * - handler: Interrupt handler (may be NULL to detach) + * Input Parameters: + * pinset - GPIO pin configuration + * handler - Interrupt handler (may be NULL to detach) + * arg - The argument that accompanies the interrupt * - * Returns: - * The previous value of the interrupt handler function pointer. This - * value may, for example, be used to restore the previous handler when - * multiple handlers are used. + * Returned Value: + * Zero (OK) is returned on success. A negated error value is returned on + * any failure to indicate the nature of the failure. * ****************************************************************************/ -xcpt_t pic32mz_gpioattach(pinset_t pinset, xcpt_t handler) +#ifdef CONFIG_PIC32MZ_GPIOIRQ +int pic32mz_gpioattach(uint32_t pinset, xcpt_t handler, void *arg) { struct ioport_level2_s *handlers; - xcpt_t oldhandler = NULL; irqstate_t flags; uintptr_t base; int ioport; @@ -415,7 +420,6 @@ xcpt_t pic32mz_gpioattach(pinset_t pinset, xcpt_t handler) /* Get the previously attached handler as the return value */ flags = enter_critical_section(); - oldhandler = handlers->handler[pin]; /* Are we attaching or detaching? */ @@ -467,12 +471,13 @@ xcpt_t pic32mz_gpioattach(pinset_t pinset, xcpt_t handler) /* Set the new handler (perhaps NULLifying the current handler) */ - handlers->handler[pin] = handler; + handlers->handler[pin].entry = handler; + handlers->handler[pin].arg = arg; leave_critical_section(flags); } } - return oldhandler; + return OK; } /**************************************************************************** diff --git a/configs/pic32mz-starterkit/src/pic32mz_buttons.c b/configs/pic32mz-starterkit/src/pic32mz_buttons.c index d5e06bd3104..21fed886e55 100644 --- a/configs/pic32mz-starterkit/src/pic32mz_buttons.c +++ b/configs/pic32mz-starterkit/src/pic32mz_buttons.c @@ -155,19 +155,19 @@ uint8_t board_buttons(void) xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #ifdef CONFIG_PIC32MZ_GPIOIRQ_PORTB - xcpt_t oldhandler = NULL; + int ret = OK; if ((unsigned)id < NUM_BUTTONS) { /* Perform the attach/detach operation */ - oldhandler = pic32mz_gpioattach(g_buttons[id], irqhandler); + ret = pic32mz_gpioattach(g_buttons[id], irqhandler, arg); /* The interrupt is now disabled. Are we attaching or detaching from * button interrupt? */ - if (irqhandler) + if (ret >= 0) { /* Attaching... enable button interrupts now */ @@ -175,9 +175,9 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } } - return oldhandler; + return ret; #else - return NULL; + return -ENOSYS; #endif } #endif