2014-06-10 20:15:42 +02:00
|
|
|
/*
|
2015-05-18 18:47:17 +02:00
|
|
|
* Copyright (C) 2014-2015 Freie Universität Berlin
|
2014-06-10 20:15:42 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-05-18 18:47:17 +02:00
|
|
|
* @ingroup cpu_cortexm_common
|
2014-06-10 20:15:42 +02:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Implementation of the kernels irq interface
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2020-05-04 08:39:58 +02:00
|
|
|
#ifndef IRQ_ARCH_H
|
|
|
|
#define IRQ_ARCH_H
|
2020-04-30 09:34:56 +02:00
|
|
|
|
2014-06-10 20:15:42 +02:00
|
|
|
#include <stdint.h>
|
2020-04-30 09:34:56 +02:00
|
|
|
#include "cpu_conf.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2014-06-10 20:15:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable all maskable interrupts
|
|
|
|
*/
|
2020-04-30 09:34:56 +02:00
|
|
|
static inline __attribute__((always_inline)) unsigned int irq_disable(void)
|
2014-06-10 20:15:42 +02:00
|
|
|
{
|
|
|
|
uint32_t mask = __get_PRIMASK();
|
2020-05-04 08:39:58 +02:00
|
|
|
|
2014-06-10 20:15:42 +02:00
|
|
|
__disable_irq();
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enable all maskable interrupts
|
|
|
|
*/
|
2020-04-30 09:34:56 +02:00
|
|
|
static inline __attribute__((always_inline)) __attribute__((used)) unsigned int
|
|
|
|
irq_enable(void)
|
2014-06-10 20:15:42 +02:00
|
|
|
{
|
2020-05-04 08:39:58 +02:00
|
|
|
unsigned result = __get_PRIMASK();
|
|
|
|
|
2014-06-10 20:15:42 +02:00
|
|
|
__enable_irq();
|
2020-05-04 08:39:58 +02:00
|
|
|
return result;
|
2014-06-10 20:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Restore the state of the IRQ flags
|
|
|
|
*/
|
2020-04-30 09:34:56 +02:00
|
|
|
static inline __attribute__((always_inline)) void irq_restore(
|
|
|
|
unsigned int state)
|
2014-06-10 20:15:42 +02:00
|
|
|
{
|
|
|
|
__set_PRIMASK(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief See if the current context is inside an ISR
|
|
|
|
*/
|
2020-04-30 09:34:56 +02:00
|
|
|
static inline __attribute__((always_inline)) int irq_is_in(void)
|
2014-06-10 20:15:42 +02:00
|
|
|
{
|
|
|
|
return (__get_IPSR() & 0xFF);
|
|
|
|
}
|
2020-04-30 09:34:56 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-04 08:39:58 +02:00
|
|
|
#endif /* IRQ_ARCH_H */
|
2020-04-30 09:34:56 +02:00
|
|
|
/** @} */
|