2015-08-20 16:46:11 -04:00
|
|
|
/* ARM Cortex-M GCC specific public inline assembler functions and macros */
|
2015-04-27 13:40:11 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-27 13:40:11 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Either public functions or macros or invoked by public functions */
|
|
|
|
|
2018-09-14 10:43:44 -07:00
|
|
|
#ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_GCC_H_
|
|
|
|
#define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_GCC_H_
|
2015-04-27 13:40:11 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The file must not be included directly
|
2015-10-04 09:37:29 -04:00
|
|
|
* Include arch/cpu.h instead
|
2015-04-27 13:40:11 -04:00
|
|
|
*/
|
|
|
|
|
2018-08-10 11:49:06 -04:00
|
|
|
#ifndef _ASMLANGUAGE
|
2015-04-27 13:40:11 -04:00
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 10:32:08 -05:00
|
|
|
#include <zephyr/types.h>
|
2018-06-08 16:34:16 -04:00
|
|
|
#include <arch/arm/exc.h>
|
2016-02-25 13:21:02 -08:00
|
|
|
#include <irq.h>
|
2015-04-27 13:40:11 -04:00
|
|
|
|
2019-08-12 12:52:55 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-07-01 17:22:39 -04:00
|
|
|
/**
|
|
|
|
*
|
2015-08-12 18:31:41 -04:00
|
|
|
* @brief Disable all interrupts on the CPU
|
2015-07-01 17:22:39 -04:00
|
|
|
*
|
2017-10-29 07:10:22 -04:00
|
|
|
* This routine disables interrupts. It can be called from either interrupt or
|
|
|
|
* thread level. This routine returns an architecture-dependent
|
2015-07-01 17:22:39 -04:00
|
|
|
* lock-out key representing the "interrupt disable state" prior to the call;
|
2015-08-12 18:31:41 -04:00
|
|
|
* this key can be passed to irq_unlock() to re-enable interrupts.
|
2015-07-01 17:22:39 -04:00
|
|
|
*
|
2015-08-12 18:31:41 -04:00
|
|
|
* The lock-out key should only be used as the argument to the irq_unlock()
|
|
|
|
* API. It should never be used to manually re-enable interrupts or to inspect
|
|
|
|
* or manipulate the contents of the source register.
|
|
|
|
*
|
|
|
|
* This function can be called recursively: it will return a key to return the
|
|
|
|
* state of interrupt locking to the previous level.
|
2015-07-01 17:22:39 -04:00
|
|
|
*
|
|
|
|
* WARNINGS
|
|
|
|
* Invoking a kernel routine with interrupts locked may result in
|
|
|
|
* interrupts being re-enabled for an unspecified period of time. If the
|
|
|
|
* called routine blocks, interrupts will be re-enabled while another
|
2015-08-20 11:04:01 -04:00
|
|
|
* thread executes, or while the system is idle.
|
2015-07-01 17:22:39 -04:00
|
|
|
*
|
2015-08-20 11:04:01 -04:00
|
|
|
* The "interrupt disable state" is an attribute of a thread. Thus, if a
|
2017-10-29 07:10:22 -04:00
|
|
|
* thread disables interrupts and subsequently invokes a kernel
|
2015-08-20 11:04:01 -04:00
|
|
|
* routine that causes the calling thread to block, the interrupt
|
|
|
|
* disable state will be restored when the thread is later rescheduled
|
2015-07-01 17:22:39 -04:00
|
|
|
* for execution.
|
|
|
|
*
|
2015-07-01 17:29:04 -04:00
|
|
|
* @return An architecture-dependent lock-out key representing the
|
2015-07-01 17:22:39 -04:00
|
|
|
* "interrupt disable state" prior to the call.
|
|
|
|
*
|
2015-08-12 18:31:41 -04:00
|
|
|
* @internal
|
|
|
|
*
|
2019-02-07 10:01:55 +01:00
|
|
|
* On ARMv7-M and ARMv8-M Mainline CPUs, this function prevents regular
|
|
|
|
* exceptions (i.e. with interrupt priority lower than or equal to
|
|
|
|
* _EXC_IRQ_DEFAULT_PRIO) from interrupting the CPU. NMI, Faults, SVC,
|
|
|
|
* and Zero Latency IRQs (if supported) may still interrupt the CPU.
|
|
|
|
*
|
|
|
|
* On ARMv6-M and ARMv8-M Baseline CPUs, this function reads the value of
|
|
|
|
* PRIMASK which shows if interrupts are enabled, then disables all interrupts
|
|
|
|
* except NMI.
|
2015-07-01 17:22:39 -04:00
|
|
|
*/
|
2015-04-27 13:40:11 -04:00
|
|
|
|
2019-03-08 14:19:05 -07:00
|
|
|
static ALWAYS_INLINE unsigned int z_arch_irq_lock(void)
|
2015-04-27 13:40:11 -04:00
|
|
|
{
|
|
|
|
unsigned int key;
|
|
|
|
|
2018-02-06 23:47:58 +01:00
|
|
|
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
|
2016-12-02 23:30:45 +00:00
|
|
|
__asm__ volatile("mrs %0, PRIMASK;"
|
|
|
|
"cpsid i"
|
2016-12-02 12:18:04 +00:00
|
|
|
: "=r" (key)
|
|
|
|
:
|
|
|
|
: "memory");
|
2018-02-06 23:47:58 +01:00
|
|
|
#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
|
2016-12-02 23:28:49 +00:00
|
|
|
unsigned int tmp;
|
|
|
|
|
2015-04-27 13:40:11 -04:00
|
|
|
__asm__ volatile(
|
2016-12-02 23:30:45 +00:00
|
|
|
"mov %1, %2;"
|
|
|
|
"mrs %0, BASEPRI;"
|
2019-03-06 14:33:58 +01:00
|
|
|
"msr BASEPRI, %1;"
|
|
|
|
"isb;"
|
2016-12-02 23:28:49 +00:00
|
|
|
: "=r"(key), "=r"(tmp)
|
2015-04-27 13:40:11 -04:00
|
|
|
: "i"(_EXC_IRQ_DEFAULT_PRIO)
|
2016-12-02 23:28:49 +00:00
|
|
|
: "memory");
|
2018-06-25 09:15:14 -04:00
|
|
|
#elif defined(CONFIG_ARMV7_R)
|
|
|
|
__asm__ volatile("mrs %0, cpsr;"
|
|
|
|
"cpsid i"
|
|
|
|
: "=r" (key)
|
|
|
|
:
|
|
|
|
: "memory", "cc");
|
2016-12-31 13:18:25 +00:00
|
|
|
#else
|
|
|
|
#error Unknown ARM architecture
|
2018-02-06 23:47:58 +01:00
|
|
|
#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */
|
2015-04-27 13:40:11 -04:00
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-01 17:22:39 -04:00
|
|
|
/**
|
|
|
|
*
|
2015-07-01 17:51:40 -04:00
|
|
|
* @brief Enable all interrupts on the CPU (inline)
|
2015-07-01 17:22:39 -04:00
|
|
|
*
|
2015-10-04 09:37:29 -04:00
|
|
|
* This routine re-enables interrupts on the CPU. The @a key parameter is an
|
2015-08-12 18:31:41 -04:00
|
|
|
* architecture-dependent lock-out key that is returned by a previous
|
|
|
|
* invocation of irq_lock().
|
2015-07-01 17:22:39 -04:00
|
|
|
*
|
2017-10-29 07:10:22 -04:00
|
|
|
* This routine can be called from either interrupt or thread level.
|
2015-07-01 17:22:39 -04:00
|
|
|
*
|
2015-10-04 09:37:29 -04:00
|
|
|
* @param key architecture-dependent lock-out key
|
|
|
|
*
|
2015-07-01 17:29:04 -04:00
|
|
|
* @return N/A
|
2016-10-05 19:43:36 -03:00
|
|
|
*
|
|
|
|
* On Cortex-M0/M0+, this enables all interrupts if they were not
|
|
|
|
* previously disabled.
|
|
|
|
*
|
2015-07-01 17:22:39 -04:00
|
|
|
*/
|
2015-04-27 13:40:11 -04:00
|
|
|
|
2019-03-08 14:19:05 -07:00
|
|
|
static ALWAYS_INLINE void z_arch_irq_unlock(unsigned int key)
|
2015-04-27 13:40:11 -04:00
|
|
|
{
|
2018-02-06 23:47:58 +01:00
|
|
|
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
|
2016-10-05 19:43:36 -03:00
|
|
|
if (key) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-06 20:12:26 +01:00
|
|
|
__asm__ volatile(
|
|
|
|
"cpsie i;"
|
|
|
|
"isb"
|
|
|
|
: : : "memory");
|
2018-02-06 23:47:58 +01:00
|
|
|
#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
|
2019-03-06 20:12:26 +01:00
|
|
|
__asm__ volatile(
|
|
|
|
"msr BASEPRI, %0;"
|
|
|
|
"isb;"
|
|
|
|
: : "r"(key) : "memory");
|
2018-06-25 09:15:14 -04:00
|
|
|
#elif defined(CONFIG_ARMV7_R)
|
|
|
|
__asm__ volatile("msr cpsr_c, %0"
|
|
|
|
:
|
|
|
|
: "r" (key)
|
|
|
|
: "memory", "cc");
|
2016-12-31 13:18:25 +00:00
|
|
|
#else
|
|
|
|
#error Unknown ARM architecture
|
2018-02-06 23:47:58 +01:00
|
|
|
#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */
|
2015-04-27 13:40:11 -04:00
|
|
|
}
|
|
|
|
|
2019-05-24 09:24:35 -07:00
|
|
|
/**
|
|
|
|
* Returns true if interrupts were unlocked prior to the
|
|
|
|
* z_arch_irq_lock() call that produced the key argument.
|
|
|
|
*/
|
|
|
|
static ALWAYS_INLINE bool z_arch_irq_unlocked(unsigned int key)
|
|
|
|
{
|
|
|
|
/* This convention works for both PRIMASK and BASEPRI */
|
|
|
|
return key == 0;
|
|
|
|
}
|
2015-04-27 13:40:11 -04:00
|
|
|
|
2016-01-22 12:38:49 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-12 12:52:55 -05:00
|
|
|
#endif /* _ASMLANGUAGE */
|
|
|
|
|
2018-09-14 10:43:44 -07:00
|
|
|
#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_GCC_H_ */
|