2012-07-17 02:22:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/arm/src/stm32/stm32_exti_alarm.c
|
|
|
|
*
|
2017-03-02 16:18:10 +01:00
|
|
|
* Copyright (C) 2009, 2012, 2017 Gregory Nutt. All rights reserved.
|
2012-07-17 02:22:48 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
* Diego Sanchez <dsanchez@nx-engineering.com>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <arch/irq.h>
|
|
|
|
|
|
|
|
#include "up_arch.h"
|
|
|
|
#include "chip.h"
|
|
|
|
#include "stm32_gpio.h"
|
|
|
|
#include "stm32_exti.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Interrupt handlers attached to the ALARM EXTI */
|
|
|
|
|
2017-02-27 21:21:30 +01:00
|
|
|
static xcpt_t g_alarm_callback;
|
|
|
|
static void *g_callback_arg;
|
2012-07-17 02:22:48 +02:00
|
|
|
|
2015-10-04 22:59:08 +02:00
|
|
|
/****************************************************************************
|
2012-07-17 02:22:48 +02:00
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_exti_alarm_isr
|
|
|
|
*
|
|
|
|
* Description:
|
2012-07-19 16:33:14 +02:00
|
|
|
* EXTI ALARM interrupt service routine/dispatcher
|
2012-07-17 02:22:48 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-02-27 13:27:56 +01:00
|
|
|
static int stm32_exti_alarm_isr(int irq, void *context, FAR void *arg)
|
2012-07-17 02:22:48 +02:00
|
|
|
{
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
/* Clear the pending EXTI interrupt */
|
|
|
|
|
|
|
|
putreg32(EXTI_RTC_ALARM, STM32_EXTI_PR);
|
|
|
|
|
|
|
|
/* And dispatch the interrupt to the handler */
|
|
|
|
|
2017-02-27 21:21:30 +01:00
|
|
|
if (g_alarm_callback)
|
2012-07-17 02:22:48 +02:00
|
|
|
{
|
2017-02-27 21:21:30 +01:00
|
|
|
ret = g_alarm_callback(irq, context, g_callback_arg);
|
2012-07-17 02:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_exti_alarm
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Sets/clears EXTI alarm interrupt.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-10-13 14:32:33 +02:00
|
|
|
* - rising/falling edge: enables interrupt on rising/falling edge
|
2012-07-17 02:22:48 +02:00
|
|
|
* - event: generate event when set
|
|
|
|
* - func: when non-NULL, generate interrupt
|
2017-02-27 21:21:30 +01:00
|
|
|
* - arg: Argument passed to the interrupt callback
|
2012-07-17 02:22:48 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-03-02 16:18:10 +01:00
|
|
|
* Zero (OK) on success; a negated errno value on failure indicating the
|
|
|
|
* nature of the failure.
|
2012-07-17 02:22:48 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-03-02 16:18:10 +01:00
|
|
|
int stm32_exti_alarm(bool risingedge, bool fallingedge, bool event,
|
|
|
|
xcpt_t func, void *arg)
|
2012-07-17 02:22:48 +02:00
|
|
|
{
|
2017-02-27 21:21:30 +01:00
|
|
|
g_alarm_callback = func;
|
|
|
|
g_callback_arg = arg;
|
2012-07-17 02:22:48 +02:00
|
|
|
|
|
|
|
/* Install external interrupt handlers (if not already attached) */
|
|
|
|
|
|
|
|
if (func)
|
|
|
|
{
|
2017-02-27 13:27:56 +01:00
|
|
|
irq_attach(STM32_IRQ_RTCALRM, stm32_exti_alarm_isr, NULL);
|
2012-07-19 16:33:14 +02:00
|
|
|
up_enable_irq(STM32_IRQ_RTCALRM);
|
2012-07-17 02:22:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-19 16:33:14 +02:00
|
|
|
up_disable_irq(STM32_IRQ_RTCALRM);
|
2012-07-17 02:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure rising/falling edges */
|
|
|
|
|
|
|
|
modifyreg32(STM32_EXTI_RTSR,
|
|
|
|
risingedge ? 0 : EXTI_RTC_ALARM,
|
|
|
|
risingedge ? EXTI_RTC_ALARM : 0);
|
|
|
|
modifyreg32(STM32_EXTI_FTSR,
|
|
|
|
fallingedge ? 0 : EXTI_RTC_ALARM,
|
|
|
|
fallingedge ? EXTI_RTC_ALARM : 0);
|
|
|
|
|
|
|
|
/* Enable Events and Interrupts */
|
|
|
|
|
|
|
|
modifyreg32(STM32_EXTI_EMR,
|
|
|
|
event ? 0 : EXTI_RTC_ALARM,
|
|
|
|
event ? EXTI_RTC_ALARM : 0);
|
|
|
|
modifyreg32(STM32_EXTI_IMR,
|
|
|
|
func ? 0 : EXTI_RTC_ALARM,
|
|
|
|
func ? EXTI_RTC_ALARM : 0);
|
|
|
|
|
2017-03-02 16:18:10 +01:00
|
|
|
return OK;
|
2012-07-19 16:33:14 +02:00
|
|
|
}
|