board_button_irq: Button IRQ logic no longer returns the xcpt_t oldhandler. There value is useless and dangerous after the recent changes to interrupt argument passing.

This commit is contained in:
Gregory Nutt 2017-03-02 15:10:37 -06:00
parent 4c82827ab1
commit 0f46d714a9
17 changed files with 110 additions and 375 deletions

View File

@ -174,7 +174,7 @@ int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
if (irqhandler) if (irqhandler)
{ {
ret = irq_attach(IRQ_SW4, irqhandler, NULL); ret = irq_attach(IRQ_SW4, irqhandler, arg);
if (ret == OK) if (ret == OK)
{ {
handler = irqhandler; handler = irqhandler;

View File

@ -121,7 +121,7 @@ int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
/* Configure the interrupt */ /* Configure the interrupt */
a1x_pioirq(xxx); a1x_pioirq(xxx);
(void)irq_attach(xxx, irqhandler, NULL); (void)irq_attach(xxx, irqhandler, arg);
a1x_pioirqenable(xxx); a1x_pioirqenable(xxx);
leave_critical_section(flags); leave_critical_section(flags);

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/sam3u-ek/src/up_leds.c * configs/sam3u-ek/src/up_leds.c
* *
* Copyright (C) 2010, 2014-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2010, 2014-2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -53,19 +54,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t g_irqbutton1;
static xcpt_t g_irqbutton2;
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -79,10 +67,9 @@ static xcpt_t g_irqbutton2;
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, static int board_button_irqx(gpio_pinset_t pinset, int irq, xcpt_t irqhandler,
xcpt_t irqhandler, xcpt_t *store, void *arg) void *arg)
{ {
xcpt_t oldhandler;
irqstate_t flags; irqstate_t flags;
/* Disable interrupts until we are done. This guarantees that the following /* Disable interrupts until we are done. This guarantees that the following
@ -91,11 +78,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq,
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = *store;
*store = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -115,10 +97,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq,
} }
leave_critical_section(flags); leave_critical_section(flags);
return OK;
/* Return the old button handler (so that it can be restored) */
return oldhandler;
} }
#endif #endif
@ -182,21 +161,19 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
if (id == BUTTON1) if (id == BUTTON1)
{ {
return board_button_irqx(GPIO_BUTTON1, IRQ_BUTTON1, return board_button_irqx(GPIO_BUTTON1, IRQ_BUTTON1, irqhandler, arg);
irqhandler, &g_irqbutton1, arg);
} }
else if (id == BUTTON2) else if (id == BUTTON2)
{ {
return board_button_irqx(GPIO_BUTTON2, IRQ_BUTTON2, return board_button_irqx(GPIO_BUTTON2, IRQ_BUTTON2, irqhandler, arg);
irqhandler, &g_irqbutton2, arg);
} }
else else
{ {
return NULL; return -EINVAL;
} }
} }
#endif #endif

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/sam4e-ek/src/sam_buttons.c * configs/sam4e-ek/src/sam_buttons.c
* *
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -53,21 +54,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t g_irq_scrollup;
static xcpt_t g_irq_scrolldown;
static xcpt_t g_irq_waku;
static xcpt_t g_irq_tamp;
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -81,10 +67,9 @@ static xcpt_t g_irq_tamp;
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, static int board_button_irqx(gpio_pinset_t pinset, int irq, xcpt_t irqhandler,
xcpt_t irqhandler, xcpt_t *store, void *arg) void *arg)
{ {
xcpt_t oldhandler;
irqstate_t flags; irqstate_t flags;
/* Disable interrupts until we are done. This guarantees that the following /* Disable interrupts until we are done. This guarantees that the following
@ -93,11 +78,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq,
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = *store;
*store = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -117,10 +97,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq,
} }
leave_critical_section(flags); leave_critical_section(flags);
return OK;
/* Return the old button handler (so that it can be restored) */
return oldhandler;
} }
#endif #endif
@ -188,28 +165,24 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
switch (id) switch (id)
{ {
case BUTTON_SCROLLUP: case BUTTON_SCROLLUP:
return board_button_irqx(GPIO_SCROLLUP, IRQ_SCROLLUP, return board_button_irqx(GPIO_SCROLLUP, IRQ_SCROLLUP, irqhandler, arg);
irqhandler, &g_irq_scrollup, arg);
case BUTTON_SCROLLDOWN: case BUTTON_SCROLLDOWN:
return board_button_irqx(GPIO_SCROLLDWN, IRQ_SCROLLDWN, return board_button_irqx(GPIO_SCROLLDWN, IRQ_SCROLLDWN, irqhandler, arg);
irqhandler, &g_irq_scrolldown, arg);
case BUTTON_WAKU: case BUTTON_WAKU:
return board_button_irqx(GPIO_WAKU, IRQ_WAKU, return board_button_irqx(GPIO_WAKU, IRQ_WAKU, irqhandler, arg);
irqhandler, &g_irq_waku, arg);
case BUTTON_TAMP: case BUTTON_TAMP:
return board_button_irqx(GPIO_TAMP, IRQ_TAMP, return board_button_irqx(GPIO_TAMP, IRQ_TAMP, irqhandler, arg);
irqhandler, &g_irq_tamp, arg);
default: default:
return NULL; return -EINVAL;
} }
} }
#endif #endif

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/sam4l-xplained/src/sam_buttons.c * configs/sam4l-xplained/src/sam_buttons.c
* *
* Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2013-2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -53,18 +53,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t g_irqsw0;
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -123,9 +111,9 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = -EINVAL;
if (id == BUTTON_SW0) if (id == BUTTON_SW0)
{ {
@ -137,11 +125,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = *g_irqsw0;
*g_irqsw0 = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -149,7 +132,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
/* Configure the interrupt */ /* Configure the interrupt */
sam_gpioirq(GPIO_SW0); sam_gpioirq(GPIO_SW0);
(void)irq_attach(IRQ_SW0, irqhandler, NULL); (void)irq_attach(IRQ_SW0, irqhandler, arg);
sam_gpioirqenable(IRQ_SW0); sam_gpioirqenable(IRQ_SW0);
} }
else else
@ -161,11 +144,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
} }
leave_critical_section(flags); leave_critical_section(flags);
ret = OK;
} }
/* Return the old button handler (so that it can be restored) */ return ret;
return oldhandler;
} }
#endif #endif

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/sam4s-xplained-pro/src/sam_buttons.c * configs/sam4s-xplained-pro/src/sam_buttons.c
* *
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org> * Authors: Gregory Nutt <gnutt@nuttx.org>
* Bob Doiron * Bob Doiron
* *
@ -41,6 +41,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -54,20 +55,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
static xcpt_t g_irqsw0;
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -122,9 +109,9 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = -EINVAL;
if (id == BUTTON_SW0) if (id == BUTTON_SW0)
{ {
@ -136,11 +123,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = g_irqsw0;
g_irqsw0 = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -148,7 +130,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
/* Configure the interrupt */ /* Configure the interrupt */
sam_gpioirq(GPIO_SW0); sam_gpioirq(GPIO_SW0);
(void)irq_attach(IRQ_SW0, irqhandler, NULL); (void)irq_attach(IRQ_SW0, irqhandler, arg);
sam_gpioirqenable(IRQ_SW0); sam_gpioirqenable(IRQ_SW0);
} }
else else
@ -160,11 +142,12 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
} }
leave_critical_section(flags); leave_critical_section(flags);
ret = OK;
} }
/* Return the old button handler (so that it can be restored) */ /* Return the old button handler (so that it can be restored) */
return oldhandler; return ret;
} }
#endif #endif

View File

@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -53,22 +54,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t g_irqbp2;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -123,9 +108,9 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = -EINVAL;
if (id == BUTTON_BP2) if (id == BUTTON_BP2)
{ {
@ -137,11 +122,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = *g_irqbp2;
*g_irqbp2 = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -149,7 +129,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
/* Configure the interrupt */ /* Configure the interrupt */
sam_gpioirq(GPIO_BP2); sam_gpioirq(GPIO_BP2);
(void)irq_attach(IRQ_BP2, irqhandler, NULL); (void)irq_attach(IRQ_BP2, irqhandler, arg);
sam_gpioirqenable(IRQ_BP2); sam_gpioirqenable(IRQ_BP2);
} }
else else
@ -161,11 +141,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
} }
leave_critical_section(flags); leave_critical_section(flags);
ret = OK;
} }
/* Return the old button handler (so that it can be restored) */ return ret;
return oldhandler;
} }
#endif #endif

View File

@ -51,6 +51,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -64,22 +65,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_SAMA5_PIOB_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t g_irquser1;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -132,9 +117,9 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAMA5_PIOB_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAMA5_PIOB_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = -EINVAL;
if (id == BUTTON_USER) if (id == BUTTON_USER)
{ {
@ -146,11 +131,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = g_irquser1;
g_irquser1 = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -158,7 +138,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
/* Configure the interrupt */ /* Configure the interrupt */
sam_pioirq(PIO_BTN_USER); sam_pioirq(PIO_BTN_USER);
(void)irq_attach(IRQ_BTN_USER, irqhandler, NULL); (void)irq_attach(IRQ_BTN_USER, irqhandler, arg);
sam_pioirqenable(IRQ_BTN_USER); sam_pioirqenable(IRQ_BTN_USER);
} }
else else
@ -170,11 +150,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
} }
leave_critical_section(flags); leave_critical_section(flags);
ret = OK;
} }
/* Return the old button handler (so that it can be restored) */ return ret;
return oldhandler;
} }
#endif #endif

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/sama5d3-xplained/src/sam_buttons.c * configs/sama5d3-xplained/src/sam_buttons.c
* *
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -55,6 +55,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -68,22 +69,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t g_irquser1;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -136,9 +121,9 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = -EINVAL;
if (id == BUTTON_USER) if (id == BUTTON_USER)
{ {
@ -150,11 +135,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = g_irquser1;
g_irquser1 = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -162,7 +142,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
/* Configure the interrupt */ /* Configure the interrupt */
sam_pioirq(PIO_USER); sam_pioirq(PIO_USER);
(void)irq_attach(IRQ_USER1, irqhandler, NULL); (void)irq_attach(IRQ_USER1, irqhandler, arg);
sam_pioirqenable(IRQ_USER1); sam_pioirqenable(IRQ_USER1);
} }
else else
@ -172,14 +152,12 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
sam_pioirqdisable(IRQ_USER1); sam_pioirqdisable(IRQ_USER1);
(void)irq_detach(IRQ_USER1); (void)irq_detach(IRQ_USER1);
} }
/* Configure the interrupt */
leave_critical_section(flags); leave_critical_section(flags);
ret = OK;
} }
/* Return the old button handler (so that it can be restored) */ return ret;
return oldhandler;
} }
#endif #endif

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/sama5d3x-ek/src/sam_buttons.c * configs/sama5d3x-ek/src/sam_buttons.c
* *
* Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved. * Copyright (C) 2013, 2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -55,6 +55,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -68,22 +69,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t g_irquser1;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -136,9 +121,9 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = -EINVAL;
if (id == BUTTON_USER1) if (id == BUTTON_USER1)
{ {
@ -150,11 +135,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = g_irquser1;
g_irquser1 = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -162,7 +142,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
/* Configure the interrupt */ /* Configure the interrupt */
sam_pioirq(PIO_USER1); sam_pioirq(PIO_USER1);
(void)irq_attach(IRQ_USER1, irqhandler, NULL); (void)irq_attach(IRQ_USER1, irqhandler, arg);
sam_pioirqenable(IRQ_USER1); sam_pioirqenable(IRQ_USER1);
} }
else else
@ -174,11 +154,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
} }
leave_critical_section(flags); leave_critical_section(flags);
ret = OK;
} }
/* Return the old button handler (so that it can be restored) */ return ret;
return oldhandler;
} }
#endif #endif

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/sama5d4-ek/src/sam_buttons.c * configs/sama5d4-ek/src/sam_buttons.c
* *
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -51,6 +51,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -64,22 +65,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t g_irquser1;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -132,9 +117,9 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = -EINVAL;
if (id == BUTTON_USER) if (id == BUTTON_USER)
{ {
@ -146,11 +131,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = g_irquser1;
g_irquser1 = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -158,7 +138,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
/* Configure the interrupt */ /* Configure the interrupt */
sam_pioirq(PIO_BTN_USER); sam_pioirq(PIO_BTN_USER);
(void)irq_attach(IRQ_BTN_USER, irqhandler, NULL); (void)irq_attach(IRQ_BTN_USER, irqhandler, arg);
sam_pioirqenable(IRQ_BTN_USER); sam_pioirqenable(IRQ_BTN_USER);
} }
else else
@ -170,11 +150,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
} }
leave_critical_section(flags); leave_critical_section(flags);
ret = OK;
} }
/* Return the old button handler (so that it can be restored) */ return ret;
return oldhandler;
} }
#endif #endif

View File

@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -53,22 +54,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t g_irqsw0;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -123,9 +108,9 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = -EINVAL;
if (id == BUTTON_SW0) if (id == BUTTON_SW0)
{ {
@ -137,20 +122,15 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = *g_irqsw0;
*g_irqsw0 = irqhandler;
/* Configure the interrupt */ /* Configure the interrupt */
sam_portirq(IRQ_SW0); sam_portirq(IRQ_SW0);
(void)irq_attach(IRQ_SW0, irqhandler, NULL); (void)irq_attach(IRQ_SW0, irqhandler, arg);
sam_portirqenable(IRQ_SW0); sam_portirqenable(IRQ_SW0);
leave_critical_section(flags);
}
/* Return the old button handler (so that it can be restored) */ leave_critical_section(flags);
ret = OK;
}
return oldhandler; return oldhandler;
} }

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/samd21-xplained/src/sam_buttons.c * configs/samd21-xplained/src/sam_buttons.c
* *
* Copyright (C) 2015 Gregory Nutt. All rights reserved. * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -53,22 +54,6 @@
#ifdef CONFIG_ARCH_BUTTONS #ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
static xcpt_t g_irqsw0;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -123,9 +108,9 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) #if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS)
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = -EINVAL;
if (id == BUTTON_SW0) if (id == BUTTON_SW0)
{ {
@ -137,22 +122,17 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = *g_irqsw0;
*g_irqsw0 = irqhandler;
/* Configure the interrupt */ /* Configure the interrupt */
sam_portirq(IRQ_SW0); sam_portirq(IRQ_SW0);
(void)irq_attach(IRQ_SW0, irqhandler, NULL); (void)irq_attach(IRQ_SW0, irqhandler, arg);
sam_portirqenable(IRQ_SW0); sam_portirqenable(IRQ_SW0);
leave_critical_section(flags); leave_critical_section(flags);
ret = OK;
} }
/* Return the old button handler (so that it can be restored) */ return ret;
return oldhandler;
} }
#endif #endif

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/sam4e-ek/src/sam_buttons.c * configs/sam4e-ek/src/sam_buttons.c
* *
* Copyright (C) 2015 Gregory Nutt. All rights reserved. * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -59,20 +60,11 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_ARCH_IRQBUTTONS #ifdef CONFIG_ARCH_IRQBUTTONS
# define HAVE_IRQBUTTONS 1
#define HAVE_IRQBUTTONS 1 # ifndef CONFIG_SAMV7_GPIOA_IRQ
#ifndef CONFIG_SAMV7_GPIOA_IRQ # undef HAVE_IRQBUTTONS
# undef HAVE_IRQBUTTONS # endif
#endif
#ifdef CONFIG_SAMV7_GPIOA_IRQ
static xcpt_t g_irq_sw0;
#endif
#endif #endif
/**************************************************************************** /****************************************************************************
@ -88,10 +80,9 @@ static xcpt_t g_irq_sw0;
****************************************************************************/ ****************************************************************************/
#ifdef HAVE_IRQBUTTONS #ifdef HAVE_IRQBUTTONS
static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, static int board_button_irqx(gpio_pinset_t pinset, int irq,
xcpt_t irqhandler, xcpt_t *store, void *arg) xcpt_t irqhandler, void *arg)
{ {
xcpt_t oldhandler;
irqstate_t flags; irqstate_t flags;
/* Disable interrupts until we are done. This guarantees that the following /* Disable interrupts until we are done. This guarantees that the following
@ -100,11 +91,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq,
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = *store;
*store = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -124,10 +110,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq,
} }
leave_critical_section(flags); leave_critical_section(flags);
return OK;
/* Return the old button handler (so that it can be restored) */
return oldhandler;
} }
#endif #endif
@ -187,17 +170,16 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_ARCH_IRQBUTTONS #ifdef CONFIG_ARCH_IRQBUTTONS
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
#ifdef HAVE_IRQBUTTONS #ifdef HAVE_IRQBUTTONS
if (id == BUTTON_SW0) if (id == BUTTON_SW0)
{ {
return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, &g_irq_sw0, arg); return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, arg);
} }
#endif #endif
return NULL; return -EINVAL;
} }
#endif #endif

View File

@ -145,7 +145,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
/* Configure the interrupt */ /* Configure the interrupt */
sam_portirq(IRQ_SW0); sam_portirq(IRQ_SW0);
(void)irq_attach(IRQ_SW0, irqhandler, NULL); (void)irq_attach(IRQ_SW0, irqhandler, arg);
sam_portirqenable(IRQ_SW0); sam_portirqenable(IRQ_SW0);
leave_critical_section(flags); leave_critical_section(flags);
} }

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/sam4e-ek/src/sam_buttons.c * configs/sam4e-ek/src/sam_buttons.c
* *
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/board.h> #include <nuttx/board.h>
@ -64,18 +65,10 @@
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_ARCH_IRQBUTTONS #ifdef CONFIG_ARCH_IRQBUTTONS
# define HAVE_IRQBUTTONS 1
#define HAVE_IRQBUTTONS 1 # if !defined(CONFIG_SAMV7_GPIOA_IRQ) && !defined(CONFIG_SAMV7_GPIOB_IRQ)
#if !defined(CONFIG_SAMV7_GPIOA_IRQ) && !defined(CONFIG_SAMV7_GPIOB_IRQ) # undef HAVE_IRQBUTTONS
# undef HAVE_IRQBUTTONS # endif
#endif
#ifdef CONFIG_SAMV7_GPIOA_IRQ
static xcpt_t g_irq_sw0;
#endif
#ifdef CONFIG_SAMV7_GPIOB_IRQ
static xcpt_t g_irq_sw1;
#endif
#endif #endif
/**************************************************************************** /****************************************************************************
@ -92,9 +85,8 @@ static xcpt_t g_irq_sw1;
#ifdef HAVE_IRQBUTTONS #ifdef HAVE_IRQBUTTONS
static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq,
xcpt_t irqhandler, xcpt_t *store, void *arg) xcpt_t irqhandler, void *arg)
{ {
xcpt_t oldhandler;
irqstate_t flags; irqstate_t flags;
/* Disable interrupts until we are done. This guarantees that the following /* Disable interrupts until we are done. This guarantees that the following
@ -103,11 +95,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq,
flags = enter_critical_section(); flags = enter_critical_section();
/* Get the old button interrupt handler and save the new one */
oldhandler = *store;
*store = irqhandler;
/* Are we attaching or detaching? */ /* Are we attaching or detaching? */
if (irqhandler != NULL) if (irqhandler != NULL)
@ -127,10 +114,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq,
} }
leave_critical_section(flags); leave_critical_section(flags);
return OK;
/* Return the old button handler (so that it can be restored) */
return oldhandler;
} }
#endif #endif
@ -207,7 +191,7 @@ uint8_t board_buttons(void)
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_ARCH_IRQBUTTONS #ifdef CONFIG_ARCH_IRQBUTTONS
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
#ifdef HAVE_IRQBUTTONS #ifdef HAVE_IRQBUTTONS
@ -215,21 +199,21 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
#ifdef CONFIG_SAMV7_GPIOA_IRQ #ifdef CONFIG_SAMV7_GPIOA_IRQ
case BUTTON_SW0: case BUTTON_SW0:
return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, &g_irq_sw0, arg); return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, arg);
#endif #endif
#ifdef CONFIG_SAMV7_GPIOB_IRQ #ifdef CONFIG_SAMV7_GPIOB_IRQ
case BUTTON_SW1: case BUTTON_SW1:
return board_button_irqx(GPIO_SW1, IRQ_SW1, irqhandler, &g_irq_sw1, arg); return board_button_irqx(GPIO_SW1, IRQ_SW1, irqhandler, arg);
#endif #endif
default: default:
return NULL; return -EINVAL;
} }
#else #else
return NULL; return -ENOSYS;
#endif #endif
} }

View File

@ -176,7 +176,7 @@ int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
/* Attach the new interrupt handler and enable the interrupt */ /* Attach the new interrupt handler and enable the interrupt */
ret = irq_attach(ZKITARM_KEY5_IRQ, irqhandler, NULL); ret = irq_attach(ZKITARM_KEY5_IRQ, irqhandler, arg);
if (ret == OK) if (ret == OK)
{ {
up_enable_irq(ZKITARM_KEY5_IRQ); up_enable_irq(ZKITARM_KEY5_IRQ);