2012-07-17 02:22:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/arm/src/stm32/stm32_exti_alarm.c
|
|
|
|
*
|
2021-05-27 10:49:33 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-07-17 02:22:48 +02:00
|
|
|
*
|
2021-05-27 10:49:33 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-07-17 02:22:48 +02:00
|
|
|
*
|
2021-05-27 10:49:33 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-07-17 02:22:48 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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>
|
|
|
|
|
2020-05-01 03:20:29 +02:00
|
|
|
#include "arm_arch.h"
|
2012-07-17 02:22:48 +02:00
|
|
|
#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
|
|
|
}
|