2013-11-27 16:28:31 +01:00
|
|
|
/*
|
2019-03-06 18:00:49 +01:00
|
|
|
* Copyright (C) 2013,2019 Freie Universität Berlin
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2014-08-23 15:43:13 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-11-27 16:28:31 +01:00
|
|
|
* @defgroup core_irq IRQ Handling
|
|
|
|
* @ingroup core
|
|
|
|
* @brief Provides an API to control interrupt processing
|
|
|
|
* @{
|
|
|
|
*
|
2015-05-22 07:34:41 +02:00
|
|
|
* @file
|
2010-09-22 15:10:42 +02:00
|
|
|
* @brief IRQ driver interface
|
|
|
|
*
|
2013-02-27 20:22:19 +01:00
|
|
|
* @author Freie Universität Berlin, Computer Systems & Telematics
|
2019-03-06 18:00:49 +01:00
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
|
|
|
|
2017-01-18 13:00:05 +01:00
|
|
|
#ifndef IRQ_H
|
|
|
|
#define IRQ_H
|
2013-11-27 16:28:31 +01:00
|
|
|
|
2014-10-13 14:44:28 +02:00
|
|
|
#include <stdbool.h>
|
2020-04-30 09:34:56 +02:00
|
|
|
#include "cpu_conf.h"
|
2014-10-13 14:44:28 +02:00
|
|
|
|
2014-10-09 01:18:16 +02:00
|
|
|
#ifdef __cplusplus
|
2020-03-30 17:02:08 +02:00
|
|
|
extern "C" {
|
2014-10-09 01:18:16 +02:00
|
|
|
#endif
|
|
|
|
|
2020-04-30 09:34:56 +02:00
|
|
|
#ifdef IRQ_API_INLINED
|
|
|
|
#define MAYBE_INLINE static inline __attribute__((always_inline))
|
|
|
|
#else
|
|
|
|
#define MAYBE_INLINE
|
|
|
|
#endif /* IRQ_API_INLINED */
|
|
|
|
|
2022-10-24 22:44:42 +02:00
|
|
|
#ifndef IRQ_API_INLINED
|
2010-09-22 15:10:42 +02:00
|
|
|
/**
|
|
|
|
* @brief This function sets the IRQ disable bit in the status register
|
2013-02-27 20:22:19 +01:00
|
|
|
*
|
2019-01-07 20:50:59 +01:00
|
|
|
* @return Previous value of status register. The return value should not be
|
2014-04-06 17:26:51 +02:00
|
|
|
* interpreted as a boolean value. The actual value is only
|
2016-03-19 09:25:47 +01:00
|
|
|
* significant for irq_restore().
|
2014-04-06 17:26:51 +02:00
|
|
|
*
|
2016-03-19 09:25:47 +01:00
|
|
|
* @see irq_restore
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
2020-04-30 09:34:56 +02:00
|
|
|
MAYBE_INLINE unsigned irq_disable(void);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function clears the IRQ disable bit in the status register
|
2014-04-06 17:26:51 +02:00
|
|
|
*
|
2019-01-07 20:50:59 +01:00
|
|
|
* @return Previous value of status register. The return value should not be
|
2014-04-06 17:26:51 +02:00
|
|
|
* interpreted as a boolean value. The actual value is only
|
2016-03-19 09:25:47 +01:00
|
|
|
* significant for irq_restore().
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2021-12-21 18:03:55 +01:00
|
|
|
* @warning This function is here primarily for internal use, and for
|
|
|
|
* compatibility with the Arduino environment (which lacks the
|
|
|
|
* "disable / restore" concept. Enabling interrupts when a different
|
|
|
|
* component disabled them can easily cause unintended behavior there.
|
|
|
|
*
|
|
|
|
* Use @ref irq_restore instead.
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
2020-04-30 09:34:56 +02:00
|
|
|
MAYBE_INLINE unsigned irq_enable(void);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function restores the IRQ disable bit in the status register
|
|
|
|
* to the value contained within passed state
|
2014-04-06 17:26:51 +02:00
|
|
|
*
|
|
|
|
* @param[in] state state to restore
|
2010-09-22 15:10:42 +02:00
|
|
|
*
|
2016-03-19 09:25:47 +01:00
|
|
|
* @see irq_disable
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
2020-04-30 09:34:56 +02:00
|
|
|
MAYBE_INLINE void irq_restore(unsigned state);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2019-03-06 18:00:49 +01:00
|
|
|
/**
|
|
|
|
* @brief Test if IRQs are currently enabled
|
|
|
|
*
|
|
|
|
* @warning Use this function from thread context only. When used in interrupt
|
|
|
|
* context the returned state may be incorrect.
|
|
|
|
*
|
2021-12-08 15:53:15 +01:00
|
|
|
* @return false if IRQs are currently disabled
|
|
|
|
* @return true if IRQs are currently enabled
|
2019-03-06 18:00:49 +01:00
|
|
|
*/
|
2021-12-08 15:53:15 +01:00
|
|
|
MAYBE_INLINE bool irq_is_enabled(void);
|
2019-03-06 18:00:49 +01:00
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
/**
|
2014-02-15 18:49:27 +01:00
|
|
|
* @brief Check whether called from interrupt service routine
|
|
|
|
* @return true, if in interrupt service routine, false if not
|
2010-09-22 15:10:42 +02:00
|
|
|
*/
|
2021-12-08 15:53:15 +01:00
|
|
|
MAYBE_INLINE bool irq_is_in(void);
|
2020-04-30 09:34:56 +02:00
|
|
|
|
2022-10-24 22:44:42 +02:00
|
|
|
#else
|
2020-04-30 09:34:56 +02:00
|
|
|
#include "irq_arch.h"
|
|
|
|
#endif /* IRQ_API_INLINED */
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-10-09 01:18:16 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-18 13:00:05 +01:00
|
|
|
#endif /* IRQ_H */
|
2014-04-06 17:26:51 +02:00
|
|
|
/** @} */
|