mirror of https://github.com/ARMmbed/mbed-os.git
Remove RTOS and CMSIS files
Remove the RTOS and CMSIS files in preperation for CMSIS 5. Note that the RTOS heap ad stack test is left since this is still applicable to RTX5. This file can be found here: rtos\rtx\TARGET_CORTEX_M\TESTS\memory\heap_and_stack\main.cpppull/4294/head
parent
1a37ea608a
commit
fd233778db
7556
cmsis/arm_math.h
7556
cmsis/arm_math.h
File diff suppressed because it is too large
Load Diff
750
cmsis/core_cm0.h
750
cmsis/core_cm0.h
|
@ -1,750 +0,0 @@
|
|||
/**************************************************************************//**
|
||||
* @file core_cm0.h
|
||||
* @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File
|
||||
* @version V4.10
|
||||
* @date 18. March 2015
|
||||
*
|
||||
* @note
|
||||
*
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- 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.
|
||||
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CM0_H_GENERIC
|
||||
#define __CORE_CM0_H_GENERIC
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
|
||||
CMSIS violates the following MISRA-C:2004 rules:
|
||||
|
||||
\li Required Rule 8.5, object/function definition in header file.<br>
|
||||
Function definitions in header files are used to allow 'inlining'.
|
||||
|
||||
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
|
||||
Unions are used for effective representation of core registers.
|
||||
|
||||
\li Advisory Rule 19.7, Function-like macro defined.<br>
|
||||
Function-like macros are used to allow more efficient code.
|
||||
*/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* CMSIS definitions
|
||||
******************************************************************************/
|
||||
/** \ingroup Cortex_M0
|
||||
@{
|
||||
*/
|
||||
|
||||
/* CMSIS CM0 definitions */
|
||||
#define __CM0_CMSIS_VERSION_MAIN (0x04) /*!< [31:16] CMSIS HAL main version */
|
||||
#define __CM0_CMSIS_VERSION_SUB (0x00) /*!< [15:0] CMSIS HAL sub version */
|
||||
#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16) | \
|
||||
__CM0_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
|
||||
|
||||
#define __CORTEX_M (0x00) /*!< Cortex-M Core */
|
||||
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
||||
#define __STATIC_INLINE static __inline
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
#define __ASM __asm /*!< asm keyword for IAR Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __TMS470__ )
|
||||
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __TASKING__ )
|
||||
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __CSMC__ )
|
||||
#define __packed
|
||||
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
|
||||
#define __INLINE inline /*use -pc99 on compile line !< inline keyword for COSMIC Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#endif
|
||||
|
||||
/** __FPU_USED indicates whether an FPU is used or not.
|
||||
This core does not support an FPU at all
|
||||
*/
|
||||
#define __FPU_USED 0
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#if defined __TARGET_FPU_VFP
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
#if defined __ARMVFP__
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __TMS470__ )
|
||||
#if defined __TI__VFP_SUPPORT____
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __TASKING__ )
|
||||
#if defined __FPU_VFP__
|
||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __CSMC__ ) /* Cosmic */
|
||||
#if ( __CSMC__ & 0x400) // FPU present for parser
|
||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdint.h> /* standard types definitions */
|
||||
#include <core_cmInstr.h> /* Core Instruction Access */
|
||||
#include <core_cmFunc.h> /* Core Function Access */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CORE_CM0_H_GENERIC */
|
||||
|
||||
#ifndef __CMSIS_GENERIC
|
||||
|
||||
#ifndef __CORE_CM0_H_DEPENDANT
|
||||
#define __CORE_CM0_H_DEPENDANT
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* check device defines and use defaults */
|
||||
#if defined __CHECK_DEVICE_DEFINES
|
||||
#ifndef __CM0_REV
|
||||
#define __CM0_REV 0x0000
|
||||
#warning "__CM0_REV not defined in device header file; using default!"
|
||||
#endif
|
||||
|
||||
#ifndef __NVIC_PRIO_BITS
|
||||
#define __NVIC_PRIO_BITS 2
|
||||
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
|
||||
#endif
|
||||
|
||||
#ifndef __Vendor_SysTickConfig
|
||||
#define __Vendor_SysTickConfig 0
|
||||
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* IO definitions (access restrictions to peripheral registers) */
|
||||
/**
|
||||
\defgroup CMSIS_glob_defs CMSIS Global Defines
|
||||
|
||||
<strong>IO Type Qualifiers</strong> are used
|
||||
\li to specify the access to peripheral variables.
|
||||
\li for automatic generation of peripheral register debug information.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
#define __I volatile /*!< Defines 'read only' permissions */
|
||||
#else
|
||||
#define __I volatile const /*!< Defines 'read only' permissions */
|
||||
#endif
|
||||
#define __O volatile /*!< Defines 'write only' permissions */
|
||||
#define __IO volatile /*!< Defines 'read / write' permissions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define __IM volatile /*!< Defines 'read only' permissions */
|
||||
#else
|
||||
#define __IM volatile const /*!< Defines 'read only' permissions */
|
||||
#endif
|
||||
#define __OM volatile /*!< Defines 'write only' permissions */
|
||||
#define __IOM volatile /*!< Defines 'read / write' permissions */
|
||||
|
||||
/*@} end of group Cortex_M0 */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Register Abstraction
|
||||
Core Register contain:
|
||||
- Core Register
|
||||
- Core NVIC Register
|
||||
- Core SCB Register
|
||||
- Core SysTick Register
|
||||
******************************************************************************/
|
||||
/** \defgroup CMSIS_core_register Defines and Type Definitions
|
||||
\brief Type definitions and defines for Cortex-M processor based devices.
|
||||
*/
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_CORE Status and Control Registers
|
||||
\brief Core Register type definitions.
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Union type to access the Application Program Status Register (APSR).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */
|
||||
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
|
||||
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} APSR_Type;
|
||||
|
||||
/* APSR Register Definitions */
|
||||
#define APSR_N_Pos 31 /*!< APSR: N Position */
|
||||
#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
|
||||
|
||||
#define APSR_Z_Pos 30 /*!< APSR: Z Position */
|
||||
#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
|
||||
|
||||
#define APSR_C_Pos 29 /*!< APSR: C Position */
|
||||
#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
|
||||
|
||||
#define APSR_V_Pos 28 /*!< APSR: V Position */
|
||||
#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
|
||||
|
||||
|
||||
/** \brief Union type to access the Interrupt Program Status Register (IPSR).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} IPSR_Type;
|
||||
|
||||
/* IPSR Register Definitions */
|
||||
#define IPSR_ISR_Pos 0 /*!< IPSR: ISR Position */
|
||||
#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
|
||||
|
||||
|
||||
/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
|
||||
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
|
||||
uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */
|
||||
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
|
||||
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} xPSR_Type;
|
||||
|
||||
/* xPSR Register Definitions */
|
||||
#define xPSR_N_Pos 31 /*!< xPSR: N Position */
|
||||
#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
|
||||
|
||||
#define xPSR_Z_Pos 30 /*!< xPSR: Z Position */
|
||||
#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
|
||||
|
||||
#define xPSR_C_Pos 29 /*!< xPSR: C Position */
|
||||
#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
|
||||
|
||||
#define xPSR_V_Pos 28 /*!< xPSR: V Position */
|
||||
#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
|
||||
|
||||
#define xPSR_T_Pos 24 /*!< xPSR: T Position */
|
||||
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
|
||||
|
||||
#define xPSR_ISR_Pos 0 /*!< xPSR: ISR Position */
|
||||
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
|
||||
|
||||
|
||||
/** \brief Union type to access the Control Registers (CONTROL).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t _reserved0:1; /*!< bit: 0 Reserved */
|
||||
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
|
||||
uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} CONTROL_Type;
|
||||
|
||||
/* CONTROL Register Definitions */
|
||||
#define CONTROL_SPSEL_Pos 1 /*!< CONTROL: SPSEL Position */
|
||||
#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
|
||||
|
||||
/*@} end of group CMSIS_CORE */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
|
||||
\brief Type definitions for the NVIC Registers
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
||||
uint32_t RESERVED0[31];
|
||||
__IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
||||
uint32_t RSERVED1[31];
|
||||
__IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
||||
uint32_t RESERVED2[31];
|
||||
__IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
||||
uint32_t RESERVED3[31];
|
||||
uint32_t RESERVED4[64];
|
||||
__IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
|
||||
} NVIC_Type;
|
||||
|
||||
/*@} end of group CMSIS_NVIC */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_SCB System Control Block (SCB)
|
||||
\brief Type definitions for the System Control Block Registers
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the System Control Block (SCB).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
|
||||
__IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
|
||||
uint32_t RESERVED0;
|
||||
__IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
|
||||
__IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
|
||||
__IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
|
||||
uint32_t RESERVED1;
|
||||
__IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
|
||||
__IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
|
||||
} SCB_Type;
|
||||
|
||||
/* SCB CPUID Register Definitions */
|
||||
#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
|
||||
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
|
||||
|
||||
#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
|
||||
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
|
||||
|
||||
#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
|
||||
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
|
||||
|
||||
#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
|
||||
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
|
||||
|
||||
#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
|
||||
#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
|
||||
|
||||
/* SCB Interrupt Control State Register Definitions */
|
||||
#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
|
||||
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
|
||||
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
|
||||
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
|
||||
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
|
||||
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
|
||||
|
||||
#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
|
||||
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
|
||||
|
||||
#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
|
||||
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
|
||||
|
||||
#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
|
||||
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
|
||||
|
||||
#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
|
||||
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
|
||||
|
||||
/* SCB Application Interrupt and Reset Control Register Definitions */
|
||||
#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
|
||||
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
|
||||
|
||||
#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
|
||||
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
|
||||
|
||||
#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
|
||||
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
|
||||
|
||||
#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
|
||||
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
|
||||
|
||||
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
|
||||
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
|
||||
|
||||
/* SCB System Control Register Definitions */
|
||||
#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
|
||||
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
|
||||
|
||||
#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
|
||||
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
|
||||
|
||||
#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
|
||||
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
|
||||
|
||||
/* SCB Configuration Control Register Definitions */
|
||||
#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
|
||||
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
|
||||
|
||||
#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
|
||||
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
|
||||
|
||||
/* SCB System Handler Control and State Register Definitions */
|
||||
#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
|
||||
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
|
||||
|
||||
/*@} end of group CMSIS_SCB */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
|
||||
\brief Type definitions for the System Timer Registers.
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the System Timer (SysTick).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
|
||||
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
|
||||
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
|
||||
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
|
||||
} SysTick_Type;
|
||||
|
||||
/* SysTick Control / Status Register Definitions */
|
||||
#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
|
||||
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
|
||||
|
||||
#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
|
||||
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
|
||||
|
||||
#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
|
||||
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
|
||||
|
||||
#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
|
||||
#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
|
||||
|
||||
/* SysTick Reload Register Definitions */
|
||||
#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
|
||||
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
|
||||
|
||||
/* SysTick Current Register Definitions */
|
||||
#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
|
||||
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
|
||||
|
||||
/* SysTick Calibration Register Definitions */
|
||||
#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
|
||||
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
|
||||
|
||||
#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
|
||||
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
|
||||
|
||||
#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
|
||||
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
|
||||
|
||||
/*@} end of group CMSIS_SysTick */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
|
||||
\brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR)
|
||||
are only accessible over DAP and not via processor. Therefore
|
||||
they are not covered by the Cortex-M0 header file.
|
||||
@{
|
||||
*/
|
||||
/*@} end of group CMSIS_CoreDebug */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_core_base Core Definitions
|
||||
\brief Definitions for base addresses, unions, and structures.
|
||||
@{
|
||||
*/
|
||||
|
||||
/* Memory mapping of Cortex-M0 Hardware */
|
||||
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
||||
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
|
||||
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
|
||||
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
|
||||
|
||||
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
|
||||
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
|
||||
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
|
||||
|
||||
|
||||
/*@} */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Hardware Abstraction Layer
|
||||
Core Function Interface contains:
|
||||
- Core NVIC Functions
|
||||
- Core SysTick Functions
|
||||
- Core Register Access Functions
|
||||
******************************************************************************/
|
||||
/** \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ########################## NVIC functions #################################### */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
|
||||
\brief Functions that manage interrupts and exceptions via the NVIC.
|
||||
@{
|
||||
*/
|
||||
|
||||
/* Interrupt Priorities are WORD accessible only under ARMv6M */
|
||||
/* The following MACROS handle generation of the register offset and byte masks */
|
||||
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
|
||||
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
|
||||
#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
|
||||
|
||||
|
||||
/** \brief Enable External Interrupt
|
||||
|
||||
The function enables a device-specific interrupt in the NVIC interrupt controller.
|
||||
|
||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ISER[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Disable External Interrupt
|
||||
|
||||
The function disables a device-specific interrupt in the NVIC interrupt controller.
|
||||
|
||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ICER[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
__DSB();
|
||||
__ISB();
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Pending Interrupt
|
||||
|
||||
The function reads the pending register in the NVIC and returns the pending bit
|
||||
for the specified interrupt.
|
||||
|
||||
\param [in] IRQn Interrupt number.
|
||||
|
||||
\return 0 Interrupt status is not pending.
|
||||
\return 1 Interrupt status is pending.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
return((uint32_t)(((NVIC->ISPR[0] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Pending Interrupt
|
||||
|
||||
The function sets the pending bit of an external interrupt.
|
||||
|
||||
\param [in] IRQn Interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ISPR[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Clear Pending Interrupt
|
||||
|
||||
The function clears the pending bit of an external interrupt.
|
||||
|
||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ICPR[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Interrupt Priority
|
||||
|
||||
The function sets the priority of an interrupt.
|
||||
|
||||
\note The priority cannot be set for every core interrupt.
|
||||
|
||||
\param [in] IRQn Interrupt number.
|
||||
\param [in] priority Priority to set.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
||||
{
|
||||
if((int32_t)(IRQn) < 0) {
|
||||
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||
(((priority << (8 - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||
}
|
||||
else {
|
||||
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||
(((priority << (8 - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Interrupt Priority
|
||||
|
||||
The function reads the priority of an interrupt. The interrupt
|
||||
number can be positive to specify an external (device specific)
|
||||
interrupt, or negative to specify an internal (core) interrupt.
|
||||
|
||||
|
||||
\param [in] IRQn Interrupt number.
|
||||
\return Interrupt Priority. Value is aligned automatically to the implemented
|
||||
priority bits of the microcontroller.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
||||
{
|
||||
|
||||
if((int32_t)(IRQn) < 0) {
|
||||
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8 - __NVIC_PRIO_BITS)));
|
||||
}
|
||||
else {
|
||||
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8 - __NVIC_PRIO_BITS)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief System Reset
|
||||
|
||||
The function initiates a system reset request to reset the MCU.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_SystemReset(void)
|
||||
{
|
||||
__DSB(); /* Ensure all outstanding memory accesses included
|
||||
buffered write are completed before reset */
|
||||
SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
|
||||
SCB_AIRCR_SYSRESETREQ_Msk);
|
||||
__DSB(); /* Ensure completion of memory access */
|
||||
while(1) { __NOP(); } /* wait until reset */
|
||||
}
|
||||
|
||||
/*@} end of CMSIS_Core_NVICFunctions */
|
||||
|
||||
|
||||
|
||||
/* ################################## SysTick function ############################################ */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
|
||||
\brief Functions that configure the System.
|
||||
@{
|
||||
*/
|
||||
|
||||
#if (__Vendor_SysTickConfig == 0)
|
||||
|
||||
/** \brief System Tick Configuration
|
||||
|
||||
The function initializes the System Timer and its interrupt, and starts the System Tick Timer.
|
||||
Counter is in free running mode to generate periodic interrupts.
|
||||
|
||||
\param [in] ticks Number of ticks between two interrupts.
|
||||
|
||||
\return 0 Function succeeded.
|
||||
\return 1 Function failed.
|
||||
|
||||
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
|
||||
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
|
||||
must contain a vendor-specific implementation of this function.
|
||||
|
||||
*/
|
||||
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
|
||||
{
|
||||
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) { return (1UL); } /* Reload value impossible */
|
||||
|
||||
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
|
||||
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
|
||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_TICKINT_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
return (0UL); /* Function successful */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of CMSIS_Core_SysTickFunctions */
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CORE_CM0_H_DEPENDANT */
|
||||
|
||||
#endif /* __CMSIS_GENERIC */
|
|
@ -1,864 +0,0 @@
|
|||
/**************************************************************************//**
|
||||
* @file core_cm0plus.h
|
||||
* @brief CMSIS Cortex-M0+ Core Peripheral Access Layer Header File
|
||||
* @version V4.10
|
||||
* @date 18. March 2015
|
||||
*
|
||||
* @note
|
||||
*
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- 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.
|
||||
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CM0PLUS_H_GENERIC
|
||||
#define __CORE_CM0PLUS_H_GENERIC
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
|
||||
CMSIS violates the following MISRA-C:2004 rules:
|
||||
|
||||
\li Required Rule 8.5, object/function definition in header file.<br>
|
||||
Function definitions in header files are used to allow 'inlining'.
|
||||
|
||||
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
|
||||
Unions are used for effective representation of core registers.
|
||||
|
||||
\li Advisory Rule 19.7, Function-like macro defined.<br>
|
||||
Function-like macros are used to allow more efficient code.
|
||||
*/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* CMSIS definitions
|
||||
******************************************************************************/
|
||||
/** \ingroup Cortex-M0+
|
||||
@{
|
||||
*/
|
||||
|
||||
/* CMSIS CM0P definitions */
|
||||
#define __CM0PLUS_CMSIS_VERSION_MAIN (0x04) /*!< [31:16] CMSIS HAL main version */
|
||||
#define __CM0PLUS_CMSIS_VERSION_SUB (0x00) /*!< [15:0] CMSIS HAL sub version */
|
||||
#define __CM0PLUS_CMSIS_VERSION ((__CM0PLUS_CMSIS_VERSION_MAIN << 16) | \
|
||||
__CM0PLUS_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */
|
||||
|
||||
#define __CORTEX_M (0x00) /*!< Cortex-M Core */
|
||||
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
||||
#define __STATIC_INLINE static __inline
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
#define __ASM __asm /*!< asm keyword for IAR Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __TMS470__ )
|
||||
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __TASKING__ )
|
||||
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __CSMC__ )
|
||||
#define __packed
|
||||
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
|
||||
#define __INLINE inline /*use -pc99 on compile line !< inline keyword for COSMIC Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#endif
|
||||
|
||||
/** __FPU_USED indicates whether an FPU is used or not.
|
||||
This core does not support an FPU at all
|
||||
*/
|
||||
#define __FPU_USED 0
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#if defined __TARGET_FPU_VFP
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
#if defined __ARMVFP__
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __TMS470__ )
|
||||
#if defined __TI__VFP_SUPPORT____
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __TASKING__ )
|
||||
#if defined __FPU_VFP__
|
||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __CSMC__ ) /* Cosmic */
|
||||
#if ( __CSMC__ & 0x400) // FPU present for parser
|
||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdint.h> /* standard types definitions */
|
||||
#include <core_cmInstr.h> /* Core Instruction Access */
|
||||
#include <core_cmFunc.h> /* Core Function Access */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CORE_CM0PLUS_H_GENERIC */
|
||||
|
||||
#ifndef __CMSIS_GENERIC
|
||||
|
||||
#ifndef __CORE_CM0PLUS_H_DEPENDANT
|
||||
#define __CORE_CM0PLUS_H_DEPENDANT
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* check device defines and use defaults */
|
||||
#if defined __CHECK_DEVICE_DEFINES
|
||||
#ifndef __CM0PLUS_REV
|
||||
#define __CM0PLUS_REV 0x0000
|
||||
#warning "__CM0PLUS_REV not defined in device header file; using default!"
|
||||
#endif
|
||||
|
||||
#ifndef __MPU_PRESENT
|
||||
#define __MPU_PRESENT 0
|
||||
#warning "__MPU_PRESENT not defined in device header file; using default!"
|
||||
#endif
|
||||
|
||||
#ifndef __VTOR_PRESENT
|
||||
#define __VTOR_PRESENT 0
|
||||
#warning "__VTOR_PRESENT not defined in device header file; using default!"
|
||||
#endif
|
||||
|
||||
#ifndef __NVIC_PRIO_BITS
|
||||
#define __NVIC_PRIO_BITS 2
|
||||
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
|
||||
#endif
|
||||
|
||||
#ifndef __Vendor_SysTickConfig
|
||||
#define __Vendor_SysTickConfig 0
|
||||
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* IO definitions (access restrictions to peripheral registers) */
|
||||
/**
|
||||
\defgroup CMSIS_glob_defs CMSIS Global Defines
|
||||
|
||||
<strong>IO Type Qualifiers</strong> are used
|
||||
\li to specify the access to peripheral variables.
|
||||
\li for automatic generation of peripheral register debug information.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
#define __I volatile /*!< Defines 'read only' permissions */
|
||||
#else
|
||||
#define __I volatile const /*!< Defines 'read only' permissions */
|
||||
#endif
|
||||
#define __O volatile /*!< Defines 'write only' permissions */
|
||||
#define __IO volatile /*!< Defines 'read / write' permissions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define __IM volatile /*!< Defines 'read only' permissions */
|
||||
#else
|
||||
#define __IM volatile const /*!< Defines 'read only' permissions */
|
||||
#endif
|
||||
#define __OM volatile /*!< Defines 'write only' permissions */
|
||||
#define __IOM volatile /*!< Defines 'read / write' permissions */
|
||||
|
||||
/*@} end of group Cortex-M0+ */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Register Abstraction
|
||||
Core Register contain:
|
||||
- Core Register
|
||||
- Core NVIC Register
|
||||
- Core SCB Register
|
||||
- Core SysTick Register
|
||||
- Core MPU Register
|
||||
******************************************************************************/
|
||||
/** \defgroup CMSIS_core_register Defines and Type Definitions
|
||||
\brief Type definitions and defines for Cortex-M processor based devices.
|
||||
*/
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_CORE Status and Control Registers
|
||||
\brief Core Register type definitions.
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Union type to access the Application Program Status Register (APSR).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */
|
||||
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
|
||||
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} APSR_Type;
|
||||
|
||||
/* APSR Register Definitions */
|
||||
#define APSR_N_Pos 31 /*!< APSR: N Position */
|
||||
#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
|
||||
|
||||
#define APSR_Z_Pos 30 /*!< APSR: Z Position */
|
||||
#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
|
||||
|
||||
#define APSR_C_Pos 29 /*!< APSR: C Position */
|
||||
#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
|
||||
|
||||
#define APSR_V_Pos 28 /*!< APSR: V Position */
|
||||
#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
|
||||
|
||||
|
||||
/** \brief Union type to access the Interrupt Program Status Register (IPSR).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} IPSR_Type;
|
||||
|
||||
/* IPSR Register Definitions */
|
||||
#define IPSR_ISR_Pos 0 /*!< IPSR: ISR Position */
|
||||
#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
|
||||
|
||||
|
||||
/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
|
||||
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
|
||||
uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */
|
||||
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
|
||||
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} xPSR_Type;
|
||||
|
||||
/* xPSR Register Definitions */
|
||||
#define xPSR_N_Pos 31 /*!< xPSR: N Position */
|
||||
#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
|
||||
|
||||
#define xPSR_Z_Pos 30 /*!< xPSR: Z Position */
|
||||
#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
|
||||
|
||||
#define xPSR_C_Pos 29 /*!< xPSR: C Position */
|
||||
#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
|
||||
|
||||
#define xPSR_V_Pos 28 /*!< xPSR: V Position */
|
||||
#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
|
||||
|
||||
#define xPSR_T_Pos 24 /*!< xPSR: T Position */
|
||||
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
|
||||
|
||||
#define xPSR_ISR_Pos 0 /*!< xPSR: ISR Position */
|
||||
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
|
||||
|
||||
|
||||
/** \brief Union type to access the Control Registers (CONTROL).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
|
||||
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
|
||||
uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} CONTROL_Type;
|
||||
|
||||
/* CONTROL Register Definitions */
|
||||
#define CONTROL_SPSEL_Pos 1 /*!< CONTROL: SPSEL Position */
|
||||
#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
|
||||
|
||||
#define CONTROL_nPRIV_Pos 0 /*!< CONTROL: nPRIV Position */
|
||||
#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV Mask */
|
||||
|
||||
/*@} end of group CMSIS_CORE */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
|
||||
\brief Type definitions for the NVIC Registers
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
||||
uint32_t RESERVED0[31];
|
||||
__IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
||||
uint32_t RSERVED1[31];
|
||||
__IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
||||
uint32_t RESERVED2[31];
|
||||
__IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
||||
uint32_t RESERVED3[31];
|
||||
uint32_t RESERVED4[64];
|
||||
__IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
|
||||
} NVIC_Type;
|
||||
|
||||
/*@} end of group CMSIS_NVIC */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_SCB System Control Block (SCB)
|
||||
\brief Type definitions for the System Control Block Registers
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the System Control Block (SCB).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
|
||||
__IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
|
||||
#if (__VTOR_PRESENT == 1)
|
||||
__IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
|
||||
#else
|
||||
uint32_t RESERVED0;
|
||||
#endif
|
||||
__IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
|
||||
__IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
|
||||
__IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
|
||||
uint32_t RESERVED1;
|
||||
__IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
|
||||
__IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
|
||||
} SCB_Type;
|
||||
|
||||
/* SCB CPUID Register Definitions */
|
||||
#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
|
||||
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
|
||||
|
||||
#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
|
||||
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
|
||||
|
||||
#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
|
||||
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
|
||||
|
||||
#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
|
||||
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
|
||||
|
||||
#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
|
||||
#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
|
||||
|
||||
/* SCB Interrupt Control State Register Definitions */
|
||||
#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
|
||||
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
|
||||
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
|
||||
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
|
||||
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
|
||||
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
|
||||
|
||||
#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
|
||||
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
|
||||
|
||||
#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
|
||||
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
|
||||
|
||||
#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
|
||||
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
|
||||
|
||||
#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
|
||||
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
|
||||
|
||||
#if (__VTOR_PRESENT == 1)
|
||||
/* SCB Interrupt Control State Register Definitions */
|
||||
#define SCB_VTOR_TBLOFF_Pos 8 /*!< SCB VTOR: TBLOFF Position */
|
||||
#define SCB_VTOR_TBLOFF_Msk (0xFFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
|
||||
#endif
|
||||
|
||||
/* SCB Application Interrupt and Reset Control Register Definitions */
|
||||
#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
|
||||
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
|
||||
|
||||
#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
|
||||
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
|
||||
|
||||
#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
|
||||
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
|
||||
|
||||
#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
|
||||
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
|
||||
|
||||
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
|
||||
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
|
||||
|
||||
/* SCB System Control Register Definitions */
|
||||
#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
|
||||
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
|
||||
|
||||
#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
|
||||
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
|
||||
|
||||
#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
|
||||
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
|
||||
|
||||
/* SCB Configuration Control Register Definitions */
|
||||
#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
|
||||
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
|
||||
|
||||
#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
|
||||
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
|
||||
|
||||
/* SCB System Handler Control and State Register Definitions */
|
||||
#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
|
||||
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
|
||||
|
||||
/*@} end of group CMSIS_SCB */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
|
||||
\brief Type definitions for the System Timer Registers.
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the System Timer (SysTick).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
|
||||
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
|
||||
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
|
||||
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
|
||||
} SysTick_Type;
|
||||
|
||||
/* SysTick Control / Status Register Definitions */
|
||||
#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
|
||||
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
|
||||
|
||||
#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
|
||||
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
|
||||
|
||||
#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
|
||||
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
|
||||
|
||||
#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
|
||||
#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
|
||||
|
||||
/* SysTick Reload Register Definitions */
|
||||
#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
|
||||
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
|
||||
|
||||
/* SysTick Current Register Definitions */
|
||||
#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
|
||||
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
|
||||
|
||||
/* SysTick Calibration Register Definitions */
|
||||
#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
|
||||
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
|
||||
|
||||
#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
|
||||
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
|
||||
|
||||
#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
|
||||
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
|
||||
|
||||
/*@} end of group CMSIS_SysTick */
|
||||
|
||||
#if (__MPU_PRESENT == 1)
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
||||
\brief Type definitions for the Memory Protection Unit (MPU)
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the Memory Protection Unit (MPU).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__I uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */
|
||||
__IO uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */
|
||||
__IO uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */
|
||||
__IO uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */
|
||||
__IO uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
|
||||
} MPU_Type;
|
||||
|
||||
/* MPU Type Register */
|
||||
#define MPU_TYPE_IREGION_Pos 16 /*!< MPU TYPE: IREGION Position */
|
||||
#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
|
||||
|
||||
#define MPU_TYPE_DREGION_Pos 8 /*!< MPU TYPE: DREGION Position */
|
||||
#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */
|
||||
|
||||
#define MPU_TYPE_SEPARATE_Pos 0 /*!< MPU TYPE: SEPARATE Position */
|
||||
#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */
|
||||
|
||||
/* MPU Control Register */
|
||||
#define MPU_CTRL_PRIVDEFENA_Pos 2 /*!< MPU CTRL: PRIVDEFENA Position */
|
||||
#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */
|
||||
|
||||
#define MPU_CTRL_HFNMIENA_Pos 1 /*!< MPU CTRL: HFNMIENA Position */
|
||||
#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */
|
||||
|
||||
#define MPU_CTRL_ENABLE_Pos 0 /*!< MPU CTRL: ENABLE Position */
|
||||
#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */
|
||||
|
||||
/* MPU Region Number Register */
|
||||
#define MPU_RNR_REGION_Pos 0 /*!< MPU RNR: REGION Position */
|
||||
#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */
|
||||
|
||||
/* MPU Region Base Address Register */
|
||||
#define MPU_RBAR_ADDR_Pos 8 /*!< MPU RBAR: ADDR Position */
|
||||
#define MPU_RBAR_ADDR_Msk (0xFFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */
|
||||
|
||||
#define MPU_RBAR_VALID_Pos 4 /*!< MPU RBAR: VALID Position */
|
||||
#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */
|
||||
|
||||
#define MPU_RBAR_REGION_Pos 0 /*!< MPU RBAR: REGION Position */
|
||||
#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */
|
||||
|
||||
/* MPU Region Attribute and Size Register */
|
||||
#define MPU_RASR_ATTRS_Pos 16 /*!< MPU RASR: MPU Region Attribute field Position */
|
||||
#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */
|
||||
|
||||
#define MPU_RASR_XN_Pos 28 /*!< MPU RASR: ATTRS.XN Position */
|
||||
#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */
|
||||
|
||||
#define MPU_RASR_AP_Pos 24 /*!< MPU RASR: ATTRS.AP Position */
|
||||
#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */
|
||||
|
||||
#define MPU_RASR_TEX_Pos 19 /*!< MPU RASR: ATTRS.TEX Position */
|
||||
#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */
|
||||
|
||||
#define MPU_RASR_S_Pos 18 /*!< MPU RASR: ATTRS.S Position */
|
||||
#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */
|
||||
|
||||
#define MPU_RASR_C_Pos 17 /*!< MPU RASR: ATTRS.C Position */
|
||||
#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */
|
||||
|
||||
#define MPU_RASR_B_Pos 16 /*!< MPU RASR: ATTRS.B Position */
|
||||
#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */
|
||||
|
||||
#define MPU_RASR_SRD_Pos 8 /*!< MPU RASR: Sub-Region Disable Position */
|
||||
#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */
|
||||
|
||||
#define MPU_RASR_SIZE_Pos 1 /*!< MPU RASR: Region Size Field Position */
|
||||
#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */
|
||||
|
||||
#define MPU_RASR_ENABLE_Pos 0 /*!< MPU RASR: Region enable bit Position */
|
||||
#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */
|
||||
|
||||
/*@} end of group CMSIS_MPU */
|
||||
#endif
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
|
||||
\brief Cortex-M0+ Core Debug Registers (DCB registers, SHCSR, and DFSR)
|
||||
are only accessible over DAP and not via processor. Therefore
|
||||
they are not covered by the Cortex-M0 header file.
|
||||
@{
|
||||
*/
|
||||
/*@} end of group CMSIS_CoreDebug */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_core_base Core Definitions
|
||||
\brief Definitions for base addresses, unions, and structures.
|
||||
@{
|
||||
*/
|
||||
|
||||
/* Memory mapping of Cortex-M0+ Hardware */
|
||||
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
||||
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
|
||||
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
|
||||
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
|
||||
|
||||
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
|
||||
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
|
||||
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
|
||||
|
||||
#if (__MPU_PRESENT == 1)
|
||||
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
||||
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
||||
#endif
|
||||
|
||||
/*@} */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Hardware Abstraction Layer
|
||||
Core Function Interface contains:
|
||||
- Core NVIC Functions
|
||||
- Core SysTick Functions
|
||||
- Core Register Access Functions
|
||||
******************************************************************************/
|
||||
/** \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ########################## NVIC functions #################################### */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
|
||||
\brief Functions that manage interrupts and exceptions via the NVIC.
|
||||
@{
|
||||
*/
|
||||
|
||||
/* Interrupt Priorities are WORD accessible only under ARMv6M */
|
||||
/* The following MACROS handle generation of the register offset and byte masks */
|
||||
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
|
||||
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
|
||||
#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
|
||||
|
||||
|
||||
/** \brief Enable External Interrupt
|
||||
|
||||
The function enables a device-specific interrupt in the NVIC interrupt controller.
|
||||
|
||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ISER[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Disable External Interrupt
|
||||
|
||||
The function disables a device-specific interrupt in the NVIC interrupt controller.
|
||||
|
||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ICER[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
__DSB();
|
||||
__ISB();
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Pending Interrupt
|
||||
|
||||
The function reads the pending register in the NVIC and returns the pending bit
|
||||
for the specified interrupt.
|
||||
|
||||
\param [in] IRQn Interrupt number.
|
||||
|
||||
\return 0 Interrupt status is not pending.
|
||||
\return 1 Interrupt status is pending.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
return((uint32_t)(((NVIC->ISPR[0] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Pending Interrupt
|
||||
|
||||
The function sets the pending bit of an external interrupt.
|
||||
|
||||
\param [in] IRQn Interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ISPR[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Clear Pending Interrupt
|
||||
|
||||
The function clears the pending bit of an external interrupt.
|
||||
|
||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ICPR[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Interrupt Priority
|
||||
|
||||
The function sets the priority of an interrupt.
|
||||
|
||||
\note The priority cannot be set for every core interrupt.
|
||||
|
||||
\param [in] IRQn Interrupt number.
|
||||
\param [in] priority Priority to set.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
||||
{
|
||||
if((int32_t)(IRQn) < 0) {
|
||||
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||
(((priority << (8 - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||
}
|
||||
else {
|
||||
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||
(((priority << (8 - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Interrupt Priority
|
||||
|
||||
The function reads the priority of an interrupt. The interrupt
|
||||
number can be positive to specify an external (device specific)
|
||||
interrupt, or negative to specify an internal (core) interrupt.
|
||||
|
||||
|
||||
\param [in] IRQn Interrupt number.
|
||||
\return Interrupt Priority. Value is aligned automatically to the implemented
|
||||
priority bits of the microcontroller.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
||||
{
|
||||
|
||||
if((int32_t)(IRQn) < 0) {
|
||||
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8 - __NVIC_PRIO_BITS)));
|
||||
}
|
||||
else {
|
||||
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8 - __NVIC_PRIO_BITS)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief System Reset
|
||||
|
||||
The function initiates a system reset request to reset the MCU.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_SystemReset(void)
|
||||
{
|
||||
__DSB(); /* Ensure all outstanding memory accesses included
|
||||
buffered write are completed before reset */
|
||||
SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
|
||||
SCB_AIRCR_SYSRESETREQ_Msk);
|
||||
__DSB(); /* Ensure completion of memory access */
|
||||
while(1) { __NOP(); } /* wait until reset */
|
||||
}
|
||||
|
||||
/*@} end of CMSIS_Core_NVICFunctions */
|
||||
|
||||
|
||||
|
||||
/* ################################## SysTick function ############################################ */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
|
||||
\brief Functions that configure the System.
|
||||
@{
|
||||
*/
|
||||
|
||||
#if (__Vendor_SysTickConfig == 0)
|
||||
|
||||
/** \brief System Tick Configuration
|
||||
|
||||
The function initializes the System Timer and its interrupt, and starts the System Tick Timer.
|
||||
Counter is in free running mode to generate periodic interrupts.
|
||||
|
||||
\param [in] ticks Number of ticks between two interrupts.
|
||||
|
||||
\return 0 Function succeeded.
|
||||
\return 1 Function failed.
|
||||
|
||||
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
|
||||
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
|
||||
must contain a vendor-specific implementation of this function.
|
||||
|
||||
*/
|
||||
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
|
||||
{
|
||||
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) {return (1UL);} /* Reload value impossible */
|
||||
|
||||
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
|
||||
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
|
||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_TICKINT_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
return (0UL); /* Function successful */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of CMSIS_Core_SysTickFunctions */
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CORE_CM0PLUS_H_DEPENDANT */
|
||||
|
||||
#endif /* __CMSIS_GENERIC */
|
1732
cmsis/core_cm3.h
1732
cmsis/core_cm3.h
File diff suppressed because it is too large
Load Diff
1898
cmsis/core_cm4.h
1898
cmsis/core_cm4.h
File diff suppressed because it is too large
Load Diff
|
@ -1,673 +0,0 @@
|
|||
/**************************************************************************//**
|
||||
* @file core_cm4_simd.h
|
||||
* @brief CMSIS Cortex-M4 SIMD Header File
|
||||
* @version V3.20
|
||||
* @date 25. February 2013
|
||||
*
|
||||
* @note
|
||||
*
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2013 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- 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.
|
||||
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CM4_SIMD_H
|
||||
#define __CORE_CM4_SIMD_H
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Hardware Abstraction Layer
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/* ################### Compiler specific Intrinsics ########################### */
|
||||
/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
|
||||
Access to dedicated SIMD instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
|
||||
/* ARM armcc specific functions */
|
||||
|
||||
/*------ CM4 SIMD Intrinsics -----------------------------------------------------*/
|
||||
#define __SADD8 __sadd8
|
||||
#define __QADD8 __qadd8
|
||||
#define __SHADD8 __shadd8
|
||||
#define __UADD8 __uadd8
|
||||
#define __UQADD8 __uqadd8
|
||||
#define __UHADD8 __uhadd8
|
||||
#define __SSUB8 __ssub8
|
||||
#define __QSUB8 __qsub8
|
||||
#define __SHSUB8 __shsub8
|
||||
#define __USUB8 __usub8
|
||||
#define __UQSUB8 __uqsub8
|
||||
#define __UHSUB8 __uhsub8
|
||||
#define __SADD16 __sadd16
|
||||
#define __QADD16 __qadd16
|
||||
#define __SHADD16 __shadd16
|
||||
#define __UADD16 __uadd16
|
||||
#define __UQADD16 __uqadd16
|
||||
#define __UHADD16 __uhadd16
|
||||
#define __SSUB16 __ssub16
|
||||
#define __QSUB16 __qsub16
|
||||
#define __SHSUB16 __shsub16
|
||||
#define __USUB16 __usub16
|
||||
#define __UQSUB16 __uqsub16
|
||||
#define __UHSUB16 __uhsub16
|
||||
#define __SASX __sasx
|
||||
#define __QASX __qasx
|
||||
#define __SHASX __shasx
|
||||
#define __UASX __uasx
|
||||
#define __UQASX __uqasx
|
||||
#define __UHASX __uhasx
|
||||
#define __SSAX __ssax
|
||||
#define __QSAX __qsax
|
||||
#define __SHSAX __shsax
|
||||
#define __USAX __usax
|
||||
#define __UQSAX __uqsax
|
||||
#define __UHSAX __uhsax
|
||||
#define __USAD8 __usad8
|
||||
#define __USADA8 __usada8
|
||||
#define __SSAT16 __ssat16
|
||||
#define __USAT16 __usat16
|
||||
#define __UXTB16 __uxtb16
|
||||
#define __UXTAB16 __uxtab16
|
||||
#define __SXTB16 __sxtb16
|
||||
#define __SXTAB16 __sxtab16
|
||||
#define __SMUAD __smuad
|
||||
#define __SMUADX __smuadx
|
||||
#define __SMLAD __smlad
|
||||
#define __SMLADX __smladx
|
||||
#define __SMLALD __smlald
|
||||
#define __SMLALDX __smlaldx
|
||||
#define __SMUSD __smusd
|
||||
#define __SMUSDX __smusdx
|
||||
#define __SMLSD __smlsd
|
||||
#define __SMLSDX __smlsdx
|
||||
#define __SMLSLD __smlsld
|
||||
#define __SMLSLDX __smlsldx
|
||||
#define __SEL __sel
|
||||
#define __QADD __qadd
|
||||
#define __QSUB __qsub
|
||||
|
||||
#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
|
||||
((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
|
||||
|
||||
#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
|
||||
((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
|
||||
|
||||
#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
|
||||
((int64_t)(ARG3) << 32) ) >> 32))
|
||||
|
||||
/*-- End CM4 SIMD Intrinsics -----------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
|
||||
/* IAR iccarm specific functions */
|
||||
|
||||
/*------ CM4 SIMD Intrinsics -----------------------------------------------------*/
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
/*-- End CM4 SIMD Intrinsics -----------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
|
||||
/* TI CCS specific functions */
|
||||
|
||||
/*------ CM4 SIMD Intrinsics -----------------------------------------------------*/
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
/*-- End CM4 SIMD Intrinsics -----------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
|
||||
/* GNU gcc specific functions */
|
||||
|
||||
/*------ CM4 SIMD Intrinsics -----------------------------------------------------*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
#define __SSAT16(ARG1,ARG2) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1); \
|
||||
__ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
#define __USAT16(ARG1,ARG2) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1); \
|
||||
__ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
#define __SMLALD(ARG1,ARG2,ARG3) \
|
||||
({ \
|
||||
uint32_t __ARG1 = (ARG1), __ARG2 = (ARG2), __ARG3_H = (uint32_t)((uint64_t)(ARG3) >> 32), __ARG3_L = (uint32_t)((uint64_t)(ARG3) & 0xFFFFFFFFUL); \
|
||||
__ASM volatile ("smlald %0, %1, %2, %3" : "=r" (__ARG3_L), "=r" (__ARG3_H) : "r" (__ARG1), "r" (__ARG2), "0" (__ARG3_L), "1" (__ARG3_H) ); \
|
||||
(uint64_t)(((uint64_t)__ARG3_H << 32) | __ARG3_L); \
|
||||
})
|
||||
|
||||
#define __SMLALDX(ARG1,ARG2,ARG3) \
|
||||
({ \
|
||||
uint32_t __ARG1 = (ARG1), __ARG2 = (ARG2), __ARG3_H = (uint32_t)((uint64_t)(ARG3) >> 32), __ARG3_L = (uint32_t)((uint64_t)(ARG3) & 0xFFFFFFFFUL); \
|
||||
__ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (__ARG3_L), "=r" (__ARG3_H) : "r" (__ARG1), "r" (__ARG2), "0" (__ARG3_L), "1" (__ARG3_H) ); \
|
||||
(uint64_t)(((uint64_t)__ARG3_H << 32) | __ARG3_L); \
|
||||
})
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
#define __SMLSLD(ARG1,ARG2,ARG3) \
|
||||
({ \
|
||||
uint32_t __ARG1 = (ARG1), __ARG2 = (ARG2), __ARG3_H = (uint32_t)((ARG3) >> 32), __ARG3_L = (uint32_t)((ARG3) & 0xFFFFFFFFUL); \
|
||||
__ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (__ARG3_L), "=r" (__ARG3_H) : "r" (__ARG1), "r" (__ARG2), "0" (__ARG3_L), "1" (__ARG3_H) ); \
|
||||
(uint64_t)(((uint64_t)__ARG3_H << 32) | __ARG3_L); \
|
||||
})
|
||||
|
||||
#define __SMLSLDX(ARG1,ARG2,ARG3) \
|
||||
({ \
|
||||
uint32_t __ARG1 = (ARG1), __ARG2 = (ARG2), __ARG3_H = (uint32_t)((ARG3) >> 32), __ARG3_L = (uint32_t)((ARG3) & 0xFFFFFFFFUL); \
|
||||
__ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (__ARG3_L), "=r" (__ARG3_H) : "r" (__ARG1), "r" (__ARG2), "0" (__ARG3_L), "1" (__ARG3_H) ); \
|
||||
(uint64_t)(((uint64_t)__ARG3_H << 32) | __ARG3_L); \
|
||||
})
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
#define __PKHBT(ARG1,ARG2,ARG3) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
|
||||
__ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
#define __PKHTB(ARG1,ARG2,ARG3) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
|
||||
if (ARG3 == 0) \
|
||||
__ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
|
||||
else \
|
||||
__ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
|
||||
{
|
||||
int32_t result;
|
||||
|
||||
__ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
/*-- End CM4 SIMD Intrinsics -----------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
|
||||
/* TASKING carm specific functions */
|
||||
|
||||
|
||||
/*------ CM4 SIMD Intrinsics -----------------------------------------------------*/
|
||||
/* not yet supported */
|
||||
/*-- End CM4 SIMD Intrinsics -----------------------------------------------------*/
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of group CMSIS_SIMD_intrinsics */
|
||||
|
||||
|
||||
#endif /* __CORE_CM4_SIMD_H */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
2407
cmsis/core_cm7.h
2407
cmsis/core_cm7.h
File diff suppressed because it is too large
Load Diff
|
@ -1,664 +0,0 @@
|
|||
/**************************************************************************//**
|
||||
* @file core_cmFunc.h
|
||||
* @brief CMSIS Cortex-M Core Function Access Header File
|
||||
* @version V4.10
|
||||
* @date 18. March 2015
|
||||
*
|
||||
* @note
|
||||
*
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- 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.
|
||||
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef __CORE_CMFUNC_H
|
||||
#define __CORE_CMFUNC_H
|
||||
|
||||
|
||||
/* ########################### Core Function Access ########################### */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
|
||||
@{
|
||||
*/
|
||||
|
||||
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
|
||||
/* ARM armcc specific functions */
|
||||
|
||||
#if (__ARMCC_VERSION < 400677)
|
||||
#error "Please use ARM Compiler Toolchain V4.0.677 or later!"
|
||||
#endif
|
||||
|
||||
/* intrinsic void __enable_irq(); */
|
||||
/* intrinsic void __disable_irq(); */
|
||||
|
||||
/** \brief Get Control Register
|
||||
|
||||
This function returns the content of the Control Register.
|
||||
|
||||
\return Control Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_CONTROL(void)
|
||||
{
|
||||
register uint32_t __regControl __ASM("control");
|
||||
return(__regControl);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Control Register
|
||||
|
||||
This function writes the given value to the Control Register.
|
||||
|
||||
\param [in] control Control Register value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_CONTROL(uint32_t control)
|
||||
{
|
||||
register uint32_t __regControl __ASM("control");
|
||||
__regControl = control;
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get IPSR Register
|
||||
|
||||
This function returns the content of the IPSR Register.
|
||||
|
||||
\return IPSR Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_IPSR(void)
|
||||
{
|
||||
register uint32_t __regIPSR __ASM("ipsr");
|
||||
return(__regIPSR);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get APSR Register
|
||||
|
||||
This function returns the content of the APSR Register.
|
||||
|
||||
\return APSR Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_APSR(void)
|
||||
{
|
||||
register uint32_t __regAPSR __ASM("apsr");
|
||||
return(__regAPSR);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get xPSR Register
|
||||
|
||||
This function returns the content of the xPSR Register.
|
||||
|
||||
\return xPSR Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_xPSR(void)
|
||||
{
|
||||
register uint32_t __regXPSR __ASM("xpsr");
|
||||
return(__regXPSR);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Process Stack Pointer
|
||||
|
||||
This function returns the current value of the Process Stack Pointer (PSP).
|
||||
|
||||
\return PSP Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_PSP(void)
|
||||
{
|
||||
register uint32_t __regProcessStackPointer __ASM("psp");
|
||||
return(__regProcessStackPointer);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Process Stack Pointer
|
||||
|
||||
This function assigns the given value to the Process Stack Pointer (PSP).
|
||||
|
||||
\param [in] topOfProcStack Process Stack Pointer value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
|
||||
{
|
||||
register uint32_t __regProcessStackPointer __ASM("psp");
|
||||
__regProcessStackPointer = topOfProcStack;
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Main Stack Pointer
|
||||
|
||||
This function returns the current value of the Main Stack Pointer (MSP).
|
||||
|
||||
\return MSP Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_MSP(void)
|
||||
{
|
||||
register uint32_t __regMainStackPointer __ASM("msp");
|
||||
return(__regMainStackPointer);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Main Stack Pointer
|
||||
|
||||
This function assigns the given value to the Main Stack Pointer (MSP).
|
||||
|
||||
\param [in] topOfMainStack Main Stack Pointer value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
|
||||
{
|
||||
register uint32_t __regMainStackPointer __ASM("msp");
|
||||
__regMainStackPointer = topOfMainStack;
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Priority Mask
|
||||
|
||||
This function returns the current state of the priority mask bit from the Priority Mask Register.
|
||||
|
||||
\return Priority Mask value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_PRIMASK(void)
|
||||
{
|
||||
register uint32_t __regPriMask __ASM("primask");
|
||||
return(__regPriMask);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Priority Mask
|
||||
|
||||
This function assigns the given value to the Priority Mask Register.
|
||||
|
||||
\param [in] priMask Priority Mask
|
||||
*/
|
||||
__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
|
||||
{
|
||||
register uint32_t __regPriMask __ASM("primask");
|
||||
__regPriMask = (priMask);
|
||||
}
|
||||
|
||||
|
||||
#if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300)
|
||||
|
||||
/** \brief Enable FIQ
|
||||
|
||||
This function enables FIQ interrupts by clearing the F-bit in the CPSR.
|
||||
Can only be executed in Privileged modes.
|
||||
*/
|
||||
#define __enable_fault_irq __enable_fiq
|
||||
|
||||
|
||||
/** \brief Disable FIQ
|
||||
|
||||
This function disables FIQ interrupts by setting the F-bit in the CPSR.
|
||||
Can only be executed in Privileged modes.
|
||||
*/
|
||||
#define __disable_fault_irq __disable_fiq
|
||||
|
||||
|
||||
/** \brief Get Base Priority
|
||||
|
||||
This function returns the current value of the Base Priority register.
|
||||
|
||||
\return Base Priority register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_BASEPRI(void)
|
||||
{
|
||||
register uint32_t __regBasePri __ASM("basepri");
|
||||
return(__regBasePri);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Base Priority
|
||||
|
||||
This function assigns the given value to the Base Priority register.
|
||||
|
||||
\param [in] basePri Base Priority value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
|
||||
{
|
||||
register uint32_t __regBasePri __ASM("basepri");
|
||||
__regBasePri = (basePri & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Base Priority with condition
|
||||
|
||||
This function assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
|
||||
or the new value increases the BASEPRI priority level.
|
||||
|
||||
\param [in] basePri Base Priority value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
|
||||
{
|
||||
register uint32_t __regBasePriMax __ASM("basepri_max");
|
||||
__regBasePriMax = (basePri & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Fault Mask
|
||||
|
||||
This function returns the current value of the Fault Mask register.
|
||||
|
||||
\return Fault Mask register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_FAULTMASK(void)
|
||||
{
|
||||
register uint32_t __regFaultMask __ASM("faultmask");
|
||||
return(__regFaultMask);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Fault Mask
|
||||
|
||||
This function assigns the given value to the Fault Mask register.
|
||||
|
||||
\param [in] faultMask Fault Mask value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
|
||||
{
|
||||
register uint32_t __regFaultMask __ASM("faultmask");
|
||||
__regFaultMask = (faultMask & (uint32_t)1);
|
||||
}
|
||||
|
||||
#endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */
|
||||
|
||||
|
||||
#if (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07)
|
||||
|
||||
/** \brief Get FPSCR
|
||||
|
||||
This function returns the current value of the Floating Point Status/Control register.
|
||||
|
||||
\return Floating Point Status/Control register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_FPSCR(void)
|
||||
{
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
register uint32_t __regfpscr __ASM("fpscr");
|
||||
return(__regfpscr);
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set FPSCR
|
||||
|
||||
This function assigns the given value to the Floating Point Status/Control register.
|
||||
|
||||
\param [in] fpscr Floating Point Status/Control value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
|
||||
{
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
register uint32_t __regfpscr __ASM("fpscr");
|
||||
__regfpscr = (fpscr);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) */
|
||||
|
||||
|
||||
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
|
||||
/* GNU gcc specific functions */
|
||||
|
||||
/** \brief Enable IRQ Interrupts
|
||||
|
||||
This function enables IRQ interrupts by clearing the I-bit in the CPSR.
|
||||
Can only be executed in Privileged modes.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
|
||||
{
|
||||
__ASM volatile ("cpsie i" : : : "memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Disable IRQ Interrupts
|
||||
|
||||
This function disables IRQ interrupts by setting the I-bit in the CPSR.
|
||||
Can only be executed in Privileged modes.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
|
||||
{
|
||||
__ASM volatile ("cpsid i" : : : "memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Control Register
|
||||
|
||||
This function returns the content of the Control Register.
|
||||
|
||||
\return Control Register value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("MRS %0, control" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Control Register
|
||||
|
||||
This function writes the given value to the Control Register.
|
||||
|
||||
\param [in] control Control Register value to set
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control)
|
||||
{
|
||||
__ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get IPSR Register
|
||||
|
||||
This function returns the content of the IPSR Register.
|
||||
|
||||
\return IPSR Register value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("MRS %0, ipsr" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get APSR Register
|
||||
|
||||
This function returns the content of the APSR Register.
|
||||
|
||||
\return APSR Register value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("MRS %0, apsr" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get xPSR Register
|
||||
|
||||
This function returns the content of the xPSR Register.
|
||||
|
||||
\return xPSR Register value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("MRS %0, xpsr" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Process Stack Pointer
|
||||
|
||||
This function returns the current value of the Process Stack Pointer (PSP).
|
||||
|
||||
\return PSP Register value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
|
||||
{
|
||||
register uint32_t result;
|
||||
|
||||
__ASM volatile ("MRS %0, psp\n" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Process Stack Pointer
|
||||
|
||||
This function assigns the given value to the Process Stack Pointer (PSP).
|
||||
|
||||
\param [in] topOfProcStack Process Stack Pointer value to set
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
|
||||
{
|
||||
__ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Main Stack Pointer
|
||||
|
||||
This function returns the current value of the Main Stack Pointer (MSP).
|
||||
|
||||
\return MSP Register value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
|
||||
{
|
||||
register uint32_t result;
|
||||
|
||||
__ASM volatile ("MRS %0, msp\n" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Main Stack Pointer
|
||||
|
||||
This function assigns the given value to the Main Stack Pointer (MSP).
|
||||
|
||||
\param [in] topOfMainStack Main Stack Pointer value to set
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
|
||||
{
|
||||
__ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Priority Mask
|
||||
|
||||
This function returns the current state of the priority mask bit from the Priority Mask Register.
|
||||
|
||||
\return Priority Mask value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("MRS %0, primask" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Priority Mask
|
||||
|
||||
This function assigns the given value to the Priority Mask Register.
|
||||
|
||||
\param [in] priMask Priority Mask
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
|
||||
{
|
||||
__ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
|
||||
}
|
||||
|
||||
|
||||
#if (__CORTEX_M >= 0x03)
|
||||
|
||||
/** \brief Enable FIQ
|
||||
|
||||
This function enables FIQ interrupts by clearing the F-bit in the CPSR.
|
||||
Can only be executed in Privileged modes.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void)
|
||||
{
|
||||
__ASM volatile ("cpsie f" : : : "memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Disable FIQ
|
||||
|
||||
This function disables FIQ interrupts by setting the F-bit in the CPSR.
|
||||
Can only be executed in Privileged modes.
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void)
|
||||
{
|
||||
__ASM volatile ("cpsid f" : : : "memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Base Priority
|
||||
|
||||
This function returns the current value of the Base Priority register.
|
||||
|
||||
\return Base Priority register value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("MRS %0, basepri" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Base Priority
|
||||
|
||||
This function assigns the given value to the Base Priority register.
|
||||
|
||||
\param [in] basePri Base Priority value to set
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
|
||||
{
|
||||
__ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Base Priority with condition
|
||||
|
||||
This function assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
|
||||
or the new value increases the BASEPRI priority level.
|
||||
|
||||
\param [in] basePri Base Priority value to set
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t value)
|
||||
{
|
||||
__ASM volatile ("MSR basepri_max, %0" : : "r" (value) : "memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Fault Mask
|
||||
|
||||
This function returns the current value of the Fault Mask register.
|
||||
|
||||
\return Fault Mask register value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("MRS %0, faultmask" : "=r" (result) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Fault Mask
|
||||
|
||||
This function assigns the given value to the Fault Mask register.
|
||||
|
||||
\param [in] faultMask Fault Mask value to set
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
|
||||
{
|
||||
__ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
|
||||
}
|
||||
|
||||
#endif /* (__CORTEX_M >= 0x03) */
|
||||
|
||||
|
||||
#if (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07)
|
||||
|
||||
/** \brief Get FPSCR
|
||||
|
||||
This function returns the current value of the Floating Point Status/Control register.
|
||||
|
||||
\return Floating Point Status/Control register value
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
|
||||
{
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
uint32_t result;
|
||||
|
||||
/* Empty asm statement works as a scheduling barrier */
|
||||
__ASM volatile ("");
|
||||
__ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
|
||||
__ASM volatile ("");
|
||||
return(result);
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set FPSCR
|
||||
|
||||
This function assigns the given value to the Floating Point Status/Control register.
|
||||
|
||||
\param [in] fpscr Floating Point Status/Control value to set
|
||||
*/
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
|
||||
{
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
/* Empty asm statement works as a scheduling barrier */
|
||||
__ASM volatile ("");
|
||||
__ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc");
|
||||
__ASM volatile ("");
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) */
|
||||
|
||||
|
||||
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
|
||||
/* IAR iccarm specific functions */
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
|
||||
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
|
||||
/* TI CCS specific functions */
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
|
||||
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
|
||||
/* TASKING carm specific functions */
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
|
||||
#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/
|
||||
/* Cosmic specific functions */
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of CMSIS_Core_RegAccFunctions */
|
||||
|
||||
#endif /* __CORE_CMFUNC_H */
|
|
@ -1,916 +0,0 @@
|
|||
/**************************************************************************//**
|
||||
* @file core_cmInstr.h
|
||||
* @brief CMSIS Cortex-M Core Instruction Access Header File
|
||||
* @version V4.10
|
||||
* @date 18. March 2015
|
||||
*
|
||||
* @note
|
||||
*
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2014 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- 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.
|
||||
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef __CORE_CMINSTR_H
|
||||
#define __CORE_CMINSTR_H
|
||||
|
||||
|
||||
/* ########################## Core Instruction Access ######################### */
|
||||
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
|
||||
Access to dedicated instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
|
||||
/* ARM armcc specific functions */
|
||||
|
||||
#if (__ARMCC_VERSION < 400677)
|
||||
#error "Please use ARM Compiler Toolchain V4.0.677 or later!"
|
||||
#endif
|
||||
|
||||
|
||||
/** \brief No Operation
|
||||
|
||||
No Operation does nothing. This instruction can be used for code alignment purposes.
|
||||
*/
|
||||
#define __NOP __nop
|
||||
|
||||
|
||||
/** \brief Wait For Interrupt
|
||||
|
||||
Wait For Interrupt is a hint instruction that suspends execution
|
||||
until one of a number of events occurs.
|
||||
*/
|
||||
#define __WFI __wfi
|
||||
|
||||
|
||||
/** \brief Wait For Event
|
||||
|
||||
Wait For Event is a hint instruction that permits the processor to enter
|
||||
a low-power state until one of a number of events occurs.
|
||||
*/
|
||||
#define __WFE __wfe
|
||||
|
||||
|
||||
/** \brief Send Event
|
||||
|
||||
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
|
||||
*/
|
||||
#define __SEV __sev
|
||||
|
||||
|
||||
/** \brief Instruction Synchronization Barrier
|
||||
|
||||
Instruction Synchronization Barrier flushes the pipeline in the processor,
|
||||
so that all instructions following the ISB are fetched from cache or
|
||||
memory, after the instruction has been completed.
|
||||
*/
|
||||
#define __ISB() do {\
|
||||
__schedule_barrier();\
|
||||
__isb(0xF);\
|
||||
__schedule_barrier();\
|
||||
} while (0)
|
||||
|
||||
/** \brief Data Synchronization Barrier
|
||||
|
||||
This function acts as a special kind of Data Memory Barrier.
|
||||
It completes when all explicit memory accesses before this instruction complete.
|
||||
*/
|
||||
#define __DSB() do {\
|
||||
__schedule_barrier();\
|
||||
__dsb(0xF);\
|
||||
__schedule_barrier();\
|
||||
} while (0)
|
||||
|
||||
/** \brief Data Memory Barrier
|
||||
|
||||
This function ensures the apparent order of the explicit memory operations before
|
||||
and after the instruction, without ensuring their completion.
|
||||
*/
|
||||
#define __DMB() do {\
|
||||
__schedule_barrier();\
|
||||
__dmb(0xF);\
|
||||
__schedule_barrier();\
|
||||
} while (0)
|
||||
|
||||
/** \brief Reverse byte order (32 bit)
|
||||
|
||||
This function reverses the byte order in integer value.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#define __REV __rev
|
||||
|
||||
|
||||
/** \brief Reverse byte order (16 bit)
|
||||
|
||||
This function reverses the byte order in two unsigned short values.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#ifndef __NO_EMBEDDED_ASM
|
||||
__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
|
||||
{
|
||||
rev16 r0, r0
|
||||
bx lr
|
||||
}
|
||||
#endif
|
||||
|
||||
/** \brief Reverse byte order in signed short value
|
||||
|
||||
This function reverses the byte order in a signed short value with sign extension to integer.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#ifndef __NO_EMBEDDED_ASM
|
||||
__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
|
||||
{
|
||||
revsh r0, r0
|
||||
bx lr
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** \brief Rotate Right in unsigned value (32 bit)
|
||||
|
||||
This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
|
||||
|
||||
\param [in] value Value to rotate
|
||||
\param [in] value Number of Bits to rotate
|
||||
\return Rotated value
|
||||
*/
|
||||
#define __ROR __ror
|
||||
|
||||
|
||||
/** \brief Breakpoint
|
||||
|
||||
This function causes the processor to enter Debug state.
|
||||
Debug tools can use this to investigate system state when the instruction at a particular address is reached.
|
||||
|
||||
\param [in] value is ignored by the processor.
|
||||
If required, a debugger can use it to store additional information about the breakpoint.
|
||||
*/
|
||||
#define __BKPT(value) __breakpoint(value)
|
||||
|
||||
|
||||
/** \brief Reverse bit order of value
|
||||
|
||||
This function reverses the bit order of the given value.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300)
|
||||
#define __RBIT __rbit
|
||||
#else
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
|
||||
{
|
||||
uint32_t result;
|
||||
int32_t s = 4 /*sizeof(v)*/ * 8 - 1; // extra shift needed at end
|
||||
|
||||
result = value; // r will be reversed bits of v; first get LSB of v
|
||||
for (value >>= 1; value; value >>= 1)
|
||||
{
|
||||
result <<= 1;
|
||||
result |= value & 1;
|
||||
s--;
|
||||
}
|
||||
result <<= s; // shift when v's highest bits are zero
|
||||
return(result);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** \brief Count leading zeros
|
||||
|
||||
This function counts the number of leading zeros of a data value.
|
||||
|
||||
\param [in] value Value to count the leading zeros
|
||||
\return number of leading zeros in value
|
||||
*/
|
||||
#define __CLZ __clz
|
||||
|
||||
|
||||
#if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300)
|
||||
|
||||
/** \brief LDR Exclusive (8 bit)
|
||||
|
||||
This function executes a exclusive LDR instruction for 8 bit value.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint8_t at (*ptr)
|
||||
*/
|
||||
#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (16 bit)
|
||||
|
||||
This function executes a exclusive LDR instruction for 16 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint16_t at (*ptr)
|
||||
*/
|
||||
#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (32 bit)
|
||||
|
||||
This function executes a exclusive LDR instruction for 32 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint32_t at (*ptr)
|
||||
*/
|
||||
#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
|
||||
|
||||
|
||||
/** \brief STR Exclusive (8 bit)
|
||||
|
||||
This function executes a exclusive STR instruction for 8 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
#define __STREXB(value, ptr) __strex(value, ptr)
|
||||
|
||||
|
||||
/** \brief STR Exclusive (16 bit)
|
||||
|
||||
This function executes a exclusive STR instruction for 16 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
#define __STREXH(value, ptr) __strex(value, ptr)
|
||||
|
||||
|
||||
/** \brief STR Exclusive (32 bit)
|
||||
|
||||
This function executes a exclusive STR instruction for 32 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
#define __STREXW(value, ptr) __strex(value, ptr)
|
||||
|
||||
|
||||
/** \brief Remove the exclusive lock
|
||||
|
||||
This function removes the exclusive lock which is created by LDREX.
|
||||
|
||||
*/
|
||||
#define __CLREX __clrex
|
||||
|
||||
|
||||
/** \brief Signed Saturate
|
||||
|
||||
This function saturates a signed value.
|
||||
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (1..32)
|
||||
\return Saturated value
|
||||
*/
|
||||
#define __SSAT __ssat
|
||||
|
||||
|
||||
/** \brief Unsigned Saturate
|
||||
|
||||
This function saturates an unsigned value.
|
||||
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (0..31)
|
||||
\return Saturated value
|
||||
*/
|
||||
#define __USAT __usat
|
||||
|
||||
|
||||
/** \brief Rotate Right with Extend (32 bit)
|
||||
|
||||
This function moves each bit of a bitstring right by one bit.
|
||||
The carry input is shifted in at the left end of the bitstring.
|
||||
|
||||
\param [in] value Value to rotate
|
||||
\return Rotated value
|
||||
*/
|
||||
#ifndef __NO_EMBEDDED_ASM
|
||||
__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
|
||||
{
|
||||
rrx r0, r0
|
||||
bx lr
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** \brief LDRT Unprivileged (8 bit)
|
||||
|
||||
This function executes a Unprivileged LDRT instruction for 8 bit value.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint8_t at (*ptr)
|
||||
*/
|
||||
#define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr))
|
||||
|
||||
|
||||
/** \brief LDRT Unprivileged (16 bit)
|
||||
|
||||
This function executes a Unprivileged LDRT instruction for 16 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint16_t at (*ptr)
|
||||
*/
|
||||
#define __LDRHT(ptr) ((uint16_t) __ldrt(ptr))
|
||||
|
||||
|
||||
/** \brief LDRT Unprivileged (32 bit)
|
||||
|
||||
This function executes a Unprivileged LDRT instruction for 32 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint32_t at (*ptr)
|
||||
*/
|
||||
#define __LDRT(ptr) ((uint32_t ) __ldrt(ptr))
|
||||
|
||||
|
||||
/** \brief STRT Unprivileged (8 bit)
|
||||
|
||||
This function executes a Unprivileged STRT instruction for 8 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
*/
|
||||
#define __STRBT(value, ptr) __strt(value, ptr)
|
||||
|
||||
|
||||
/** \brief STRT Unprivileged (16 bit)
|
||||
|
||||
This function executes a Unprivileged STRT instruction for 16 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
*/
|
||||
#define __STRHT(value, ptr) __strt(value, ptr)
|
||||
|
||||
|
||||
/** \brief STRT Unprivileged (32 bit)
|
||||
|
||||
This function executes a Unprivileged STRT instruction for 32 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
*/
|
||||
#define __STRT(value, ptr) __strt(value, ptr)
|
||||
|
||||
#endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */
|
||||
|
||||
|
||||
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
|
||||
/* GNU gcc specific functions */
|
||||
|
||||
/* Define macros for porting to both thumb1 and thumb2.
|
||||
* For thumb1, use low register (r0-r7), specified by constrant "l"
|
||||
* Otherwise, use general registers, specified by constrant "r" */
|
||||
#if defined (__thumb__) && !defined (__thumb2__)
|
||||
#define __CMSIS_GCC_OUT_REG(r) "=l" (r)
|
||||
#define __CMSIS_GCC_USE_REG(r) "l" (r)
|
||||
#else
|
||||
#define __CMSIS_GCC_OUT_REG(r) "=r" (r)
|
||||
#define __CMSIS_GCC_USE_REG(r) "r" (r)
|
||||
#endif
|
||||
|
||||
/** \brief No Operation
|
||||
|
||||
No Operation does nothing. This instruction can be used for code alignment purposes.
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __NOP(void)
|
||||
{
|
||||
__ASM volatile ("nop");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Wait For Interrupt
|
||||
|
||||
Wait For Interrupt is a hint instruction that suspends execution
|
||||
until one of a number of events occurs.
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __WFI(void)
|
||||
{
|
||||
__ASM volatile ("wfi");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Wait For Event
|
||||
|
||||
Wait For Event is a hint instruction that permits the processor to enter
|
||||
a low-power state until one of a number of events occurs.
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __WFE(void)
|
||||
{
|
||||
__ASM volatile ("wfe");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Send Event
|
||||
|
||||
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __SEV(void)
|
||||
{
|
||||
__ASM volatile ("sev");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Instruction Synchronization Barrier
|
||||
|
||||
Instruction Synchronization Barrier flushes the pipeline in the processor,
|
||||
so that all instructions following the ISB are fetched from cache or
|
||||
memory, after the instruction has been completed.
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __ISB(void)
|
||||
{
|
||||
__ASM volatile ("isb 0xF":::"memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Data Synchronization Barrier
|
||||
|
||||
This function acts as a special kind of Data Memory Barrier.
|
||||
It completes when all explicit memory accesses before this instruction complete.
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __DSB(void)
|
||||
{
|
||||
__ASM volatile ("dsb 0xF":::"memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Data Memory Barrier
|
||||
|
||||
This function ensures the apparent order of the explicit memory operations before
|
||||
and after the instruction, without ensuring their completion.
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __DMB(void)
|
||||
{
|
||||
__ASM volatile ("dmb 0xF":::"memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Reverse byte order (32 bit)
|
||||
|
||||
This function reverses the byte order in integer value.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __REV(uint32_t value)
|
||||
{
|
||||
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
|
||||
return __builtin_bswap32(value);
|
||||
#else
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
|
||||
return(result);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/** \brief Reverse byte order (16 bit)
|
||||
|
||||
This function reverses the byte order in two unsigned short values.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __REV16(uint32_t value)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Reverse byte order in signed short value
|
||||
|
||||
This function reverses the byte order in a signed short value with sign extension to integer.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE int32_t __REVSH(int32_t value)
|
||||
{
|
||||
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
return (short)__builtin_bswap16(value);
|
||||
#else
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
|
||||
return(result);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/** \brief Rotate Right in unsigned value (32 bit)
|
||||
|
||||
This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
|
||||
|
||||
\param [in] value Value to rotate
|
||||
\param [in] value Number of Bits to rotate
|
||||
\return Rotated value
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
return (op1 >> op2) | (op1 << (32 - op2));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Breakpoint
|
||||
|
||||
This function causes the processor to enter Debug state.
|
||||
Debug tools can use this to investigate system state when the instruction at a particular address is reached.
|
||||
|
||||
\param [in] value is ignored by the processor.
|
||||
If required, a debugger can use it to store additional information about the breakpoint.
|
||||
*/
|
||||
#define __BKPT(value) __ASM volatile ("bkpt "#value)
|
||||
|
||||
|
||||
/** \brief Reverse bit order of value
|
||||
|
||||
This function reverses the bit order of the given value.
|
||||
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
#if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300)
|
||||
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
|
||||
#else
|
||||
int32_t s = 4 /*sizeof(v)*/ * 8 - 1; // extra shift needed at end
|
||||
|
||||
result = value; // r will be reversed bits of v; first get LSB of v
|
||||
for (value >>= 1; value; value >>= 1)
|
||||
{
|
||||
result <<= 1;
|
||||
result |= value & 1;
|
||||
s--;
|
||||
}
|
||||
result <<= s; // shift when v's highest bits are zero
|
||||
#endif
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Count leading zeros
|
||||
|
||||
This function counts the number of leading zeros of a data value.
|
||||
|
||||
\param [in] value Value to count the leading zeros
|
||||
\return number of leading zeros in value
|
||||
*/
|
||||
#define __CLZ __builtin_clz
|
||||
|
||||
|
||||
#if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300)
|
||||
|
||||
/** \brief LDR Exclusive (8 bit)
|
||||
|
||||
This function executes a exclusive LDR instruction for 8 bit value.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint8_t at (*ptr)
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
__ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
|
||||
#else
|
||||
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
|
||||
accepted by assembler. So has to use following less efficient pattern.
|
||||
*/
|
||||
__ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
|
||||
#endif
|
||||
return ((uint8_t) result); /* Add explicit type cast here */
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (16 bit)
|
||||
|
||||
This function executes a exclusive LDR instruction for 16 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint16_t at (*ptr)
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
__ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
|
||||
#else
|
||||
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
|
||||
accepted by assembler. So has to use following less efficient pattern.
|
||||
*/
|
||||
__ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
|
||||
#endif
|
||||
return ((uint16_t) result); /* Add explicit type cast here */
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDR Exclusive (32 bit)
|
||||
|
||||
This function executes a exclusive LDR instruction for 32 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint32_t at (*ptr)
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief STR Exclusive (8 bit)
|
||||
|
||||
This function executes a exclusive STR instruction for 8 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief STR Exclusive (16 bit)
|
||||
|
||||
This function executes a exclusive STR instruction for 16 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief STR Exclusive (32 bit)
|
||||
|
||||
This function executes a exclusive STR instruction for 32 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Remove the exclusive lock
|
||||
|
||||
This function removes the exclusive lock which is created by LDREX.
|
||||
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __CLREX(void)
|
||||
{
|
||||
__ASM volatile ("clrex" ::: "memory");
|
||||
}
|
||||
|
||||
|
||||
/** \brief Signed Saturate
|
||||
|
||||
This function saturates a signed value.
|
||||
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (1..32)
|
||||
\return Saturated value
|
||||
*/
|
||||
#define __SSAT(ARG1,ARG2) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1); \
|
||||
__ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
|
||||
/** \brief Unsigned Saturate
|
||||
|
||||
This function saturates an unsigned value.
|
||||
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (0..31)
|
||||
\return Saturated value
|
||||
*/
|
||||
#define __USAT(ARG1,ARG2) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1); \
|
||||
__ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
|
||||
/** \brief Rotate Right with Extend (32 bit)
|
||||
|
||||
This function moves each bit of a bitstring right by one bit.
|
||||
The carry input is shifted in at the left end of the bitstring.
|
||||
|
||||
\param [in] value Value to rotate
|
||||
\return Rotated value
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __RRX(uint32_t value)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDRT Unprivileged (8 bit)
|
||||
|
||||
This function executes a Unprivileged LDRT instruction for 8 bit value.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint8_t at (*ptr)
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
__ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*addr) );
|
||||
#else
|
||||
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
|
||||
accepted by assembler. So has to use following less efficient pattern.
|
||||
*/
|
||||
__ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
|
||||
#endif
|
||||
return ((uint8_t) result); /* Add explicit type cast here */
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDRT Unprivileged (16 bit)
|
||||
|
||||
This function executes a Unprivileged LDRT instruction for 16 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint16_t at (*ptr)
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
__ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*addr) );
|
||||
#else
|
||||
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
|
||||
accepted by assembler. So has to use following less efficient pattern.
|
||||
*/
|
||||
__ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
|
||||
#endif
|
||||
return ((uint16_t) result); /* Add explicit type cast here */
|
||||
}
|
||||
|
||||
|
||||
/** \brief LDRT Unprivileged (32 bit)
|
||||
|
||||
This function executes a Unprivileged LDRT instruction for 32 bit values.
|
||||
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint32_t at (*ptr)
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t *addr)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*addr) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
/** \brief STRT Unprivileged (8 bit)
|
||||
|
||||
This function executes a Unprivileged STRT instruction for 8 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *addr)
|
||||
{
|
||||
__ASM volatile ("strbt %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) );
|
||||
}
|
||||
|
||||
|
||||
/** \brief STRT Unprivileged (16 bit)
|
||||
|
||||
This function executes a Unprivileged STRT instruction for 16 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *addr)
|
||||
{
|
||||
__ASM volatile ("strht %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) );
|
||||
}
|
||||
|
||||
|
||||
/** \brief STRT Unprivileged (32 bit)
|
||||
|
||||
This function executes a Unprivileged STRT instruction for 32 bit values.
|
||||
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *addr)
|
||||
{
|
||||
__ASM volatile ("strt %1, %0" : "=Q" (*addr) : "r" (value) );
|
||||
}
|
||||
|
||||
#endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */
|
||||
|
||||
|
||||
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
|
||||
/* IAR iccarm specific functions */
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
|
||||
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
|
||||
/* TI CCS specific functions */
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
|
||||
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
|
||||
/* TASKING carm specific functions */
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
|
||||
#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/
|
||||
/* Cosmic specific functions */
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
|
||||
|
||||
#endif /* __CORE_CMINSTR_H */
|
|
@ -1,697 +0,0 @@
|
|||
/**************************************************************************//**
|
||||
* @file core_cmSimd.h
|
||||
* @brief CMSIS Cortex-M SIMD Header File
|
||||
* @version V4.10
|
||||
* @date 18. March 2015
|
||||
*
|
||||
* @note
|
||||
*
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2014 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- 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.
|
||||
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CMSIMD_H
|
||||
#define __CORE_CMSIMD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Hardware Abstraction Layer
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/* ################### Compiler specific Intrinsics ########################### */
|
||||
/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
|
||||
Access to dedicated SIMD instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
|
||||
/* ARM armcc specific functions */
|
||||
#define __SADD8 __sadd8
|
||||
#define __QADD8 __qadd8
|
||||
#define __SHADD8 __shadd8
|
||||
#define __UADD8 __uadd8
|
||||
#define __UQADD8 __uqadd8
|
||||
#define __UHADD8 __uhadd8
|
||||
#define __SSUB8 __ssub8
|
||||
#define __QSUB8 __qsub8
|
||||
#define __SHSUB8 __shsub8
|
||||
#define __USUB8 __usub8
|
||||
#define __UQSUB8 __uqsub8
|
||||
#define __UHSUB8 __uhsub8
|
||||
#define __SADD16 __sadd16
|
||||
#define __QADD16 __qadd16
|
||||
#define __SHADD16 __shadd16
|
||||
#define __UADD16 __uadd16
|
||||
#define __UQADD16 __uqadd16
|
||||
#define __UHADD16 __uhadd16
|
||||
#define __SSUB16 __ssub16
|
||||
#define __QSUB16 __qsub16
|
||||
#define __SHSUB16 __shsub16
|
||||
#define __USUB16 __usub16
|
||||
#define __UQSUB16 __uqsub16
|
||||
#define __UHSUB16 __uhsub16
|
||||
#define __SASX __sasx
|
||||
#define __QASX __qasx
|
||||
#define __SHASX __shasx
|
||||
#define __UASX __uasx
|
||||
#define __UQASX __uqasx
|
||||
#define __UHASX __uhasx
|
||||
#define __SSAX __ssax
|
||||
#define __QSAX __qsax
|
||||
#define __SHSAX __shsax
|
||||
#define __USAX __usax
|
||||
#define __UQSAX __uqsax
|
||||
#define __UHSAX __uhsax
|
||||
#define __USAD8 __usad8
|
||||
#define __USADA8 __usada8
|
||||
#define __SSAT16 __ssat16
|
||||
#define __USAT16 __usat16
|
||||
#define __UXTB16 __uxtb16
|
||||
#define __UXTAB16 __uxtab16
|
||||
#define __SXTB16 __sxtb16
|
||||
#define __SXTAB16 __sxtab16
|
||||
#define __SMUAD __smuad
|
||||
#define __SMUADX __smuadx
|
||||
#define __SMLAD __smlad
|
||||
#define __SMLADX __smladx
|
||||
#define __SMLALD __smlald
|
||||
#define __SMLALDX __smlaldx
|
||||
#define __SMUSD __smusd
|
||||
#define __SMUSDX __smusdx
|
||||
#define __SMLSD __smlsd
|
||||
#define __SMLSDX __smlsdx
|
||||
#define __SMLSLD __smlsld
|
||||
#define __SMLSLDX __smlsldx
|
||||
#define __SEL __sel
|
||||
#define __QADD __qadd
|
||||
#define __QSUB __qsub
|
||||
|
||||
#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
|
||||
((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
|
||||
|
||||
#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
|
||||
((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
|
||||
|
||||
#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
|
||||
((int64_t)(ARG3) << 32) ) >> 32))
|
||||
|
||||
|
||||
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
|
||||
/* GNU gcc specific functions */
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
#define __SSAT16(ARG1,ARG2) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1); \
|
||||
__ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
#define __USAT16(ARG1,ARG2) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1); \
|
||||
__ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
|
||||
{
|
||||
union llreg_u{
|
||||
uint32_t w32[2];
|
||||
uint64_t w64;
|
||||
} llr;
|
||||
llr.w64 = acc;
|
||||
|
||||
#ifndef __ARMEB__ // Little endian
|
||||
__ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
|
||||
#else // Big endian
|
||||
__ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
|
||||
#endif
|
||||
|
||||
return(llr.w64);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
|
||||
{
|
||||
union llreg_u{
|
||||
uint32_t w32[2];
|
||||
uint64_t w64;
|
||||
} llr;
|
||||
llr.w64 = acc;
|
||||
|
||||
#ifndef __ARMEB__ // Little endian
|
||||
__ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
|
||||
#else // Big endian
|
||||
__ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
|
||||
#endif
|
||||
|
||||
return(llr.w64);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
|
||||
{
|
||||
union llreg_u{
|
||||
uint32_t w32[2];
|
||||
uint64_t w64;
|
||||
} llr;
|
||||
llr.w64 = acc;
|
||||
|
||||
#ifndef __ARMEB__ // Little endian
|
||||
__ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
|
||||
#else // Big endian
|
||||
__ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
|
||||
#endif
|
||||
|
||||
return(llr.w64);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
|
||||
{
|
||||
union llreg_u{
|
||||
uint32_t w32[2];
|
||||
uint64_t w64;
|
||||
} llr;
|
||||
llr.w64 = acc;
|
||||
|
||||
#ifndef __ARMEB__ // Little endian
|
||||
__ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
|
||||
#else // Big endian
|
||||
__ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
|
||||
#endif
|
||||
|
||||
return(llr.w64);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB(uint32_t op1, uint32_t op2)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
__ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
#define __PKHBT(ARG1,ARG2,ARG3) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
|
||||
__ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
#define __PKHTB(ARG1,ARG2,ARG3) \
|
||||
({ \
|
||||
uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
|
||||
if (ARG3 == 0) \
|
||||
__ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
|
||||
else \
|
||||
__ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
|
||||
__RES; \
|
||||
})
|
||||
|
||||
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
|
||||
{
|
||||
int32_t result;
|
||||
|
||||
__ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
||||
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
|
||||
/* IAR iccarm specific functions */
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
|
||||
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
|
||||
/* TI CCS specific functions */
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
|
||||
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
|
||||
/* TASKING carm specific functions */
|
||||
/* not yet supported */
|
||||
|
||||
|
||||
#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/
|
||||
/* Cosmic specific functions */
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of group CMSIS_SIMD_intrinsics */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CORE_CMSIMD_H */
|
|
@ -1,866 +0,0 @@
|
|||
/**************************************************************************//**
|
||||
* @file core_sc000.h
|
||||
* @brief CMSIS SC000 Core Peripheral Access Layer Header File
|
||||
* @version V4.10
|
||||
* @date 18. March 2015
|
||||
*
|
||||
* @note
|
||||
*
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- 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.
|
||||
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_SC000_H_GENERIC
|
||||
#define __CORE_SC000_H_GENERIC
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
|
||||
CMSIS violates the following MISRA-C:2004 rules:
|
||||
|
||||
\li Required Rule 8.5, object/function definition in header file.<br>
|
||||
Function definitions in header files are used to allow 'inlining'.
|
||||
|
||||
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
|
||||
Unions are used for effective representation of core registers.
|
||||
|
||||
\li Advisory Rule 19.7, Function-like macro defined.<br>
|
||||
Function-like macros are used to allow more efficient code.
|
||||
*/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* CMSIS definitions
|
||||
******************************************************************************/
|
||||
/** \ingroup SC000
|
||||
@{
|
||||
*/
|
||||
|
||||
/* CMSIS SC000 definitions */
|
||||
#define __SC000_CMSIS_VERSION_MAIN (0x04) /*!< [31:16] CMSIS HAL main version */
|
||||
#define __SC000_CMSIS_VERSION_SUB (0x00) /*!< [15:0] CMSIS HAL sub version */
|
||||
#define __SC000_CMSIS_VERSION ((__SC000_CMSIS_VERSION_MAIN << 16) | \
|
||||
__SC000_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
|
||||
|
||||
#define __CORTEX_SC (000) /*!< Cortex secure core */
|
||||
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
||||
#define __STATIC_INLINE static __inline
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
#define __ASM __asm /*!< asm keyword for IAR Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __TMS470__ )
|
||||
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __TASKING__ )
|
||||
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#elif defined ( __CSMC__ )
|
||||
#define __packed
|
||||
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
|
||||
#define __INLINE inline /*use -pc99 on compile line !< inline keyword for COSMIC Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#endif
|
||||
|
||||
/** __FPU_USED indicates whether an FPU is used or not.
|
||||
This core does not support an FPU at all
|
||||
*/
|
||||
#define __FPU_USED 0
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#if defined __TARGET_FPU_VFP
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
#if defined __ARMVFP__
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __TMS470__ )
|
||||
#if defined __TI__VFP_SUPPORT____
|
||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __TASKING__ )
|
||||
#if defined __FPU_VFP__
|
||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
|
||||
#elif defined ( __CSMC__ ) /* Cosmic */
|
||||
#if ( __CSMC__ & 0x400) // FPU present for parser
|
||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdint.h> /* standard types definitions */
|
||||
#include <core_cmInstr.h> /* Core Instruction Access */
|
||||
#include <core_cmFunc.h> /* Core Function Access */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CORE_SC000_H_GENERIC */
|
||||
|
||||
#ifndef __CMSIS_GENERIC
|
||||
|
||||
#ifndef __CORE_SC000_H_DEPENDANT
|
||||
#define __CORE_SC000_H_DEPENDANT
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* check device defines and use defaults */
|
||||
#if defined __CHECK_DEVICE_DEFINES
|
||||
#ifndef __SC000_REV
|
||||
#define __SC000_REV 0x0000
|
||||
#warning "__SC000_REV not defined in device header file; using default!"
|
||||
#endif
|
||||
|
||||
#ifndef __MPU_PRESENT
|
||||
#define __MPU_PRESENT 0
|
||||
#warning "__MPU_PRESENT not defined in device header file; using default!"
|
||||
#endif
|
||||
|
||||
#ifndef __NVIC_PRIO_BITS
|
||||
#define __NVIC_PRIO_BITS 2
|
||||
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
|
||||
#endif
|
||||
|
||||
#ifndef __Vendor_SysTickConfig
|
||||
#define __Vendor_SysTickConfig 0
|
||||
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* IO definitions (access restrictions to peripheral registers) */
|
||||
/**
|
||||
\defgroup CMSIS_glob_defs CMSIS Global Defines
|
||||
|
||||
<strong>IO Type Qualifiers</strong> are used
|
||||
\li to specify the access to peripheral variables.
|
||||
\li for automatic generation of peripheral register debug information.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
#define __I volatile /*!< Defines 'read only' permissions */
|
||||
#else
|
||||
#define __I volatile const /*!< Defines 'read only' permissions */
|
||||
#endif
|
||||
#define __O volatile /*!< Defines 'write only' permissions */
|
||||
#define __IO volatile /*!< Defines 'read / write' permissions */
|
||||
|
||||
/*@} end of group SC000 */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Register Abstraction
|
||||
Core Register contain:
|
||||
- Core Register
|
||||
- Core NVIC Register
|
||||
- Core SCB Register
|
||||
- Core SysTick Register
|
||||
- Core MPU Register
|
||||
******************************************************************************/
|
||||
/** \defgroup CMSIS_core_register Defines and Type Definitions
|
||||
\brief Type definitions and defines for Cortex-M processor based devices.
|
||||
*/
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_CORE Status and Control Registers
|
||||
\brief Core Register type definitions.
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Union type to access the Application Program Status Register (APSR).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */
|
||||
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
|
||||
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} APSR_Type;
|
||||
|
||||
/* APSR Register Definitions */
|
||||
#define APSR_N_Pos 31 /*!< APSR: N Position */
|
||||
#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
|
||||
|
||||
#define APSR_Z_Pos 30 /*!< APSR: Z Position */
|
||||
#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
|
||||
|
||||
#define APSR_C_Pos 29 /*!< APSR: C Position */
|
||||
#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
|
||||
|
||||
#define APSR_V_Pos 28 /*!< APSR: V Position */
|
||||
#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
|
||||
|
||||
|
||||
/** \brief Union type to access the Interrupt Program Status Register (IPSR).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} IPSR_Type;
|
||||
|
||||
/* IPSR Register Definitions */
|
||||
#define IPSR_ISR_Pos 0 /*!< IPSR: ISR Position */
|
||||
#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
|
||||
|
||||
|
||||
/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
|
||||
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
|
||||
uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */
|
||||
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
|
||||
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} xPSR_Type;
|
||||
|
||||
/* xPSR Register Definitions */
|
||||
#define xPSR_N_Pos 31 /*!< xPSR: N Position */
|
||||
#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
|
||||
|
||||
#define xPSR_Z_Pos 30 /*!< xPSR: Z Position */
|
||||
#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
|
||||
|
||||
#define xPSR_C_Pos 29 /*!< xPSR: C Position */
|
||||
#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
|
||||
|
||||
#define xPSR_V_Pos 28 /*!< xPSR: V Position */
|
||||
#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
|
||||
|
||||
#define xPSR_T_Pos 24 /*!< xPSR: T Position */
|
||||
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
|
||||
|
||||
#define xPSR_ISR_Pos 0 /*!< xPSR: ISR Position */
|
||||
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
|
||||
|
||||
|
||||
/** \brief Union type to access the Control Registers (CONTROL).
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t _reserved0:1; /*!< bit: 0 Reserved */
|
||||
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
|
||||
uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */
|
||||
} b; /*!< Structure used for bit access */
|
||||
uint32_t w; /*!< Type used for word access */
|
||||
} CONTROL_Type;
|
||||
|
||||
/* CONTROL Register Definitions */
|
||||
#define CONTROL_SPSEL_Pos 1 /*!< CONTROL: SPSEL Position */
|
||||
#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
|
||||
|
||||
/*@} end of group CMSIS_CORE */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
|
||||
\brief Type definitions for the NVIC Registers
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
||||
uint32_t RESERVED0[31];
|
||||
__IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
||||
uint32_t RSERVED1[31];
|
||||
__IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
||||
uint32_t RESERVED2[31];
|
||||
__IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
||||
uint32_t RESERVED3[31];
|
||||
uint32_t RESERVED4[64];
|
||||
__IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
|
||||
} NVIC_Type;
|
||||
|
||||
/*@} end of group CMSIS_NVIC */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_SCB System Control Block (SCB)
|
||||
\brief Type definitions for the System Control Block Registers
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the System Control Block (SCB).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
|
||||
__IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
|
||||
__IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
|
||||
__IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
|
||||
__IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
|
||||
__IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
|
||||
uint32_t RESERVED0[1];
|
||||
__IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
|
||||
__IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
|
||||
uint32_t RESERVED1[154];
|
||||
__IO uint32_t SFCR; /*!< Offset: 0x290 (R/W) Security Features Control Register */
|
||||
} SCB_Type;
|
||||
|
||||
/* SCB CPUID Register Definitions */
|
||||
#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
|
||||
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
|
||||
|
||||
#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
|
||||
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
|
||||
|
||||
#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
|
||||
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
|
||||
|
||||
#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
|
||||
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
|
||||
|
||||
#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
|
||||
#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
|
||||
|
||||
/* SCB Interrupt Control State Register Definitions */
|
||||
#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
|
||||
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
|
||||
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
|
||||
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
|
||||
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
|
||||
|
||||
#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
|
||||
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
|
||||
|
||||
#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
|
||||
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
|
||||
|
||||
#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
|
||||
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
|
||||
|
||||
#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
|
||||
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
|
||||
|
||||
#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
|
||||
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
|
||||
|
||||
/* SCB Interrupt Control State Register Definitions */
|
||||
#define SCB_VTOR_TBLOFF_Pos 7 /*!< SCB VTOR: TBLOFF Position */
|
||||
#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
|
||||
|
||||
/* SCB Application Interrupt and Reset Control Register Definitions */
|
||||
#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
|
||||
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
|
||||
|
||||
#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
|
||||
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
|
||||
|
||||
#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
|
||||
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
|
||||
|
||||
#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
|
||||
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
|
||||
|
||||
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
|
||||
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
|
||||
|
||||
/* SCB System Control Register Definitions */
|
||||
#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
|
||||
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
|
||||
|
||||
#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
|
||||
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
|
||||
|
||||
#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
|
||||
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
|
||||
|
||||
/* SCB Configuration Control Register Definitions */
|
||||
#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
|
||||
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
|
||||
|
||||
#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
|
||||
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
|
||||
|
||||
/* SCB System Handler Control and State Register Definitions */
|
||||
#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
|
||||
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
|
||||
|
||||
/*@} end of group CMSIS_SCB */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB)
|
||||
\brief Type definitions for the System Control and ID Register not in the SCB
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the System Control and ID Register not in the SCB.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t RESERVED0[2];
|
||||
__IO uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
|
||||
} SCnSCB_Type;
|
||||
|
||||
/* Auxiliary Control Register Definitions */
|
||||
#define SCnSCB_ACTLR_DISMCYCINT_Pos 0 /*!< ACTLR: DISMCYCINT Position */
|
||||
#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT Mask */
|
||||
|
||||
/*@} end of group CMSIS_SCnotSCB */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
|
||||
\brief Type definitions for the System Timer Registers.
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the System Timer (SysTick).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
|
||||
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
|
||||
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
|
||||
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
|
||||
} SysTick_Type;
|
||||
|
||||
/* SysTick Control / Status Register Definitions */
|
||||
#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
|
||||
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
|
||||
|
||||
#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
|
||||
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
|
||||
|
||||
#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
|
||||
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
|
||||
|
||||
#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
|
||||
#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
|
||||
|
||||
/* SysTick Reload Register Definitions */
|
||||
#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
|
||||
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
|
||||
|
||||
/* SysTick Current Register Definitions */
|
||||
#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
|
||||
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
|
||||
|
||||
/* SysTick Calibration Register Definitions */
|
||||
#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
|
||||
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
|
||||
|
||||
#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
|
||||
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
|
||||
|
||||
#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
|
||||
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
|
||||
|
||||
/*@} end of group CMSIS_SysTick */
|
||||
|
||||
#if (__MPU_PRESENT == 1)
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
||||
\brief Type definitions for the Memory Protection Unit (MPU)
|
||||
@{
|
||||
*/
|
||||
|
||||
/** \brief Structure type to access the Memory Protection Unit (MPU).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__I uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */
|
||||
__IO uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */
|
||||
__IO uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */
|
||||
__IO uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */
|
||||
__IO uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
|
||||
} MPU_Type;
|
||||
|
||||
/* MPU Type Register */
|
||||
#define MPU_TYPE_IREGION_Pos 16 /*!< MPU TYPE: IREGION Position */
|
||||
#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
|
||||
|
||||
#define MPU_TYPE_DREGION_Pos 8 /*!< MPU TYPE: DREGION Position */
|
||||
#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */
|
||||
|
||||
#define MPU_TYPE_SEPARATE_Pos 0 /*!< MPU TYPE: SEPARATE Position */
|
||||
#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */
|
||||
|
||||
/* MPU Control Register */
|
||||
#define MPU_CTRL_PRIVDEFENA_Pos 2 /*!< MPU CTRL: PRIVDEFENA Position */
|
||||
#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */
|
||||
|
||||
#define MPU_CTRL_HFNMIENA_Pos 1 /*!< MPU CTRL: HFNMIENA Position */
|
||||
#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */
|
||||
|
||||
#define MPU_CTRL_ENABLE_Pos 0 /*!< MPU CTRL: ENABLE Position */
|
||||
#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */
|
||||
|
||||
/* MPU Region Number Register */
|
||||
#define MPU_RNR_REGION_Pos 0 /*!< MPU RNR: REGION Position */
|
||||
#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */
|
||||
|
||||
/* MPU Region Base Address Register */
|
||||
#define MPU_RBAR_ADDR_Pos 8 /*!< MPU RBAR: ADDR Position */
|
||||
#define MPU_RBAR_ADDR_Msk (0xFFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */
|
||||
|
||||
#define MPU_RBAR_VALID_Pos 4 /*!< MPU RBAR: VALID Position */
|
||||
#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */
|
||||
|
||||
#define MPU_RBAR_REGION_Pos 0 /*!< MPU RBAR: REGION Position */
|
||||
#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */
|
||||
|
||||
/* MPU Region Attribute and Size Register */
|
||||
#define MPU_RASR_ATTRS_Pos 16 /*!< MPU RASR: MPU Region Attribute field Position */
|
||||
#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */
|
||||
|
||||
#define MPU_RASR_XN_Pos 28 /*!< MPU RASR: ATTRS.XN Position */
|
||||
#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */
|
||||
|
||||
#define MPU_RASR_AP_Pos 24 /*!< MPU RASR: ATTRS.AP Position */
|
||||
#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */
|
||||
|
||||
#define MPU_RASR_TEX_Pos 19 /*!< MPU RASR: ATTRS.TEX Position */
|
||||
#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */
|
||||
|
||||
#define MPU_RASR_S_Pos 18 /*!< MPU RASR: ATTRS.S Position */
|
||||
#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */
|
||||
|
||||
#define MPU_RASR_C_Pos 17 /*!< MPU RASR: ATTRS.C Position */
|
||||
#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */
|
||||
|
||||
#define MPU_RASR_B_Pos 16 /*!< MPU RASR: ATTRS.B Position */
|
||||
#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */
|
||||
|
||||
#define MPU_RASR_SRD_Pos 8 /*!< MPU RASR: Sub-Region Disable Position */
|
||||
#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */
|
||||
|
||||
#define MPU_RASR_SIZE_Pos 1 /*!< MPU RASR: Region Size Field Position */
|
||||
#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */
|
||||
|
||||
#define MPU_RASR_ENABLE_Pos 0 /*!< MPU RASR: Region enable bit Position */
|
||||
#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */
|
||||
|
||||
/*@} end of group CMSIS_MPU */
|
||||
#endif
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
|
||||
\brief SC000 Core Debug Registers (DCB registers, SHCSR, and DFSR)
|
||||
are only accessible over DAP and not via processor. Therefore
|
||||
they are not covered by the Cortex-M0 header file.
|
||||
@{
|
||||
*/
|
||||
/*@} end of group CMSIS_CoreDebug */
|
||||
|
||||
|
||||
/** \ingroup CMSIS_core_register
|
||||
\defgroup CMSIS_core_base Core Definitions
|
||||
\brief Definitions for base addresses, unions, and structures.
|
||||
@{
|
||||
*/
|
||||
|
||||
/* Memory mapping of SC000 Hardware */
|
||||
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
||||
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
|
||||
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
|
||||
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
|
||||
|
||||
#define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */
|
||||
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
|
||||
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
|
||||
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
|
||||
|
||||
#if (__MPU_PRESENT == 1)
|
||||
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
||||
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
||||
#endif
|
||||
|
||||
/*@} */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Hardware Abstraction Layer
|
||||
Core Function Interface contains:
|
||||
- Core NVIC Functions
|
||||
- Core SysTick Functions
|
||||
- Core Register Access Functions
|
||||
******************************************************************************/
|
||||
/** \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ########################## NVIC functions #################################### */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
|
||||
\brief Functions that manage interrupts and exceptions via the NVIC.
|
||||
@{
|
||||
*/
|
||||
|
||||
/* Interrupt Priorities are WORD accessible only under ARMv6M */
|
||||
/* The following MACROS handle generation of the register offset and byte masks */
|
||||
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
|
||||
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
|
||||
#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
|
||||
|
||||
|
||||
/** \brief Enable External Interrupt
|
||||
|
||||
The function enables a device-specific interrupt in the NVIC interrupt controller.
|
||||
|
||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ISER[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Disable External Interrupt
|
||||
|
||||
The function disables a device-specific interrupt in the NVIC interrupt controller.
|
||||
|
||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ICER[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
__DSB();
|
||||
__ISB();
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Pending Interrupt
|
||||
|
||||
The function reads the pending register in the NVIC and returns the pending bit
|
||||
for the specified interrupt.
|
||||
|
||||
\param [in] IRQn Interrupt number.
|
||||
|
||||
\return 0 Interrupt status is not pending.
|
||||
\return 1 Interrupt status is pending.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
return((uint32_t)(((NVIC->ISPR[0] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Pending Interrupt
|
||||
|
||||
The function sets the pending bit of an external interrupt.
|
||||
|
||||
\param [in] IRQn Interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ISPR[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Clear Pending Interrupt
|
||||
|
||||
The function clears the pending bit of an external interrupt.
|
||||
|
||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
NVIC->ICPR[0] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
||||
}
|
||||
|
||||
|
||||
/** \brief Set Interrupt Priority
|
||||
|
||||
The function sets the priority of an interrupt.
|
||||
|
||||
\note The priority cannot be set for every core interrupt.
|
||||
|
||||
\param [in] IRQn Interrupt number.
|
||||
\param [in] priority Priority to set.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
||||
{
|
||||
if((int32_t)(IRQn) < 0) {
|
||||
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||
(((priority << (8 - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||
}
|
||||
else {
|
||||
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||
(((priority << (8 - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief Get Interrupt Priority
|
||||
|
||||
The function reads the priority of an interrupt. The interrupt
|
||||
number can be positive to specify an external (device specific)
|
||||
interrupt, or negative to specify an internal (core) interrupt.
|
||||
|
||||
|
||||
\param [in] IRQn Interrupt number.
|
||||
\return Interrupt Priority. Value is aligned automatically to the implemented
|
||||
priority bits of the microcontroller.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
||||
{
|
||||
|
||||
if((int32_t)(IRQn) < 0) {
|
||||
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8 - __NVIC_PRIO_BITS)));
|
||||
}
|
||||
else {
|
||||
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8 - __NVIC_PRIO_BITS)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** \brief System Reset
|
||||
|
||||
The function initiates a system reset request to reset the MCU.
|
||||
*/
|
||||
__STATIC_INLINE void NVIC_SystemReset(void)
|
||||
{
|
||||
__DSB(); /* Ensure all outstanding memory accesses included
|
||||
buffered write are completed before reset */
|
||||
SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
|
||||
SCB_AIRCR_SYSRESETREQ_Msk);
|
||||
__DSB(); /* Ensure completion of memory access */
|
||||
while(1) { __NOP(); } /* wait until reset */
|
||||
}
|
||||
|
||||
/*@} end of CMSIS_Core_NVICFunctions */
|
||||
|
||||
|
||||
|
||||
/* ################################## SysTick function ############################################ */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
|
||||
\brief Functions that configure the System.
|
||||
@{
|
||||
*/
|
||||
|
||||
#if (__Vendor_SysTickConfig == 0)
|
||||
|
||||
/** \brief System Tick Configuration
|
||||
|
||||
The function initializes the System Timer and its interrupt, and starts the System Tick Timer.
|
||||
Counter is in free running mode to generate periodic interrupts.
|
||||
|
||||
\param [in] ticks Number of ticks between two interrupts.
|
||||
|
||||
\return 0 Function succeeded.
|
||||
\return 1 Function failed.
|
||||
|
||||
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
|
||||
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
|
||||
must contain a vendor-specific implementation of this function.
|
||||
|
||||
*/
|
||||
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
|
||||
{
|
||||
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) {return (1UL);} /* Reload value impossible */
|
||||
|
||||
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
|
||||
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
|
||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_TICKINT_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
return (0UL); /* Function successful */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of CMSIS_Core_SysTickFunctions */
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CORE_SC000_H_DEPENDANT */
|
||||
|
||||
#endif /* __CMSIS_GENERIC */
|
1677
cmsis/core_sc300.h
1677
cmsis/core_sc300.h
File diff suppressed because it is too large
Load Diff
|
@ -1,180 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM.C
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Variables
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef DBG_MSG
|
||||
BIT dbg_msg;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_init_stack ---------------------------------*/
|
||||
|
||||
void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
|
||||
/* Prepare TCB and saved context for a first time start of a task. */
|
||||
U32 *stk,i,size;
|
||||
|
||||
/* Prepare a complete interrupt frame for first task start */
|
||||
size = p_TCB->priv_stack >> 2;
|
||||
if (size == 0U) {
|
||||
size = (U16)os_stackinfo >> 2;
|
||||
}
|
||||
|
||||
/* Write to the top of stack. */
|
||||
stk = &p_TCB->stack[size];
|
||||
|
||||
/* Auto correct to 8-byte ARM stack alignment. */
|
||||
if ((U32)stk & 0x04U) {
|
||||
stk--;
|
||||
}
|
||||
|
||||
stk -= 16;
|
||||
|
||||
/* Default xPSR and initial PC */
|
||||
stk[15] = INITIAL_xPSR;
|
||||
stk[14] = (U32)task_body;
|
||||
|
||||
/* Clear R4-R11,R0-R3,R12,LR registers. */
|
||||
for (i = 0U; i < 14U; i++) {
|
||||
stk[i] = 0U;
|
||||
}
|
||||
|
||||
/* Assign a void pointer to R0. */
|
||||
stk[8] = (U32)p_TCB->msg;
|
||||
|
||||
/* Initial Task stack pointer. */
|
||||
p_TCB->tsk_stack = (U32)stk;
|
||||
|
||||
/* Task entry point. */
|
||||
p_TCB->ptask = task_body;
|
||||
|
||||
/* Initialize stack with magic pattern. */
|
||||
if (os_stackinfo & 0x10000000U) {
|
||||
if (size > (16U+1U)) {
|
||||
for (i = ((size - 16U)/2U) - 1U; i; i--) {
|
||||
stk -= 2U;
|
||||
stk[1] = MAGIC_PATTERN;
|
||||
stk[0] = MAGIC_PATTERN;
|
||||
}
|
||||
if (--stk > p_TCB->stack) {
|
||||
*stk = MAGIC_PATTERN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set a magic word for checking of stack overflow. */
|
||||
p_TCB->stack[0] = MAGIC_WORD;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_ret_val ----------------------------------*/
|
||||
|
||||
static __inline U32 *rt_ret_regs (P_TCB p_TCB) {
|
||||
/* Get pointer to task return value registers (R0..R3) in Stack */
|
||||
#if defined(__TARGET_FPU_VFP)
|
||||
if (p_TCB->stack_frame) {
|
||||
/* Extended Stack Frame: R4-R11,S16-S31,R0-R3,R12,LR,PC,xPSR,S0-S15,FPSCR */
|
||||
return (U32 *)(p_TCB->tsk_stack + (8U*4U) + (16U*4U));
|
||||
} else {
|
||||
/* Basic Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
|
||||
return (U32 *)(p_TCB->tsk_stack + (8U*4U));
|
||||
}
|
||||
#else
|
||||
/* Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
|
||||
return (U32 *)(p_TCB->tsk_stack + (8U*4U));
|
||||
#endif
|
||||
}
|
||||
|
||||
void rt_ret_val (P_TCB p_TCB, U32 v0) {
|
||||
U32 *ret;
|
||||
|
||||
ret = rt_ret_regs(p_TCB);
|
||||
ret[0] = v0;
|
||||
}
|
||||
|
||||
void rt_ret_val2(P_TCB p_TCB, U32 v0, U32 v1) {
|
||||
U32 *ret;
|
||||
|
||||
ret = rt_ret_regs(p_TCB);
|
||||
ret[0] = v0;
|
||||
ret[1] = v1;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- dbg_init --------------------------------------*/
|
||||
|
||||
#ifdef DBG_MSG
|
||||
void dbg_init (void) {
|
||||
if (((DEMCR & DEMCR_TRCENA) != 0U) &&
|
||||
((ITM_CONTROL & ITM_ITMENA) != 0U) &&
|
||||
((ITM_ENABLE & (1UL << 31)) != 0U)) {
|
||||
dbg_msg = __TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*--------------------------- dbg_task_notify -------------------------------*/
|
||||
|
||||
#ifdef DBG_MSG
|
||||
void dbg_task_notify (P_TCB p_tcb, BOOL create) {
|
||||
while (ITM_PORT31_U32 == 0U);
|
||||
ITM_PORT31_U32 = (U32)p_tcb->ptask;
|
||||
while (ITM_PORT31_U32 == 0U);
|
||||
ITM_PORT31_U16 = (U16)((create << 8) | p_tcb->task_id);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*--------------------------- dbg_task_switch -------------------------------*/
|
||||
|
||||
#ifdef DBG_MSG
|
||||
void dbg_task_switch (U32 task_id) {
|
||||
while (ITM_PORT31_U32 == 0U);
|
||||
ITM_PORT31_U8 = (U8)task_id;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,698 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RTX_CM_LIB.H
|
||||
* Purpose: RTX Kernel System Configuration
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
#include "mbed_error.h"
|
||||
|
||||
#if defined (__CC_ARM)
|
||||
#include <rt_misc.h>
|
||||
#pragma O3
|
||||
#define __USED __attribute__((used))
|
||||
#elif defined (__GNUC__)
|
||||
#pragma GCC optimize ("O3")
|
||||
#define __USED __attribute__((used))
|
||||
#elif defined (__ICCARM__)
|
||||
#define __USED __root
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Definitions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#define _declare_box(pool,size,cnt) uint32_t pool[(((size)+3)/4)*(cnt) + 3]
|
||||
#define _declare_box8(pool,size,cnt) uint64_t pool[(((size)+7)/8)*(cnt) + 2]
|
||||
|
||||
#define OS_TCB_SIZE 64
|
||||
#define OS_TMR_SIZE 8
|
||||
|
||||
typedef void *OS_ID;
|
||||
typedef uint32_t OS_TID;
|
||||
typedef uint32_t OS_MUT[4];
|
||||
typedef uint32_t OS_RESULT;
|
||||
|
||||
#if defined (__CC_ARM) && !defined (__MICROLIB)
|
||||
|
||||
#define runtask_id() rt_tsk_self()
|
||||
#define mutex_init(m) rt_mut_init(m)
|
||||
#define mutex_wait(m) os_mut_wait(m,0xFFFFU)
|
||||
#define mutex_rel(m) os_mut_release(m)
|
||||
|
||||
extern uint8_t os_running;
|
||||
extern OS_TID rt_tsk_self (void);
|
||||
extern void rt_mut_init (OS_ID mutex);
|
||||
extern OS_RESULT rt_mut_release (OS_ID mutex);
|
||||
extern OS_RESULT rt_mut_wait (OS_ID mutex, uint16_t timeout);
|
||||
|
||||
#define os_mut_wait(mutex,timeout) _os_mut_wait((uint32_t)rt_mut_wait,mutex,timeout)
|
||||
#define os_mut_release(mutex) _os_mut_release((uint32_t)rt_mut_release,mutex)
|
||||
|
||||
OS_RESULT _os_mut_release (uint32_t p, OS_ID mutex) __svc_indirect(0);
|
||||
OS_RESULT _os_mut_wait (uint32_t p, OS_ID mutex, uint16_t timeout) __svc_indirect(0);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Variables
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#if (OS_TASKCNT == 0)
|
||||
#error "Invalid number of concurrent running threads!"
|
||||
#endif
|
||||
|
||||
#if (OS_PRIVCNT >= OS_TASKCNT)
|
||||
#error "Too many threads with user-provided stack size!"
|
||||
#endif
|
||||
|
||||
#if (OS_TIMERS != 0)
|
||||
#define OS_TASK_CNT (OS_TASKCNT + 1)
|
||||
#ifndef __MBED_CMSIS_RTOS_CM
|
||||
#define OS_PRIV_CNT (OS_PRIVCNT + 2)
|
||||
#define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE+OS_TIMERSTKSZ))
|
||||
#endif
|
||||
#else
|
||||
#define OS_TASK_CNT OS_TASKCNT
|
||||
#ifndef __MBED_CMSIS_RTOS_CM
|
||||
#define OS_PRIV_CNT (OS_PRIVCNT + 1)
|
||||
#define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef OS_STKINIT
|
||||
#define OS_STKINIT 0
|
||||
#endif
|
||||
|
||||
uint16_t const os_maxtaskrun = OS_TASK_CNT;
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
uint32_t const os_stackinfo = (OS_STKINIT<<28) | (OS_STKCHECK<<24) | (OS_IDLESTKSIZE*4);
|
||||
#else
|
||||
uint32_t const os_stackinfo = (OS_STKINIT<<28) | (OS_STKCHECK<<24) | (OS_PRIV_CNT<<16) | (OS_STKSIZE*4);
|
||||
#endif
|
||||
uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT;
|
||||
uint32_t const os_tickfreq = OS_CLOCK;
|
||||
uint16_t const os_tickus_i = OS_CLOCK/1000000;
|
||||
uint16_t const os_tickus_f = (((uint64_t)(OS_CLOCK-1000000*(OS_CLOCK/1000000)))<<16)/1000000;
|
||||
uint32_t const os_trv = OS_TRV;
|
||||
#if defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)
|
||||
uint8_t const os_flags = 0;
|
||||
#else /* defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED) */
|
||||
uint8_t const os_flags = OS_RUNPRIV;
|
||||
#endif /* defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED) */
|
||||
|
||||
/* Export following defines to uVision debugger. */
|
||||
__USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS;
|
||||
__USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX;
|
||||
__USED uint32_t const os_clockrate = OS_TICK;
|
||||
__USED uint32_t const os_timernum = 0U;
|
||||
|
||||
/* Memory pool for TCB allocation */
|
||||
_declare_box (mp_tcb, OS_TCB_SIZE, OS_TASK_CNT);
|
||||
uint16_t const mp_tcb_size = sizeof(mp_tcb);
|
||||
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
/* Memory pool for os_idle_demon stack allocation. */
|
||||
_declare_box8 (mp_stk, OS_IDLESTKSIZE*4, 1);
|
||||
uint32_t const mp_stk_size = sizeof(mp_stk);
|
||||
#else
|
||||
/* Memory pool for System stack allocation (+os_idle_demon). */
|
||||
_declare_box8 (mp_stk, OS_STKSIZE*4, OS_TASK_CNT-OS_PRIV_CNT+1);
|
||||
uint32_t const mp_stk_size = sizeof(mp_stk);
|
||||
|
||||
/* Memory pool for user specified stack allocation (+main, +timer) */
|
||||
uint64_t os_stack_mem[2+OS_PRIV_CNT+(OS_STACK_SZ/8)];
|
||||
uint32_t const os_stack_sz = sizeof(os_stack_mem);
|
||||
#endif
|
||||
|
||||
#ifndef OS_FIFOSZ
|
||||
#define OS_FIFOSZ 16
|
||||
#endif
|
||||
|
||||
/* Fifo Queue buffer for ISR requests.*/
|
||||
uint32_t os_fifo[OS_FIFOSZ*2+1];
|
||||
uint8_t const os_fifo_size = OS_FIFOSZ;
|
||||
|
||||
/* An array of Active task pointers. */
|
||||
void *os_active_TCB[OS_TASK_CNT];
|
||||
|
||||
/* User Timers Resources */
|
||||
#if (OS_TIMERS != 0)
|
||||
extern void osTimerThread (void const *argument);
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ);
|
||||
#else
|
||||
osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 1, 4*OS_TIMERSTKSZ);
|
||||
#endif
|
||||
osThreadId osThreadId_osTimerThread;
|
||||
osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *);
|
||||
osMessageQId osMessageQId_osTimerMessageQ;
|
||||
#else
|
||||
osThreadDef_t os_thread_def_osTimerThread = { NULL };
|
||||
osThreadId osThreadId_osTimerThread;
|
||||
osMessageQDef(osTimerMessageQ, 0U, void *);
|
||||
osMessageQId osMessageQId_osTimerMessageQ;
|
||||
#endif
|
||||
|
||||
/* Legacy RTX User Timers not used */
|
||||
uint32_t os_tmr = 0U;
|
||||
uint32_t const *m_tmr = NULL;
|
||||
uint16_t const mp_tmr_size = 0U;
|
||||
|
||||
/* singleton mutex */
|
||||
osMutexId singleton_mutex_id;
|
||||
osMutexDef(singleton_mutex);
|
||||
|
||||
#if defined (__CC_ARM) && !defined (__MICROLIB)
|
||||
/* A memory space for arm standard library. */
|
||||
static uint32_t std_libspace[OS_TASK_CNT][96/4];
|
||||
static OS_MUT std_libmutex[OS_MUTEXCNT];
|
||||
static uint32_t nr_mutex;
|
||||
extern void *__libspace_start;
|
||||
#endif
|
||||
|
||||
#if defined (__ICCARM__)
|
||||
static osMutexId std_mutex_id_sys[_MAX_LOCK] = {0};
|
||||
static OS_MUT std_mutex_sys[_MAX_LOCK] = {0};
|
||||
#define _FOPEN_MAX 10
|
||||
static osMutexId std_mutex_id_file[_FOPEN_MAX] = {0};
|
||||
static OS_MUT std_mutex_file[_FOPEN_MAX] = {0};
|
||||
void __iar_system_Mtxinit(__iar_Rmtx *mutex) /* Initialize a system lock */
|
||||
{
|
||||
osMutexDef_t def;
|
||||
uint32_t index;
|
||||
for (index = 0; index < _MAX_LOCK; index++) {
|
||||
if (0 == std_mutex_id_sys[index]) {
|
||||
def.mutex = &std_mutex_sys[index];
|
||||
std_mutex_id_sys[index] = osMutexCreate(&def);
|
||||
*mutex = (__iar_Rmtx*)&std_mutex_id_sys[index];
|
||||
return;
|
||||
}
|
||||
}
|
||||
// This should never happen
|
||||
error("Not enough mutexes\n");
|
||||
}
|
||||
|
||||
void __iar_system_Mtxdst(__iar_Rmtx *mutex)/*Destroy a system lock */
|
||||
{
|
||||
osMutexDelete(*(osMutexId*)*mutex);
|
||||
*mutex = 0;
|
||||
}
|
||||
|
||||
void __iar_system_Mtxlock(__iar_Rmtx *mutex) /* Lock a system lock */
|
||||
{
|
||||
osMutexWait(*(osMutexId*)*mutex, osWaitForever);
|
||||
}
|
||||
|
||||
void __iar_system_Mtxunlock(__iar_Rmtx *mutex) /* Unlock a system lock */
|
||||
{
|
||||
osMutexRelease(*(osMutexId*)*mutex);
|
||||
}
|
||||
|
||||
void __iar_file_Mtxinit(__iar_Rmtx *mutex)/*Initialize a file lock */
|
||||
{
|
||||
osMutexDef_t def;
|
||||
uint32_t index;
|
||||
for (index = 0; index < _FOPEN_MAX; index++) {
|
||||
if (0 == std_mutex_id_file[index]) {
|
||||
def.mutex = &std_mutex_file[index];
|
||||
std_mutex_id_file[index] = osMutexCreate(&def);
|
||||
*mutex = (__iar_Rmtx*)&std_mutex_id_file[index];
|
||||
return;
|
||||
}
|
||||
}
|
||||
// The variable _FOPEN_MAX needs to be increased
|
||||
error("Not enough mutexes\n");
|
||||
}
|
||||
|
||||
void __iar_file_Mtxdst(__iar_Rmtx *mutex) /* Destroy a file lock */
|
||||
{
|
||||
osMutexDelete(*(osMutexId*)*mutex);
|
||||
*mutex = 0;
|
||||
}
|
||||
|
||||
void __iar_file_Mtxlock(__iar_Rmtx *mutex) /* Lock a file lock */
|
||||
{
|
||||
osMutexWait(*(osMutexId*)*mutex, osWaitForever);
|
||||
}
|
||||
|
||||
void __iar_file_Mtxunlock(__iar_Rmtx *mutex) /* Unlock a file lock */
|
||||
{
|
||||
osMutexRelease(*(osMutexId*)*mutex);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* RTX Optimizations (empty functions)
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#if OS_ROBIN == 0
|
||||
void rt_init_robin (void) {;}
|
||||
void rt_chk_robin (void) {;}
|
||||
#endif
|
||||
|
||||
#if OS_STKCHECK == 0
|
||||
void rt_stk_check (void) {;}
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Standard Library multithreading interface
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#if defined (__CC_ARM) && !defined (__MICROLIB)
|
||||
|
||||
/*--------------------------- __user_perthread_libspace ---------------------*/
|
||||
|
||||
void *__user_perthread_libspace (void) {
|
||||
/* Provide a separate libspace for each task. */
|
||||
uint32_t idx;
|
||||
|
||||
idx = (os_running != 0U) ? runtask_id () : 0U;
|
||||
if (idx == 0U) {
|
||||
/* RTX not running yet. */
|
||||
return (&__libspace_start);
|
||||
}
|
||||
return ((void *)&std_libspace[idx-1]);
|
||||
}
|
||||
|
||||
/*--------------------------- _mutex_initialize -----------------------------*/
|
||||
|
||||
int _mutex_initialize (OS_ID *mutex) {
|
||||
/* Allocate and initialize a system mutex. */
|
||||
|
||||
if (nr_mutex >= OS_MUTEXCNT) {
|
||||
/* If you are here, you need to increase the number OS_MUTEXCNT. */
|
||||
error("Not enough stdlib mutexes\n");
|
||||
}
|
||||
*mutex = &std_libmutex[nr_mutex++];
|
||||
mutex_init (*mutex);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _mutex_acquire --------------------------------*/
|
||||
|
||||
__attribute__((used)) void _mutex_acquire (OS_ID *mutex) {
|
||||
/* Acquire a system mutex, lock stdlib resources. */
|
||||
if (os_running) {
|
||||
/* RTX running, acquire a mutex. */
|
||||
mutex_wait (*mutex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _mutex_release --------------------------------*/
|
||||
|
||||
__attribute__((used)) void _mutex_release (OS_ID *mutex) {
|
||||
/* Release a system mutex, unlock stdlib resources. */
|
||||
if (os_running) {
|
||||
/* RTX running, release a mutex. */
|
||||
mutex_rel (*mutex);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* RTX Startup
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Main Thread definition */
|
||||
extern void pre_main (void);
|
||||
|
||||
#if defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832) || defined (TARGET_STM32F334R8) ||\
|
||||
defined(TARGET_STM32F070RB) || defined(TARGET_STM32F072RB) || \
|
||||
defined(TARGET_STM32F302R8) || defined(TARGET_STM32F303K8) || defined (TARGET_STM32F334C8) ||\
|
||||
defined(TARGET_STM32F103RB)
|
||||
static uint32_t thread_stack_main[DEFAULT_STACK_SIZE / sizeof(uint32_t)];
|
||||
#elif defined(TARGET_XDOT_L151CC)
|
||||
static uint32_t thread_stack_main[DEFAULT_STACK_SIZE * 6 / sizeof(uint32_t)];
|
||||
#else
|
||||
static uint32_t thread_stack_main[DEFAULT_STACK_SIZE * 2 / sizeof(uint32_t)];
|
||||
#endif
|
||||
osThreadDef_t os_thread_def_main = {(os_pthread)pre_main, osPriorityNormal, 1U, sizeof(thread_stack_main), thread_stack_main};
|
||||
|
||||
/*
|
||||
* IAR Default Memory layout notes:
|
||||
* -Heap defined by "HEAP" region in .icf file
|
||||
* -Interrupt stack defined by "CSTACK" region in .icf file
|
||||
* -Value INITIAL_SP is ignored
|
||||
*
|
||||
* IAR Custom Memory layout notes:
|
||||
* -There is no custom layout available for IAR - everything must be defined in
|
||||
* the .icf file and use the default layout
|
||||
*
|
||||
*
|
||||
* GCC Default Memory layout notes:
|
||||
* -Block of memory from symbol __end__ to define INITIAL_SP used to setup interrupt
|
||||
* stack and heap in the function set_stack_heap()
|
||||
* -ISR_STACK_SIZE can be overridden to be larger or smaller
|
||||
*
|
||||
* GCC Custom Memory layout notes:
|
||||
* -Heap can be explicitly placed by defining both HEAP_START and HEAP_SIZE
|
||||
* -Interrupt stack can be explicitly placed by defining both ISR_STACK_START and ISR_STACK_SIZE
|
||||
*
|
||||
*
|
||||
* ARM Memory layout
|
||||
* -Block of memory from end of region "RW_IRAM1" to define INITIAL_SP used to setup interrupt
|
||||
* stack and heap in the function set_stack_heap()
|
||||
* -ISR_STACK_SIZE can be overridden to be larger or smaller
|
||||
*
|
||||
* ARM Custom Memory layout notes:
|
||||
* -Heap can be explicitly placed by defining both HEAP_START and HEAP_SIZE
|
||||
* -Interrupt stack can be explicitly placed by defining both ISR_STACK_START and ISR_STACK_SIZE
|
||||
*
|
||||
*/
|
||||
|
||||
extern unsigned char *mbed_heap_start;
|
||||
extern uint32_t mbed_heap_size;
|
||||
|
||||
unsigned char *mbed_stack_isr_start = 0;
|
||||
uint32_t mbed_stack_isr_size = 0;
|
||||
|
||||
/*
|
||||
* Sanity check values
|
||||
*/
|
||||
#if defined(__ICCARM__) && \
|
||||
(defined(HEAP_START) || defined(HEAP_SIZE) || \
|
||||
defined(ISR_STACK_START) && defined(ISR_STACK_SIZE))
|
||||
#error "No custom layout allowed for IAR. Use .icf file instead"
|
||||
#endif
|
||||
#if defined(HEAP_START) && !defined(HEAP_SIZE)
|
||||
#error "HEAP_SIZE must be defined if HEAP_START is defined"
|
||||
#endif
|
||||
#if defined(ISR_STACK_START) && !defined(ISR_STACK_SIZE)
|
||||
#error "ISR_STACK_SIZE must be defined if ISR_STACK_START is defined"
|
||||
#endif
|
||||
#if defined(HEAP_SIZE) && !defined(HEAP_START)
|
||||
#error "HEAP_START must be defined if HEAP_SIZE is defined"
|
||||
#endif
|
||||
|
||||
/* Interrupt stack and heap always defined for IAR
|
||||
* Main thread defined here
|
||||
*/
|
||||
#if defined(__ICCARM__)
|
||||
#pragma section="CSTACK"
|
||||
#pragma section="HEAP"
|
||||
#define HEAP_START ((unsigned char*)__section_begin("HEAP"))
|
||||
#define HEAP_SIZE ((uint32_t)__section_size("HEAP"))
|
||||
#define ISR_STACK_START ((unsigned char*)__section_begin("CSTACK"))
|
||||
#define ISR_STACK_SIZE ((uint32_t)__section_size("CSTACK"))
|
||||
#endif
|
||||
|
||||
#if !defined(INITIAL_SP) && !defined(HEAP_START)
|
||||
#error "no target defined"
|
||||
#endif
|
||||
|
||||
/* Define heap region if it has not been defined already */
|
||||
#if !defined(HEAP_START)
|
||||
#if defined(__ICCARM__)
|
||||
#error "Heap should already be defined for IAR"
|
||||
#elif defined(__CC_ARM)
|
||||
extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[];
|
||||
#define HEAP_START ((unsigned char*)Image$$RW_IRAM1$$ZI$$Limit)
|
||||
#define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START))
|
||||
#elif defined(__GNUC__)
|
||||
extern uint32_t __end__[];
|
||||
#define HEAP_START ((unsigned char*)__end__)
|
||||
#define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Define stack sizes if they haven't been set already */
|
||||
#if !defined(ISR_STACK_SIZE)
|
||||
#define ISR_STACK_SIZE ((uint32_t)OS_MAINSTKSIZE * 4)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* set_stack_heap purpose is to set the following variables:
|
||||
* -mbed_heap_start
|
||||
* -mbed_heap_size
|
||||
* -mbed_stack_isr_start
|
||||
* -mbed_stack_isr_size
|
||||
*
|
||||
* Along with setting up os_thread_def_main
|
||||
*/
|
||||
void set_stack_heap(void) {
|
||||
|
||||
unsigned char *free_start = HEAP_START;
|
||||
uint32_t free_size = HEAP_SIZE;
|
||||
|
||||
#ifdef ISR_STACK_START
|
||||
/* Interrupt stack explicitly specified */
|
||||
mbed_stack_isr_size = ISR_STACK_SIZE;
|
||||
mbed_stack_isr_start = ISR_STACK_START;
|
||||
#else
|
||||
/* Interrupt stack - reserve space at the end of the free block */
|
||||
mbed_stack_isr_size = ISR_STACK_SIZE < free_size ? ISR_STACK_SIZE : free_size;
|
||||
mbed_stack_isr_start = free_start + free_size - mbed_stack_isr_size;
|
||||
free_size -= mbed_stack_isr_size;
|
||||
#endif
|
||||
|
||||
/* Heap - everything else */
|
||||
mbed_heap_size = free_size;
|
||||
mbed_heap_start = free_start;
|
||||
}
|
||||
|
||||
#if defined (__CC_ARM)
|
||||
|
||||
#ifdef __MICROLIB
|
||||
|
||||
int main(void);
|
||||
void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF")));
|
||||
void $Super$$__cpp_initialize__aeabi_(void);
|
||||
|
||||
void _main_init (void) {
|
||||
osKernelInitialize();
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
set_stack_heap();
|
||||
#endif
|
||||
osThreadCreate(&os_thread_def_main, NULL);
|
||||
osKernelStart();
|
||||
for (;;);
|
||||
}
|
||||
|
||||
void $Sub$$__cpp_initialize__aeabi_(void)
|
||||
{
|
||||
// this should invoke C++ initializers prior _main_init, we keep this empty and
|
||||
// invoke them after _main_init (=starts RTX kernel)
|
||||
}
|
||||
|
||||
void pre_main()
|
||||
{
|
||||
singleton_mutex_id = osMutexCreate(osMutex(singleton_mutex));
|
||||
$Super$$__cpp_initialize__aeabi_();
|
||||
main();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main(void);
|
||||
|
||||
void pre_main (void)
|
||||
{
|
||||
singleton_mutex_id = osMutexCreate(osMutex(singleton_mutex));
|
||||
__rt_lib_init((unsigned)mbed_heap_start, (unsigned)(mbed_heap_start + mbed_heap_size));
|
||||
main();
|
||||
}
|
||||
|
||||
/* The single memory model is checking for stack collision at run time, verifing
|
||||
that the heap pointer is underneath the stack pointer.
|
||||
|
||||
With the RTOS there is not only one stack above the heap, there are multiple
|
||||
stacks and some of them are underneath the heap pointer.
|
||||
*/
|
||||
#pragma import(__use_two_region_memory)
|
||||
|
||||
__asm void __rt_entry (void) {
|
||||
|
||||
IMPORT __user_setup_stackheap
|
||||
IMPORT _platform_post_stackheap_init
|
||||
IMPORT os_thread_def_main
|
||||
IMPORT osKernelInitialize
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
IMPORT set_stack_heap
|
||||
#endif
|
||||
IMPORT osKernelStart
|
||||
IMPORT osThreadCreate
|
||||
|
||||
/* __user_setup_stackheap returns:
|
||||
* - Heap base in r0 (if the program uses the heap).
|
||||
* - Stack base in sp.
|
||||
* - Heap limit in r2 (if the program uses the heap and uses two-region memory).
|
||||
*
|
||||
* More info can be found in:
|
||||
* ARM Compiler ARM C and C++ Libraries and Floating-Point Support User Guide
|
||||
*/
|
||||
BL __user_setup_stackheap
|
||||
/* Ignore return value of __user_setup_stackheap since
|
||||
* this will be setup by set_stack_heap
|
||||
*/
|
||||
BL _platform_post_stackheap_init
|
||||
BL osKernelInitialize
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
BL set_stack_heap
|
||||
#endif
|
||||
LDR R0,=os_thread_def_main
|
||||
MOVS R1,#0
|
||||
BL osThreadCreate
|
||||
BL osKernelStart
|
||||
/* osKernelStart should not return */
|
||||
B .
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#elif defined (__GNUC__)
|
||||
|
||||
osMutexDef(malloc_mutex);
|
||||
static osMutexId malloc_mutex_id;
|
||||
osMutexDef(env_mutex);
|
||||
static osMutexId env_mutex_id;
|
||||
|
||||
extern int atexit(void (*func)(void));
|
||||
extern void __libc_fini_array(void);
|
||||
extern void __libc_init_array (void);
|
||||
extern int main(int argc, char **argv);
|
||||
|
||||
void pre_main(void) {
|
||||
singleton_mutex_id = osMutexCreate(osMutex(singleton_mutex));
|
||||
malloc_mutex_id = osMutexCreate(osMutex(malloc_mutex));
|
||||
env_mutex_id = osMutexCreate(osMutex(env_mutex));
|
||||
__libc_init_array();
|
||||
main(0, NULL);
|
||||
}
|
||||
|
||||
__attribute__((naked)) void software_init_hook_rtos (void) {
|
||||
__asm (
|
||||
"bl osKernelInitialize\n"
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
"bl set_stack_heap\n"
|
||||
#endif
|
||||
"ldr r0,=os_thread_def_main\n"
|
||||
"movs r1,#0\n"
|
||||
"bl osThreadCreate\n"
|
||||
"bl osKernelStart\n"
|
||||
/* osKernelStart should not return */
|
||||
"B .\n"
|
||||
);
|
||||
}
|
||||
|
||||
// Opaque declaration of _reent structure
|
||||
struct _reent;
|
||||
|
||||
void __rtos_malloc_lock( struct _reent *_r )
|
||||
{
|
||||
osMutexWait(malloc_mutex_id, osWaitForever);
|
||||
}
|
||||
|
||||
void __rtos_malloc_unlock( struct _reent *_r )
|
||||
{
|
||||
osMutexRelease(malloc_mutex_id);
|
||||
}
|
||||
|
||||
void __rtos_env_lock( struct _reent *_r )
|
||||
{
|
||||
osMutexWait(env_mutex_id, osWaitForever);
|
||||
}
|
||||
|
||||
void __rtos_env_unlock( struct _reent *_r )
|
||||
{
|
||||
osMutexRelease(env_mutex_id);
|
||||
}
|
||||
|
||||
#elif defined (__ICCARM__)
|
||||
|
||||
extern void* __vector_table;
|
||||
extern int __low_level_init(void);
|
||||
extern void __iar_data_init3(void);
|
||||
extern __weak void __iar_init_core( void );
|
||||
extern __weak void __iar_init_vfp( void );
|
||||
extern void __iar_dynamic_initialization(void);
|
||||
extern void mbed_sdk_init(void);
|
||||
extern void mbed_main(void);
|
||||
extern int main(void);
|
||||
extern void exit(int arg);
|
||||
|
||||
static uint8_t low_level_init_needed;
|
||||
|
||||
void pre_main(void) {
|
||||
singleton_mutex_id = osMutexCreate(osMutex(singleton_mutex));
|
||||
if (low_level_init_needed) {
|
||||
__iar_dynamic_initialization();
|
||||
}
|
||||
mbed_main();
|
||||
main();
|
||||
}
|
||||
|
||||
#pragma required=__vector_table
|
||||
void __iar_program_start( void )
|
||||
{
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
__iar_init_core();
|
||||
__iar_init_vfp();
|
||||
|
||||
uint8_t low_level_init_needed_local;
|
||||
|
||||
low_level_init_needed_local = __low_level_init();
|
||||
if (low_level_init_needed_local) {
|
||||
__iar_data_init3();
|
||||
mbed_sdk_init();
|
||||
}
|
||||
/* Store in a global variable after RAM has been initialized */
|
||||
low_level_init_needed = low_level_init_needed_local;
|
||||
#endif
|
||||
osKernelInitialize();
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
set_stack_heap();
|
||||
#endif
|
||||
osThreadCreate(&os_thread_def_main, NULL);
|
||||
osKernelStart();
|
||||
/* osKernelStart should not return */
|
||||
while (1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/** @}*/
|
|
@ -1,281 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RTX_Conf_CM.C
|
||||
* Purpose: Configuration of CMSIS RTX Kernel for Cortex-M
|
||||
* Rev.: V4.70.1
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "cmsis_os.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* RTX User configuration part BEGIN
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
// Include per-target RTX config file
|
||||
#include "mbed_rtx.h"
|
||||
|
||||
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
|
||||
//
|
||||
// <h>Thread Configuration
|
||||
// =======================
|
||||
//
|
||||
// <o>Number of concurrent running user threads <1-250>
|
||||
// <i> Defines max. number of user threads that will run at the same time.
|
||||
// <i> Default: 6
|
||||
#ifndef OS_TASKCNT
|
||||
#error "no target defined"
|
||||
#endif
|
||||
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
// <o>Idle stack size [bytes] <64-4096:8><#/4>
|
||||
// <i> Defines default stack size for the Idle thread.
|
||||
#ifndef OS_IDLESTKSIZE
|
||||
#define OS_IDLESTKSIZE 128
|
||||
#endif
|
||||
#else // __MBED_CMSIS_RTOS_CM
|
||||
// <o>Default Thread stack size [bytes] <64-4096:8><#/4>
|
||||
// <i> Defines default stack size for threads with osThreadDef stacksz = 0
|
||||
// <i> Default: 200
|
||||
#ifndef OS_STKSIZE
|
||||
#define OS_STKSIZE 200
|
||||
#endif
|
||||
#endif // __MBED_CMSIS_RTOS_CM
|
||||
|
||||
// <o>Main Thread stack size [bytes] <64-32768:8><#/4>
|
||||
#ifndef OS_MAINSTKSIZE
|
||||
#error "no target defined"
|
||||
#endif
|
||||
|
||||
#ifndef __MBED_CMSIS_RTOS_CM
|
||||
// <o>Number of threads with user-provided stack size <0-250>
|
||||
// <i> Defines the number of threads with user-provided stack size.
|
||||
// <i> Default: 0
|
||||
#ifndef OS_PRIVCNT
|
||||
#define OS_PRIVCNT 0
|
||||
#endif
|
||||
|
||||
// <o>Total stack size [bytes] for threads with user-provided stack size <0-1048576:8><#/4>
|
||||
// <i> Defines the combined stack size for threads with user-provided stack size.
|
||||
// <i> Default: 0
|
||||
#ifndef OS_PRIVSTKSIZE
|
||||
#define OS_PRIVSTKSIZE 0 // this stack size value is in words
|
||||
#endif
|
||||
#endif // __MBED_CMSIS_RTOS_CM
|
||||
|
||||
// <q>Stack overflow checking
|
||||
// <i> Enable stack overflow checks at thread switch.
|
||||
// <i> Enabling this option increases slightly the execution time of a thread switch.
|
||||
#ifndef OS_STKCHECK
|
||||
#define OS_STKCHECK 1
|
||||
#endif
|
||||
|
||||
// <q>Stack usage watermark
|
||||
// <i> Initialize thread stack with watermark pattern for analyzing stack usage (current/maximum) in System and Thread Viewer.
|
||||
// <i> Enabling this option increases significantly the execution time of osThreadCreate.
|
||||
#ifndef OS_STKINIT
|
||||
#if (defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED)
|
||||
#define OS_STKINIT 1
|
||||
#else
|
||||
#define OS_STKINIT 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// <o>Processor mode for thread execution
|
||||
// <0=> Unprivileged mode
|
||||
// <1=> Privileged mode
|
||||
// <i> Default: Privileged mode
|
||||
#ifndef OS_RUNPRIV
|
||||
#define OS_RUNPRIV 1
|
||||
#endif
|
||||
|
||||
// </h>
|
||||
|
||||
// <h>RTX Kernel Timer Tick Configuration
|
||||
// ======================================
|
||||
// <q> Use Cortex-M SysTick timer as RTX Kernel Timer
|
||||
// <i> Cortex-M processors provide in most cases a SysTick timer that can be used as
|
||||
// <i> as time-base for RTX.
|
||||
#ifndef OS_SYSTICK
|
||||
#define OS_SYSTICK 1
|
||||
#endif
|
||||
//
|
||||
// <o>RTOS Kernel Timer input clock frequency [Hz] <1-1000000000>
|
||||
// <i> Defines the input frequency of the RTOS Kernel Timer.
|
||||
// <i> When the Cortex-M SysTick timer is used, the input clock
|
||||
// <i> is on most systems identical with the core clock.
|
||||
#ifndef OS_CLOCK
|
||||
#error "no target defined"
|
||||
#endif
|
||||
|
||||
// <o>RTX Timer tick interval value [us] <1-1000000>
|
||||
// <i> The RTX Timer tick interval value is used to calculate timeout values.
|
||||
// <i> When the Cortex-M SysTick timer is enabled, the value also configures the SysTick timer.
|
||||
// <i> Default: 1000 (1ms)
|
||||
#ifndef OS_TICK
|
||||
#define OS_TICK 1000
|
||||
#endif
|
||||
|
||||
// </h>
|
||||
|
||||
// <h>System Configuration
|
||||
// =======================
|
||||
//
|
||||
// <e>Round-Robin Thread switching
|
||||
// ===============================
|
||||
//
|
||||
// <i> Enables Round-Robin Thread switching.
|
||||
#ifndef OS_ROBIN
|
||||
#define OS_ROBIN 1
|
||||
#endif
|
||||
|
||||
// <o>Round-Robin Timeout [ticks] <1-1000>
|
||||
// <i> Defines how long a thread will execute before a thread switch.
|
||||
// <i> Default: 5
|
||||
#ifndef OS_ROBINTOUT
|
||||
#define OS_ROBINTOUT 5
|
||||
#endif
|
||||
|
||||
// </e>
|
||||
|
||||
// <e>User Timers
|
||||
// ==============
|
||||
// <i> Enables user Timers
|
||||
#ifndef OS_TIMERS
|
||||
#define OS_TIMERS 1
|
||||
#endif
|
||||
|
||||
// <o>Timer Thread Priority
|
||||
// <1=> Low
|
||||
// <2=> Below Normal <3=> Normal <4=> Above Normal
|
||||
// <5=> High
|
||||
// <6=> Realtime (highest)
|
||||
// <i> Defines priority for Timer Thread
|
||||
// <i> Default: High
|
||||
#ifndef OS_TIMERPRIO
|
||||
#define OS_TIMERPRIO 5
|
||||
#endif
|
||||
|
||||
// <o>Timer Thread stack size [bytes] <64-4096:8><#/4>
|
||||
// <i> Defines stack size for Timer thread.
|
||||
// <i> Default: 200
|
||||
#ifndef OS_TIMERSTKSZ
|
||||
#define OS_TIMERSTKSZ 200
|
||||
#endif
|
||||
|
||||
// <o>Timer Callback Queue size <1-32>
|
||||
// <i> Number of concurrent active timer callback functions.
|
||||
// <i> Default: 4
|
||||
#ifndef OS_TIMERCBQS
|
||||
#define OS_TIMERCBQS 4
|
||||
#endif
|
||||
|
||||
// </e>
|
||||
|
||||
// <o>ISR FIFO Queue size<4=> 4 entries <8=> 8 entries
|
||||
// <12=> 12 entries <16=> 16 entries
|
||||
// <24=> 24 entries <32=> 32 entries
|
||||
// <48=> 48 entries <64=> 64 entries
|
||||
// <96=> 96 entries
|
||||
// <i> ISR functions store requests to this buffer,
|
||||
// <i> when they are called from the interrupt handler.
|
||||
// <i> Default: 16 entries
|
||||
#ifndef OS_FIFOSZ
|
||||
#define OS_FIFOSZ 16
|
||||
#endif
|
||||
|
||||
// </h>
|
||||
|
||||
//------------- <<< end of configuration section >>> -----------------------
|
||||
|
||||
// Standard library system mutexes
|
||||
// ===============================
|
||||
// Define max. number system mutexes that are used to protect
|
||||
// the arm standard runtime library. For microlib they are not used.
|
||||
#ifndef OS_MUTEXCNT
|
||||
#define OS_MUTEXCNT 12
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* RTX User configuration part END
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#define OS_TRV ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* OS Idle daemon
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern void rtos_idle_loop(void);
|
||||
|
||||
void os_idle_demon (void) {
|
||||
/* The idle demon is a system thread, running when no other thread is */
|
||||
/* ready to run. */
|
||||
rtos_idle_loop();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* RTX Errors
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern osThreadId svcThreadGetId (void);
|
||||
|
||||
void os_error (uint32_t err_code) {
|
||||
/* This function is called when a runtime error is detected. Parameter */
|
||||
/* 'err_code' holds the runtime error code (defined in RTX_Config.h). */
|
||||
osThreadId err_task = svcThreadGetId();
|
||||
error("RTX error code: 0x%08X, task ID: 0x%08X\n", err_code, err_task);
|
||||
}
|
||||
|
||||
void sysThreadError(osStatus status) {
|
||||
if (status != osOK) {
|
||||
osThreadId err_task = svcThreadGetId();
|
||||
error("CMSIS-RTOS error status: 0x%08X, task ID: 0x%08X\n", status, err_task);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* RTX Hooks
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern void thread_terminate_hook(osThreadId id);
|
||||
|
||||
void sysThreadTerminate(osThreadId id) {
|
||||
thread_terminate_hook(id);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* RTX Configuration Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "RTX_CM_lib.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,84 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RTX_CONFIG.H
|
||||
* Purpose: Exported functions of RTX_Config.c
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* Error Codes */
|
||||
#define OS_ERR_STK_OVF 1U
|
||||
#define OS_ERR_FIFO_OVF 2U
|
||||
#define OS_ERR_MBX_OVF 3U
|
||||
#define OS_ERR_TIMER_OVF 4U
|
||||
|
||||
/* Definitions */
|
||||
#define BOX_ALIGN_8 0x80000000U
|
||||
#define _declare_box(pool,size,cnt) U32 pool[(((size)+3)/4)*(cnt) + 3]
|
||||
#define _declare_box8(pool,size,cnt) U64 pool[(((size)+7)/8)*(cnt) + 2]
|
||||
#define _init_box8(pool,size,bsize) _init_box (pool,size,(bsize) | BOX_ALIGN_8)
|
||||
|
||||
/* Variables */
|
||||
extern U32 mp_tcb[];
|
||||
extern U64 mp_stk[];
|
||||
extern U32 os_fifo[];
|
||||
extern void *os_active_TCB[];
|
||||
|
||||
/* Constants */
|
||||
extern U16 const os_maxtaskrun;
|
||||
extern U32 const os_trv;
|
||||
extern U8 const os_flags;
|
||||
extern U32 const os_stackinfo;
|
||||
extern U32 const os_rrobin;
|
||||
extern U32 const os_clockrate;
|
||||
extern U32 const os_timernum;
|
||||
extern U16 const mp_tcb_size;
|
||||
extern U32 const mp_stk_size;
|
||||
extern U32 const *m_tmr;
|
||||
extern U16 const mp_tmr_size;
|
||||
extern U8 const os_fifo_size;
|
||||
|
||||
/* Functions */
|
||||
extern void os_idle_demon (void);
|
||||
extern S32 os_tick_init (void);
|
||||
extern U32 os_tick_val (void);
|
||||
extern U32 os_tick_ovf (void);
|
||||
extern void os_tick_irqack (void);
|
||||
extern void os_tmr_call (U16 info);
|
||||
extern void os_error (U32 err_code);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/** @}*/
|
|
@ -1,301 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM0.C
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M0
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_MemBox.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
__asm void rt_set_PSP (U32 stack) {
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
__asm U32 rt_get_PSP (void) {
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
__asm void os_set_env (void) {
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
MOV R0,SP ; PSP = MSP
|
||||
MSR PSP,R0
|
||||
LDR R0,=__cpp(&os_flags)
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
BNE PrivilegedE
|
||||
MOVS R0,#0x03 ; Unprivileged Thread mode, use PSP
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
PrivilegedE
|
||||
MOVS R0,#0x02 ; Privileged Thread mode, use PSP
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
__asm void *_alloc_box (void *box_mem) {
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
LDR R3,=__cpp(rt_alloc_box)
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedA
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedA
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedA
|
||||
BX R12
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
__asm U32 _free_box (void *box_mem, void *box) {
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
LDR R3,=__cpp(rt_free_box)
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedF
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedF
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedF
|
||||
BX R12
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
__asm void SVC_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
IMPORT SVC_Count
|
||||
IMPORT SVC_Table
|
||||
IMPORT rt_stk_check
|
||||
|
||||
MRS R0,PSP ; Read PSP
|
||||
LDR R1,[R0,#24] ; Read Saved PC from Stack
|
||||
SUBS R1,R1,#2 ; Point to SVC Instruction
|
||||
LDRB R1,[R1] ; Load SVC Number
|
||||
CMP R1,#0
|
||||
BNE SVC_User ; User SVC Number > 0
|
||||
|
||||
MOV LR,R4
|
||||
LDMIA R0,{R0-R3,R4} ; Read R0-R3,R12 from stack
|
||||
MOV R12,R4
|
||||
MOV R4,LR
|
||||
BLX R12 ; Call SVC Function
|
||||
|
||||
MRS R3,PSP ; Read PSP
|
||||
STMIA R3!,{R0-R2} ; Store return values
|
||||
|
||||
LDR R3,=__cpp(&os_tsk)
|
||||
LDMIA R3!,{R1,R2} ; os_tsk.run, os_tsk.new
|
||||
CMP R1,R2
|
||||
BEQ SVC_Exit ; no task switch
|
||||
|
||||
SUBS R3,#8
|
||||
CMP R1,#0 ; Runtask deleted?
|
||||
BEQ SVC_Next
|
||||
|
||||
MRS R0,PSP ; Read PSP
|
||||
SUBS R0,R0,#32 ; Adjust Start Address
|
||||
STR R0,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
|
||||
STMIA R0!,{R4-R7} ; Save old context (R4-R7)
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} ; Save old context (R8-R11)
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check ; Check for Stack overflow
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_Next
|
||||
STR R2,[R3] ; os_tsk.run = os_tsk.new
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
|
||||
ADDS R0,R0,#16 ; Adjust Start Address
|
||||
LDMIA R0!,{R4-R7} ; Restore new Context (R8-R11)
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 ; Write PSP
|
||||
SUBS R0,R0,#32 ; Adjust Start Address
|
||||
LDMIA R0!,{R4-R7} ; Restore new Context (R4-R7)
|
||||
|
||||
SVC_Exit
|
||||
MOVS R0,#:NOT:0xFFFFFFFD ; Set EXC_RETURN value
|
||||
MVNS R0,R0
|
||||
BX R0 ; RETI to Thread Mode, use PSP
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User
|
||||
PUSH {R4,LR} ; Save Registers
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done ; Overflow
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LSLS R1,R1,#2
|
||||
LDR R4,[R4,R1] ; Load SVC Function Address
|
||||
MOV LR,R4
|
||||
|
||||
LDMIA R0,{R0-R3,R4} ; Read R0-R3,R12 from stack
|
||||
MOV R12,R4
|
||||
BLX LR ; Call SVC Function
|
||||
|
||||
MRS R4,PSP ; Read PSP
|
||||
STMIA R4!,{R0-R3} ; Function return values
|
||||
SVC_Done
|
||||
POP {R4,PC} ; RETI
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
__asm void PendSV_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
BL __cpp(rt_pop_req)
|
||||
|
||||
Sys_Switch
|
||||
LDR R3,=__cpp(&os_tsk)
|
||||
LDMIA R3!,{R1,R2} ; os_tsk.run, os_tsk.new
|
||||
CMP R1,R2
|
||||
BEQ Sys_Exit ; no task switch
|
||||
|
||||
SUBS R3,#8
|
||||
|
||||
MRS R0,PSP ; Read PSP
|
||||
SUBS R0,R0,#32 ; Adjust Start Address
|
||||
STR R0,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
|
||||
STMIA R0!,{R4-R7} ; Save old context (R4-R7)
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} ; Save old context (R8-R11)
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check ; Check for Stack overflow
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] ; os_tsk.run = os_tsk.new
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
|
||||
ADDS R0,R0,#16 ; Adjust Start Address
|
||||
LDMIA R0!,{R4-R7} ; Restore new Context (R8-R11)
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 ; Write PSP
|
||||
SUBS R0,R0,#32 ; Adjust Start Address
|
||||
LDMIA R0!,{R4-R7} ; Restore new Context (R4-R7)
|
||||
|
||||
Sys_Exit
|
||||
MOVS R0,#:NOT:0xFFFFFFFD ; Set EXC_RETURN value
|
||||
MVNS R0,R0
|
||||
BX R0 ; RETI to Thread Mode, use PSP
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
__asm void SysTick_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
BL __cpp(rt_systick)
|
||||
B Sys_Switch
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
__asm void OS_Tick_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
BL __cpp(os_tick_irqack)
|
||||
BL __cpp(rt_systick)
|
||||
B Sys_Switch
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
AREA SVC_TABLE, CODE, READONLY
|
||||
|
||||
EXPORT SVC_Count
|
||||
|
||||
SVC_Cnt EQU (SVC_End-SVC_Table)/4
|
||||
SVC_Count DCD SVC_Cnt
|
||||
|
||||
; Import user SVC functions here.
|
||||
; IMPORT __SVC_1
|
||||
|
||||
EXPORT SVC_Table
|
||||
SVC_Table
|
||||
; Insert user SVC functions here. SVC 0 used by RTL Kernel.
|
||||
; DCD __SVC_1 ; user SVC function
|
||||
|
||||
SVC_End
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,370 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM0.S
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M0
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
.file "HAL_CM0.S"
|
||||
.syntax unified
|
||||
|
||||
.equ TCB_TSTACK, 44
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
.thumb
|
||||
|
||||
.section ".text"
|
||||
.align 2
|
||||
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
# void rt_set_PSP (U32 stack);
|
||||
|
||||
.thumb_func
|
||||
.type rt_set_PSP, %function
|
||||
.global rt_set_PSP
|
||||
rt_set_PSP:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size rt_set_PSP, .-rt_set_PSP
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
# U32 rt_get_PSP (void);
|
||||
|
||||
.thumb_func
|
||||
.type rt_get_PSP, %function
|
||||
.global rt_get_PSP
|
||||
rt_get_PSP:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size rt_get_PSP, .-rt_get_PSP
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
# void os_set_env (void);
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
|
||||
.thumb_func
|
||||
.type os_set_env, %function
|
||||
.global os_set_env
|
||||
os_set_env:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MOV R0,SP /* PSP = MSP */
|
||||
MSR PSP,R0
|
||||
LDR R0,=os_flags
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
BNE PrivilegedE
|
||||
MOVS R0,#0x03 /* Unprivileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
PrivilegedE:
|
||||
MOVS R0,#0x02 /* Privileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size os_set_env, .-os_set_env
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
# void *_alloc_box (void *box_mem);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
.thumb_func
|
||||
.type _alloc_box, %function
|
||||
.global _alloc_box
|
||||
_alloc_box:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
LDR R3,=rt_alloc_box
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedA
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedA
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedA:
|
||||
BX R12
|
||||
|
||||
.fnend
|
||||
.size _alloc_box, .-_alloc_box
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
# U32 _free_box (void *box_mem, void *box);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
.thumb_func
|
||||
.type _free_box, %function
|
||||
.global _free_box
|
||||
_free_box:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
LDR R3,=rt_free_box
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedF
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedF
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedF:
|
||||
BX R12
|
||||
|
||||
.fnend
|
||||
.size _free_box, .-_free_box
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
# void SVC_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type SVC_Handler, %function
|
||||
.global SVC_Handler
|
||||
SVC_Handler:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
LDR R1,[R0,#24] /* Read Saved PC from Stack */
|
||||
SUBS R1,R1,#2 /* Point to SVC Instruction */
|
||||
LDRB R1,[R1] /* Load SVC Number */
|
||||
CMP R1,#0
|
||||
BNE SVC_User /* User SVC Number > 0 */
|
||||
|
||||
MOV LR,R4
|
||||
LDMIA R0,{R0-R3,R4} /* Read R0-R3,R12 from stack */
|
||||
MOV R12,R4
|
||||
MOV R4,LR
|
||||
BLX R12 /* Call SVC Function */
|
||||
|
||||
MRS R3,PSP /* Read PSP */
|
||||
STMIA R3!,{R0-R2} /* Store return values */
|
||||
|
||||
LDR R3,=os_tsk
|
||||
LDMIA R3!,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ SVC_Exit /* no task switch */
|
||||
|
||||
SUBS R3,#8
|
||||
CMP R1,#0 /* Runtask deleted? */
|
||||
BEQ SVC_Next
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
STR R0,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
STMIA R0!,{R4-R7} /* Save old context (R4-R7) */
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} /* Save old context (R8-R11) */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_Next:
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
ADDS R0,R0,#16 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R8-R11) */
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 /* Write PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R4-R7) */
|
||||
|
||||
SVC_Exit:
|
||||
MOVS R0,#~0xFFFFFFFD /* Set EXC_RETURN value */
|
||||
MVNS R0,R0
|
||||
BX R0 /* RETI to Thread Mode, use PSP */
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User:
|
||||
PUSH {R4,LR} /* Save Registers */
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done /* Overflow */
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LSLS R1,R1,#2
|
||||
LDR R4,[R4,R1] /* Load SVC Function Address */
|
||||
MOV LR,R4
|
||||
|
||||
LDMIA R0,{R0-R3,R4} /* Read R0-R3,R12 from stack */
|
||||
MOV R12,R4
|
||||
BLX LR /* Call SVC Function */
|
||||
|
||||
MRS R4,PSP /* Read PSP */
|
||||
STMIA R4!,{R0-R3} /* Function return values */
|
||||
SVC_Done:
|
||||
POP {R4,PC} /* RETI */
|
||||
|
||||
.fnend
|
||||
.size SVC_Handler, .-SVC_Handler
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
# void PendSV_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type PendSV_Handler, %function
|
||||
.global PendSV_Handler
|
||||
.global Sys_Switch
|
||||
PendSV_Handler:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
BL rt_pop_req
|
||||
|
||||
Sys_Switch:
|
||||
LDR R3,=os_tsk
|
||||
LDMIA R3!,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ Sys_Exit /* no task switch */
|
||||
|
||||
SUBS R3,#8
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
STR R0,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
STMIA R0!,{R4-R7} /* Save old context (R4-R7) */
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} /* Save old context (R8-R11) */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
ADDS R0,R0,#16 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R8-R11) */
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 /* Write PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R4-R7) */
|
||||
|
||||
Sys_Exit:
|
||||
MOVS R0,#~0xFFFFFFFD /* Set EXC_RETURN value */
|
||||
MVNS R0,R0
|
||||
BX R0 /* RETI to Thread Mode, use PSP */
|
||||
|
||||
.fnend
|
||||
.size PendSV_Handler, .-PendSV_Handler
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
# void SysTick_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type SysTick_Handler, %function
|
||||
.global SysTick_Handler
|
||||
SysTick_Handler:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
.fnend
|
||||
.size SysTick_Handler, .-SysTick_Handler
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
# void OS_Tick_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type OS_Tick_Handler, %function
|
||||
.global OS_Tick_Handler
|
||||
OS_Tick_Handler:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
BL os_tick_irqack
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
.fnend
|
||||
.size OS_Tick_Handler, .-OS_Tick_Handler
|
||||
|
||||
|
||||
.end
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,56 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
.file "SVC_Table.S"
|
||||
|
||||
|
||||
.section ".svc_table"
|
||||
|
||||
.global SVC_Table
|
||||
SVC_Table:
|
||||
/* Insert user SVC functions here. SVC 0 used by RTL Kernel. */
|
||||
# .long __SVC_1 /* user SVC function */
|
||||
SVC_End:
|
||||
|
||||
.global SVC_Count
|
||||
SVC_Count:
|
||||
.long (SVC_End-SVC_Table)/4
|
||||
|
||||
|
||||
.end
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,312 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM0.S
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M0
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
NAME HAL_CM0.S
|
||||
|
||||
#define TCB_TSTACK 44
|
||||
|
||||
EXTERN os_flags
|
||||
EXTERN os_tsk
|
||||
EXTERN rt_alloc_box
|
||||
EXTERN rt_free_box
|
||||
EXTERN rt_stk_check
|
||||
EXTERN rt_pop_req
|
||||
EXTERN rt_systick
|
||||
EXTERN os_tick_irqack
|
||||
EXTERN SVC_Table
|
||||
EXTERN SVC_Count
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
SECTION .text:CODE:NOROOT(2)
|
||||
THUMB
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
; void rt_set_PSP (U32 stack);
|
||||
|
||||
PUBLIC rt_set_PSP
|
||||
rt_set_PSP:
|
||||
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
; U32 rt_get_PSP (void);
|
||||
|
||||
PUBLIC rt_get_PSP
|
||||
rt_get_PSP:
|
||||
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
; void os_set_env (void);
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
|
||||
PUBLIC os_set_env
|
||||
os_set_env:
|
||||
|
||||
MOV R0,SP /* PSP = MSP */
|
||||
MSR PSP,R0
|
||||
LDR R0,=os_flags
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
BNE PrivilegedE
|
||||
MOVS R0,#0x03 /* Unprivileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
PrivilegedE:
|
||||
MOVS R0,#0x02 /* Privileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
; void *_alloc_box (void *box_mem);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
PUBLIC _alloc_box
|
||||
_alloc_box:
|
||||
|
||||
LDR R3,=rt_alloc_box
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedA
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedA
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedA:
|
||||
BX R12
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
; U32 _free_box (void *box_mem, void *box);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
PUBLIC _free_box
|
||||
_free_box:
|
||||
|
||||
LDR R3,=rt_free_box
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedF
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedF
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedF:
|
||||
BX R12
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
; void SVC_Handler (void);
|
||||
|
||||
PUBLIC SVC_Handler
|
||||
SVC_Handler:
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
LDR R1,[R0,#24] /* Read Saved PC from Stack */
|
||||
SUBS R1,R1,#2 /* Point to SVC Instruction */
|
||||
LDRB R1,[R1] /* Load SVC Number */
|
||||
CMP R1,#0
|
||||
BNE SVC_User /* User SVC Number > 0 */
|
||||
|
||||
MOV LR,R4
|
||||
LDMIA R0,{R0-R3,R4} /* Read R0-R3,R12 from stack */
|
||||
MOV R12,R4
|
||||
MOV R4,LR
|
||||
BLX R12 /* Call SVC Function */
|
||||
|
||||
MRS R3,PSP /* Read PSP */
|
||||
STMIA R3!,{R0-R2} /* Store return values */
|
||||
|
||||
LDR R3,=os_tsk
|
||||
LDMIA R3!,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ SVC_Exit /* no task switch */
|
||||
|
||||
SUBS R3,#8
|
||||
CMP R1,#0 /* Runtask deleted? */
|
||||
BEQ SVC_Next
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
STR R0,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
STMIA R0!,{R4-R7} /* Save old context (R4-R7) */
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} /* Save old context (R8-R11) */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_Next:
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
ADDS R0,R0,#16 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R8-R11) */
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 /* Write PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R4-R7) */
|
||||
|
||||
SVC_Exit:
|
||||
MOVS R0,#~0xFFFFFFFD /* Set EXC_RETURN value */
|
||||
MVNS R0,R0
|
||||
BX R0 /* RETI to Thread Mode, use PSP */
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User:
|
||||
PUSH {R4,LR} /* Save Registers */
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done /* Overflow */
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LSLS R1,R1,#2
|
||||
LDR R4,[R4,R1] /* Load SVC Function Address */
|
||||
MOV LR,R4
|
||||
|
||||
LDMIA R0,{R0-R3,R4} /* Read R0-R3,R12 from stack */
|
||||
MOV R12,R4
|
||||
BLX LR /* Call SVC Function */
|
||||
|
||||
MRS R4,PSP /* Read PSP */
|
||||
STMIA R4!,{R0-R3} /* Function return values */
|
||||
SVC_Done:
|
||||
POP {R4,PC} /* RETI */
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
; void PendSV_Handler (void);
|
||||
|
||||
PUBLIC PendSV_Handler
|
||||
PendSV_Handler:
|
||||
|
||||
BL rt_pop_req
|
||||
|
||||
Sys_Switch:
|
||||
LDR R3,=os_tsk
|
||||
LDMIA R3!,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ Sys_Exit /* no task switch */
|
||||
|
||||
SUBS R3,#8
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
STR R0,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
STMIA R0!,{R4-R7} /* Save old context (R4-R7) */
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} /* Save old context (R8-R11) */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
ADDS R0,R0,#16 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R8-R11) */
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 /* Write PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R4-R7) */
|
||||
|
||||
Sys_Exit:
|
||||
MOVS R0,#~0xFFFFFFFD /* Set EXC_RETURN value */
|
||||
MVNS R0,R0
|
||||
BX R0 /* RETI to Thread Mode, use PSP */
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
; void SysTick_Handler (void);
|
||||
|
||||
PUBLIC SysTick_Handler
|
||||
SysTick_Handler:
|
||||
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
; void OS_Tick_Handler (void);
|
||||
|
||||
PUBLIC OS_Tick_Handler
|
||||
OS_Tick_Handler:
|
||||
|
||||
BL os_tick_irqack
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,58 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
NAME SVC_TABLE
|
||||
SECTION .text:CONST (2)
|
||||
|
||||
PUBLIC SVC_Count
|
||||
|
||||
SVC_Cnt EQU (SVC_End-SVC_Table)/4
|
||||
SVC_Count DCD SVC_Cnt
|
||||
|
||||
; Import user SVC functions here.
|
||||
; IMPORT __SVC_1
|
||||
|
||||
PUBLIC SVC_Table
|
||||
SVC_Table
|
||||
; Insert user SVC functions here. SVC 0 used by RTL Kernel.
|
||||
; DCD __SVC_1 ; user SVC function
|
||||
|
||||
SVC_End
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,301 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM0.C
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M0
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_MemBox.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
__asm void rt_set_PSP (U32 stack) {
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
__asm U32 rt_get_PSP (void) {
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
__asm void os_set_env (void) {
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
MOV R0,SP ; PSP = MSP
|
||||
MSR PSP,R0
|
||||
LDR R0,=__cpp(&os_flags)
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
BNE PrivilegedE
|
||||
MOVS R0,#0x03 ; Unprivileged Thread mode, use PSP
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
PrivilegedE
|
||||
MOVS R0,#0x02 ; Privileged Thread mode, use PSP
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
__asm void *_alloc_box (void *box_mem) {
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
LDR R3,=__cpp(rt_alloc_box)
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedA
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedA
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedA
|
||||
BX R12
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
__asm U32 _free_box (void *box_mem, void *box) {
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
LDR R3,=__cpp(rt_free_box)
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedF
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedF
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedF
|
||||
BX R12
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
__asm void SVC_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
IMPORT SVC_Count
|
||||
IMPORT SVC_Table
|
||||
IMPORT rt_stk_check
|
||||
|
||||
MRS R0,PSP ; Read PSP
|
||||
LDR R1,[R0,#24] ; Read Saved PC from Stack
|
||||
SUBS R1,R1,#2 ; Point to SVC Instruction
|
||||
LDRB R1,[R1] ; Load SVC Number
|
||||
CMP R1,#0
|
||||
BNE SVC_User ; User SVC Number > 0
|
||||
|
||||
MOV LR,R4
|
||||
LDMIA R0,{R0-R3,R4} ; Read R0-R3,R12 from stack
|
||||
MOV R12,R4
|
||||
MOV R4,LR
|
||||
BLX R12 ; Call SVC Function
|
||||
|
||||
MRS R3,PSP ; Read PSP
|
||||
STMIA R3!,{R0-R2} ; Store return values
|
||||
|
||||
LDR R3,=__cpp(&os_tsk)
|
||||
LDMIA R3!,{R1,R2} ; os_tsk.run, os_tsk.new
|
||||
CMP R1,R2
|
||||
BEQ SVC_Exit ; no task switch
|
||||
|
||||
SUBS R3,#8
|
||||
CMP R1,#0 ; Runtask deleted?
|
||||
BEQ SVC_Next
|
||||
|
||||
MRS R0,PSP ; Read PSP
|
||||
SUBS R0,R0,#32 ; Adjust Start Address
|
||||
STR R0,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
|
||||
STMIA R0!,{R4-R7} ; Save old context (R4-R7)
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} ; Save old context (R8-R11)
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check ; Check for Stack overflow
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_Next
|
||||
STR R2,[R3] ; os_tsk.run = os_tsk.new
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
|
||||
ADDS R0,R0,#16 ; Adjust Start Address
|
||||
LDMIA R0!,{R4-R7} ; Restore new Context (R8-R11)
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 ; Write PSP
|
||||
SUBS R0,R0,#32 ; Adjust Start Address
|
||||
LDMIA R0!,{R4-R7} ; Restore new Context (R4-R7)
|
||||
|
||||
SVC_Exit
|
||||
MOVS R0,#:NOT:0xFFFFFFFD ; Set EXC_RETURN value
|
||||
MVNS R0,R0
|
||||
BX R0 ; RETI to Thread Mode, use PSP
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User
|
||||
PUSH {R4,LR} ; Save Registers
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done ; Overflow
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LSLS R1,R1,#2
|
||||
LDR R4,[R4,R1] ; Load SVC Function Address
|
||||
MOV LR,R4
|
||||
|
||||
LDMIA R0,{R0-R3,R4} ; Read R0-R3,R12 from stack
|
||||
MOV R12,R4
|
||||
BLX LR ; Call SVC Function
|
||||
|
||||
MRS R4,PSP ; Read PSP
|
||||
STMIA R4!,{R0-R3} ; Function return values
|
||||
SVC_Done
|
||||
POP {R4,PC} ; RETI
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
__asm void PendSV_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
BL __cpp(rt_pop_req)
|
||||
|
||||
Sys_Switch
|
||||
LDR R3,=__cpp(&os_tsk)
|
||||
LDMIA R3!,{R1,R2} ; os_tsk.run, os_tsk.new
|
||||
CMP R1,R2
|
||||
BEQ Sys_Exit ; no task switch
|
||||
|
||||
SUBS R3,#8
|
||||
|
||||
MRS R0,PSP ; Read PSP
|
||||
SUBS R0,R0,#32 ; Adjust Start Address
|
||||
STR R0,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
|
||||
STMIA R0!,{R4-R7} ; Save old context (R4-R7)
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} ; Save old context (R8-R11)
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check ; Check for Stack overflow
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] ; os_tsk.run = os_tsk.new
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
|
||||
ADDS R0,R0,#16 ; Adjust Start Address
|
||||
LDMIA R0!,{R4-R7} ; Restore new Context (R8-R11)
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 ; Write PSP
|
||||
SUBS R0,R0,#32 ; Adjust Start Address
|
||||
LDMIA R0!,{R4-R7} ; Restore new Context (R4-R7)
|
||||
|
||||
Sys_Exit
|
||||
MOVS R0,#:NOT:0xFFFFFFFD ; Set EXC_RETURN value
|
||||
MVNS R0,R0
|
||||
BX R0 ; RETI to Thread Mode, use PSP
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
__asm void SysTick_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
BL __cpp(rt_systick)
|
||||
B Sys_Switch
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
__asm void OS_Tick_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
BL __cpp(os_tick_irqack)
|
||||
BL __cpp(rt_systick)
|
||||
B Sys_Switch
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
AREA SVC_TABLE, CODE, READONLY
|
||||
|
||||
EXPORT SVC_Count
|
||||
|
||||
SVC_Cnt EQU (SVC_End-SVC_Table)/4
|
||||
SVC_Count DCD SVC_Cnt
|
||||
|
||||
; Import user SVC functions here.
|
||||
; IMPORT __SVC_1
|
||||
|
||||
EXPORT SVC_Table
|
||||
SVC_Table
|
||||
; Insert user SVC functions here. SVC 0 used by RTL Kernel.
|
||||
; DCD __SVC_1 ; user SVC function
|
||||
|
||||
SVC_End
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,370 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM0.S
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M0
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
.file "HAL_CM0.S"
|
||||
.syntax unified
|
||||
|
||||
.equ TCB_TSTACK, 44
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
.thumb
|
||||
|
||||
.section ".text"
|
||||
.align 2
|
||||
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
# void rt_set_PSP (U32 stack);
|
||||
|
||||
.thumb_func
|
||||
.type rt_set_PSP, %function
|
||||
.global rt_set_PSP
|
||||
rt_set_PSP:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size rt_set_PSP, .-rt_set_PSP
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
# U32 rt_get_PSP (void);
|
||||
|
||||
.thumb_func
|
||||
.type rt_get_PSP, %function
|
||||
.global rt_get_PSP
|
||||
rt_get_PSP:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size rt_get_PSP, .-rt_get_PSP
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
# void os_set_env (void);
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
|
||||
.thumb_func
|
||||
.type os_set_env, %function
|
||||
.global os_set_env
|
||||
os_set_env:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MOV R0,SP /* PSP = MSP */
|
||||
MSR PSP,R0
|
||||
LDR R0,=os_flags
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
BNE PrivilegedE
|
||||
MOVS R0,#0x03 /* Unprivileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
PrivilegedE:
|
||||
MOVS R0,#0x02 /* Privileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size os_set_env, .-os_set_env
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
# void *_alloc_box (void *box_mem);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
.thumb_func
|
||||
.type _alloc_box, %function
|
||||
.global _alloc_box
|
||||
_alloc_box:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
LDR R3,=rt_alloc_box
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedA
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedA
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedA:
|
||||
BX R12
|
||||
|
||||
.fnend
|
||||
.size _alloc_box, .-_alloc_box
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
# U32 _free_box (void *box_mem, void *box);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
.thumb_func
|
||||
.type _free_box, %function
|
||||
.global _free_box
|
||||
_free_box:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
LDR R3,=rt_free_box
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedF
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedF
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedF:
|
||||
BX R12
|
||||
|
||||
.fnend
|
||||
.size _free_box, .-_free_box
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
# void SVC_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type SVC_Handler, %function
|
||||
.global SVC_Handler
|
||||
SVC_Handler:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
LDR R1,[R0,#24] /* Read Saved PC from Stack */
|
||||
SUBS R1,R1,#2 /* Point to SVC Instruction */
|
||||
LDRB R1,[R1] /* Load SVC Number */
|
||||
CMP R1,#0
|
||||
BNE SVC_User /* User SVC Number > 0 */
|
||||
|
||||
MOV LR,R4
|
||||
LDMIA R0,{R0-R3,R4} /* Read R0-R3,R12 from stack */
|
||||
MOV R12,R4
|
||||
MOV R4,LR
|
||||
BLX R12 /* Call SVC Function */
|
||||
|
||||
MRS R3,PSP /* Read PSP */
|
||||
STMIA R3!,{R0-R2} /* Store return values */
|
||||
|
||||
LDR R3,=os_tsk
|
||||
LDMIA R3!,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ SVC_Exit /* no task switch */
|
||||
|
||||
SUBS R3,#8
|
||||
CMP R1,#0 /* Runtask deleted? */
|
||||
BEQ SVC_Next
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
STR R0,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
STMIA R0!,{R4-R7} /* Save old context (R4-R7) */
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} /* Save old context (R8-R11) */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_Next:
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
ADDS R0,R0,#16 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R8-R11) */
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 /* Write PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R4-R7) */
|
||||
|
||||
SVC_Exit:
|
||||
MOVS R0,#~0xFFFFFFFD /* Set EXC_RETURN value */
|
||||
MVNS R0,R0
|
||||
BX R0 /* RETI to Thread Mode, use PSP */
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User:
|
||||
PUSH {R4,LR} /* Save Registers */
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done /* Overflow */
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LSLS R1,R1,#2
|
||||
LDR R4,[R4,R1] /* Load SVC Function Address */
|
||||
MOV LR,R4
|
||||
|
||||
LDMIA R0,{R0-R3,R4} /* Read R0-R3,R12 from stack */
|
||||
MOV R12,R4
|
||||
BLX LR /* Call SVC Function */
|
||||
|
||||
MRS R4,PSP /* Read PSP */
|
||||
STMIA R4!,{R0-R3} /* Function return values */
|
||||
SVC_Done:
|
||||
POP {R4,PC} /* RETI */
|
||||
|
||||
.fnend
|
||||
.size SVC_Handler, .-SVC_Handler
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
# void PendSV_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type PendSV_Handler, %function
|
||||
.global PendSV_Handler
|
||||
.global Sys_Switch
|
||||
PendSV_Handler:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
BL rt_pop_req
|
||||
|
||||
Sys_Switch:
|
||||
LDR R3,=os_tsk
|
||||
LDMIA R3!,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ Sys_Exit /* no task switch */
|
||||
|
||||
SUBS R3,#8
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
STR R0,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
STMIA R0!,{R4-R7} /* Save old context (R4-R7) */
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} /* Save old context (R8-R11) */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
ADDS R0,R0,#16 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R8-R11) */
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 /* Write PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R4-R7) */
|
||||
|
||||
Sys_Exit:
|
||||
MOVS R0,#~0xFFFFFFFD /* Set EXC_RETURN value */
|
||||
MVNS R0,R0
|
||||
BX R0 /* RETI to Thread Mode, use PSP */
|
||||
|
||||
.fnend
|
||||
.size PendSV_Handler, .-PendSV_Handler
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
# void SysTick_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type SysTick_Handler, %function
|
||||
.global SysTick_Handler
|
||||
SysTick_Handler:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
.fnend
|
||||
.size SysTick_Handler, .-SysTick_Handler
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
# void OS_Tick_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type OS_Tick_Handler, %function
|
||||
.global OS_Tick_Handler
|
||||
OS_Tick_Handler:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
BL os_tick_irqack
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
.fnend
|
||||
.size OS_Tick_Handler, .-OS_Tick_Handler
|
||||
|
||||
|
||||
.end
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,56 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
.file "SVC_Table.S"
|
||||
|
||||
|
||||
.section ".svc_table"
|
||||
|
||||
.global SVC_Table
|
||||
SVC_Table:
|
||||
/* Insert user SVC functions here. SVC 0 used by RTL Kernel. */
|
||||
# .long __SVC_1 /* user SVC function */
|
||||
SVC_End:
|
||||
|
||||
.global SVC_Count
|
||||
SVC_Count:
|
||||
.long (SVC_End-SVC_Table)/4
|
||||
|
||||
|
||||
.end
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,312 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM0.S
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M0
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
NAME HAL_CM0.S
|
||||
|
||||
#define TCB_TSTACK 44
|
||||
|
||||
EXTERN os_flags
|
||||
EXTERN os_tsk
|
||||
EXTERN rt_alloc_box
|
||||
EXTERN rt_free_box
|
||||
EXTERN rt_stk_check
|
||||
EXTERN rt_pop_req
|
||||
EXTERN rt_systick
|
||||
EXTERN os_tick_irqack
|
||||
EXTERN SVC_Table
|
||||
EXTERN SVC_Count
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
SECTION .text:CODE:NOROOT(2)
|
||||
THUMB
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
; void rt_set_PSP (U32 stack);
|
||||
|
||||
PUBLIC rt_set_PSP
|
||||
rt_set_PSP:
|
||||
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
; U32 rt_get_PSP (void);
|
||||
|
||||
PUBLIC rt_get_PSP
|
||||
rt_get_PSP:
|
||||
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
; void os_set_env (void);
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
|
||||
PUBLIC os_set_env
|
||||
os_set_env:
|
||||
|
||||
MOV R0,SP /* PSP = MSP */
|
||||
MSR PSP,R0
|
||||
LDR R0,=os_flags
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
BNE PrivilegedE
|
||||
MOVS R0,#0x03 /* Unprivileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
PrivilegedE:
|
||||
MOVS R0,#0x02 /* Privileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
; void *_alloc_box (void *box_mem);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
PUBLIC _alloc_box
|
||||
_alloc_box:
|
||||
|
||||
LDR R3,=rt_alloc_box
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedA
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedA
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedA:
|
||||
BX R12
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
; U32 _free_box (void *box_mem, void *box);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
PUBLIC _free_box
|
||||
_free_box:
|
||||
|
||||
LDR R3,=rt_free_box
|
||||
MOV R12,R3
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BNE PrivilegedF
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BEQ PrivilegedF
|
||||
SVC 0
|
||||
BX LR
|
||||
PrivilegedF:
|
||||
BX R12
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
; void SVC_Handler (void);
|
||||
|
||||
PUBLIC SVC_Handler
|
||||
SVC_Handler:
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
LDR R1,[R0,#24] /* Read Saved PC from Stack */
|
||||
SUBS R1,R1,#2 /* Point to SVC Instruction */
|
||||
LDRB R1,[R1] /* Load SVC Number */
|
||||
CMP R1,#0
|
||||
BNE SVC_User /* User SVC Number > 0 */
|
||||
|
||||
MOV LR,R4
|
||||
LDMIA R0,{R0-R3,R4} /* Read R0-R3,R12 from stack */
|
||||
MOV R12,R4
|
||||
MOV R4,LR
|
||||
BLX R12 /* Call SVC Function */
|
||||
|
||||
MRS R3,PSP /* Read PSP */
|
||||
STMIA R3!,{R0-R2} /* Store return values */
|
||||
|
||||
LDR R3,=os_tsk
|
||||
LDMIA R3!,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ SVC_Exit /* no task switch */
|
||||
|
||||
SUBS R3,#8
|
||||
CMP R1,#0 /* Runtask deleted? */
|
||||
BEQ SVC_Next
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
STR R0,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
STMIA R0!,{R4-R7} /* Save old context (R4-R7) */
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} /* Save old context (R8-R11) */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_Next:
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
ADDS R0,R0,#16 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R8-R11) */
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 /* Write PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R4-R7) */
|
||||
|
||||
SVC_Exit:
|
||||
MOVS R0,#~0xFFFFFFFD /* Set EXC_RETURN value */
|
||||
MVNS R0,R0
|
||||
BX R0 /* RETI to Thread Mode, use PSP */
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User:
|
||||
PUSH {R4,LR} /* Save Registers */
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done /* Overflow */
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LSLS R1,R1,#2
|
||||
LDR R4,[R4,R1] /* Load SVC Function Address */
|
||||
MOV LR,R4
|
||||
|
||||
LDMIA R0,{R0-R3,R4} /* Read R0-R3,R12 from stack */
|
||||
MOV R12,R4
|
||||
BLX LR /* Call SVC Function */
|
||||
|
||||
MRS R4,PSP /* Read PSP */
|
||||
STMIA R4!,{R0-R3} /* Function return values */
|
||||
SVC_Done:
|
||||
POP {R4,PC} /* RETI */
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
; void PendSV_Handler (void);
|
||||
|
||||
PUBLIC PendSV_Handler
|
||||
PendSV_Handler:
|
||||
|
||||
BL rt_pop_req
|
||||
|
||||
Sys_Switch:
|
||||
LDR R3,=os_tsk
|
||||
LDMIA R3!,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ Sys_Exit /* no task switch */
|
||||
|
||||
SUBS R3,#8
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
STR R0,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
STMIA R0!,{R4-R7} /* Save old context (R4-R7) */
|
||||
MOV R4,R8
|
||||
MOV R5,R9
|
||||
MOV R6,R10
|
||||
MOV R7,R11
|
||||
STMIA R0!,{R4-R7} /* Save old context (R8-R11) */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R0,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
ADDS R0,R0,#16 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R8-R11) */
|
||||
MOV R8,R4
|
||||
MOV R9,R5
|
||||
MOV R10,R6
|
||||
MOV R11,R7
|
||||
MSR PSP,R0 /* Write PSP */
|
||||
SUBS R0,R0,#32 /* Adjust Start Address */
|
||||
LDMIA R0!,{R4-R7} /* Restore new Context (R4-R7) */
|
||||
|
||||
Sys_Exit:
|
||||
MOVS R0,#~0xFFFFFFFD /* Set EXC_RETURN value */
|
||||
MVNS R0,R0
|
||||
BX R0 /* RETI to Thread Mode, use PSP */
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
; void SysTick_Handler (void);
|
||||
|
||||
PUBLIC SysTick_Handler
|
||||
SysTick_Handler:
|
||||
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
; void OS_Tick_Handler (void);
|
||||
|
||||
PUBLIC OS_Tick_Handler
|
||||
OS_Tick_Handler:
|
||||
|
||||
BL os_tick_irqack
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,58 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
NAME SVC_TABLE
|
||||
SECTION .text:CONST (2)
|
||||
|
||||
PUBLIC SVC_Count
|
||||
|
||||
SVC_Cnt EQU (SVC_End-SVC_Table)/4
|
||||
SVC_Count DCD SVC_Cnt
|
||||
|
||||
; Import user SVC functions here.
|
||||
; IMPORT __SVC_1
|
||||
|
||||
PUBLIC SVC_Table
|
||||
SVC_Table
|
||||
; Insert user SVC functions here. SVC 0 used by RTL Kernel.
|
||||
; DCD __SVC_1 ; user SVC function
|
||||
|
||||
SVC_End
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,274 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM3.C
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M3
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_MemBox.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
__asm void rt_set_PSP (U32 stack) {
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
__asm U32 rt_get_PSP (void) {
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
__asm void os_set_env (void) {
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
MOV R0,SP ; PSP = MSP
|
||||
MSR PSP,R0
|
||||
LDR R0,=__cpp(&os_flags)
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
MOVNE R0,#0x02 ; Privileged Thread mode, use PSP
|
||||
MOVEQ R0,#0x03 ; Unprivileged Thread mode, use PSP
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
__asm void *_alloc_box (void *box_mem) {
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
LDR R12,=__cpp(rt_alloc_box)
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
__asm U32 _free_box (void *box_mem, void *box) {
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
LDR R12,=__cpp(rt_free_box)
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
__asm void SVC_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
IMPORT SVC_Count
|
||||
IMPORT SVC_Table
|
||||
IMPORT rt_stk_check
|
||||
|
||||
#ifdef IFX_XMC4XXX
|
||||
EXPORT SVC_Handler_Veneer
|
||||
SVC_Handler_Veneer
|
||||
#endif
|
||||
|
||||
MRS R0,PSP ; Read PSP
|
||||
LDR R1,[R0,#24] ; Read Saved PC from Stack
|
||||
LDRB R1,[R1,#-2] ; Load SVC Number
|
||||
CBNZ R1,SVC_User
|
||||
|
||||
LDM R0,{R0-R3,R12} ; Read R0-R3,R12 from stack
|
||||
BLX R12 ; Call SVC Function
|
||||
|
||||
MRS R12,PSP ; Read PSP
|
||||
STM R12,{R0-R2} ; Store return values
|
||||
|
||||
LDR R3,=__cpp(&os_tsk)
|
||||
LDM R3,{R1,R2} ; os_tsk.run, os_tsk.new
|
||||
CMP R1,R2
|
||||
BEQ SVC_Exit ; no task switch
|
||||
|
||||
CBZ R1,SVC_Next ; Runtask deleted?
|
||||
STMDB R12!,{R4-R11} ; Save Old context
|
||||
STR R12,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check ; Check for Stack overflow
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_Next
|
||||
STR R2,[R3] ; os_tsk.run = os_tsk.new
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
|
||||
LDMIA R12!,{R4-R11} ; Restore New Context
|
||||
MSR PSP,R12 ; Write PSP
|
||||
|
||||
SVC_Exit
|
||||
MVN LR,#:NOT:0xFFFFFFFD ; set EXC_RETURN value
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUSH {LR}
|
||||
POP {PC}
|
||||
#else
|
||||
BX LR
|
||||
#endif
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User
|
||||
PUSH {R4,LR} ; Save Registers
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done ; Overflow
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LDR R4,[R4,R1,LSL #2] ; Load SVC Function Address
|
||||
|
||||
LDM R0,{R0-R3,R12} ; Read R0-R3,R12 from stack
|
||||
BLX R4 ; Call SVC Function
|
||||
|
||||
MRS R12,PSP
|
||||
STM R12,{R0-R3} ; Function return values
|
||||
SVC_Done
|
||||
POP {R4,PC} ; RETI
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
__asm void PendSV_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
#ifdef IFX_XMC4XXX
|
||||
EXPORT PendSV_Handler_Veneer
|
||||
PendSV_Handler_Veneer
|
||||
#endif
|
||||
|
||||
BL __cpp(rt_pop_req)
|
||||
|
||||
Sys_Switch
|
||||
LDR R3,=__cpp(&os_tsk)
|
||||
LDM R3,{R1,R2} ; os_tsk.run, os_tsk.new
|
||||
CMP R1,R2
|
||||
BEQ Sys_Exit
|
||||
|
||||
MRS R12,PSP ; Read PSP
|
||||
STMDB R12!,{R4-R11} ; Save Old context
|
||||
STR R12,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check ; Check for Stack overflow
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] ; os_tsk.run = os_tsk.new
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
|
||||
LDMIA R12!,{R4-R11} ; Restore New Context
|
||||
MSR PSP,R12 ; Write PSP
|
||||
|
||||
Sys_Exit
|
||||
MVN LR,#:NOT:0xFFFFFFFD ; set EXC_RETURN value
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUSH {LR}
|
||||
POP {PC}
|
||||
#else
|
||||
BX LR ; Return to Thread Mode
|
||||
#endif
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
__asm void SysTick_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
#ifdef IFX_XMC4XXX
|
||||
EXPORT SysTick_Handler_Veneer
|
||||
SysTick_Handler_Veneer
|
||||
#endif
|
||||
|
||||
BL __cpp(rt_systick)
|
||||
B Sys_Switch
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
__asm void OS_Tick_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
BL __cpp(os_tick_irqack)
|
||||
BL __cpp(rt_systick)
|
||||
B Sys_Switch
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
AREA SVC_TABLE, CODE, READONLY
|
||||
|
||||
EXPORT SVC_Count
|
||||
|
||||
SVC_Cnt EQU (SVC_End-SVC_Table)/4
|
||||
SVC_Count DCD SVC_Cnt
|
||||
|
||||
; Import user SVC functions here.
|
||||
; IMPORT __SVC_1
|
||||
|
||||
EXPORT SVC_Table
|
||||
SVC_Table
|
||||
; Insert user SVC functions here. SVC 0 used by RTL Kernel.
|
||||
; DCD __SVC_1 ; user SVC function
|
||||
|
||||
SVC_End
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,345 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM3.S
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M3
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
.file "HAL_CM3.S"
|
||||
.syntax unified
|
||||
|
||||
.equ TCB_TSTACK, 44
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
.thumb
|
||||
|
||||
.section ".text"
|
||||
.align 2
|
||||
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
# void rt_set_PSP (U32 stack);
|
||||
|
||||
.thumb_func
|
||||
.type rt_set_PSP, %function
|
||||
.global rt_set_PSP
|
||||
rt_set_PSP:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size rt_set_PSP, .-rt_set_PSP
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
# U32 rt_get_PSP (void);
|
||||
|
||||
.thumb_func
|
||||
.type rt_get_PSP, %function
|
||||
.global rt_get_PSP
|
||||
rt_get_PSP:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size rt_get_PSP, .-rt_get_PSP
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
# void os_set_env (void);
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
|
||||
.thumb_func
|
||||
.type os_set_env, %function
|
||||
.global os_set_env
|
||||
os_set_env:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MOV R0,SP /* PSP = MSP */
|
||||
MSR PSP,R0
|
||||
LDR R0,=os_flags
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
ITE NE
|
||||
MOVNE R0,#0x02 /* Privileged Thread mode, use PSP */
|
||||
MOVEQ R0,#0x03 /* Unprivileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size os_set_env, .-os_set_env
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
# void *_alloc_box (void *box_mem);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
.thumb_func
|
||||
.type _alloc_box, %function
|
||||
.global _alloc_box
|
||||
_alloc_box:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
LDR R12,=rt_alloc_box
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
IT NE
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
IT EQ
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size _alloc_box, .-_alloc_box
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
# U32 _free_box (void *box_mem, void *box);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
.thumb_func
|
||||
.type _free_box, %function
|
||||
.global _free_box
|
||||
_free_box:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
LDR R12,=rt_free_box
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
IT NE
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
IT EQ
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size _free_box, .-_free_box
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
# void SVC_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type SVC_Handler, %function
|
||||
.global SVC_Handler
|
||||
SVC_Handler:
|
||||
.ifdef IFX_XMC4XXX
|
||||
.global SVC_Handler_Veneer
|
||||
SVC_Handler_Veneer:
|
||||
.endif
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
LDR R1,[R0,#24] /* Read Saved PC from Stack */
|
||||
LDRB R1,[R1,#-2] /* Load SVC Number */
|
||||
CBNZ R1,SVC_User
|
||||
|
||||
LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
|
||||
BLX R12 /* Call SVC Function */
|
||||
|
||||
MRS R12,PSP /* Read PSP */
|
||||
STM R12,{R0-R2} /* Store return values */
|
||||
|
||||
LDR R3,=os_tsk
|
||||
LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ SVC_Exit /* no task switch */
|
||||
|
||||
CBZ R1,SVC_Next /* Runtask deleted? */
|
||||
STMDB R12!,{R4-R11} /* Save Old context */
|
||||
STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_Next:
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
LDMIA R12!,{R4-R11} /* Restore New Context */
|
||||
MSR PSP,R12 /* Write PSP */
|
||||
|
||||
SVC_Exit:
|
||||
MVN LR,#~0xFFFFFFFD /* set EXC_RETURN value */
|
||||
.ifdef IFX_XMC4XXX
|
||||
PUSH {LR}
|
||||
POP {PC}
|
||||
.else
|
||||
BX LR
|
||||
.endif
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User:
|
||||
PUSH {R4,LR} /* Save Registers */
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done /* Overflow */
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LDR R4,[R4,R1,LSL #2] /* Load SVC Function Address */
|
||||
|
||||
LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
|
||||
BLX R4 /* Call SVC Function */
|
||||
|
||||
MRS R12,PSP
|
||||
STM R12,{R0-R3} /* Function return values */
|
||||
SVC_Done:
|
||||
POP {R4,PC} /* RETI */
|
||||
|
||||
.fnend
|
||||
.size SVC_Handler, .-SVC_Handler
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
# void PendSV_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type PendSV_Handler, %function
|
||||
.global PendSV_Handler
|
||||
.global Sys_Switch
|
||||
PendSV_Handler:
|
||||
.ifdef IFX_XMC4XXX
|
||||
.global PendSV_Handler_Veneer
|
||||
PendSV_Handler_Veneer:
|
||||
.endif
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
BL rt_pop_req
|
||||
|
||||
Sys_Switch:
|
||||
LDR R3,=os_tsk
|
||||
LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ Sys_Exit
|
||||
|
||||
MRS R12,PSP /* Read PSP */
|
||||
STMDB R12!,{R4-R11} /* Save Old context */
|
||||
STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
LDMIA R12!,{R4-R11} /* Restore New Context */
|
||||
MSR PSP,R12 /* Write PSP */
|
||||
|
||||
Sys_Exit:
|
||||
MVN LR,#~0xFFFFFFFD /* set EXC_RETURN value */
|
||||
.ifdef IFX_XMC4XXX
|
||||
PUSH {LR}
|
||||
POP {PC}
|
||||
.else
|
||||
BX LR /* Return to Thread Mode */
|
||||
.endif
|
||||
|
||||
.fnend
|
||||
.size PendSV_Handler, .-PendSV_Handler
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
# void SysTick_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type SysTick_Handler, %function
|
||||
.global SysTick_Handler
|
||||
SysTick_Handler:
|
||||
.ifdef IFX_XMC4XXX
|
||||
.global SysTick_Handler_Veneer
|
||||
SysTick_Handler_Veneer:
|
||||
.endif
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
.fnend
|
||||
.size SysTick_Handler, .-SysTick_Handler
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
# void OS_Tick_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type OS_Tick_Handler, %function
|
||||
.global OS_Tick_Handler
|
||||
OS_Tick_Handler:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
BL os_tick_irqack
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
.fnend
|
||||
.size OS_Tick_Handler, .-OS_Tick_Handler
|
||||
|
||||
|
||||
.end
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,56 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
.file "SVC_Table.S"
|
||||
|
||||
|
||||
.section ".svc_table"
|
||||
|
||||
.global SVC_Table
|
||||
SVC_Table:
|
||||
/* Insert user SVC functions here. SVC 0 used by RTL Kernel. */
|
||||
# .long __SVC_1 /* user SVC function */
|
||||
SVC_End:
|
||||
|
||||
.global SVC_Count
|
||||
SVC_Count:
|
||||
.long (SVC_End-SVC_Table)/4
|
||||
|
||||
|
||||
.end
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,265 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM3.S
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M3
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
NAME HAL_CM3.S
|
||||
|
||||
#define TCB_TSTACK 44
|
||||
|
||||
EXTERN os_flags
|
||||
EXTERN os_tsk
|
||||
EXTERN rt_alloc_box
|
||||
EXTERN rt_free_box
|
||||
EXTERN rt_stk_check
|
||||
EXTERN rt_pop_req
|
||||
EXTERN rt_systick
|
||||
EXTERN os_tick_irqack
|
||||
EXTERN SVC_Table
|
||||
EXTERN SVC_Count
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
SECTION .text:CODE:NOROOT(2)
|
||||
THUMB
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
; void rt_set_PSP (U32 stack);
|
||||
|
||||
PUBLIC rt_set_PSP
|
||||
rt_set_PSP:
|
||||
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
; U32 rt_get_PSP (void);
|
||||
|
||||
PUBLIC rt_get_PSP
|
||||
rt_get_PSP:
|
||||
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
; void os_set_env (void);
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
|
||||
PUBLIC os_set_env
|
||||
os_set_env:
|
||||
|
||||
MOV R0,SP /* PSP = MSP */
|
||||
MSR PSP,R0
|
||||
LDR R0,=os_flags
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
ITE NE
|
||||
MOVNE R0,#0x02 /* Privileged Thread mode, use PSP */
|
||||
MOVEQ R0,#0x03 /* Unprivileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
; void *_alloc_box (void *box_mem);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
PUBLIC _alloc_box
|
||||
_alloc_box:
|
||||
|
||||
LDR R12,=rt_alloc_box
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
IT NE
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
IT EQ
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
; U32 _free_box (void *box_mem, void *box);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
PUBLIC _free_box
|
||||
_free_box:
|
||||
|
||||
LDR R12,=rt_free_box
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
IT NE
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
IT EQ
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
; void SVC_Handler (void);
|
||||
|
||||
PUBLIC SVC_Handler
|
||||
SVC_Handler:
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
LDR R1,[R0,#24] /* Read Saved PC from Stack */
|
||||
LDRB R1,[R1,#-2] /* Load SVC Number */
|
||||
CBNZ R1,SVC_User
|
||||
|
||||
LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
|
||||
BLX R12 /* Call SVC Function */
|
||||
|
||||
MRS R12,PSP /* Read PSP */
|
||||
STM R12,{R0-R2} /* Store return values */
|
||||
|
||||
LDR R3,=os_tsk
|
||||
LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ SVC_Exit /* no task switch */
|
||||
|
||||
CBZ R1,SVC_Next /* Runtask deleted? */
|
||||
STMDB R12!,{R4-R11} /* Save Old context */
|
||||
STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_Next:
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
LDMIA R12!,{R4-R11} /* Restore New Context */
|
||||
MSR PSP,R12 /* Write PSP */
|
||||
|
||||
SVC_Exit:
|
||||
MVN LR,#~0xFFFFFFFD /* set EXC_RETURN value */
|
||||
BX LR
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User:
|
||||
PUSH {R4,LR} /* Save Registers */
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done /* Overflow */
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LDR R4,[R4,R1,LSL #2] /* Load SVC Function Address */
|
||||
|
||||
LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
|
||||
BLX R4 /* Call SVC Function */
|
||||
|
||||
MRS R12,PSP
|
||||
STM R12,{R0-R3} /* Function return values */
|
||||
SVC_Done:
|
||||
POP {R4,PC} /* RETI */
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
; void PendSV_Handler (void);
|
||||
|
||||
PUBLIC PendSV_Handler
|
||||
PendSV_Handler:
|
||||
|
||||
BL rt_pop_req
|
||||
|
||||
Sys_Switch:
|
||||
LDR R3,=os_tsk
|
||||
LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
BEQ Sys_Exit
|
||||
|
||||
MRS R12,PSP /* Read PSP */
|
||||
STMDB R12!,{R4-R11} /* Save Old context */
|
||||
STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
LDMIA R12!,{R4-R11} /* Restore New Context */
|
||||
MSR PSP,R12 /* Write PSP */
|
||||
|
||||
Sys_Exit:
|
||||
MVN LR,#~0xFFFFFFFD /* set EXC_RETURN value */
|
||||
BX LR /* Return to Thread Mode */
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
; void SysTick_Handler (void);
|
||||
|
||||
PUBLIC SysTick_Handler
|
||||
SysTick_Handler:
|
||||
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
; void OS_Tick_Handler (void);
|
||||
|
||||
PUBLIC OS_Tick_Handler
|
||||
OS_Tick_Handler:
|
||||
|
||||
BL os_tick_irqack
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,58 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
NAME SVC_TABLE
|
||||
SECTION .text:CONST (2)
|
||||
|
||||
PUBLIC SVC_Count
|
||||
|
||||
SVC_Cnt EQU (SVC_End-SVC_Table)/4
|
||||
SVC_Count DCD SVC_Cnt
|
||||
|
||||
; Import user SVC functions here.
|
||||
; IMPORT __SVC_1
|
||||
|
||||
PUBLIC SVC_Table
|
||||
SVC_Table
|
||||
; Insert user SVC functions here. SVC 0 used by RTL Kernel.
|
||||
; DCD __SVC_1 ; user SVC function
|
||||
|
||||
SVC_End
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,327 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM4.C
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M4
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_MemBox.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
__asm void rt_set_PSP (U32 stack) {
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
__asm U32 rt_get_PSP (void) {
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
__asm void os_set_env (void) {
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
MOV R0,SP ; PSP = MSP
|
||||
MSR PSP,R0
|
||||
LDR R0,=__cpp(&os_flags)
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
MOVNE R0,#0x02 ; Privileged Thread mode, use PSP
|
||||
MOVEQ R0,#0x03 ; Unprivileged Thread mode, use PSP
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
__asm void *_alloc_box (void *box_mem) {
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
LDR R12,=__cpp(rt_alloc_box)
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
__asm U32 _free_box (void *box_mem, void *box) {
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
LDR R12,=__cpp(rt_free_box)
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
__asm void SVC_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
IMPORT SVC_Count
|
||||
IMPORT SVC_Table
|
||||
IMPORT rt_stk_check
|
||||
|
||||
#ifdef IFX_XMC4XXX
|
||||
EXPORT SVC_Handler_Veneer
|
||||
SVC_Handler_Veneer
|
||||
#endif
|
||||
|
||||
MRS R0,PSP ; Read PSP
|
||||
LDR R1,[R0,#24] ; Read Saved PC from Stack
|
||||
LDRB R1,[R1,#-2] ; Load SVC Number
|
||||
CBNZ R1,SVC_User
|
||||
|
||||
LDM R0,{R0-R3,R12} ; Read R0-R3,R12 from stack
|
||||
PUSH {R4,LR} ; Save EXC_RETURN
|
||||
BLX R12 ; Call SVC Function
|
||||
POP {R4,LR} ; Restore EXC_RETURN
|
||||
|
||||
MRS R12,PSP ; Read PSP
|
||||
STM R12,{R0-R2} ; Store return values
|
||||
|
||||
LDR R3,=__cpp(&os_tsk)
|
||||
LDM R3,{R1,R2} ; os_tsk.run, os_tsk.new
|
||||
CMP R1,R2
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUSHEQ {LR}
|
||||
POPEQ {PC}
|
||||
#else
|
||||
BXEQ LR ; RETI, no task switch
|
||||
#endif
|
||||
|
||||
CBNZ R1,SVC_ContextSave ; Runtask not deleted?
|
||||
|
||||
TST LR,#0x10 ; is it extended frame?
|
||||
BNE SVC_ContextRestore
|
||||
LDR R1,=0xE000EF34
|
||||
LDR R0,[R1] ; Load FPCCR
|
||||
BIC R0,#1 ; Clear LSPACT (Lazy state)
|
||||
STR R0,[R1] ; Store FPCCR
|
||||
B SVC_ContextRestore
|
||||
|
||||
SVC_ContextSave
|
||||
TST LR,#0x10 ; is it extended frame?
|
||||
#if (__FPU_PRESENT == 1)
|
||||
VSTMDBEQ R12!,{S16-S31} ; yes, stack also VFP hi-regs
|
||||
#endif
|
||||
MOVEQ R0,#0x01 ; os_tsk->stack_frame val
|
||||
MOVNE R0,#0x00
|
||||
STRB R0,[R1,#TCB_STACKF] ; os_tsk.run->stack_frame = val
|
||||
STMDB R12!,{R4-R11} ; Save Old context
|
||||
STR R12,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check ; Check for Stack overflow
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_ContextRestore
|
||||
STR R2,[R3] ; os_tsk.run = os_tsk.new
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
|
||||
LDMIA R12!,{R4-R11} ; Restore New Context
|
||||
LDRB R0,[R2,#TCB_STACKF] ; Stack Frame
|
||||
CMP R0,#0 ; Basic/Extended Stack Frame
|
||||
MVNEQ LR,#:NOT:0xFFFFFFFD ; set EXC_RETURN value
|
||||
MVNNE LR,#:NOT:0xFFFFFFED
|
||||
#if (__FPU_PRESENT == 1)
|
||||
VLDMIANE R12!,{S16-S31} ; restore VFP hi-registers
|
||||
#endif
|
||||
MSR PSP,R12 ; Write PSP
|
||||
|
||||
SVC_Exit
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUSH {LR}
|
||||
POP {PC}
|
||||
#else
|
||||
BX LR
|
||||
#endif
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User
|
||||
PUSH {R4,LR} ; Save Registers
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done ; Overflow
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LDR R4,[R4,R1,LSL #2] ; Load SVC Function Address
|
||||
|
||||
LDM R0,{R0-R3,R12} ; Read R0-R3,R12 from stack
|
||||
BLX R4 ; Call SVC Function
|
||||
|
||||
MRS R12,PSP
|
||||
STM R12,{R0-R3} ; Function return values
|
||||
SVC_Done
|
||||
POP {R4,PC} ; RETI
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
__asm void PendSV_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
#ifdef IFX_XMC4XXX
|
||||
EXPORT PendSV_Handler_Veneer
|
||||
PendSV_Handler_Veneer
|
||||
#endif
|
||||
|
||||
PUSH {R4,LR} ; Save EXC_RETURN
|
||||
BL __cpp(rt_pop_req)
|
||||
|
||||
Sys_Switch
|
||||
POP {R4,LR} ; Restore EXC_RETURN
|
||||
|
||||
LDR R3,=__cpp(&os_tsk)
|
||||
LDM R3,{R1,R2} ; os_tsk.run, os_tsk.new
|
||||
CMP R1,R2
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUSHEQ {LR}
|
||||
POPEQ {PC}
|
||||
#else
|
||||
BXEQ LR ; RETI, no task switch
|
||||
#endif
|
||||
|
||||
MRS R12,PSP ; Read PSP
|
||||
TST LR,#0x10 ; is it extended frame?
|
||||
#if (__FPU_PRESENT == 1)
|
||||
VSTMDBEQ R12!,{S16-S31} ; yes, stack also VFP hi-regs
|
||||
#endif
|
||||
MOVEQ R0,#0x01 ; os_tsk->stack_frame val
|
||||
MOVNE R0,#0x00
|
||||
STRB R0,[R1,#TCB_STACKF] ; os_tsk.run->stack_frame = val
|
||||
STMDB R12!,{R4-R11} ; Save Old context
|
||||
STR R12,[R1,#TCB_TSTACK] ; Update os_tsk.run->tsk_stack
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check ; Check for Stack overflow
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] ; os_tsk.run = os_tsk.new
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] ; os_tsk.new->tsk_stack
|
||||
LDMIA R12!,{R4-R11} ; Restore New Context
|
||||
LDRB R0,[R2,#TCB_STACKF] ; Stack Frame
|
||||
CMP R0,#0 ; Basic/Extended Stack Frame
|
||||
MVNEQ LR,#:NOT:0xFFFFFFFD ; set EXC_RETURN value
|
||||
MVNNE LR,#:NOT:0xFFFFFFED
|
||||
#if (__FPU_PRESENT == 1)
|
||||
VLDMIANE R12!,{S16-S31} ; restore VFP hi-regs
|
||||
#endif
|
||||
MSR PSP,R12 ; Write PSP
|
||||
|
||||
Sys_Exit
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUSH {LR}
|
||||
POP {PC}
|
||||
#else
|
||||
BX LR ; Return to Thread Mode
|
||||
#endif
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
__asm void SysTick_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
#ifdef IFX_XMC4XXX
|
||||
EXPORT SysTick_Handler_Veneer
|
||||
SysTick_Handler_Veneer
|
||||
#endif
|
||||
|
||||
PUSH {R4,LR} ; Save EXC_RETURN
|
||||
BL __cpp(rt_systick)
|
||||
B Sys_Switch
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
__asm void OS_Tick_Handler (void) {
|
||||
PRESERVE8
|
||||
|
||||
PUSH {R4,LR} ; Save EXC_RETURN
|
||||
BL __cpp(os_tick_irqack)
|
||||
BL __cpp(rt_systick)
|
||||
B Sys_Switch
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
AREA SVC_TABLE, CODE, READONLY
|
||||
|
||||
EXPORT SVC_Count
|
||||
|
||||
SVC_Cnt EQU (SVC_End-SVC_Table)/4
|
||||
SVC_Count DCD SVC_Cnt
|
||||
|
||||
; Import user SVC functions here.
|
||||
; IMPORT __SVC_1
|
||||
|
||||
EXPORT SVC_Table
|
||||
SVC_Table
|
||||
; Insert user SVC functions here. SVC 0 used by RTL Kernel.
|
||||
; DCD __SVC_1 ; user SVC function
|
||||
|
||||
SVC_End
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,419 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM4.S
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M4
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
.file "HAL_CM4.S"
|
||||
.syntax unified
|
||||
|
||||
.equ TCB_STACKF, 37
|
||||
.equ TCB_TSTACK, 44
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
.thumb
|
||||
|
||||
.section ".text"
|
||||
.align 2
|
||||
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
# void rt_set_PSP (U32 stack);
|
||||
|
||||
.thumb_func
|
||||
.type rt_set_PSP, %function
|
||||
.global rt_set_PSP
|
||||
rt_set_PSP:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size rt_set_PSP, .-rt_set_PSP
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
# U32 rt_get_PSP (void);
|
||||
|
||||
.thumb_func
|
||||
.type rt_get_PSP, %function
|
||||
.global rt_get_PSP
|
||||
rt_get_PSP:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size rt_get_PSP, .-rt_get_PSP
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
# void os_set_env (void);
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
|
||||
.thumb_func
|
||||
.type os_set_env, %function
|
||||
.global os_set_env
|
||||
os_set_env:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MOV R0,SP /* PSP = MSP */
|
||||
MSR PSP,R0
|
||||
LDR R0,=os_flags
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
ITE NE
|
||||
MOVNE R0,#0x02 /* Privileged Thread mode, use PSP */
|
||||
MOVEQ R0,#0x03 /* Unprivileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size os_set_env, .-os_set_env
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
# void *_alloc_box (void *box_mem);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
.thumb_func
|
||||
.type _alloc_box, %function
|
||||
.global _alloc_box
|
||||
_alloc_box:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
LDR R12,=rt_alloc_box
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
IT NE
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
IT EQ
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size _alloc_box, .-_alloc_box
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
# U32 _free_box (void *box_mem, void *box);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
.thumb_func
|
||||
.type _free_box, %function
|
||||
.global _free_box
|
||||
_free_box:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
LDR R12,=rt_free_box
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
IT NE
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
IT EQ
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
.fnend
|
||||
.size _free_box, .-_free_box
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
# void SVC_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type SVC_Handler, %function
|
||||
.global SVC_Handler
|
||||
SVC_Handler:
|
||||
.ifdef IFX_XMC4XXX
|
||||
.global SVC_Handler_Veneer
|
||||
SVC_Handler_Veneer:
|
||||
.endif
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
LDR R1,[R0,#24] /* Read Saved PC from Stack */
|
||||
LDRB R1,[R1,#-2] /* Load SVC Number */
|
||||
CBNZ R1,SVC_User
|
||||
|
||||
LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
|
||||
PUSH {R4,LR} /* Save EXC_RETURN */
|
||||
BLX R12 /* Call SVC Function */
|
||||
POP {R4,LR} /* Restore EXC_RETURN */
|
||||
|
||||
MRS R12,PSP /* Read PSP */
|
||||
STM R12,{R0-R2} /* Store return values */
|
||||
|
||||
LDR R3,=os_tsk
|
||||
LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
.ifdef IFX_XMC4XXX
|
||||
ITT EQ
|
||||
PUSHEQ {LR}
|
||||
POPEQ {PC}
|
||||
.else
|
||||
IT EQ
|
||||
BXEQ LR /* RETI, no task switch */
|
||||
.endif
|
||||
|
||||
CBNZ R1,SVC_ContextSave /* Runtask not deleted? */
|
||||
|
||||
TST LR,#0x10 /* is it extended frame? */
|
||||
BNE SVC_ContextRestore
|
||||
LDR R1,=0xE000EF34
|
||||
LDR R0,[R1] /* Load FPCCR */
|
||||
BIC R0,#1 /* Clear LSPACT (Lazy state) */
|
||||
STR R0,[R1] /* Store FPCCR */
|
||||
B SVC_ContextRestore
|
||||
|
||||
SVC_ContextSave:
|
||||
TST LR,#0x10 /* is it extended frame? */
|
||||
#ifdef __FPU_PRESENT
|
||||
ITTE EQ
|
||||
VSTMDBEQ R12!,{S16-S31} /* yes, stack also VFP hi-regs */
|
||||
#else
|
||||
ITE EQ
|
||||
#endif
|
||||
MOVEQ R0,#0x01 /* os_tsk->stack_frame val */
|
||||
MOVNE R0,#0x00
|
||||
STRB R0,[R1,#TCB_STACKF] /* os_tsk.run->stack_frame = val */
|
||||
STMDB R12!,{R4-R11} /* Save Old context */
|
||||
STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_ContextRestore:
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
LDMIA R12!,{R4-R11} /* Restore New Context */
|
||||
LDRB R0,[R2,#TCB_STACKF] /* Stack Frame */
|
||||
CMP R0,#0 /* Basic/Extended Stack Frame */
|
||||
#ifdef __FPU_PRESENT
|
||||
ITEE EQ
|
||||
#else
|
||||
ITE EQ
|
||||
#endif
|
||||
MVNEQ LR,#~0xFFFFFFFD /* set EXC_RETURN value */
|
||||
MVNNE LR,#~0xFFFFFFED
|
||||
#ifdef __FPU_PRESENT
|
||||
VLDMIANE R12!,{S16-S31} /* restore VFP hi-registers */
|
||||
#endif
|
||||
MSR PSP,R12 /* Write PSP */
|
||||
|
||||
SVC_Exit:
|
||||
.ifdef IFX_XMC4XXX
|
||||
PUSH {LR}
|
||||
POP {PC}
|
||||
.else
|
||||
BX LR
|
||||
.endif
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User:
|
||||
PUSH {R4,LR} /* Save Registers */
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done /* Overflow */
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LDR R4,[R4,R1,LSL #2] /* Load SVC Function Address */
|
||||
|
||||
LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
|
||||
BLX R4 /* Call SVC Function */
|
||||
|
||||
MRS R12,PSP
|
||||
STM R12,{R0-R3} /* Function return values */
|
||||
SVC_Done:
|
||||
POP {R4,PC} /* RETI */
|
||||
|
||||
.fnend
|
||||
.size SVC_Handler, .-SVC_Handler
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
# void PendSV_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type PendSV_Handler, %function
|
||||
.global PendSV_Handler
|
||||
.global Sys_Switch
|
||||
PendSV_Handler:
|
||||
.ifdef IFX_XMC4XXX
|
||||
.global PendSV_Handler_Veneer
|
||||
PendSV_Handler_Veneer:
|
||||
.endif
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
PUSH {R4,LR} /* Save EXC_RETURN */
|
||||
BL rt_pop_req
|
||||
|
||||
Sys_Switch:
|
||||
POP {R4,LR} /* Restore EXC_RETURN */
|
||||
|
||||
LDR R3,=os_tsk
|
||||
LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
.ifdef IFX_XMC4XXX
|
||||
ITT EQ
|
||||
PUSHEQ {LR}
|
||||
POPEQ {PC}
|
||||
.else
|
||||
IT EQ
|
||||
BXEQ LR /* RETI, no task switch */
|
||||
.endif
|
||||
|
||||
MRS R12,PSP /* Read PSP */
|
||||
TST LR,#0x10 /* is it extended frame? */
|
||||
#ifdef __FPU_PRESENT
|
||||
ITTE EQ
|
||||
VSTMDBEQ R12!,{S16-S31} /* yes, stack also VFP hi-regs */
|
||||
#else
|
||||
ITE EQ
|
||||
#endif
|
||||
MOVEQ R0,#0x01 /* os_tsk->stack_frame val */
|
||||
MOVNE R0,#0x00
|
||||
STRB R0,[R1,#TCB_STACKF] /* os_tsk.run->stack_frame = val */
|
||||
STMDB R12!,{R4-R11} /* Save Old context */
|
||||
STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
LDMIA R12!,{R4-R11} /* Restore New Context */
|
||||
LDRB R0,[R2,#TCB_STACKF] /* Stack Frame */
|
||||
CMP R0,#0 /* Basic/Extended Stack Frame */
|
||||
#ifdef __FPU_PRESENT
|
||||
ITEE EQ
|
||||
#else
|
||||
ITE EQ
|
||||
#endif
|
||||
MVNEQ LR,#~0xFFFFFFFD /* set EXC_RETURN value */
|
||||
MVNNE LR,#~0xFFFFFFED
|
||||
#ifdef __FPU_PRESENT
|
||||
VLDMIANE R12!,{S16-S31} /* restore VFP hi-registers */
|
||||
#endif
|
||||
MSR PSP,R12 /* Write PSP */
|
||||
|
||||
Sys_Exit:
|
||||
.ifdef IFX_XMC4XXX
|
||||
PUSH {LR}
|
||||
POP {PC}
|
||||
.else
|
||||
BX LR /* Return to Thread Mode */
|
||||
.endif
|
||||
|
||||
.fnend
|
||||
.size PendSV_Handler, .-PendSV_Handler
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
# void SysTick_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type SysTick_Handler, %function
|
||||
.global SysTick_Handler
|
||||
SysTick_Handler:
|
||||
.ifdef IFX_XMC4XXX
|
||||
.global SysTick_Handler_Veneer
|
||||
SysTick_Handler_Veneer:
|
||||
.endif
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
PUSH {R4,LR} /* Save EXC_RETURN */
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
.fnend
|
||||
.size SysTick_Handler, .-SysTick_Handler
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
# void OS_Tick_Handler (void);
|
||||
|
||||
.thumb_func
|
||||
.type OS_Tick_Handler, %function
|
||||
.global OS_Tick_Handler
|
||||
OS_Tick_Handler:
|
||||
.fnstart
|
||||
.cantunwind
|
||||
|
||||
PUSH {R4,LR} /* Save EXC_RETURN */
|
||||
BL os_tick_irqack
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
.fnend
|
||||
.size OS_Tick_Handler, .-OS_Tick_Handler
|
||||
|
||||
|
||||
.end
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,56 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
.file "SVC_Table.S"
|
||||
|
||||
|
||||
.section ".svc_table"
|
||||
|
||||
.global SVC_Table
|
||||
SVC_Table:
|
||||
/* Insert user SVC functions here. SVC 0 used by RTL Kernel. */
|
||||
# .long __SVC_1 /* user SVC function */
|
||||
SVC_End:
|
||||
|
||||
.global SVC_Count
|
||||
SVC_Count:
|
||||
.long (SVC_End-SVC_Table)/4
|
||||
|
||||
|
||||
.end
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,363 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: HAL_CM4.S
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M4
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
NAME HAL_CM4.S
|
||||
|
||||
#define TCB_STACKF 37
|
||||
#define TCB_TSTACK 44
|
||||
|
||||
EXTERN os_flags
|
||||
EXTERN os_tsk
|
||||
EXTERN rt_alloc_box
|
||||
EXTERN rt_free_box
|
||||
EXTERN rt_stk_check
|
||||
EXTERN rt_pop_req
|
||||
EXTERN rt_systick
|
||||
EXTERN os_tick_irqack
|
||||
EXTERN SVC_Table
|
||||
EXTERN SVC_Count
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
SECTION .text:CODE:NOROOT(2)
|
||||
THUMB
|
||||
|
||||
/*--------------------------- rt_set_PSP ------------------------------------*/
|
||||
|
||||
; void rt_set_PSP (U32 stack);
|
||||
|
||||
PUBLIC rt_set_PSP
|
||||
rt_set_PSP:
|
||||
|
||||
MSR PSP,R0
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- rt_get_PSP ------------------------------------*/
|
||||
|
||||
; U32 rt_get_PSP (void);
|
||||
|
||||
PUBLIC rt_get_PSP
|
||||
rt_get_PSP:
|
||||
|
||||
MRS R0,PSP
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- os_set_env ------------------------------------*/
|
||||
|
||||
; void os_set_env (void);
|
||||
/* Switch to Unprivileged/Privileged Thread mode, use PSP. */
|
||||
|
||||
PUBLIC os_set_env
|
||||
os_set_env:
|
||||
|
||||
MOV R0,SP /* PSP = MSP */
|
||||
MSR PSP,R0
|
||||
LDR R0,=os_flags
|
||||
LDRB R0,[R0]
|
||||
LSLS R0,#31
|
||||
ITE NE
|
||||
MOVNE R0,#0x02 /* Privileged Thread mode, use PSP */
|
||||
MOVEQ R0,#0x03 /* Unprivileged Thread mode, use PSP */
|
||||
MSR CONTROL,R0
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- _alloc_box ------------------------------------*/
|
||||
|
||||
; void *_alloc_box (void *box_mem);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
PUBLIC _alloc_box
|
||||
_alloc_box:
|
||||
|
||||
LDR R12,=rt_alloc_box
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
IT NE
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
IT EQ
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
|
||||
/*--------------------------- _free_box -------------------------------------*/
|
||||
|
||||
; U32 _free_box (void *box_mem, void *box);
|
||||
/* Function wrapper for Unprivileged/Privileged mode. */
|
||||
|
||||
PUBLIC _free_box
|
||||
_free_box:
|
||||
|
||||
LDR R12,=rt_free_box
|
||||
MRS R3,IPSR
|
||||
LSLS R3,#24
|
||||
IT NE
|
||||
BXNE R12
|
||||
MRS R3,CONTROL
|
||||
LSLS R3,#31
|
||||
IT EQ
|
||||
BXEQ R12
|
||||
SVC 0
|
||||
BX LR
|
||||
|
||||
|
||||
/*-------------------------- SVC_Handler ------------------------------------*/
|
||||
|
||||
; void SVC_Handler (void);
|
||||
|
||||
PUBLIC SVC_Handler
|
||||
SVC_Handler:
|
||||
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUBLIC SVC_Handler_Veneer
|
||||
SVC_Handler_Veneer:
|
||||
#endif
|
||||
|
||||
MRS R0,PSP /* Read PSP */
|
||||
LDR R1,[R0,#24] /* Read Saved PC from Stack */
|
||||
LDRB R1,[R1,#-2] /* Load SVC Number */
|
||||
CBNZ R1,SVC_User
|
||||
|
||||
LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
|
||||
PUSH {R4,LR} /* Save EXC_RETURN */
|
||||
BLX R12 /* Call SVC Function */
|
||||
POP {R4,LR} /* Restore EXC_RETURN */
|
||||
|
||||
MRS R12,PSP /* Read PSP */
|
||||
STM R12,{R0-R2} /* Store return values */
|
||||
|
||||
LDR R3,=os_tsk
|
||||
LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
#ifdef IFX_XMC4XXX
|
||||
ITT EQ
|
||||
PUSHEQ {LR}
|
||||
POPEQ {PC}
|
||||
#else
|
||||
IT EQ
|
||||
BXEQ LR /* RETI, no task switch */
|
||||
#endif
|
||||
|
||||
CBNZ R1,SVC_ContextSave /* Runtask not deleted? */
|
||||
|
||||
TST LR,#0x10 /* is it extended frame? */
|
||||
BNE SVC_ContextRestore
|
||||
LDR R1,=0xE000EF34
|
||||
LDR R0,[R1] /* Load FPCCR */
|
||||
BIC R0,R0,#1 /* Clear LSPACT (Lazy state) */
|
||||
STR R0,[R1] /* Store FPCCR */
|
||||
B SVC_ContextRestore
|
||||
|
||||
SVC_ContextSave:
|
||||
TST LR,#0x10 /* is it extended frame? */
|
||||
#if (__FPU_PRESENT == 1)
|
||||
ITTE EQ
|
||||
VSTMDBEQ R12!,{S16-S31} /* yes, stack also VFP hi-regs */
|
||||
#else
|
||||
ITE EQ
|
||||
#endif
|
||||
MOVEQ R0,#0x01 /* os_tsk->stack_frame val */
|
||||
MOVNE R0,#0x00
|
||||
STRB R0,[R1,#TCB_STACKF] /* os_tsk.run->stack_frame = val */
|
||||
STMDB R12!,{R4-R11} /* Save Old context */
|
||||
STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
SVC_ContextRestore:
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
LDMIA R12!,{R4-R11} /* Restore New Context */
|
||||
LDRB R0,[R2,#TCB_STACKF] /* Stack Frame */
|
||||
CMP R0,#0 /* Basic/Extended Stack Frame */
|
||||
#if (__FPU_PRESENT == 1)
|
||||
ITEE EQ
|
||||
#else
|
||||
ITE EQ
|
||||
#endif
|
||||
MVNEQ LR,#~0xFFFFFFFD /* set EXC_RETURN value */
|
||||
MVNNE LR,#~0xFFFFFFED
|
||||
#if (__FPU_PRESENT == 1)
|
||||
VLDMIANE R12!,{S16-S31} /* restore VFP hi-registers */
|
||||
#endif
|
||||
MSR PSP,R12 /* Write PSP */
|
||||
|
||||
SVC_Exit:
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUSH {LR}
|
||||
POP {PC}
|
||||
#else
|
||||
BX LR
|
||||
#endif
|
||||
|
||||
/*------------------- User SVC ------------------------------*/
|
||||
|
||||
SVC_User:
|
||||
PUSH {R4,LR} /* Save Registers */
|
||||
LDR R2,=SVC_Count
|
||||
LDR R2,[R2]
|
||||
CMP R1,R2
|
||||
BHI SVC_Done /* Overflow */
|
||||
|
||||
LDR R4,=SVC_Table-4
|
||||
LDR R4,[R4,R1,LSL #2] /* Load SVC Function Address */
|
||||
|
||||
LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
|
||||
BLX R4 /* Call SVC Function */
|
||||
|
||||
MRS R12,PSP
|
||||
STM R12,{R0-R3} /* Function return values */
|
||||
SVC_Done:
|
||||
POP {R4,PC} /* RETI */
|
||||
|
||||
|
||||
/*-------------------------- PendSV_Handler ---------------------------------*/
|
||||
|
||||
; void PendSV_Handler (void);
|
||||
|
||||
PUBLIC PendSV_Handler
|
||||
PendSV_Handler:
|
||||
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUBLIC PendSV_Handler_Veneer
|
||||
PendSV_Handler_Veneer:
|
||||
#endif
|
||||
|
||||
PUSH {R4,LR} /* Save EXC_RETURN */
|
||||
BL rt_pop_req
|
||||
|
||||
Sys_Switch:
|
||||
POP {R4,LR} /* Restore EXC_RETURN */
|
||||
|
||||
LDR R3,=os_tsk
|
||||
LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
|
||||
CMP R1,R2
|
||||
#ifdef IFX_XMC4XXX
|
||||
ITT EQ
|
||||
PUSHEQ {LR}
|
||||
POPEQ {PC}
|
||||
#else
|
||||
IT EQ
|
||||
BXEQ LR /* RETI, no task switch */
|
||||
#endif
|
||||
|
||||
MRS R12,PSP /* Read PSP */
|
||||
TST LR,#0x10 /* is it extended frame? */
|
||||
#if (__FPU_PRESENT == 1)
|
||||
ITTE EQ
|
||||
VSTMDBEQ R12!,{S16-S31} /* yes, stack also VFP hi-regs */
|
||||
#else
|
||||
ITE EQ
|
||||
#endif
|
||||
MOVEQ R0,#0x01 /* os_tsk->stack_frame val */
|
||||
MOVNE R0,#0x00
|
||||
STRB R0,[R1,#TCB_STACKF] /* os_tsk.run->stack_frame = val */
|
||||
STMDB R12!,{R4-R11} /* Save Old context */
|
||||
STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
|
||||
|
||||
PUSH {R2,R3}
|
||||
BL rt_stk_check /* Check for Stack overflow */
|
||||
POP {R2,R3}
|
||||
|
||||
STR R2,[R3] /* os_tsk.run = os_tsk.new */
|
||||
|
||||
LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
|
||||
LDMIA R12!,{R4-R11} /* Restore New Context */
|
||||
LDRB R0,[R2,#TCB_STACKF] /* Stack Frame */
|
||||
CMP R0,#0 /* Basic/Extended Stack Frame */
|
||||
#if (__FPU_PRESENT == 1)
|
||||
ITEE EQ
|
||||
#else
|
||||
ITE EQ
|
||||
#endif
|
||||
MVNEQ LR,#~0xFFFFFFFD /* set EXC_RETURN value */
|
||||
MVNNE LR,#~0xFFFFFFED
|
||||
#if (__FPU_PRESENT == 1)
|
||||
VLDMIANE R12!,{S16-S31} /* restore VFP hi-registers */
|
||||
#endif
|
||||
MSR PSP,R12 /* Write PSP */
|
||||
|
||||
Sys_Exit:
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUSH {LR}
|
||||
POP {PC}
|
||||
#else
|
||||
BX LR /* Return to Thread Mode */
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------- SysTick_Handler --------------------------------*/
|
||||
|
||||
; void SysTick_Handler (void);
|
||||
|
||||
PUBLIC SysTick_Handler
|
||||
SysTick_Handler:
|
||||
#ifdef IFX_XMC4XXX
|
||||
PUBLIC SysTick_Handler_Veneer
|
||||
SysTick_Handler_Veneer:
|
||||
#endif
|
||||
|
||||
PUSH {R4,LR} /* Save EXC_RETURN */
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
|
||||
/*-------------------------- OS_Tick_Handler --------------------------------*/
|
||||
|
||||
; void OS_Tick_Handler (void);
|
||||
|
||||
PUBLIC OS_Tick_Handler
|
||||
OS_Tick_Handler:
|
||||
|
||||
PUSH {R4,LR} /* Save EXC_RETURN */
|
||||
BL os_tick_irqack
|
||||
BL rt_systick
|
||||
B Sys_Switch
|
||||
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,58 +0,0 @@
|
|||
;/*----------------------------------------------------------------------------
|
||||
; * CMSIS-RTOS - RTX
|
||||
; *----------------------------------------------------------------------------
|
||||
; * Name: SVC_TABLE.S
|
||||
; * Purpose: Pre-defined SVC Table for Cortex-M
|
||||
; * Rev.: V4.70
|
||||
; *----------------------------------------------------------------------------
|
||||
; *
|
||||
; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
; * All rights reserved.
|
||||
; * Redistribution and use in source and binary forms, with or without
|
||||
; * modification, are permitted provided that the following conditions are met:
|
||||
; * - Redistributions of source code must retain the above copyright
|
||||
; * notice, this list of conditions and the following disclaimer.
|
||||
; * - 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.
|
||||
; * - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
; *---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
NAME SVC_TABLE
|
||||
SECTION .text:CONST (2)
|
||||
|
||||
PUBLIC SVC_Count
|
||||
|
||||
SVC_Cnt EQU (SVC_End-SVC_Table)/4
|
||||
SVC_Count DCD SVC_Cnt
|
||||
|
||||
; Import user SVC functions here.
|
||||
; IMPORT __SVC_1
|
||||
|
||||
PUBLIC SVC_Table
|
||||
SVC_Table
|
||||
; Insert user SVC functions here. SVC 0 used by RTL Kernel.
|
||||
; DCD __SVC_1 ; user SVC function
|
||||
|
||||
SVC_End
|
||||
|
||||
END
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,747 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/* ----------------------------------------------------------------------
|
||||
* $Date: 5. February 2013
|
||||
* $Revision: V1.02
|
||||
*
|
||||
* Project: CMSIS-RTOS API
|
||||
* Title: cmsis_os.h RTX header file
|
||||
*
|
||||
* Version 0.02
|
||||
* Initial Proposal Phase
|
||||
* Version 0.03
|
||||
* osKernelStart added, optional feature: main started as thread
|
||||
* osSemaphores have standard behavior
|
||||
* osTimerCreate does not start the timer, added osTimerStart
|
||||
* osThreadPass is renamed to osThreadYield
|
||||
* Version 1.01
|
||||
* Support for C++ interface
|
||||
* - const attribute removed from the osXxxxDef_t typedef's
|
||||
* - const attribute added to the osXxxxDef macros
|
||||
* Added: osTimerDelete, osMutexDelete, osSemaphoreDelete
|
||||
* Added: osKernelInitialize
|
||||
* Version 1.02
|
||||
* Control functions for short timeouts in microsecond resolution:
|
||||
* Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec
|
||||
* Removed: osSignalGet
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 2013 ARM LIMITED
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _CMSIS_OS_H
|
||||
#define _CMSIS_OS_H
|
||||
|
||||
#define CMSIS_OS_RTX
|
||||
|
||||
// __MBED_CMSIS_RTOS_CM captures our changes to the RTX kernel
|
||||
#ifndef __MBED_CMSIS_RTOS_CM
|
||||
#define __MBED_CMSIS_RTOS_CM
|
||||
#endif
|
||||
// we use __CMSIS_RTOS version, which changes some API in the kernel
|
||||
#ifndef __CMSIS_RTOS
|
||||
#define __CMSIS_RTOS
|
||||
#endif
|
||||
|
||||
// The stack space occupied is mainly dependent on the underling C standard library
|
||||
#if defined(TOOLCHAIN_GCC) || defined(TOOLCHAIN_ARM_STD) || defined(TOOLCHAIN_IAR)
|
||||
# define WORDS_STACK_SIZE 512
|
||||
#elif defined(TOOLCHAIN_ARM_MICRO)
|
||||
# define WORDS_STACK_SIZE 128
|
||||
#endif
|
||||
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
|
||||
/* Single thread - disable timers and set task count to one */
|
||||
#if defined(MBED_RTOS_SINGLE_THREAD)
|
||||
#define OS_TASKCNT 1
|
||||
#define OS_TIMERS 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(TARGET_XDOT_L151CC)
|
||||
#define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE/2)
|
||||
#else
|
||||
#define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4)
|
||||
#endif
|
||||
|
||||
#define osCMSIS 0x10002U ///< CMSIS-RTOS API version (main [31:16] .sub [15:0])
|
||||
|
||||
#define osCMSIS_RTX ((4<<16)|80) ///< RTOS identification and version (main [31:16] .sub [15:0])
|
||||
|
||||
#define osKernelSystemId "RTX V4.80" ///< RTOS identification string
|
||||
|
||||
|
||||
#define osFeature_MainThread 1 ///< main can be thread
|
||||
#define osFeature_Pool 1 ///< Memory Pools available
|
||||
#define osFeature_MailQ 1 ///< Mail Queues available
|
||||
#define osFeature_MessageQ 1 ///< Message Queues available
|
||||
#define osFeature_Signals 16 ///< 16 Signal Flags available per thread
|
||||
#define osFeature_Semaphore 65535 ///< Maximum count for \ref osSemaphoreCreate function
|
||||
#define osFeature_Wait 0 ///< osWait not available
|
||||
#define osFeature_SysTick 1 ///< osKernelSysTick functions available
|
||||
#define osFeature_ThreadEnum 1 ///< Thread enumeration available
|
||||
|
||||
#if defined (__CC_ARM)
|
||||
#define os_InRegs __value_in_regs // Compiler specific: force struct in registers
|
||||
#elif defined (__ICCARM__)
|
||||
#define os_InRegs __value_in_regs // Compiler specific: force struct in registers
|
||||
#else
|
||||
#define os_InRegs
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
// ==== Enumeration, structures, defines ====
|
||||
|
||||
/// Priority used for thread control.
|
||||
typedef enum {
|
||||
osPriorityIdle = -3, ///< priority: idle (lowest)
|
||||
osPriorityLow = -2, ///< priority: low
|
||||
osPriorityBelowNormal = -1, ///< priority: below normal
|
||||
osPriorityNormal = 0, ///< priority: normal (default)
|
||||
osPriorityAboveNormal = +1, ///< priority: above normal
|
||||
osPriorityHigh = +2, ///< priority: high
|
||||
osPriorityRealtime = +3, ///< priority: realtime (highest)
|
||||
osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
|
||||
} osPriority;
|
||||
|
||||
/// Timeout value.
|
||||
#define osWaitForever 0xFFFFFFFFU ///< wait forever timeout value
|
||||
|
||||
/// Status code values returned by CMSIS-RTOS functions.
|
||||
typedef enum {
|
||||
osOK = 0, ///< function completed; no error or event occurred.
|
||||
osEventSignal = 0x08, ///< function completed; signal event occurred.
|
||||
osEventMessage = 0x10, ///< function completed; message event occurred.
|
||||
osEventMail = 0x20, ///< function completed; mail event occurred.
|
||||
osEventTimeout = 0x40, ///< function completed; timeout occurred.
|
||||
osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object.
|
||||
osErrorResource = 0x81, ///< resource not available: a specified resource was not available.
|
||||
osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period.
|
||||
osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines.
|
||||
osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object.
|
||||
osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority.
|
||||
osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation.
|
||||
osErrorValue = 0x86, ///< value of a parameter is out of range.
|
||||
osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits.
|
||||
os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization.
|
||||
} osStatus;
|
||||
|
||||
|
||||
/// Timer type value for the timer definition.
|
||||
typedef enum {
|
||||
osTimerOnce = 0, ///< one-shot timer
|
||||
osTimerPeriodic = 1 ///< repeating timer
|
||||
} os_timer_type;
|
||||
|
||||
typedef enum {
|
||||
osThreadInfoState,
|
||||
osThreadInfoStackSize,
|
||||
osThreadInfoStackMax,
|
||||
osThreadInfoEntry,
|
||||
osThreadInfoArg,
|
||||
|
||||
osThreadInfo_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization.
|
||||
} osThreadInfo;
|
||||
|
||||
/// Entry point of a thread.
|
||||
typedef void (*os_pthread) (void const *argument);
|
||||
|
||||
/// Entry point of a timer call back function.
|
||||
typedef void (*os_ptimer) (void const *argument);
|
||||
|
||||
// >>> the following data type definitions may shall adapted towards a specific RTOS
|
||||
|
||||
/// Thread ID identifies the thread (pointer to a thread control block).
|
||||
typedef struct os_thread_cb *osThreadId;
|
||||
|
||||
/// Timer ID identifies the timer (pointer to a timer control block).
|
||||
typedef struct os_timer_cb *osTimerId;
|
||||
|
||||
/// Mutex ID identifies the mutex (pointer to a mutex control block).
|
||||
typedef struct os_mutex_cb *osMutexId;
|
||||
|
||||
/// Semaphore ID identifies the semaphore (pointer to a semaphore control block).
|
||||
typedef struct os_semaphore_cb *osSemaphoreId;
|
||||
|
||||
/// Pool ID identifies the memory pool (pointer to a memory pool control block).
|
||||
typedef struct os_pool_cb *osPoolId;
|
||||
|
||||
/// Message ID identifies the message queue (pointer to a message queue control block).
|
||||
typedef struct os_messageQ_cb *osMessageQId;
|
||||
|
||||
/// Mail ID identifies the mail queue (pointer to a mail queue control block).
|
||||
typedef struct os_mailQ_cb *osMailQId;
|
||||
|
||||
/// Thread enumeration ID identifies the enumeration (pointer to a thread enumeration control block).
|
||||
typedef uint32_t *osThreadEnumId;
|
||||
|
||||
/// Thread Definition structure contains startup information of a thread.
|
||||
typedef struct os_thread_def {
|
||||
os_pthread pthread; ///< start address of thread function
|
||||
osPriority tpriority; ///< initial thread priority
|
||||
uint32_t instances; ///< maximum number of instances of that thread function
|
||||
uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
uint32_t *stack_pointer; ///< pointer to the stack memory block
|
||||
#endif
|
||||
} osThreadDef_t;
|
||||
|
||||
/// Timer Definition structure contains timer parameters.
|
||||
typedef struct os_timer_def {
|
||||
os_ptimer ptimer; ///< start address of a timer function
|
||||
void *timer; ///< pointer to internal data
|
||||
} osTimerDef_t;
|
||||
|
||||
/// Mutex Definition structure contains setup information for a mutex.
|
||||
typedef struct os_mutex_def {
|
||||
void *mutex; ///< pointer to internal data
|
||||
} osMutexDef_t;
|
||||
|
||||
/// Semaphore Definition structure contains setup information for a semaphore.
|
||||
typedef struct os_semaphore_def {
|
||||
void *semaphore; ///< pointer to internal data
|
||||
} osSemaphoreDef_t;
|
||||
|
||||
/// Definition structure for memory block allocation.
|
||||
typedef struct os_pool_def {
|
||||
uint32_t pool_sz; ///< number of items (elements) in the pool
|
||||
uint32_t item_sz; ///< size of an item
|
||||
void *pool; ///< pointer to memory for pool
|
||||
} osPoolDef_t;
|
||||
|
||||
/// Definition structure for message queue.
|
||||
typedef struct os_messageQ_def {
|
||||
uint32_t queue_sz; ///< number of elements in the queue
|
||||
void *pool; ///< memory array for messages
|
||||
} osMessageQDef_t;
|
||||
|
||||
/// Definition structure for mail queue.
|
||||
typedef struct os_mailQ_def {
|
||||
uint32_t queue_sz; ///< number of elements in the queue
|
||||
uint32_t item_sz; ///< size of an item
|
||||
void *pool; ///< memory array for mail
|
||||
} osMailQDef_t;
|
||||
|
||||
/// Event structure contains detailed information about an event.
|
||||
typedef struct {
|
||||
osStatus status; ///< status code: event or error information
|
||||
union {
|
||||
uint32_t v; ///< message as 32-bit value
|
||||
void *p; ///< message or mail as void pointer
|
||||
int32_t signals; ///< signal flags
|
||||
} value; ///< event value
|
||||
union {
|
||||
osMailQId mail_id; ///< mail id obtained by \ref osMailCreate
|
||||
osMessageQId message_id; ///< message id obtained by \ref osMessageCreate
|
||||
} def; ///< event definition
|
||||
} osEvent;
|
||||
|
||||
|
||||
// ==== Kernel Control Functions ====
|
||||
|
||||
/// Initialize the RTOS Kernel for creating objects.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osKernelInitialize (void);
|
||||
|
||||
/// Start the RTOS Kernel.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osKernelStart (void);
|
||||
|
||||
/// Check if the RTOS kernel is already started.
|
||||
/// \return 0 RTOS is not started, 1 RTOS is started.
|
||||
int32_t osKernelRunning(void);
|
||||
|
||||
#if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available
|
||||
|
||||
/// \cond INTERNAL_VARIABLES
|
||||
extern uint32_t const os_tickfreq;
|
||||
extern uint16_t const os_tickus_i;
|
||||
extern uint16_t const os_tickus_f;
|
||||
/// \endcond
|
||||
|
||||
/// Get the RTOS kernel system timer counter.
|
||||
/// \return RTOS kernel system timer as 32-bit value
|
||||
uint32_t osKernelSysTick (void);
|
||||
|
||||
/// The RTOS kernel system timer frequency in Hz.
|
||||
/// \note Reflects the system timer setting and is typically defined in a configuration file.
|
||||
#define osKernelSysTickFrequency os_tickfreq
|
||||
|
||||
/// Convert a microseconds value to a RTOS kernel system timer value.
|
||||
/// \param microsec time value in microseconds.
|
||||
/// \return time value normalized to the \ref osKernelSysTickFrequency
|
||||
/*
|
||||
#define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000)
|
||||
*/
|
||||
#define osKernelSysTickMicroSec(microsec) ((microsec * os_tickus_i) + ((microsec * os_tickus_f) >> 16))
|
||||
|
||||
#endif // System Timer available
|
||||
|
||||
// ==== Thread Management ====
|
||||
|
||||
/// Create a Thread Definition with function, priority, and stack requirements.
|
||||
/// \param name name of the thread function.
|
||||
/// \param priority initial priority of the thread function.
|
||||
/// \param instances number of possible thread instances.
|
||||
/// \param stacksz stack size (in bytes) requirements for the thread function.
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osThreadDef(name, priority, instances, stacksz) \
|
||||
extern const osThreadDef_t os_thread_def_##name
|
||||
#else // define the object
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
#define osThreadDef(name, priority, stacksz) \
|
||||
uint32_t os_thread_def_stack_##name [stacksz / sizeof(uint32_t)]; \
|
||||
const osThreadDef_t os_thread_def_##name = \
|
||||
{ (name), (priority), 1, (stacksz), (os_thread_def_stack_##name) }
|
||||
#else
|
||||
#define osThreadDef(name, priority, instances, stacksz) \
|
||||
const osThreadDef_t os_thread_def_##name = \
|
||||
{ (name), (priority), (instances), (stacksz) }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/// Access a Thread definition.
|
||||
/// \param name name of the thread definition object.
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#define osThread(name) \
|
||||
&os_thread_def_##name
|
||||
|
||||
/// Create a thread and add it to Active Threads and set it to state READY.
|
||||
/// \param[in] thread_def thread definition referenced with \ref osThread.
|
||||
/// \param[in] argument pointer that is passed to the thread function as start argument.
|
||||
/// \return thread ID for reference by other functions or NULL in case of error.
|
||||
osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument);
|
||||
|
||||
osThreadId osThreadContextCreate (const osThreadDef_t *thread_def, void *argument, void *context);
|
||||
|
||||
/// Return the thread ID of the current running thread.
|
||||
/// \return thread ID for reference by other functions or NULL in case of error.
|
||||
osThreadId osThreadGetId (void);
|
||||
|
||||
/// Terminate execution of a thread and remove it from Active Threads.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osThreadTerminate (osThreadId thread_id);
|
||||
|
||||
/// Pass control to next thread that is in state \b READY.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osThreadYield (void);
|
||||
|
||||
/// Change priority of an active thread.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \param[in] priority new priority value for the thread function.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
|
||||
|
||||
/// Get current priority of an active thread.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \return current priority value of the thread function.
|
||||
osPriority osThreadGetPriority (osThreadId thread_id);
|
||||
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
/// Get current thread state.
|
||||
uint8_t osThreadGetState (osThreadId thread_id);
|
||||
#endif
|
||||
|
||||
/// Get into from an active thread.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \param[in] info information to read.
|
||||
/// \return current state of the thread function.
|
||||
/// \return requested info that includes the status code.
|
||||
os_InRegs osEvent _osThreadGetInfo(osThreadId thread_id, osThreadInfo info);
|
||||
|
||||
// ==== Generic Wait Functions ====
|
||||
|
||||
/// Wait for Timeout (Time Delay).
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "Time delay" value
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osDelay (uint32_t millisec);
|
||||
|
||||
#if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available
|
||||
|
||||
/// Wait for Signal, Message, Mail, or Timeout.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
|
||||
/// \return event that contains signal, message, or mail information or error code.
|
||||
os_InRegs osEvent osWait (uint32_t millisec);
|
||||
|
||||
#endif // Generic Wait available
|
||||
|
||||
|
||||
// ==== Timer Management Functions ====
|
||||
/// Define a Timer object.
|
||||
/// \param name name of the timer object.
|
||||
/// \param function name of the timer call back function.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osTimerDef(name, function) \
|
||||
extern const osTimerDef_t os_timer_def_##name
|
||||
#else // define the object
|
||||
#define osTimerDef(name, function) \
|
||||
uint32_t os_timer_cb_##name[6]; \
|
||||
const osTimerDef_t os_timer_def_##name = \
|
||||
{ (function), (os_timer_cb_##name) }
|
||||
#endif
|
||||
|
||||
/// Access a Timer definition.
|
||||
/// \param name name of the timer object.
|
||||
#define osTimer(name) \
|
||||
&os_timer_def_##name
|
||||
|
||||
/// Create a timer.
|
||||
/// \param[in] timer_def timer object referenced with \ref osTimer.
|
||||
/// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
|
||||
/// \param[in] argument argument to the timer call back function.
|
||||
/// \return timer ID for reference by other functions or NULL in case of error.
|
||||
osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument);
|
||||
|
||||
/// Start or restart a timer.
|
||||
/// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "Time delay" value of the timer.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
|
||||
|
||||
/// Stop the timer.
|
||||
/// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osTimerStop (osTimerId timer_id);
|
||||
|
||||
/// Delete a timer that was created by \ref osTimerCreate.
|
||||
/// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osTimerDelete (osTimerId timer_id);
|
||||
|
||||
|
||||
// ==== Signal Management ====
|
||||
|
||||
/// Set the specified Signal Flags of an active thread.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \param[in] signals specifies the signal flags of the thread that should be set.
|
||||
/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
|
||||
int32_t osSignalSet (osThreadId thread_id, int32_t signals);
|
||||
|
||||
/// Clear the specified Signal Flags of an active thread.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \param[in] signals specifies the signal flags of the thread that shall be cleared.
|
||||
/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR.
|
||||
int32_t osSignalClear (osThreadId thread_id, int32_t signals);
|
||||
|
||||
/// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
|
||||
/// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
|
||||
/// \return event flag information or error code.
|
||||
os_InRegs osEvent osSignalWait (int32_t signals, uint32_t millisec);
|
||||
|
||||
|
||||
// ==== Mutex Management ====
|
||||
|
||||
/// Define a Mutex.
|
||||
/// \param name name of the mutex object.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osMutexDef(name) \
|
||||
extern const osMutexDef_t os_mutex_def_##name
|
||||
#else // define the object
|
||||
#define osMutexDef(name) \
|
||||
uint32_t os_mutex_cb_##name[4] = { 0 }; \
|
||||
const osMutexDef_t os_mutex_def_##name = { (os_mutex_cb_##name) }
|
||||
#endif
|
||||
|
||||
/// Access a Mutex definition.
|
||||
/// \param name name of the mutex object.
|
||||
#define osMutex(name) \
|
||||
&os_mutex_def_##name
|
||||
|
||||
/// Create and Initialize a Mutex object.
|
||||
/// \param[in] mutex_def mutex definition referenced with \ref osMutex.
|
||||
/// \return mutex ID for reference by other functions or NULL in case of error.
|
||||
osMutexId osMutexCreate (const osMutexDef_t *mutex_def);
|
||||
|
||||
/// Wait until a Mutex becomes available.
|
||||
/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
|
||||
|
||||
/// Release a Mutex that was obtained by \ref osMutexWait.
|
||||
/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osMutexRelease (osMutexId mutex_id);
|
||||
|
||||
/// Delete a Mutex that was created by \ref osMutexCreate.
|
||||
/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osMutexDelete (osMutexId mutex_id);
|
||||
|
||||
|
||||
// ==== Semaphore Management Functions ====
|
||||
|
||||
#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available
|
||||
|
||||
/// Define a Semaphore object.
|
||||
/// \param name name of the semaphore object.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osSemaphoreDef(name) \
|
||||
extern const osSemaphoreDef_t os_semaphore_def_##name
|
||||
#else // define the object
|
||||
#define osSemaphoreDef(name) \
|
||||
uint32_t os_semaphore_cb_##name[2] = { 0 }; \
|
||||
const osSemaphoreDef_t os_semaphore_def_##name = { (os_semaphore_cb_##name) }
|
||||
#endif
|
||||
|
||||
/// Access a Semaphore definition.
|
||||
/// \param name name of the semaphore object.
|
||||
#define osSemaphore(name) \
|
||||
&os_semaphore_def_##name
|
||||
|
||||
/// Create and Initialize a Semaphore object used for managing resources.
|
||||
/// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore.
|
||||
/// \param[in] count number of available resources.
|
||||
/// \return semaphore ID for reference by other functions or NULL in case of error.
|
||||
osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count);
|
||||
|
||||
/// Wait until a Semaphore token becomes available.
|
||||
/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
|
||||
/// \return number of available tokens, or -1 in case of incorrect parameters.
|
||||
int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);
|
||||
|
||||
/// Release a Semaphore token.
|
||||
/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
|
||||
|
||||
/// Delete a Semaphore that was created by \ref osSemaphoreCreate.
|
||||
/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);
|
||||
|
||||
#endif // Semaphore available
|
||||
|
||||
|
||||
// ==== Memory Pool Management Functions ====
|
||||
|
||||
#if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available
|
||||
|
||||
/// \brief Define a Memory Pool.
|
||||
/// \param name name of the memory pool.
|
||||
/// \param no maximum number of blocks (objects) in the memory pool.
|
||||
/// \param type data type of a single block (object).
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osPoolDef(name, no, type) \
|
||||
extern const osPoolDef_t os_pool_def_##name
|
||||
#else // define the object
|
||||
#define osPoolDef(name, no, type) \
|
||||
uint32_t os_pool_m_##name[3+((sizeof(type)+3)/4)*(no)]; \
|
||||
const osPoolDef_t os_pool_def_##name = \
|
||||
{ (no), sizeof(type), (os_pool_m_##name) }
|
||||
#endif
|
||||
|
||||
/// \brief Access a Memory Pool definition.
|
||||
/// \param name name of the memory pool
|
||||
#define osPool(name) \
|
||||
&os_pool_def_##name
|
||||
|
||||
/// Create and Initialize a memory pool.
|
||||
/// \param[in] pool_def memory pool definition referenced with \ref osPool.
|
||||
/// \return memory pool ID for reference by other functions or NULL in case of error.
|
||||
osPoolId osPoolCreate (const osPoolDef_t *pool_def);
|
||||
|
||||
/// Allocate a memory block from a memory pool.
|
||||
/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
|
||||
/// \return address of the allocated memory block or NULL in case of no memory available.
|
||||
void *osPoolAlloc (osPoolId pool_id);
|
||||
|
||||
/// Allocate a memory block from a memory pool and set memory block to zero.
|
||||
/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
|
||||
/// \return address of the allocated memory block or NULL in case of no memory available.
|
||||
void *osPoolCAlloc (osPoolId pool_id);
|
||||
|
||||
/// Return an allocated memory block back to a specific memory pool.
|
||||
/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
|
||||
/// \param[in] block address of the allocated memory block that is returned to the memory pool.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osPoolFree (osPoolId pool_id, void *block);
|
||||
|
||||
#endif // Memory Pool Management available
|
||||
|
||||
|
||||
// ==== Message Queue Management Functions ====
|
||||
|
||||
#if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available
|
||||
|
||||
/// \brief Create a Message Queue Definition.
|
||||
/// \param name name of the queue.
|
||||
/// \param queue_sz maximum number of messages in the queue.
|
||||
/// \param type data type of a single message element (for debugger).
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osMessageQDef(name, queue_sz, type) \
|
||||
extern const osMessageQDef_t os_messageQ_def_##name
|
||||
#else // define the object
|
||||
#define osMessageQDef(name, queue_sz, type) \
|
||||
uint32_t os_messageQ_q_##name[4+(queue_sz)] = { 0 }; \
|
||||
const osMessageQDef_t os_messageQ_def_##name = \
|
||||
{ (queue_sz), (os_messageQ_q_##name) }
|
||||
#endif
|
||||
|
||||
/// \brief Access a Message Queue Definition.
|
||||
/// \param name name of the queue
|
||||
#define osMessageQ(name) \
|
||||
&os_messageQ_def_##name
|
||||
|
||||
/// Create and Initialize a Message Queue.
|
||||
/// \param[in] queue_def queue definition referenced with \ref osMessageQ.
|
||||
/// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
|
||||
/// \return message queue ID for reference by other functions or NULL in case of error.
|
||||
osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id);
|
||||
|
||||
/// Put a Message to a Queue.
|
||||
/// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
|
||||
/// \param[in] info message information.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);
|
||||
|
||||
/// Get a Message or Wait for a Message from a Queue.
|
||||
/// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
|
||||
/// \return event information that includes status code.
|
||||
os_InRegs osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);
|
||||
|
||||
#endif // Message Queues available
|
||||
|
||||
|
||||
// ==== Mail Queue Management Functions ====
|
||||
|
||||
#if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available
|
||||
|
||||
/// \brief Create a Mail Queue Definition.
|
||||
/// \param name name of the queue
|
||||
/// \param queue_sz maximum number of messages in queue
|
||||
/// \param type data type of a single message element
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osMailQDef(name, queue_sz, type) \
|
||||
extern const osMailQDef_t os_mailQ_def_##name
|
||||
#else // define the object
|
||||
#define osMailQDef(name, queue_sz, type) \
|
||||
uint32_t os_mailQ_q_##name[4+(queue_sz)] = { 0 }; \
|
||||
uint32_t os_mailQ_m_##name[3+((sizeof(type)+3)/4)*(queue_sz)]; \
|
||||
void * os_mailQ_p_##name[2] = { (os_mailQ_q_##name), os_mailQ_m_##name }; \
|
||||
const osMailQDef_t os_mailQ_def_##name = \
|
||||
{ (queue_sz), sizeof(type), (os_mailQ_p_##name) }
|
||||
#endif
|
||||
|
||||
/// \brief Access a Mail Queue Definition.
|
||||
/// \param name name of the queue
|
||||
#define osMailQ(name) \
|
||||
&os_mailQ_def_##name
|
||||
|
||||
/// Create and Initialize mail queue.
|
||||
/// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ
|
||||
/// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
|
||||
/// \return mail queue ID for reference by other functions or NULL in case of error.
|
||||
osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id);
|
||||
|
||||
/// Allocate a memory block from a mail.
|
||||
/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
|
||||
/// \return pointer to memory block that can be filled with mail or NULL in case of error.
|
||||
void *osMailAlloc (osMailQId queue_id, uint32_t millisec);
|
||||
|
||||
/// Allocate a memory block from a mail and set memory block to zero.
|
||||
/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
|
||||
/// \return pointer to memory block that can be filled with mail or NULL in case of error.
|
||||
void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);
|
||||
|
||||
/// Put a mail to a queue.
|
||||
/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
/// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osMailPut (osMailQId queue_id, void *mail);
|
||||
|
||||
/// Get a mail from a queue.
|
||||
/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
|
||||
/// \return event that contains mail information or error code.
|
||||
os_InRegs osEvent osMailGet (osMailQId queue_id, uint32_t millisec);
|
||||
|
||||
/// Free a memory block from a mail.
|
||||
/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
/// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osMailFree (osMailQId queue_id, void *mail);
|
||||
|
||||
#endif // Mail Queues available
|
||||
|
||||
|
||||
// ==== Thread Enumeration Functions ====
|
||||
|
||||
#if (defined (osFeature_ThreadEnum) && (osFeature_ThreadEnum != 0)) // Thread enumeration available
|
||||
|
||||
/// Start a thread enumeration.
|
||||
/// \return an enumeration ID or NULL on error.
|
||||
osThreadEnumId _osThreadsEnumStart(void);
|
||||
|
||||
/// Get the next task ID in the enumeration.
|
||||
/// \return a thread ID or NULL on if the end of the enumeration has been reached.
|
||||
osThreadId _osThreadEnumNext(osThreadEnumId enum_id);
|
||||
|
||||
/// Free the enumeration structure.
|
||||
/// \param[in] enum_id pointer to the enumeration ID that was obtained with \ref _osThreadsEnumStart.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus _osThreadEnumFree(osThreadEnumId enum_id);
|
||||
|
||||
#endif // Thread Enumeration available
|
||||
|
||||
|
||||
// ==== RTX Extensions ====
|
||||
|
||||
/// Suspend the RTX task scheduler.
|
||||
/// \return number of ticks, for how long the system can sleep or power-down.
|
||||
uint32_t os_suspend (void);
|
||||
|
||||
/// Resume the RTX task scheduler
|
||||
/// \param[in] sleep_time specifies how long the system was in sleep or power-down mode.
|
||||
void os_resume (uint32_t sleep_time);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _CMSIS_OS_H
|
||||
|
||||
/** @}*/
|
File diff suppressed because it is too large
Load Diff
|
@ -1,190 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_EVENT.C
|
||||
* Purpose: Implements waits and wake-ups for event flags
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_Event.h"
|
||||
#include "rt_List.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_evt_wait -----------------------------------*/
|
||||
|
||||
OS_RESULT rt_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait) {
|
||||
/* Wait for one or more event flags with optional time-out. */
|
||||
/* "wait_flags" identifies the flags to wait for. */
|
||||
/* "timeout" is the time-out limit in system ticks (0xffff if no time-out) */
|
||||
/* "and_wait" specifies the AND-ing of "wait_flags" as condition to be met */
|
||||
/* to complete the wait. (OR-ing if set to 0). */
|
||||
U32 block_state;
|
||||
|
||||
if (and_wait) {
|
||||
/* Check for AND-connected events */
|
||||
if ((os_tsk.run->events & wait_flags) == wait_flags) {
|
||||
os_tsk.run->events &= ~wait_flags;
|
||||
return (OS_R_EVT);
|
||||
}
|
||||
block_state = WAIT_AND;
|
||||
}
|
||||
else {
|
||||
/* Check for OR-connected events */
|
||||
if (os_tsk.run->events & wait_flags) {
|
||||
os_tsk.run->waits = os_tsk.run->events & wait_flags;
|
||||
os_tsk.run->events &= ~wait_flags;
|
||||
return (OS_R_EVT);
|
||||
}
|
||||
block_state = WAIT_OR;
|
||||
}
|
||||
/* Task has to wait */
|
||||
os_tsk.run->waits = wait_flags;
|
||||
rt_block (timeout, (U8)block_state);
|
||||
return (OS_R_TMO);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_evt_set ------------------------------------*/
|
||||
|
||||
void rt_evt_set (U16 event_flags, OS_TID task_id) {
|
||||
/* Set one or more event flags of a selectable task. */
|
||||
P_TCB p_tcb;
|
||||
|
||||
p_tcb = os_active_TCB[task_id-1U];
|
||||
if (p_tcb == NULL) {
|
||||
return;
|
||||
}
|
||||
p_tcb->events |= event_flags;
|
||||
event_flags = p_tcb->waits;
|
||||
/* If the task is not waiting for an event, it should not be put */
|
||||
/* to ready state. */
|
||||
if (p_tcb->state == WAIT_AND) {
|
||||
/* Check for AND-connected events */
|
||||
if ((p_tcb->events & event_flags) == event_flags) {
|
||||
goto wkup;
|
||||
}
|
||||
}
|
||||
if (p_tcb->state == WAIT_OR) {
|
||||
/* Check for OR-connected events */
|
||||
if (p_tcb->events & event_flags) {
|
||||
p_tcb->waits &= p_tcb->events;
|
||||
wkup: p_tcb->events &= ~event_flags;
|
||||
rt_rmv_dly (p_tcb);
|
||||
p_tcb->state = READY;
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val2(p_tcb, 0x08U/*osEventSignal*/, p_tcb->waits);
|
||||
#else
|
||||
rt_ret_val (p_tcb, OS_R_EVT);
|
||||
#endif
|
||||
rt_dispatch (p_tcb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_evt_clr ------------------------------------*/
|
||||
|
||||
void rt_evt_clr (U16 clear_flags, OS_TID task_id) {
|
||||
/* Clear one or more event flags (identified by "clear_flags") of a */
|
||||
/* selectable task (identified by "task"). */
|
||||
P_TCB task = os_active_TCB[task_id-1U];
|
||||
|
||||
if (task == NULL) {
|
||||
return;
|
||||
}
|
||||
task->events &= ~clear_flags;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- isr_evt_set -----------------------------------*/
|
||||
|
||||
void isr_evt_set (U16 event_flags, OS_TID task_id) {
|
||||
/* Same function as "os_evt_set", but to be called by ISRs. */
|
||||
P_TCB p_tcb = os_active_TCB[task_id-1U];
|
||||
|
||||
if (p_tcb == NULL) {
|
||||
return;
|
||||
}
|
||||
rt_psq_enq (p_tcb, event_flags);
|
||||
rt_psh_req ();
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_evt_get ------------------------------------*/
|
||||
|
||||
U16 rt_evt_get (void) {
|
||||
/* Get events of a running task after waiting for OR connected events. */
|
||||
return (os_tsk.run->waits);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_evt_psh ------------------------------------*/
|
||||
|
||||
void rt_evt_psh (P_TCB p_CB, U16 set_flags) {
|
||||
/* Check if task has to be waken up */
|
||||
U16 event_flags;
|
||||
|
||||
p_CB->events |= set_flags;
|
||||
event_flags = p_CB->waits;
|
||||
if (p_CB->state == WAIT_AND) {
|
||||
/* Check for AND-connected events */
|
||||
if ((p_CB->events & event_flags) == event_flags) {
|
||||
goto rdy;
|
||||
}
|
||||
}
|
||||
if (p_CB->state == WAIT_OR) {
|
||||
/* Check for OR-connected events */
|
||||
if (p_CB->events & event_flags) {
|
||||
p_CB->waits &= p_CB->events;
|
||||
rdy: p_CB->events &= ~event_flags;
|
||||
rt_rmv_dly (p_CB);
|
||||
p_CB->state = READY;
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val2(p_CB, 0x08U/*osEventSignal*/, p_CB->waits);
|
||||
#else
|
||||
rt_ret_val (p_CB, OS_R_EVT);
|
||||
#endif
|
||||
rt_put_prio (&os_rdy, p_CB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,51 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_EVENT.H
|
||||
* Purpose: Implements waits and wake-ups for event flags
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Functions */
|
||||
extern OS_RESULT rt_evt_wait (U16 wait_flags, U16 timeout, BOOL and_wait);
|
||||
extern void rt_evt_set (U16 event_flags, OS_TID task_id);
|
||||
extern void rt_evt_clr (U16 clear_flags, OS_TID task_id);
|
||||
extern void isr_evt_set (U16 event_flags, OS_TID task_id);
|
||||
extern U16 rt_evt_get (void);
|
||||
extern void rt_evt_psh (P_TCB p_CB, U16 set_flags);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/** @}*/
|
|
@ -1,344 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_HAL_CM.H
|
||||
* Purpose: Hardware Abstraction Layer for Cortex-M definitions
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Definitions */
|
||||
#define INITIAL_xPSR 0x01000000U
|
||||
#define DEMCR_TRCENA 0x01000000U
|
||||
#define ITM_ITMENA 0x00000001U
|
||||
#define MAGIC_WORD 0xE25A2EA5U
|
||||
#define MAGIC_PATTERN 0xCCCCCCCCU
|
||||
|
||||
#if defined (__CC_ARM) /* ARM Compiler */
|
||||
|
||||
#if ((defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M)) && !defined(NO_EXCLUSIVE_ACCESS))
|
||||
#define __USE_EXCLUSIVE_ACCESS
|
||||
#else
|
||||
#undef __USE_EXCLUSIVE_ACCESS
|
||||
#endif
|
||||
|
||||
/* Supress __ldrex and __strex deprecated warnings - "#3731-D: intrinsic is deprecated" */
|
||||
#ifdef __USE_EXCLUSIVE_ACCESS
|
||||
#pragma diag_suppress 3731
|
||||
#endif
|
||||
|
||||
#ifndef __CMSIS_GENERIC
|
||||
|
||||
__attribute__((always_inline)) static inline U32 __get_PRIMASK(void)
|
||||
{
|
||||
register U32 primask __asm("primask");
|
||||
return primask;
|
||||
}
|
||||
|
||||
#define __DMB() do {\
|
||||
__schedule_barrier();\
|
||||
__dmb(0xF);\
|
||||
__schedule_barrier();\
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
||||
#elif defined (__GNUC__) /* GNU Compiler */
|
||||
|
||||
#undef __USE_EXCLUSIVE_ACCESS
|
||||
|
||||
#if defined (__CORTEX_M0) || defined (__CORTEX_M0PLUS)
|
||||
#define __TARGET_ARCH_6S_M
|
||||
#endif
|
||||
|
||||
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
||||
#define __TARGET_FPU_VFP
|
||||
#endif
|
||||
|
||||
#define __inline inline
|
||||
#define __weak __attribute__((weak))
|
||||
|
||||
#ifndef __CMSIS_GENERIC
|
||||
|
||||
__attribute__((always_inline)) static inline U32 __get_PRIMASK(void)
|
||||
{
|
||||
U32 result;
|
||||
|
||||
__asm volatile ("mrs %0, primask" : "=r" (result));
|
||||
return result;
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void __enable_irq(void)
|
||||
{
|
||||
__asm volatile ("cpsie i");
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline U32 __disable_irq(void)
|
||||
{
|
||||
U32 result;
|
||||
|
||||
__asm volatile ("mrs %0, primask" : "=r" (result));
|
||||
__asm volatile ("cpsid i");
|
||||
return(result & 1);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void __DMB(void)
|
||||
{
|
||||
__asm volatile ("dmb 0xF":::"memory");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
__attribute__(( always_inline)) static inline U8 __clz(U32 value)
|
||||
{
|
||||
U8 result;
|
||||
|
||||
__asm volatile ("clz %0, %1" : "=r" (result) : "r" (value));
|
||||
return(result);
|
||||
}
|
||||
|
||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||
|
||||
#undef __USE_EXCLUSIVE_ACCESS
|
||||
|
||||
#if (__CORE__ == __ARM6M__)
|
||||
#define __TARGET_ARCH_6S_M 1
|
||||
#endif
|
||||
|
||||
#if defined __ARMVFP__
|
||||
#define __TARGET_FPU_VFP 1
|
||||
#endif
|
||||
|
||||
#define __inline inline
|
||||
|
||||
#ifndef __CMSIS_GENERIC
|
||||
|
||||
static inline U32 __get_PRIMASK(void)
|
||||
{
|
||||
U32 result;
|
||||
|
||||
__asm volatile ("mrs %0, primask" : "=r" (result));
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void __enable_irq(void)
|
||||
{
|
||||
__asm volatile ("cpsie i");
|
||||
}
|
||||
|
||||
static inline U32 __disable_irq(void)
|
||||
{
|
||||
U32 result;
|
||||
|
||||
__asm volatile ("mrs %0, primask" : "=r" (result));
|
||||
__asm volatile ("cpsid i");
|
||||
return(result & 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static inline U8 __clz(U32 value)
|
||||
{
|
||||
U8 result;
|
||||
|
||||
__asm volatile ("clz %0, %1" : "=r" (result) : "r" (value));
|
||||
return(result);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* NVIC registers */
|
||||
#define NVIC_ST_CTRL (*((volatile U32 *)0xE000E010U))
|
||||
#define NVIC_ST_RELOAD (*((volatile U32 *)0xE000E014U))
|
||||
#define NVIC_ST_CURRENT (*((volatile U32 *)0xE000E018U))
|
||||
#define NVIC_ISER ((volatile U32 *)0xE000E100U)
|
||||
#define NVIC_ICER ((volatile U32 *)0xE000E180U)
|
||||
#if defined(__TARGET_ARCH_6S_M)
|
||||
#define NVIC_IP ((volatile U32 *)0xE000E400U)
|
||||
#else
|
||||
#define NVIC_IP ((volatile U8 *)0xE000E400U)
|
||||
#endif
|
||||
#define NVIC_INT_CTRL (*((volatile U32 *)0xE000ED04U))
|
||||
#define NVIC_AIR_CTRL (*((volatile U32 *)0xE000ED0CU))
|
||||
#define NVIC_SYS_PRI2 (*((volatile U32 *)0xE000ED1CU))
|
||||
#define NVIC_SYS_PRI3 (*((volatile U32 *)0xE000ED20U))
|
||||
|
||||
#define OS_PEND_IRQ() NVIC_INT_CTRL = (1UL<<28)
|
||||
#define OS_PENDING ((NVIC_INT_CTRL >> 26) & 5U)
|
||||
#define OS_UNPEND(fl) NVIC_INT_CTRL = (U32)(fl = (U8)OS_PENDING) << 25
|
||||
#define OS_PEND(fl,p) NVIC_INT_CTRL = (U32)(fl | (U8)(p<<2)) << 26
|
||||
#define OS_LOCK() NVIC_ST_CTRL = 0x0005U
|
||||
#define OS_UNLOCK() NVIC_ST_CTRL = 0x0007U
|
||||
|
||||
#define OS_X_PENDING ((NVIC_INT_CTRL >> 28) & 1U)
|
||||
#define OS_X_UNPEND(fl) NVIC_INT_CTRL = (U32)(fl = (U8)OS_X_PENDING) << 27
|
||||
#define OS_X_PEND(fl,p) NVIC_INT_CTRL = (U32)(fl | p) << 28
|
||||
#if defined(__TARGET_ARCH_6S_M)
|
||||
#define OS_X_INIT(n) NVIC_IP[n>>2] |= (U32)0xFFU << ((n & 0x03U) << 3); \
|
||||
NVIC_ISER[n>>5] = (U32)1U << (n & 0x1FU)
|
||||
#else
|
||||
#define OS_X_INIT(n) NVIC_IP[n] = 0xFFU; \
|
||||
NVIC_ISER[n>>5] = (U32)1U << (n & 0x1FU)
|
||||
#endif
|
||||
#define OS_X_LOCK(n) NVIC_ICER[n>>5] = (U32)1U << (n & 0x1FU)
|
||||
#define OS_X_UNLOCK(n) NVIC_ISER[n>>5] = (U32)1U << (n & 0x1FU)
|
||||
|
||||
/* Core Debug registers */
|
||||
#define DEMCR (*((volatile U32 *)0xE000EDFCU))
|
||||
|
||||
/* ITM registers */
|
||||
#define ITM_CONTROL (*((volatile U32 *)0xE0000E80U))
|
||||
#define ITM_ENABLE (*((volatile U32 *)0xE0000E00U))
|
||||
#define ITM_PORT30_U32 (*((volatile U32 *)0xE0000078U))
|
||||
#define ITM_PORT31_U32 (*((volatile U32 *)0xE000007CU))
|
||||
#define ITM_PORT31_U16 (*((volatile U16 *)0xE000007CU))
|
||||
#define ITM_PORT31_U8 (*((volatile U8 *)0xE000007CU))
|
||||
|
||||
/* Variables */
|
||||
extern BIT dbg_msg;
|
||||
|
||||
/* Functions */
|
||||
#ifdef __USE_EXCLUSIVE_ACCESS
|
||||
#define rt_inc(p) while(__strex((__ldrex(p)+1U),p))
|
||||
#define rt_dec(p) while(__strex((__ldrex(p)-1U),p))
|
||||
#else
|
||||
#define rt_inc(p) do {\
|
||||
U32 primask = __get_PRIMASK();\
|
||||
__disable_irq();\
|
||||
(*p)++;\
|
||||
if (!primask) {\
|
||||
__enable_irq();\
|
||||
}\
|
||||
} while (0)
|
||||
#define rt_dec(p) do {\
|
||||
U32 primask = __get_PRIMASK();\
|
||||
__disable_irq();\
|
||||
(*p)--;\
|
||||
if (!primask) {\
|
||||
__enable_irq();\
|
||||
}\
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
__inline static U32 rt_inc_qi (U32 size, U8 *count, U8 *first) {
|
||||
U32 cnt,c2;
|
||||
#ifdef __USE_EXCLUSIVE_ACCESS
|
||||
do {
|
||||
if ((cnt = __ldrex(count)) == size) {
|
||||
__clrex();
|
||||
return (cnt); }
|
||||
} while (__strex(cnt+1U, count));
|
||||
do {
|
||||
c2 = (cnt = __ldrex(first)) + 1U;
|
||||
if (c2 == size) { c2 = 0U; }
|
||||
} while (__strex(c2, first));
|
||||
#else
|
||||
U32 primask = __get_PRIMASK();
|
||||
__disable_irq();
|
||||
if ((cnt = *count) < size) {
|
||||
*count = (U8)(cnt+1U);
|
||||
c2 = (cnt = *first) + 1U;
|
||||
if (c2 == size) { c2 = 0U; }
|
||||
*first = (U8)c2;
|
||||
}
|
||||
if (!primask) {
|
||||
__enable_irq ();
|
||||
}
|
||||
#endif
|
||||
return (cnt);
|
||||
}
|
||||
|
||||
__inline static void rt_systick_init (void) {
|
||||
NVIC_ST_RELOAD = os_trv;
|
||||
NVIC_ST_CURRENT = 0U;
|
||||
NVIC_ST_CTRL = 0x0007U;
|
||||
NVIC_SYS_PRI3 |= 0xFF000000U;
|
||||
}
|
||||
|
||||
__inline static U32 rt_systick_val (void) {
|
||||
return (os_trv - NVIC_ST_CURRENT);
|
||||
}
|
||||
|
||||
__inline static U32 rt_systick_ovf (void) {
|
||||
return ((NVIC_INT_CTRL >> 26) & 1U);
|
||||
}
|
||||
|
||||
__inline static void rt_svc_init (void) {
|
||||
#if !defined(__TARGET_ARCH_6S_M)
|
||||
U32 sh,prigroup;
|
||||
#endif
|
||||
NVIC_SYS_PRI3 |= 0x00FF0000U;
|
||||
#if defined(__TARGET_ARCH_6S_M)
|
||||
NVIC_SYS_PRI2 |= (NVIC_SYS_PRI3<<(8+1)) & 0xFC000000U;
|
||||
#else
|
||||
sh = 8U - __clz(~((NVIC_SYS_PRI3 << 8) & 0xFF000000U));
|
||||
prigroup = ((NVIC_AIR_CTRL >> 8) & 0x07U);
|
||||
if (prigroup >= sh) {
|
||||
sh = prigroup + 1U;
|
||||
}
|
||||
|
||||
/* Only change the SVCall priority if uVisor is not present. */
|
||||
#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
|
||||
NVIC_SYS_PRI2 = ((0xFEFFFFFFU << sh) & 0xFF000000U) | (NVIC_SYS_PRI2 & 0x00FFFFFFU);
|
||||
#endif /* !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) */
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void rt_set_PSP (U32 stack);
|
||||
extern U32 rt_get_PSP (void);
|
||||
extern void os_set_env (void);
|
||||
extern void *_alloc_box (void *box_mem);
|
||||
extern U32 _free_box (void *box_mem, void *box);
|
||||
|
||||
extern void rt_init_stack (P_TCB p_TCB, FUNCP task_body);
|
||||
extern void rt_ret_val (P_TCB p_TCB, U32 v0);
|
||||
extern void rt_ret_val2 (P_TCB p_TCB, U32 v0, U32 v1);
|
||||
|
||||
extern void dbg_init (void);
|
||||
extern void dbg_task_notify (P_TCB p_tcb, BOOL create);
|
||||
extern void dbg_task_switch (U32 task_id);
|
||||
|
||||
#ifdef DBG_MSG
|
||||
#define DBG_INIT() dbg_init()
|
||||
#define DBG_TASK_NOTIFY(p_tcb,create) if (dbg_msg) dbg_task_notify(p_tcb,create)
|
||||
#define DBG_TASK_SWITCH(task_id) if (dbg_msg && (os_tsk.new_tsk!=os_tsk.run)) \
|
||||
dbg_task_switch(task_id)
|
||||
#else
|
||||
#define DBG_INIT()
|
||||
#define DBG_TASK_NOTIFY(p_tcb,create)
|
||||
#define DBG_TASK_SWITCH(task_id)
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/** @}*/
|
|
@ -1,318 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_LIST.C
|
||||
* Purpose: Functions for the management of different lists
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_List.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_Time.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Variables
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* List head of chained ready tasks */
|
||||
struct OS_XCB os_rdy;
|
||||
/* List head of chained delay tasks */
|
||||
struct OS_XCB os_dly;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_put_prio -----------------------------------*/
|
||||
|
||||
void rt_put_prio (P_XCB p_CB, P_TCB p_task) {
|
||||
/* Put task identified with "p_task" into list ordered by priority. */
|
||||
/* "p_CB" points to head of list; list has always an element at end with */
|
||||
/* a priority less than "p_task->prio". */
|
||||
P_TCB p_CB2;
|
||||
U32 prio;
|
||||
BOOL sem_mbx = __FALSE;
|
||||
|
||||
if ((p_CB->cb_type == SCB) || (p_CB->cb_type == MCB) || (p_CB->cb_type == MUCB)) {
|
||||
sem_mbx = __TRUE;
|
||||
}
|
||||
prio = p_task->prio;
|
||||
p_CB2 = p_CB->p_lnk;
|
||||
/* Search for an entry in the list */
|
||||
while ((p_CB2 != NULL) && (prio <= p_CB2->prio)) {
|
||||
p_CB = (P_XCB)p_CB2;
|
||||
p_CB2 = p_CB2->p_lnk;
|
||||
}
|
||||
/* Entry found, insert the task into the list */
|
||||
p_task->p_lnk = p_CB2;
|
||||
p_CB->p_lnk = p_task;
|
||||
if (sem_mbx) {
|
||||
if (p_CB2 != NULL) {
|
||||
p_CB2->p_rlnk = p_task;
|
||||
}
|
||||
p_task->p_rlnk = (P_TCB)p_CB;
|
||||
}
|
||||
else {
|
||||
p_task->p_rlnk = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_get_first ----------------------------------*/
|
||||
|
||||
P_TCB rt_get_first (P_XCB p_CB) {
|
||||
/* Get task at head of list: it is the task with highest priority. */
|
||||
/* "p_CB" points to head of list. */
|
||||
P_TCB p_first;
|
||||
|
||||
p_first = p_CB->p_lnk;
|
||||
p_CB->p_lnk = p_first->p_lnk;
|
||||
if ((p_CB->cb_type == SCB) || (p_CB->cb_type == MCB) || (p_CB->cb_type == MUCB)) {
|
||||
if (p_first->p_lnk != NULL) {
|
||||
p_first->p_lnk->p_rlnk = (P_TCB)p_CB;
|
||||
p_first->p_lnk = NULL;
|
||||
}
|
||||
p_first->p_rlnk = NULL;
|
||||
}
|
||||
else {
|
||||
p_first->p_lnk = NULL;
|
||||
}
|
||||
return (p_first);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_put_rdy_first ------------------------------*/
|
||||
|
||||
void rt_put_rdy_first (P_TCB p_task) {
|
||||
/* Put task identified with "p_task" at the head of the ready list. The */
|
||||
/* task must have at least a priority equal to highest priority in list. */
|
||||
p_task->p_lnk = os_rdy.p_lnk;
|
||||
p_task->p_rlnk = NULL;
|
||||
os_rdy.p_lnk = p_task;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_get_same_rdy_prio --------------------------*/
|
||||
|
||||
P_TCB rt_get_same_rdy_prio (void) {
|
||||
/* Remove a task of same priority from ready list if any exists. Other- */
|
||||
/* wise return NULL. */
|
||||
P_TCB p_first;
|
||||
|
||||
p_first = os_rdy.p_lnk;
|
||||
if (p_first->prio == os_tsk.run->prio) {
|
||||
os_rdy.p_lnk = os_rdy.p_lnk->p_lnk;
|
||||
return (p_first);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_resort_prio --------------------------------*/
|
||||
|
||||
void rt_resort_prio (P_TCB p_task) {
|
||||
/* Re-sort ordered lists after the priority of 'p_task' has changed. */
|
||||
P_TCB p_CB;
|
||||
|
||||
if (p_task->p_rlnk == NULL) {
|
||||
if (p_task->state == READY) {
|
||||
/* Task is chained into READY list. */
|
||||
p_CB = (P_TCB)&os_rdy;
|
||||
goto res;
|
||||
}
|
||||
}
|
||||
else {
|
||||
p_CB = p_task->p_rlnk;
|
||||
while (p_CB->cb_type == TCB) {
|
||||
/* Find a header of this task chain list. */
|
||||
p_CB = p_CB->p_rlnk;
|
||||
}
|
||||
res:rt_rmv_list (p_task);
|
||||
rt_put_prio ((P_XCB)p_CB, p_task);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_put_dly ------------------------------------*/
|
||||
|
||||
void rt_put_dly (P_TCB p_task, U16 delay) {
|
||||
/* Put a task identified with "p_task" into chained delay wait list using */
|
||||
/* a delay value of "delay". */
|
||||
P_TCB p;
|
||||
U32 delta,idelay = delay;
|
||||
|
||||
p = (P_TCB)&os_dly;
|
||||
if (p->p_dlnk == NULL) {
|
||||
/* Delay list empty */
|
||||
delta = 0U;
|
||||
goto last;
|
||||
}
|
||||
delta = os_dly.delta_time;
|
||||
while (delta < idelay) {
|
||||
if (p->p_dlnk == NULL) {
|
||||
/* End of list found */
|
||||
last: p_task->p_dlnk = NULL;
|
||||
p->p_dlnk = p_task;
|
||||
p_task->p_blnk = p;
|
||||
p->delta_time = (U16)(idelay - delta);
|
||||
p_task->delta_time = 0U;
|
||||
return;
|
||||
}
|
||||
p = p->p_dlnk;
|
||||
delta += p->delta_time;
|
||||
}
|
||||
/* Right place found */
|
||||
p_task->p_dlnk = p->p_dlnk;
|
||||
p->p_dlnk = p_task;
|
||||
p_task->p_blnk = p;
|
||||
if (p_task->p_dlnk != NULL) {
|
||||
p_task->p_dlnk->p_blnk = p_task;
|
||||
}
|
||||
p_task->delta_time = (U16)(delta - idelay);
|
||||
p->delta_time -= p_task->delta_time;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_dec_dly ------------------------------------*/
|
||||
|
||||
void rt_dec_dly (void) {
|
||||
/* Decrement delta time of list head: remove tasks having a value of zero.*/
|
||||
P_TCB p_rdy;
|
||||
|
||||
if (os_dly.p_dlnk == NULL) {
|
||||
return;
|
||||
}
|
||||
os_dly.delta_time--;
|
||||
while ((os_dly.delta_time == 0U) && (os_dly.p_dlnk != NULL)) {
|
||||
p_rdy = os_dly.p_dlnk;
|
||||
if (p_rdy->p_rlnk != NULL) {
|
||||
/* Task is really enqueued, remove task from semaphore/mailbox */
|
||||
/* timeout waiting list. */
|
||||
p_rdy->p_rlnk->p_lnk = p_rdy->p_lnk;
|
||||
if (p_rdy->p_lnk != NULL) {
|
||||
p_rdy->p_lnk->p_rlnk = p_rdy->p_rlnk;
|
||||
p_rdy->p_lnk = NULL;
|
||||
}
|
||||
p_rdy->p_rlnk = NULL;
|
||||
}
|
||||
rt_put_prio (&os_rdy, p_rdy);
|
||||
os_dly.delta_time = p_rdy->delta_time;
|
||||
if (p_rdy->state == WAIT_ITV) {
|
||||
/* Calculate the next time for interval wait. */
|
||||
p_rdy->delta_time = p_rdy->interval_time + (U16)os_time;
|
||||
}
|
||||
p_rdy->state = READY;
|
||||
os_dly.p_dlnk = p_rdy->p_dlnk;
|
||||
if (p_rdy->p_dlnk != NULL) {
|
||||
p_rdy->p_dlnk->p_blnk = (P_TCB)&os_dly;
|
||||
p_rdy->p_dlnk = NULL;
|
||||
}
|
||||
p_rdy->p_blnk = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_rmv_list -----------------------------------*/
|
||||
|
||||
void rt_rmv_list (P_TCB p_task) {
|
||||
/* Remove task identified with "p_task" from ready, semaphore or mailbox */
|
||||
/* waiting list if enqueued. */
|
||||
P_TCB p_b;
|
||||
|
||||
if (p_task->p_rlnk != NULL) {
|
||||
/* A task is enqueued in semaphore / mailbox waiting list. */
|
||||
p_task->p_rlnk->p_lnk = p_task->p_lnk;
|
||||
if (p_task->p_lnk != NULL) {
|
||||
p_task->p_lnk->p_rlnk = p_task->p_rlnk;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
p_b = (P_TCB)&os_rdy;
|
||||
while (p_b != NULL) {
|
||||
/* Search the ready list for task "p_task" */
|
||||
if (p_b->p_lnk == p_task) {
|
||||
p_b->p_lnk = p_task->p_lnk;
|
||||
return;
|
||||
}
|
||||
p_b = p_b->p_lnk;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_rmv_dly ------------------------------------*/
|
||||
|
||||
void rt_rmv_dly (P_TCB p_task) {
|
||||
/* Remove task identified with "p_task" from delay list if enqueued. */
|
||||
P_TCB p_b;
|
||||
|
||||
p_b = p_task->p_blnk;
|
||||
if (p_b != NULL) {
|
||||
/* Task is really enqueued */
|
||||
p_b->p_dlnk = p_task->p_dlnk;
|
||||
if (p_task->p_dlnk != NULL) {
|
||||
/* 'p_task' is in the middle of list */
|
||||
p_b->delta_time += p_task->delta_time;
|
||||
p_task->p_dlnk->p_blnk = p_b;
|
||||
p_task->p_dlnk = NULL;
|
||||
}
|
||||
else {
|
||||
/* 'p_task' is at the end of list */
|
||||
p_b->delta_time = 0U;
|
||||
}
|
||||
p_task->p_blnk = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_psq_enq ------------------------------------*/
|
||||
|
||||
void rt_psq_enq (OS_ID entry, U32 arg) {
|
||||
/* Insert post service request "entry" into ps-queue. */
|
||||
U32 idx;
|
||||
|
||||
idx = rt_inc_qi (os_psq->size, &os_psq->count, &os_psq->first);
|
||||
if (idx < os_psq->size) {
|
||||
os_psq->q[idx].id = entry;
|
||||
os_psq->q[idx].arg = arg;
|
||||
}
|
||||
else {
|
||||
os_error (OS_ERR_FIFO_OVF);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,72 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_LIST.H
|
||||
* Purpose: Functions for the management of different lists
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Definitions */
|
||||
|
||||
/* Values for 'cb_type' */
|
||||
#define TCB 0U
|
||||
#define MCB 1U
|
||||
#define SCB 2U
|
||||
#define MUCB 3U
|
||||
#define HCB 4U
|
||||
|
||||
/* Variables */
|
||||
extern struct OS_XCB os_rdy;
|
||||
extern struct OS_XCB os_dly;
|
||||
|
||||
/* Functions */
|
||||
extern void rt_put_prio (P_XCB p_CB, P_TCB p_task);
|
||||
extern P_TCB rt_get_first (P_XCB p_CB);
|
||||
extern void rt_put_rdy_first (P_TCB p_task);
|
||||
extern P_TCB rt_get_same_rdy_prio (void);
|
||||
extern void rt_resort_prio (P_TCB p_task);
|
||||
extern void rt_put_dly (P_TCB p_task, U16 delay);
|
||||
extern void rt_dec_dly (void);
|
||||
extern void rt_rmv_list (P_TCB p_task);
|
||||
extern void rt_rmv_dly (P_TCB p_task);
|
||||
extern void rt_psq_enq (OS_ID entry, U32 arg);
|
||||
|
||||
/* This is a fast macro generating in-line code */
|
||||
#define rt_rdy_prio(void) (os_rdy.p_lnk->prio)
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/** @}*/
|
|
@ -1,293 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_MAILBOX.C
|
||||
* Purpose: Implements waits and wake-ups for mailbox messages
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_List.h"
|
||||
#include "rt_Mailbox.h"
|
||||
#include "rt_MemBox.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_mbx_init -----------------------------------*/
|
||||
|
||||
void rt_mbx_init (OS_ID mailbox, U16 mbx_size) {
|
||||
/* Initialize a mailbox */
|
||||
P_MCB p_MCB = mailbox;
|
||||
|
||||
p_MCB->cb_type = MCB;
|
||||
p_MCB->state = 0U;
|
||||
p_MCB->isr_st = 0U;
|
||||
p_MCB->p_lnk = NULL;
|
||||
p_MCB->first = 0U;
|
||||
p_MCB->last = 0U;
|
||||
p_MCB->count = 0U;
|
||||
p_MCB->size = (U16)((mbx_size - (sizeof(struct OS_MCB) - (sizeof(void *))))
|
||||
/ sizeof(void *));
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_mbx_send -----------------------------------*/
|
||||
|
||||
OS_RESULT rt_mbx_send (OS_ID mailbox, void *p_msg, U16 timeout) {
|
||||
/* Send message to a mailbox */
|
||||
P_MCB p_MCB = mailbox;
|
||||
P_TCB p_TCB;
|
||||
|
||||
if ((p_MCB->p_lnk != NULL) && (p_MCB->state == 1U)) {
|
||||
/* A task is waiting for message */
|
||||
p_TCB = rt_get_first ((P_XCB)p_MCB);
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val2(p_TCB, 0x10U/*osEventMessage*/, (U32)p_msg);
|
||||
#else
|
||||
*p_TCB->msg = p_msg;
|
||||
rt_ret_val (p_TCB, OS_R_MBX);
|
||||
#endif
|
||||
rt_rmv_dly (p_TCB);
|
||||
rt_dispatch (p_TCB);
|
||||
}
|
||||
else {
|
||||
/* Store message in mailbox queue */
|
||||
if (p_MCB->count == p_MCB->size) {
|
||||
/* No free message entry, wait for one. If message queue is full, */
|
||||
/* then no task is waiting for message. The 'p_MCB->p_lnk' list */
|
||||
/* pointer can now be reused for send message waits task list. */
|
||||
if (timeout == 0U) {
|
||||
return (OS_R_TMO);
|
||||
}
|
||||
if (p_MCB->p_lnk != NULL) {
|
||||
rt_put_prio ((P_XCB)p_MCB, os_tsk.run);
|
||||
}
|
||||
else {
|
||||
p_MCB->p_lnk = os_tsk.run;
|
||||
os_tsk.run->p_lnk = NULL;
|
||||
os_tsk.run->p_rlnk = (P_TCB)p_MCB;
|
||||
/* Task is waiting to send a message */
|
||||
p_MCB->state = 2U;
|
||||
}
|
||||
os_tsk.run->msg = p_msg;
|
||||
rt_block (timeout, WAIT_MBX);
|
||||
return (OS_R_TMO);
|
||||
}
|
||||
/* Yes, there is a free entry in a mailbox. */
|
||||
p_MCB->msg[p_MCB->first] = p_msg;
|
||||
rt_inc (&p_MCB->count);
|
||||
if (++p_MCB->first == p_MCB->size) {
|
||||
p_MCB->first = 0U;
|
||||
}
|
||||
}
|
||||
return (OS_R_OK);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_mbx_wait -----------------------------------*/
|
||||
|
||||
OS_RESULT rt_mbx_wait (OS_ID mailbox, void **message, U16 timeout) {
|
||||
/* Receive a message; possibly wait for it */
|
||||
P_MCB p_MCB = mailbox;
|
||||
P_TCB p_TCB;
|
||||
|
||||
/* If a message is available in the fifo buffer */
|
||||
/* remove it from the fifo buffer and return. */
|
||||
if (p_MCB->count) {
|
||||
*message = p_MCB->msg[p_MCB->last];
|
||||
if (++p_MCB->last == p_MCB->size) {
|
||||
p_MCB->last = 0U;
|
||||
}
|
||||
if ((p_MCB->p_lnk != NULL) && (p_MCB->state == 2U)) {
|
||||
/* A task is waiting to send message */
|
||||
p_TCB = rt_get_first ((P_XCB)p_MCB);
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val(p_TCB, 0U/*osOK*/);
|
||||
#else
|
||||
rt_ret_val(p_TCB, OS_R_OK);
|
||||
#endif
|
||||
p_MCB->msg[p_MCB->first] = p_TCB->msg;
|
||||
if (++p_MCB->first == p_MCB->size) {
|
||||
p_MCB->first = 0U;
|
||||
}
|
||||
rt_rmv_dly (p_TCB);
|
||||
rt_dispatch (p_TCB);
|
||||
}
|
||||
else {
|
||||
rt_dec (&p_MCB->count);
|
||||
}
|
||||
return (OS_R_OK);
|
||||
}
|
||||
/* No message available: wait for one */
|
||||
if (timeout == 0U) {
|
||||
return (OS_R_TMO);
|
||||
}
|
||||
if (p_MCB->p_lnk != NULL) {
|
||||
rt_put_prio ((P_XCB)p_MCB, os_tsk.run);
|
||||
}
|
||||
else {
|
||||
p_MCB->p_lnk = os_tsk.run;
|
||||
os_tsk.run->p_lnk = NULL;
|
||||
os_tsk.run->p_rlnk = (P_TCB)p_MCB;
|
||||
/* Task is waiting to receive a message */
|
||||
p_MCB->state = 1U;
|
||||
}
|
||||
rt_block(timeout, WAIT_MBX);
|
||||
#ifndef __CMSIS_RTOS
|
||||
os_tsk.run->msg = message;
|
||||
#endif
|
||||
return (OS_R_TMO);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_mbx_check ----------------------------------*/
|
||||
|
||||
OS_RESULT rt_mbx_check (OS_ID mailbox) {
|
||||
/* Check for free space in a mailbox. Returns the number of messages */
|
||||
/* that can be stored to a mailbox. It returns 0 when mailbox is full. */
|
||||
P_MCB p_MCB = mailbox;
|
||||
|
||||
return ((U32)(p_MCB->size - p_MCB->count));
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- isr_mbx_send ----------------------------------*/
|
||||
|
||||
void isr_mbx_send (OS_ID mailbox, void *p_msg) {
|
||||
/* Same function as "os_mbx_send", but to be called by ISRs. */
|
||||
P_MCB p_MCB = mailbox;
|
||||
|
||||
rt_psq_enq (p_MCB, (U32)p_msg);
|
||||
rt_psh_req ();
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- isr_mbx_receive -------------------------------*/
|
||||
|
||||
OS_RESULT isr_mbx_receive (OS_ID mailbox, void **message) {
|
||||
/* Receive a message in the interrupt function. The interrupt function */
|
||||
/* should not wait for a message since this would block the rtx os. */
|
||||
P_MCB p_MCB = mailbox;
|
||||
|
||||
if (p_MCB->count) {
|
||||
/* A message is available in the fifo buffer. */
|
||||
*message = p_MCB->msg[p_MCB->last];
|
||||
if (p_MCB->state == 2U) {
|
||||
/* A task is locked waiting to send message */
|
||||
rt_psq_enq (p_MCB, 0U);
|
||||
rt_psh_req ();
|
||||
}
|
||||
rt_dec (&p_MCB->count);
|
||||
if (++p_MCB->last == p_MCB->size) {
|
||||
p_MCB->last = 0U;
|
||||
}
|
||||
return (OS_R_MBX);
|
||||
}
|
||||
return (OS_R_OK);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_mbx_psh ------------------------------------*/
|
||||
|
||||
void rt_mbx_psh (P_MCB p_CB, void *p_msg) {
|
||||
/* Store the message to the mailbox queue or pass it to task directly. */
|
||||
P_TCB p_TCB;
|
||||
void *mem;
|
||||
|
||||
if (p_CB->p_lnk != NULL) switch (p_CB->state) {
|
||||
#ifdef __CMSIS_RTOS
|
||||
case 3:
|
||||
/* Task is waiting to allocate memory, remove it from the waiting list */
|
||||
mem = rt_alloc_box(p_msg);
|
||||
if (mem == NULL) { break; }
|
||||
p_TCB = rt_get_first ((P_XCB)p_CB);
|
||||
rt_ret_val(p_TCB, (U32)mem);
|
||||
p_TCB->state = READY;
|
||||
rt_rmv_dly (p_TCB);
|
||||
rt_put_prio (&os_rdy, p_TCB);
|
||||
break;
|
||||
#endif
|
||||
case 2:
|
||||
/* Task is waiting to send a message, remove it from the waiting list */
|
||||
p_TCB = rt_get_first ((P_XCB)p_CB);
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val(p_TCB, 0U/*osOK*/);
|
||||
#else
|
||||
rt_ret_val(p_TCB, OS_R_OK);
|
||||
#endif
|
||||
p_CB->msg[p_CB->first] = p_TCB->msg;
|
||||
rt_inc (&p_CB->count);
|
||||
if (++p_CB->first == p_CB->size) {
|
||||
p_CB->first = 0U;
|
||||
}
|
||||
p_TCB->state = READY;
|
||||
rt_rmv_dly (p_TCB);
|
||||
rt_put_prio (&os_rdy, p_TCB);
|
||||
break;
|
||||
case 1:
|
||||
/* Task is waiting for a message, pass the message to the task directly */
|
||||
p_TCB = rt_get_first ((P_XCB)p_CB);
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val2(p_TCB, 0x10U/*osEventMessage*/, (U32)p_msg);
|
||||
#else
|
||||
*p_TCB->msg = p_msg;
|
||||
rt_ret_val (p_TCB, OS_R_MBX);
|
||||
#endif
|
||||
p_TCB->state = READY;
|
||||
rt_rmv_dly (p_TCB);
|
||||
rt_put_prio (&os_rdy, p_TCB);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} else {
|
||||
/* No task is waiting for a message, store it to the mailbox queue */
|
||||
if (p_CB->count < p_CB->size) {
|
||||
p_CB->msg[p_CB->first] = p_msg;
|
||||
rt_inc (&p_CB->count);
|
||||
if (++p_CB->first == p_CB->size) {
|
||||
p_CB->first = 0U;
|
||||
}
|
||||
}
|
||||
else {
|
||||
os_error (OS_ERR_MBX_OVF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,53 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_MAILBOX.H
|
||||
* Purpose: Implements waits and wake-ups for mailbox messages
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Functions */
|
||||
extern void rt_mbx_init (OS_ID mailbox, U16 mbx_size);
|
||||
extern OS_RESULT rt_mbx_send (OS_ID mailbox, void *p_msg, U16 timeout);
|
||||
extern OS_RESULT rt_mbx_wait (OS_ID mailbox, void **message, U16 timeout);
|
||||
extern OS_RESULT rt_mbx_check (OS_ID mailbox);
|
||||
extern void isr_mbx_send (OS_ID mailbox, void *p_msg);
|
||||
extern OS_RESULT isr_mbx_receive (OS_ID mailbox, void **message);
|
||||
extern void rt_mbx_psh (P_MCB p_CB, void *p_msg);
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/** @}*/
|
|
@ -1,168 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_MEMBOX.C
|
||||
* Purpose: Interface functions for fixed memory block management system
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_MemBox.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- _init_box -------------------------------------*/
|
||||
|
||||
U32 _init_box (void *box_mem, U32 box_size, U32 blk_size) {
|
||||
/* Initialize memory block system, returns 0 if OK, 1 if fails. */
|
||||
void *end;
|
||||
void *blk;
|
||||
void *next;
|
||||
U32 sizeof_bm;
|
||||
|
||||
/* Create memory structure. */
|
||||
if (blk_size & BOX_ALIGN_8) {
|
||||
/* Memory blocks 8-byte aligned. */
|
||||
blk_size = ((blk_size & ~BOX_ALIGN_8) + 7U) & ~(U32)7U;
|
||||
sizeof_bm = (sizeof (struct OS_BM) + 7U) & ~(U32)7U;
|
||||
}
|
||||
else {
|
||||
/* Memory blocks 4-byte aligned. */
|
||||
blk_size = (blk_size + 3U) & ~(U32)3U;
|
||||
sizeof_bm = sizeof (struct OS_BM);
|
||||
}
|
||||
if (blk_size == 0U) {
|
||||
return (1U);
|
||||
}
|
||||
if ((blk_size + sizeof_bm) > box_size) {
|
||||
return (1U);
|
||||
}
|
||||
/* Create a Memory structure. */
|
||||
blk = ((U8 *) box_mem) + sizeof_bm;
|
||||
((P_BM) box_mem)->free = blk;
|
||||
end = ((U8 *) box_mem) + box_size;
|
||||
((P_BM) box_mem)->end = end;
|
||||
((P_BM) box_mem)->blk_size = blk_size;
|
||||
|
||||
/* Link all free blocks using offsets. */
|
||||
end = ((U8 *) end) - blk_size;
|
||||
while (1) {
|
||||
next = ((U8 *) blk) + blk_size;
|
||||
if (next > end) { break; }
|
||||
*((void **)blk) = next;
|
||||
blk = next;
|
||||
}
|
||||
/* end marker */
|
||||
*((void **)blk) = 0U;
|
||||
return (0U);
|
||||
}
|
||||
|
||||
/*--------------------------- rt_alloc_box ----------------------------------*/
|
||||
|
||||
void *rt_alloc_box (void *box_mem) {
|
||||
/* Allocate a memory block and return start address. */
|
||||
void **free;
|
||||
#ifndef __USE_EXCLUSIVE_ACCESS
|
||||
U32 irq_mask;
|
||||
|
||||
irq_mask = (U32)__disable_irq ();
|
||||
free = ((P_BM) box_mem)->free;
|
||||
if (free) {
|
||||
((P_BM) box_mem)->free = *free;
|
||||
}
|
||||
if (irq_mask == 0U) { __enable_irq (); }
|
||||
#else
|
||||
do {
|
||||
if ((free = (void **)__ldrex(&((P_BM) box_mem)->free)) == 0U) {
|
||||
__clrex();
|
||||
break;
|
||||
}
|
||||
} while (__strex((U32)*free, &((P_BM) box_mem)->free));
|
||||
#endif
|
||||
return (free);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- _calloc_box -----------------------------------*/
|
||||
|
||||
void *_calloc_box (void *box_mem) {
|
||||
/* Allocate a 0-initialized memory block and return start address. */
|
||||
void *free;
|
||||
U32 *p;
|
||||
U32 i;
|
||||
|
||||
free = _alloc_box (box_mem);
|
||||
if (free) {
|
||||
p = free;
|
||||
for (i = ((P_BM) box_mem)->blk_size; i; i -= 4U) {
|
||||
*p = 0U;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
return (free);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_free_box -----------------------------------*/
|
||||
|
||||
U32 rt_free_box (void *box_mem, void *box) {
|
||||
/* Free a memory block, returns 0 if OK, 1 if box does not belong to box_mem */
|
||||
#ifndef __USE_EXCLUSIVE_ACCESS
|
||||
U32 irq_mask;
|
||||
#endif
|
||||
|
||||
if ((box < box_mem) || (box >= ((P_BM) box_mem)->end)) {
|
||||
return (1U);
|
||||
}
|
||||
|
||||
#ifndef __USE_EXCLUSIVE_ACCESS
|
||||
irq_mask = (U32)__disable_irq ();
|
||||
*((void **)box) = ((P_BM) box_mem)->free;
|
||||
((P_BM) box_mem)->free = box;
|
||||
if (irq_mask == 0U) { __enable_irq (); }
|
||||
#else
|
||||
do {
|
||||
do {
|
||||
*((void **)box) = ((P_BM) box_mem)->free;
|
||||
__DMB();
|
||||
} while (*(void**)box != (void *)__ldrex(&((P_BM) box_mem)->free));
|
||||
} while (__strex ((U32)box, &((P_BM) box_mem)->free));
|
||||
#endif
|
||||
return (0U);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,50 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_MEMBOX.H
|
||||
* Purpose: Interface functions for fixed memory block management system
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Functions */
|
||||
#define rt_init_box _init_box
|
||||
#define rt_calloc_box _calloc_box
|
||||
extern U32 _init_box (void *box_mem, U32 box_size, U32 blk_size);
|
||||
extern void *rt_alloc_box (void *box_mem);
|
||||
extern void * _calloc_box (void *box_mem);
|
||||
extern U32 rt_free_box (void *box_mem, void *box);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/** @}*/
|
|
@ -1,140 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_MEMORY.C
|
||||
* Purpose: Interface functions for Dynamic Memory Management System
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "rt_Memory.h"
|
||||
|
||||
|
||||
/* Functions */
|
||||
|
||||
// Initialize Dynamic Memory pool
|
||||
// Parameters:
|
||||
// pool: Pointer to memory pool
|
||||
// size: Size of memory pool in bytes
|
||||
// Return: 0 - OK, 1 - Error
|
||||
|
||||
U32 rt_init_mem (void *pool, U32 size) {
|
||||
MEMP *ptr;
|
||||
|
||||
if ((pool == NULL) || (size < sizeof(MEMP))) { return (1U); }
|
||||
|
||||
ptr = (MEMP *)pool;
|
||||
ptr->next = (MEMP *)((U32)pool + size - sizeof(MEMP *));
|
||||
ptr->next->next = NULL;
|
||||
ptr->len = 0U;
|
||||
|
||||
return (0U);
|
||||
}
|
||||
|
||||
// Allocate Memory from Memory pool
|
||||
// Parameters:
|
||||
// pool: Pointer to memory pool
|
||||
// size: Size of memory in bytes to allocate
|
||||
// Return: Pointer to allocated memory
|
||||
|
||||
void *rt_alloc_mem (void *pool, U32 size) {
|
||||
MEMP *p, *p_search, *p_new;
|
||||
U32 hole_size;
|
||||
|
||||
if ((pool == NULL) || (size == 0U)) { return NULL; }
|
||||
|
||||
/* Add header offset to 'size' */
|
||||
size += sizeof(MEMP);
|
||||
/* Make sure that block is 4-byte aligned */
|
||||
size = (size + 3U) & ~(U32)3U;
|
||||
|
||||
p_search = (MEMP *)pool;
|
||||
while (1) {
|
||||
hole_size = (U32)p_search->next - (U32)p_search;
|
||||
hole_size -= p_search->len;
|
||||
/* Check if hole size is big enough */
|
||||
if (hole_size >= size) { break; }
|
||||
p_search = p_search->next;
|
||||
if (p_search->next == NULL) {
|
||||
/* Failed, we are at the end of the list */
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (p_search->len == 0U) {
|
||||
/* No block is allocated, set the Length of the first element */
|
||||
p_search->len = size;
|
||||
p = (MEMP *)(((U32)p_search) + sizeof(MEMP));
|
||||
} else {
|
||||
/* Insert new list element into the memory list */
|
||||
p_new = (MEMP *)((U32)p_search + p_search->len);
|
||||
p_new->next = p_search->next;
|
||||
p_new->len = size;
|
||||
p_search->next = p_new;
|
||||
p = (MEMP *)(((U32)p_new) + sizeof(MEMP));
|
||||
}
|
||||
|
||||
return (p);
|
||||
}
|
||||
|
||||
// Free Memory and return it to Memory pool
|
||||
// Parameters:
|
||||
// pool: Pointer to memory pool
|
||||
// mem: Pointer to memory to free
|
||||
// Return: 0 - OK, 1 - Error
|
||||
|
||||
U32 rt_free_mem (void *pool, void *mem) {
|
||||
MEMP *p_search, *p_prev, *p_return;
|
||||
|
||||
if ((pool == NULL) || (mem == NULL)) { return (1U); }
|
||||
|
||||
p_return = (MEMP *)((U32)mem - sizeof(MEMP));
|
||||
|
||||
/* Set list header */
|
||||
p_prev = NULL;
|
||||
p_search = (MEMP *)pool;
|
||||
while (p_search != p_return) {
|
||||
p_prev = p_search;
|
||||
p_search = p_search->next;
|
||||
if (p_search == NULL) {
|
||||
/* Valid Memory block not found */
|
||||
return (1U);
|
||||
}
|
||||
}
|
||||
|
||||
if (p_prev == NULL) {
|
||||
/* First block to be released, only set length to 0 */
|
||||
p_search->len = 0U;
|
||||
} else {
|
||||
/* Discard block from chain list */
|
||||
p_prev->next = p_search->next;
|
||||
}
|
||||
|
||||
return (0U);
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_MEMORY.H
|
||||
* Purpose: Interface functions for Dynamic Memory Management System
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Types */
|
||||
typedef struct mem { /* << Memory Pool management struct >> */
|
||||
struct mem *next; /* Next Memory Block in the list */
|
||||
U32 len; /* Length of data block */
|
||||
} MEMP;
|
||||
|
||||
/* Functions */
|
||||
extern U32 rt_init_mem (void *pool, U32 size);
|
||||
extern void *rt_alloc_mem (void *pool, U32 size);
|
||||
extern U32 rt_free_mem (void *pool, void *mem);
|
||||
|
||||
/** @}*/
|
|
@ -1,259 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_MUTEX.C
|
||||
* Purpose: Implements mutex synchronization objects
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_List.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_Mutex.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_mut_init -----------------------------------*/
|
||||
|
||||
void rt_mut_init (OS_ID mutex) {
|
||||
/* Initialize a mutex object */
|
||||
P_MUCB p_MCB = mutex;
|
||||
|
||||
p_MCB->cb_type = MUCB;
|
||||
p_MCB->level = 0U;
|
||||
p_MCB->p_lnk = NULL;
|
||||
p_MCB->owner = NULL;
|
||||
p_MCB->p_mlnk = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_mut_delete ---------------------------------*/
|
||||
|
||||
#ifdef __CMSIS_RTOS
|
||||
OS_RESULT rt_mut_delete (OS_ID mutex) {
|
||||
/* Delete a mutex object */
|
||||
P_MUCB p_MCB = mutex;
|
||||
P_TCB p_TCB;
|
||||
P_MUCB p_mlnk;
|
||||
U8 prio;
|
||||
|
||||
if (p_MCB->level != 0U) {
|
||||
|
||||
p_TCB = p_MCB->owner;
|
||||
|
||||
/* Remove mutex from task mutex owner list. */
|
||||
p_mlnk = p_TCB->p_mlnk;
|
||||
if (p_mlnk == p_MCB) {
|
||||
p_TCB->p_mlnk = p_MCB->p_mlnk;
|
||||
}
|
||||
else {
|
||||
while (p_mlnk) {
|
||||
if (p_mlnk->p_mlnk == p_MCB) {
|
||||
p_mlnk->p_mlnk = p_MCB->p_mlnk;
|
||||
break;
|
||||
}
|
||||
p_mlnk = p_mlnk->p_mlnk;
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore owner task's priority. */
|
||||
prio = p_TCB->prio_base;
|
||||
p_mlnk = p_TCB->p_mlnk;
|
||||
while (p_mlnk) {
|
||||
if ((p_mlnk->p_lnk != NULL) && (p_mlnk->p_lnk->prio > prio)) {
|
||||
/* A task with higher priority is waiting for mutex. */
|
||||
prio = p_mlnk->p_lnk->prio;
|
||||
}
|
||||
p_mlnk = p_mlnk->p_mlnk;
|
||||
}
|
||||
if (p_TCB->prio != prio) {
|
||||
p_TCB->prio = prio;
|
||||
if (p_TCB != os_tsk.run) {
|
||||
rt_resort_prio (p_TCB);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while (p_MCB->p_lnk != NULL) {
|
||||
/* A task is waiting for mutex. */
|
||||
p_TCB = rt_get_first ((P_XCB)p_MCB);
|
||||
rt_ret_val(p_TCB, 0U/*osOK*/);
|
||||
rt_rmv_dly(p_TCB);
|
||||
p_TCB->state = READY;
|
||||
rt_put_prio (&os_rdy, p_TCB);
|
||||
}
|
||||
|
||||
if ((os_rdy.p_lnk != NULL) && (os_rdy.p_lnk->prio > os_tsk.run->prio)) {
|
||||
/* preempt running task */
|
||||
rt_put_prio (&os_rdy, os_tsk.run);
|
||||
os_tsk.run->state = READY;
|
||||
rt_dispatch (NULL);
|
||||
}
|
||||
|
||||
p_MCB->cb_type = 0U;
|
||||
|
||||
return (OS_R_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*--------------------------- rt_mut_release --------------------------------*/
|
||||
|
||||
OS_RESULT rt_mut_release (OS_ID mutex) {
|
||||
/* Release a mutex object */
|
||||
P_MUCB p_MCB = mutex;
|
||||
P_TCB p_TCB;
|
||||
P_MUCB p_mlnk;
|
||||
U8 prio;
|
||||
|
||||
if ((p_MCB->level == 0U) || (p_MCB->owner != os_tsk.run)) {
|
||||
/* Unbalanced mutex release or task is not the owner */
|
||||
return (OS_R_NOK);
|
||||
}
|
||||
if (--p_MCB->level != 0U) {
|
||||
return (OS_R_OK);
|
||||
}
|
||||
|
||||
/* Remove mutex from task mutex owner list. */
|
||||
p_mlnk = os_tsk.run->p_mlnk;
|
||||
if (p_mlnk == p_MCB) {
|
||||
os_tsk.run->p_mlnk = p_MCB->p_mlnk;
|
||||
}
|
||||
else {
|
||||
while (p_mlnk) {
|
||||
if (p_mlnk->p_mlnk == p_MCB) {
|
||||
p_mlnk->p_mlnk = p_MCB->p_mlnk;
|
||||
break;
|
||||
}
|
||||
p_mlnk = p_mlnk->p_mlnk;
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore owner task's priority. */
|
||||
prio = os_tsk.run->prio_base;
|
||||
p_mlnk = os_tsk.run->p_mlnk;
|
||||
while (p_mlnk) {
|
||||
if ((p_mlnk->p_lnk != NULL) && (p_mlnk->p_lnk->prio > prio)) {
|
||||
/* A task with higher priority is waiting for mutex. */
|
||||
prio = p_mlnk->p_lnk->prio;
|
||||
}
|
||||
p_mlnk = p_mlnk->p_mlnk;
|
||||
}
|
||||
os_tsk.run->prio = prio;
|
||||
|
||||
if (p_MCB->p_lnk != NULL) {
|
||||
/* A task is waiting for mutex. */
|
||||
p_TCB = rt_get_first ((P_XCB)p_MCB);
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val(p_TCB, 0U/*osOK*/);
|
||||
#else
|
||||
rt_ret_val(p_TCB, OS_R_MUT);
|
||||
#endif
|
||||
rt_rmv_dly (p_TCB);
|
||||
/* A waiting task becomes the owner of this mutex. */
|
||||
p_MCB->level = 1U;
|
||||
p_MCB->owner = p_TCB;
|
||||
p_MCB->p_mlnk = p_TCB->p_mlnk;
|
||||
p_TCB->p_mlnk = p_MCB;
|
||||
/* Priority inversion, check which task continues. */
|
||||
if (os_tsk.run->prio >= rt_rdy_prio()) {
|
||||
rt_dispatch (p_TCB);
|
||||
}
|
||||
else {
|
||||
/* Ready task has higher priority than running task. */
|
||||
rt_put_prio (&os_rdy, os_tsk.run);
|
||||
rt_put_prio (&os_rdy, p_TCB);
|
||||
os_tsk.run->state = READY;
|
||||
p_TCB->state = READY;
|
||||
rt_dispatch (NULL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Check if own priority lowered by priority inversion. */
|
||||
if (rt_rdy_prio() > os_tsk.run->prio) {
|
||||
rt_put_prio (&os_rdy, os_tsk.run);
|
||||
os_tsk.run->state = READY;
|
||||
rt_dispatch (NULL);
|
||||
}
|
||||
}
|
||||
return (OS_R_OK);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_mut_wait -----------------------------------*/
|
||||
|
||||
OS_RESULT rt_mut_wait (OS_ID mutex, U16 timeout) {
|
||||
/* Wait for a mutex, continue when mutex is free. */
|
||||
P_MUCB p_MCB = mutex;
|
||||
|
||||
if (p_MCB->level == 0U) {
|
||||
p_MCB->owner = os_tsk.run;
|
||||
p_MCB->p_mlnk = os_tsk.run->p_mlnk;
|
||||
os_tsk.run->p_mlnk = p_MCB;
|
||||
goto inc;
|
||||
}
|
||||
if (p_MCB->owner == os_tsk.run) {
|
||||
/* OK, running task is the owner of this mutex. */
|
||||
inc:p_MCB->level++;
|
||||
return (OS_R_OK);
|
||||
}
|
||||
/* Mutex owned by another task, wait until released. */
|
||||
if (timeout == 0U) {
|
||||
return (OS_R_TMO);
|
||||
}
|
||||
/* Raise the owner task priority if lower than current priority. */
|
||||
/* This priority inversion is called priority inheritance. */
|
||||
if (p_MCB->owner->prio < os_tsk.run->prio) {
|
||||
p_MCB->owner->prio = os_tsk.run->prio;
|
||||
rt_resort_prio (p_MCB->owner);
|
||||
}
|
||||
if (p_MCB->p_lnk != NULL) {
|
||||
rt_put_prio ((P_XCB)p_MCB, os_tsk.run);
|
||||
}
|
||||
else {
|
||||
p_MCB->p_lnk = os_tsk.run;
|
||||
os_tsk.run->p_lnk = NULL;
|
||||
os_tsk.run->p_rlnk = (P_TCB)p_MCB;
|
||||
}
|
||||
rt_block(timeout, WAIT_MUT);
|
||||
return (OS_R_TMO);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_MUTEX.H
|
||||
* Purpose: Implements mutex synchronization objects
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Functions */
|
||||
extern void rt_mut_init (OS_ID mutex);
|
||||
extern OS_RESULT rt_mut_delete (OS_ID mutex);
|
||||
extern OS_RESULT rt_mut_release (OS_ID mutex);
|
||||
extern OS_RESULT rt_mut_wait (OS_ID mutex, U16 timeout);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/** @}*/
|
|
@ -1,61 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: rt_OsEventObserver.c
|
||||
* Purpose: OS Event Callbacks for CMSIS RTOS
|
||||
* Rev.: VX.XX
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_OsEventObserver.h"
|
||||
|
||||
/*
|
||||
* _____ _____ ____ __ _____
|
||||
* | ___|_ _\ \/ / \/ | ____|
|
||||
* | |_ | | \ /| |\/| | _|
|
||||
* | _| | | / \| | | | |___
|
||||
* |_| |___/_/\_\_| |_|_____|
|
||||
*
|
||||
* FIXME:
|
||||
* The osEventObs variable must be in protected memory. If not every box
|
||||
* and box 0 can modify osEventObs to point to any handler to run code
|
||||
* privileged. This issue is tracked at
|
||||
* <https://github.com/ARMmbed/uvisor/issues/235>.
|
||||
*/
|
||||
const OsEventObserver *osEventObs;
|
||||
|
||||
void osRegisterForOsEvents(const OsEventObserver *observer)
|
||||
{
|
||||
static uint8_t has_been_called = 0;
|
||||
if (has_been_called) {
|
||||
return;
|
||||
}
|
||||
has_been_called = 1;
|
||||
|
||||
osEventObs = observer;
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: os_events.h
|
||||
* Purpose: OS Event Callbacks for CMSIS RTOS
|
||||
* Rev.: VX.XX
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2016 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef _RT_OS_EVENT_OBSERVER_H
|
||||
#define _RT_OS_EVENT_OBSERVER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
void (*pre_start)(void);
|
||||
void *(*thread_create)(int thread_id, void *context);
|
||||
void (*thread_destroy)(void *context);
|
||||
void (*thread_switch)(void *context);
|
||||
} OsEventObserver;
|
||||
extern const OsEventObserver *osEventObs;
|
||||
|
||||
void osRegisterForOsEvents(const OsEventObserver *observer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/** @}*/
|
|
@ -1,83 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_ROBIN.C
|
||||
* Purpose: Round Robin Task switching
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_List.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_Time.h"
|
||||
#include "rt_Robin.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Variables
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
struct OS_ROBIN os_robin;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/*--------------------------- rt_init_robin ---------------------------------*/
|
||||
|
||||
__weak void rt_init_robin (void) {
|
||||
/* Initialize Round Robin variables. */
|
||||
os_robin.task = NULL;
|
||||
os_robin.tout = (U16)os_rrobin;
|
||||
}
|
||||
|
||||
/*--------------------------- rt_chk_robin ----------------------------------*/
|
||||
|
||||
__weak void rt_chk_robin (void) {
|
||||
/* Check if Round Robin timeout expired and switch to the next ready task.*/
|
||||
P_TCB p_new;
|
||||
|
||||
if (os_robin.task != os_rdy.p_lnk) {
|
||||
/* New task was suspended, reset Round Robin timeout. */
|
||||
os_robin.task = os_rdy.p_lnk;
|
||||
os_robin.time = (U16)os_time + os_robin.tout - 1U;
|
||||
}
|
||||
if (os_robin.time == (U16)os_time) {
|
||||
/* Round Robin timeout has expired, swap Robin tasks. */
|
||||
os_robin.task = NULL;
|
||||
p_new = rt_get_first (&os_rdy);
|
||||
rt_put_prio ((P_XCB)&os_rdy, p_new);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,50 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_ROBIN.H
|
||||
* Purpose: Round Robin Task switching definitions
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Variables */
|
||||
extern struct OS_ROBIN os_robin;
|
||||
|
||||
/* Functions */
|
||||
extern void rt_init_robin (void);
|
||||
extern void rt_chk_robin (void);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/** @}*/
|
|
@ -1,182 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_SEMAPHORE.C
|
||||
* Purpose: Implements binary and counting semaphores
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_List.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_Semaphore.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_sem_init -----------------------------------*/
|
||||
|
||||
void rt_sem_init (OS_ID semaphore, U16 token_count) {
|
||||
/* Initialize a semaphore */
|
||||
P_SCB p_SCB = semaphore;
|
||||
|
||||
p_SCB->cb_type = SCB;
|
||||
p_SCB->p_lnk = NULL;
|
||||
p_SCB->tokens = token_count;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_sem_delete ---------------------------------*/
|
||||
|
||||
#ifdef __CMSIS_RTOS
|
||||
OS_RESULT rt_sem_delete (OS_ID semaphore) {
|
||||
/* Delete semaphore */
|
||||
P_SCB p_SCB = semaphore;
|
||||
P_TCB p_TCB;
|
||||
|
||||
while (p_SCB->p_lnk != NULL) {
|
||||
/* A task is waiting for token */
|
||||
p_TCB = rt_get_first ((P_XCB)p_SCB);
|
||||
rt_ret_val(p_TCB, 0U);
|
||||
rt_rmv_dly(p_TCB);
|
||||
p_TCB->state = READY;
|
||||
rt_put_prio (&os_rdy, p_TCB);
|
||||
}
|
||||
|
||||
if ((os_rdy.p_lnk != NULL) && (os_rdy.p_lnk->prio > os_tsk.run->prio)) {
|
||||
/* preempt running task */
|
||||
rt_put_prio (&os_rdy, os_tsk.run);
|
||||
os_tsk.run->state = READY;
|
||||
rt_dispatch (NULL);
|
||||
}
|
||||
|
||||
p_SCB->cb_type = 0U;
|
||||
|
||||
return (OS_R_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*--------------------------- rt_sem_send -----------------------------------*/
|
||||
|
||||
OS_RESULT rt_sem_send (OS_ID semaphore) {
|
||||
/* Return a token to semaphore */
|
||||
P_SCB p_SCB = semaphore;
|
||||
P_TCB p_TCB;
|
||||
|
||||
if (p_SCB->p_lnk != NULL) {
|
||||
/* A task is waiting for token */
|
||||
p_TCB = rt_get_first ((P_XCB)p_SCB);
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val(p_TCB, 1U);
|
||||
#else
|
||||
rt_ret_val(p_TCB, OS_R_SEM);
|
||||
#endif
|
||||
rt_rmv_dly (p_TCB);
|
||||
rt_dispatch (p_TCB);
|
||||
}
|
||||
else {
|
||||
/* Store token. */
|
||||
p_SCB->tokens++;
|
||||
}
|
||||
return (OS_R_OK);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_sem_wait -----------------------------------*/
|
||||
|
||||
OS_RESULT rt_sem_wait (OS_ID semaphore, U16 timeout) {
|
||||
/* Obtain a token; possibly wait for it */
|
||||
P_SCB p_SCB = semaphore;
|
||||
|
||||
if (p_SCB->tokens) {
|
||||
p_SCB->tokens--;
|
||||
return (OS_R_OK);
|
||||
}
|
||||
/* No token available: wait for one */
|
||||
if (timeout == 0U) {
|
||||
return (OS_R_TMO);
|
||||
}
|
||||
if (p_SCB->p_lnk != NULL) {
|
||||
rt_put_prio ((P_XCB)p_SCB, os_tsk.run);
|
||||
}
|
||||
else {
|
||||
p_SCB->p_lnk = os_tsk.run;
|
||||
os_tsk.run->p_lnk = NULL;
|
||||
os_tsk.run->p_rlnk = (P_TCB)p_SCB;
|
||||
}
|
||||
rt_block(timeout, WAIT_SEM);
|
||||
return (OS_R_TMO);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- isr_sem_send ----------------------------------*/
|
||||
|
||||
void isr_sem_send (OS_ID semaphore) {
|
||||
/* Same function as "os_sem_send", but to be called by ISRs */
|
||||
P_SCB p_SCB = semaphore;
|
||||
|
||||
rt_psq_enq (p_SCB, 0U);
|
||||
rt_psh_req ();
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_sem_psh ------------------------------------*/
|
||||
|
||||
void rt_sem_psh (P_SCB p_CB) {
|
||||
/* Check if task has to be waken up */
|
||||
P_TCB p_TCB;
|
||||
|
||||
if (p_CB->p_lnk != NULL) {
|
||||
/* A task is waiting for token */
|
||||
p_TCB = rt_get_first ((P_XCB)p_CB);
|
||||
rt_rmv_dly (p_TCB);
|
||||
p_TCB->state = READY;
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val(p_TCB, 1U);
|
||||
#else
|
||||
rt_ret_val(p_TCB, OS_R_SEM);
|
||||
#endif
|
||||
rt_put_prio (&os_rdy, p_TCB);
|
||||
}
|
||||
else {
|
||||
/* Store token */
|
||||
p_CB->tokens++;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,51 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_SEMAPHORE.H
|
||||
* Purpose: Implements binary and counting semaphores
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Functions */
|
||||
extern void rt_sem_init (OS_ID semaphore, U16 token_count);
|
||||
extern OS_RESULT rt_sem_delete(OS_ID semaphore);
|
||||
extern OS_RESULT rt_sem_send (OS_ID semaphore);
|
||||
extern OS_RESULT rt_sem_wait (OS_ID semaphore, U16 timeout);
|
||||
extern void isr_sem_send (OS_ID semaphore);
|
||||
extern void rt_sem_psh (P_SCB p_CB);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/** @}*/
|
|
@ -1,325 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_SYSTEM.C
|
||||
* Purpose: System Task Manager
|
||||
* Rev.: V4.80
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_Event.h"
|
||||
#include "rt_List.h"
|
||||
#include "rt_Mailbox.h"
|
||||
#include "rt_Semaphore.h"
|
||||
#include "rt_Time.h"
|
||||
#include "rt_Timer.h"
|
||||
#include "rt_Robin.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Variables
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
S32 os_tick_irqn;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local Variables
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
static volatile BIT os_lock;
|
||||
static volatile BIT os_psh_flag;
|
||||
static U8 pend_flags;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#define RL_RTX_VER 0x480
|
||||
|
||||
#if defined (__CC_ARM)
|
||||
__asm void $$RTX$$version (void) {
|
||||
/* Export a version number symbol for a version control. */
|
||||
|
||||
EXPORT __RL_RTX_VER
|
||||
|
||||
__RL_RTX_VER EQU RL_RTX_VER
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*--------------------------- rt_suspend ------------------------------------*/
|
||||
|
||||
extern U32 sysUserTimerWakeupTime(void);
|
||||
|
||||
U32 rt_suspend (void) {
|
||||
/* Suspend OS scheduler */
|
||||
U32 delta = 0xFFFFU;
|
||||
#ifdef __CMSIS_RTOS
|
||||
U32 sleep;
|
||||
#endif
|
||||
|
||||
rt_tsk_lock();
|
||||
|
||||
if (os_dly.p_dlnk) {
|
||||
delta = os_dly.delta_time;
|
||||
}
|
||||
#ifdef __CMSIS_RTOS
|
||||
sleep = sysUserTimerWakeupTime();
|
||||
if (sleep < delta) { delta = sleep; }
|
||||
#else
|
||||
if (os_tmr.next) {
|
||||
if (os_tmr.tcnt < delta) delta = os_tmr.tcnt;
|
||||
}
|
||||
#endif
|
||||
|
||||
return (delta);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_resume -------------------------------------*/
|
||||
|
||||
extern void sysUserTimerUpdate (U32 sleep_time);
|
||||
|
||||
void rt_resume (U32 sleep_time) {
|
||||
/* Resume OS scheduler after suspend */
|
||||
P_TCB next;
|
||||
U32 delta;
|
||||
|
||||
os_tsk.run->state = READY;
|
||||
rt_put_rdy_first (os_tsk.run);
|
||||
|
||||
os_robin.task = NULL;
|
||||
|
||||
/* Update delays. */
|
||||
if (os_dly.p_dlnk) {
|
||||
delta = sleep_time;
|
||||
if (delta >= os_dly.delta_time) {
|
||||
delta -= os_dly.delta_time;
|
||||
os_time += os_dly.delta_time;
|
||||
os_dly.delta_time = 1U;
|
||||
while (os_dly.p_dlnk) {
|
||||
rt_dec_dly();
|
||||
if (delta == 0U) { break; }
|
||||
delta--;
|
||||
os_time++;
|
||||
}
|
||||
} else {
|
||||
os_time += delta;
|
||||
os_dly.delta_time -= (U16)delta;
|
||||
}
|
||||
} else {
|
||||
os_time += sleep_time;
|
||||
}
|
||||
|
||||
/* Check the user timers. */
|
||||
#ifdef __CMSIS_RTOS
|
||||
sysUserTimerUpdate(sleep_time);
|
||||
#else
|
||||
if (os_tmr.next) {
|
||||
delta = sleep_time;
|
||||
if (delta >= os_tmr.tcnt) {
|
||||
delta -= os_tmr.tcnt;
|
||||
os_tmr.tcnt = 1U;
|
||||
while (os_tmr.next) {
|
||||
rt_tmr_tick();
|
||||
if (delta == 0U) { break; }
|
||||
delta--;
|
||||
}
|
||||
} else {
|
||||
os_tmr.tcnt -= delta;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Switch back to highest ready task */
|
||||
next = rt_get_first (&os_rdy);
|
||||
rt_switch_req (next);
|
||||
|
||||
rt_tsk_unlock();
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_tsk_lock -----------------------------------*/
|
||||
|
||||
void rt_tsk_lock (void) {
|
||||
/* Prevent task switching by locking out scheduler */
|
||||
if (os_tick_irqn < 0) {
|
||||
OS_LOCK();
|
||||
os_lock = __TRUE;
|
||||
OS_UNPEND(pend_flags);
|
||||
} else {
|
||||
OS_X_LOCK((U32)os_tick_irqn);
|
||||
os_lock = __TRUE;
|
||||
OS_X_UNPEND(pend_flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_tsk_unlock ---------------------------------*/
|
||||
|
||||
void rt_tsk_unlock (void) {
|
||||
/* Unlock scheduler and re-enable task switching */
|
||||
if (os_tick_irqn < 0) {
|
||||
OS_UNLOCK();
|
||||
os_lock = __FALSE;
|
||||
OS_PEND(pend_flags, os_psh_flag);
|
||||
os_psh_flag = __FALSE;
|
||||
} else {
|
||||
OS_X_UNLOCK((U32)os_tick_irqn);
|
||||
os_lock = __FALSE;
|
||||
OS_X_PEND(pend_flags, os_psh_flag);
|
||||
os_psh_flag = __FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_psh_req ------------------------------------*/
|
||||
|
||||
void rt_psh_req (void) {
|
||||
/* Initiate a post service handling request if required. */
|
||||
if (os_lock == __FALSE) {
|
||||
OS_PEND_IRQ();
|
||||
}
|
||||
else {
|
||||
os_psh_flag = __TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_pop_req ------------------------------------*/
|
||||
|
||||
void rt_pop_req (void) {
|
||||
/* Process an ISR post service requests. */
|
||||
struct OS_XCB *p_CB;
|
||||
P_TCB next;
|
||||
U32 idx;
|
||||
|
||||
os_tsk.run->state = READY;
|
||||
rt_put_rdy_first (os_tsk.run);
|
||||
|
||||
idx = os_psq->last;
|
||||
while (os_psq->count) {
|
||||
p_CB = os_psq->q[idx].id;
|
||||
if (p_CB->cb_type == TCB) {
|
||||
/* Is of TCB type */
|
||||
rt_evt_psh ((P_TCB)p_CB, (U16)os_psq->q[idx].arg);
|
||||
}
|
||||
else if (p_CB->cb_type == MCB) {
|
||||
/* Is of MCB type */
|
||||
rt_mbx_psh ((P_MCB)p_CB, (void *)os_psq->q[idx].arg);
|
||||
}
|
||||
else {
|
||||
/* Must be of SCB type */
|
||||
rt_sem_psh ((P_SCB)p_CB);
|
||||
}
|
||||
if (++idx == os_psq->size) { idx = 0U; }
|
||||
rt_dec (&os_psq->count);
|
||||
}
|
||||
os_psq->last = (U8)idx;
|
||||
|
||||
next = rt_get_first (&os_rdy);
|
||||
rt_switch_req (next);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- os_tick_init ----------------------------------*/
|
||||
|
||||
__weak S32 os_tick_init (void) {
|
||||
/* Initialize SysTick timer as system tick timer. */
|
||||
rt_systick_init();
|
||||
return (-1); /* Return IRQ number of SysTick timer */
|
||||
}
|
||||
|
||||
/*--------------------------- os_tick_val -----------------------------------*/
|
||||
|
||||
__weak U32 os_tick_val (void) {
|
||||
/* Get SysTick timer current value (0 .. OS_TRV). */
|
||||
return rt_systick_val();
|
||||
}
|
||||
|
||||
/*--------------------------- os_tick_ovf -----------------------------------*/
|
||||
|
||||
__weak U32 os_tick_ovf (void) {
|
||||
/* Get SysTick timer overflow flag */
|
||||
return rt_systick_ovf();
|
||||
}
|
||||
|
||||
/*--------------------------- os_tick_irqack --------------------------------*/
|
||||
|
||||
__weak void os_tick_irqack (void) {
|
||||
/* Acknowledge timer interrupt. */
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_systick ------------------------------------*/
|
||||
|
||||
extern void sysTimerTick(void);
|
||||
|
||||
void rt_systick (void) {
|
||||
/* Check for system clock update, suspend running task. */
|
||||
P_TCB next;
|
||||
|
||||
os_tsk.run->state = READY;
|
||||
rt_put_rdy_first (os_tsk.run);
|
||||
|
||||
/* Check Round Robin timeout. */
|
||||
rt_chk_robin ();
|
||||
|
||||
/* Update delays. */
|
||||
os_time++;
|
||||
rt_dec_dly ();
|
||||
|
||||
/* Check the user timers. */
|
||||
#ifdef __CMSIS_RTOS
|
||||
sysTimerTick();
|
||||
#else
|
||||
rt_tmr_tick ();
|
||||
#endif
|
||||
|
||||
/* Switch back to highest ready task */
|
||||
next = rt_get_first (&os_rdy);
|
||||
rt_switch_req (next);
|
||||
}
|
||||
|
||||
/*--------------------------- rt_stk_check ----------------------------------*/
|
||||
|
||||
__weak void rt_stk_check (void) {
|
||||
if ((os_tsk.run->tsk_stack < (U32)os_tsk.run->stack) ||
|
||||
(os_tsk.run->stack[0] != MAGIC_WORD)) {
|
||||
os_error (OS_ERR_STK_OVF);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_SYSTEM.H
|
||||
* Purpose: System Task Manager definitions
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Variables */
|
||||
#define os_psq ((P_PSQ)&os_fifo)
|
||||
extern S32 os_tick_irqn;
|
||||
|
||||
/* Functions */
|
||||
extern U32 rt_suspend (void);
|
||||
extern void rt_resume (U32 sleep_time);
|
||||
extern void rt_tsk_lock (void);
|
||||
extern void rt_tsk_unlock (void);
|
||||
extern void rt_psh_req (void);
|
||||
extern void rt_pop_req (void);
|
||||
extern void rt_systick (void);
|
||||
extern void rt_stk_check (void);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/** @}*/
|
|
@ -1,456 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_TASK.C
|
||||
* Purpose: Task functions and system start up.
|
||||
* Rev.: V4.80
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_System.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_List.h"
|
||||
#include "rt_MemBox.h"
|
||||
#include "rt_Robin.h"
|
||||
#include "rt_HAL_CM.h"
|
||||
#include "rt_OsEventObserver.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Variables
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Running and next task info. */
|
||||
struct OS_TSK os_tsk;
|
||||
|
||||
/* Task Control Blocks of idle demon */
|
||||
struct OS_TCB os_idle_TCB;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
static OS_TID rt_get_TID (void) {
|
||||
U32 tid;
|
||||
|
||||
for (tid = 1U; tid <= os_maxtaskrun; tid++) {
|
||||
if (os_active_TCB[tid-1U] == NULL) {
|
||||
return ((OS_TID)tid);
|
||||
}
|
||||
}
|
||||
return (0U);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_init_context -------------------------------*/
|
||||
|
||||
static void rt_init_context (P_TCB p_TCB, U8 priority, FUNCP task_body) {
|
||||
/* Initialize general part of the Task Control Block. */
|
||||
p_TCB->cb_type = TCB;
|
||||
p_TCB->state = READY;
|
||||
p_TCB->prio = priority;
|
||||
p_TCB->prio_base = priority;
|
||||
p_TCB->p_lnk = NULL;
|
||||
p_TCB->p_rlnk = NULL;
|
||||
p_TCB->p_dlnk = NULL;
|
||||
p_TCB->p_blnk = NULL;
|
||||
p_TCB->p_mlnk = NULL;
|
||||
p_TCB->delta_time = 0U;
|
||||
p_TCB->interval_time = 0U;
|
||||
p_TCB->events = 0U;
|
||||
p_TCB->waits = 0U;
|
||||
p_TCB->stack_frame = 0U;
|
||||
|
||||
if (p_TCB->priv_stack == 0U) {
|
||||
/* Allocate the memory space for the stack. */
|
||||
p_TCB->stack = rt_alloc_box (mp_stk);
|
||||
}
|
||||
rt_init_stack (p_TCB, task_body);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_switch_req ---------------------------------*/
|
||||
|
||||
void rt_switch_req (P_TCB p_new) {
|
||||
/* Switch to next task (identified by "p_new"). */
|
||||
os_tsk.new_tsk = p_new;
|
||||
p_new->state = RUNNING;
|
||||
if (osEventObs && osEventObs->thread_switch) {
|
||||
osEventObs->thread_switch(p_new->context);
|
||||
}
|
||||
DBG_TASK_SWITCH(p_new->task_id);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_dispatch -----------------------------------*/
|
||||
|
||||
void rt_dispatch (P_TCB next_TCB) {
|
||||
/* Dispatch next task if any identified or dispatch highest ready task */
|
||||
/* "next_TCB" identifies a task to run or has value NULL (=no next task) */
|
||||
if (next_TCB == NULL) {
|
||||
/* Running task was blocked: continue with highest ready task */
|
||||
next_TCB = rt_get_first (&os_rdy);
|
||||
rt_switch_req (next_TCB);
|
||||
}
|
||||
else {
|
||||
/* Check which task continues */
|
||||
if (next_TCB->prio > os_tsk.run->prio) {
|
||||
/* preempt running task */
|
||||
rt_put_rdy_first (os_tsk.run);
|
||||
os_tsk.run->state = READY;
|
||||
rt_switch_req (next_TCB);
|
||||
}
|
||||
else {
|
||||
/* put next task into ready list, no task switch takes place */
|
||||
next_TCB->state = READY;
|
||||
rt_put_prio (&os_rdy, next_TCB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_block --------------------------------------*/
|
||||
|
||||
void rt_block (U16 timeout, U8 block_state) {
|
||||
/* Block running task and choose next ready task. */
|
||||
/* "timeout" sets a time-out value or is 0xffff (=no time-out). */
|
||||
/* "block_state" defines the appropriate task state */
|
||||
P_TCB next_TCB;
|
||||
|
||||
if (timeout) {
|
||||
if (timeout < 0xFFFFU) {
|
||||
rt_put_dly (os_tsk.run, timeout);
|
||||
}
|
||||
os_tsk.run->state = block_state;
|
||||
next_TCB = rt_get_first (&os_rdy);
|
||||
rt_switch_req (next_TCB);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_tsk_pass -----------------------------------*/
|
||||
|
||||
void rt_tsk_pass (void) {
|
||||
/* Allow tasks of same priority level to run cooperatively.*/
|
||||
P_TCB p_new;
|
||||
|
||||
p_new = rt_get_same_rdy_prio();
|
||||
if (p_new != NULL) {
|
||||
rt_put_prio ((P_XCB)&os_rdy, os_tsk.run);
|
||||
os_tsk.run->state = READY;
|
||||
rt_switch_req (p_new);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_tsk_self -----------------------------------*/
|
||||
|
||||
OS_TID rt_tsk_self (void) {
|
||||
/* Return own task identifier value. */
|
||||
if (os_tsk.run == NULL) {
|
||||
return (0U);
|
||||
}
|
||||
return ((OS_TID)os_tsk.run->task_id);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_tsk_prio -----------------------------------*/
|
||||
|
||||
OS_RESULT rt_tsk_prio (OS_TID task_id, U8 new_prio) {
|
||||
/* Change execution priority of a task to "new_prio". */
|
||||
P_TCB p_task;
|
||||
|
||||
if (task_id == 0U) {
|
||||
/* Change execution priority of calling task. */
|
||||
os_tsk.run->prio = new_prio;
|
||||
os_tsk.run->prio_base = new_prio;
|
||||
run:if (rt_rdy_prio() > new_prio) {
|
||||
rt_put_prio (&os_rdy, os_tsk.run);
|
||||
os_tsk.run->state = READY;
|
||||
rt_dispatch (NULL);
|
||||
}
|
||||
return (OS_R_OK);
|
||||
}
|
||||
|
||||
/* Find the task in the "os_active_TCB" array. */
|
||||
if ((task_id > os_maxtaskrun) || (os_active_TCB[task_id-1U] == NULL)) {
|
||||
/* Task with "task_id" not found or not started. */
|
||||
return (OS_R_NOK);
|
||||
}
|
||||
p_task = os_active_TCB[task_id-1U];
|
||||
p_task->prio = new_prio;
|
||||
p_task->prio_base = new_prio;
|
||||
if (p_task == os_tsk.run) {
|
||||
goto run;
|
||||
}
|
||||
rt_resort_prio (p_task);
|
||||
if (p_task->state == READY) {
|
||||
/* Task enqueued in a ready list. */
|
||||
p_task = rt_get_first (&os_rdy);
|
||||
rt_dispatch (p_task);
|
||||
}
|
||||
return (OS_R_OK);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_tsk_create ---------------------------------*/
|
||||
|
||||
OS_TID rt_tsk_create (FUNCP task, U32 prio_stksz, void *stk, void *argv) {
|
||||
/* Start a new task declared with "task". */
|
||||
P_TCB task_context;
|
||||
U32 i;
|
||||
|
||||
/* Priority 0 is reserved for idle task! */
|
||||
if ((prio_stksz & 0xFFU) == 0U) {
|
||||
prio_stksz += 1U;
|
||||
}
|
||||
task_context = rt_alloc_box (mp_tcb);
|
||||
if (task_context == NULL) {
|
||||
return (0U);
|
||||
}
|
||||
/* If "size != 0" use a private user provided stack. */
|
||||
task_context->stack = stk;
|
||||
task_context->priv_stack = prio_stksz >> 8;
|
||||
|
||||
/* Find a free entry in 'os_active_TCB' table. */
|
||||
i = rt_get_TID ();
|
||||
if (i == 0U) {
|
||||
return (0U);
|
||||
}
|
||||
task_context->task_id = (U8)i;
|
||||
/* Pass parameter 'argv' to 'rt_init_context' */
|
||||
task_context->msg = argv;
|
||||
task_context->argv = argv;
|
||||
/* For 'size == 0' system allocates the user stack from the memory pool. */
|
||||
rt_init_context (task_context, (U8)(prio_stksz & 0xFFU), task);
|
||||
|
||||
os_active_TCB[i-1U] = task_context;
|
||||
DBG_TASK_NOTIFY(task_context, __TRUE);
|
||||
rt_dispatch (task_context);
|
||||
return ((OS_TID)i);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_tsk_delete ---------------------------------*/
|
||||
|
||||
OS_RESULT rt_tsk_delete (OS_TID task_id) {
|
||||
/* Terminate the task identified with "task_id". */
|
||||
P_TCB task_context;
|
||||
P_TCB p_TCB;
|
||||
P_MUCB p_MCB, p_MCB0;
|
||||
|
||||
if ((task_id == 0U) || (task_id == os_tsk.run->task_id)) {
|
||||
/* Terminate itself. */
|
||||
os_tsk.run->state = INACTIVE;
|
||||
os_tsk.run->tsk_stack = rt_get_PSP ();
|
||||
rt_stk_check ();
|
||||
p_MCB = os_tsk.run->p_mlnk;
|
||||
while (p_MCB) {
|
||||
/* Release mutexes owned by this task */
|
||||
if (p_MCB->p_lnk) {
|
||||
/* A task is waiting for mutex. */
|
||||
p_TCB = rt_get_first ((P_XCB)p_MCB);
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val (p_TCB, 0U/*osOK*/);
|
||||
#else
|
||||
rt_ret_val (p_TCB, OS_R_MUT);
|
||||
#endif
|
||||
rt_rmv_dly (p_TCB);
|
||||
p_TCB->state = READY;
|
||||
rt_put_prio (&os_rdy, p_TCB);
|
||||
/* A waiting task becomes the owner of this mutex. */
|
||||
p_MCB0 = p_MCB->p_mlnk;
|
||||
p_MCB->level = 1U;
|
||||
p_MCB->owner = p_TCB;
|
||||
p_MCB->p_mlnk = p_TCB->p_mlnk;
|
||||
p_TCB->p_mlnk = p_MCB;
|
||||
p_MCB = p_MCB0;
|
||||
}
|
||||
else {
|
||||
p_MCB0 = p_MCB->p_mlnk;
|
||||
p_MCB->level = 0U;
|
||||
p_MCB->owner = NULL;
|
||||
p_MCB->p_mlnk = NULL;
|
||||
p_MCB = p_MCB0;
|
||||
}
|
||||
}
|
||||
os_active_TCB[os_tsk.run->task_id-1U] = NULL;
|
||||
rt_free_box (mp_stk, os_tsk.run->stack);
|
||||
os_tsk.run->stack = NULL;
|
||||
DBG_TASK_NOTIFY(os_tsk.run, __FALSE);
|
||||
rt_free_box (mp_tcb, os_tsk.run);
|
||||
os_tsk.run = NULL;
|
||||
rt_dispatch (NULL);
|
||||
/* The program should never come to this point. */
|
||||
}
|
||||
else {
|
||||
/* Find the task in the "os_active_TCB" array. */
|
||||
if ((task_id > os_maxtaskrun) || (os_active_TCB[task_id-1U] == NULL)) {
|
||||
/* Task with "task_id" not found or not started. */
|
||||
return (OS_R_NOK);
|
||||
}
|
||||
task_context = os_active_TCB[task_id-1U];
|
||||
rt_rmv_list (task_context);
|
||||
rt_rmv_dly (task_context);
|
||||
p_MCB = task_context->p_mlnk;
|
||||
while (p_MCB) {
|
||||
/* Release mutexes owned by this task */
|
||||
if (p_MCB->p_lnk) {
|
||||
/* A task is waiting for mutex. */
|
||||
p_TCB = rt_get_first ((P_XCB)p_MCB);
|
||||
#ifdef __CMSIS_RTOS
|
||||
rt_ret_val (p_TCB, 0U/*osOK*/);
|
||||
#else
|
||||
rt_ret_val (p_TCB, OS_R_MUT);
|
||||
#endif
|
||||
rt_rmv_dly (p_TCB);
|
||||
p_TCB->state = READY;
|
||||
rt_put_prio (&os_rdy, p_TCB);
|
||||
/* A waiting task becomes the owner of this mutex. */
|
||||
p_MCB0 = p_MCB->p_mlnk;
|
||||
p_MCB->level = 1U;
|
||||
p_MCB->owner = p_TCB;
|
||||
p_MCB->p_mlnk = p_TCB->p_mlnk;
|
||||
p_TCB->p_mlnk = p_MCB;
|
||||
p_MCB = p_MCB0;
|
||||
}
|
||||
else {
|
||||
p_MCB0 = p_MCB->p_mlnk;
|
||||
p_MCB->level = 0U;
|
||||
p_MCB->owner = NULL;
|
||||
p_MCB->p_mlnk = NULL;
|
||||
p_MCB = p_MCB0;
|
||||
}
|
||||
}
|
||||
os_active_TCB[task_id-1U] = NULL;
|
||||
rt_free_box (mp_stk, task_context->stack);
|
||||
task_context->stack = NULL;
|
||||
DBG_TASK_NOTIFY(task_context, __FALSE);
|
||||
rt_free_box (mp_tcb, task_context);
|
||||
if (rt_rdy_prio() > os_tsk.run->prio) {
|
||||
/* Ready task has higher priority than running task. */
|
||||
os_tsk.run->state = READY;
|
||||
rt_put_prio (&os_rdy, os_tsk.run);
|
||||
rt_dispatch (NULL);
|
||||
}
|
||||
}
|
||||
return (OS_R_OK);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_sys_init -----------------------------------*/
|
||||
|
||||
#ifdef __CMSIS_RTOS
|
||||
void rt_sys_init (void) {
|
||||
#else
|
||||
void rt_sys_init (FUNCP first_task, U32 prio_stksz, void *stk) {
|
||||
#endif
|
||||
/* Initialize system and start up task declared with "first_task". */
|
||||
U32 i;
|
||||
|
||||
DBG_INIT();
|
||||
|
||||
/* Initialize dynamic memory and task TCB pointers to NULL. */
|
||||
for (i = 0U; i < os_maxtaskrun; i++) {
|
||||
os_active_TCB[i] = NULL;
|
||||
}
|
||||
rt_init_box (mp_tcb, (U32)mp_tcb_size, sizeof(struct OS_TCB));
|
||||
rt_init_box (mp_stk, mp_stk_size, BOX_ALIGN_8 | (U16)(os_stackinfo));
|
||||
rt_init_box ((U32 *)m_tmr, (U32)mp_tmr_size, sizeof(struct OS_TMR));
|
||||
|
||||
/* Set up TCB of idle demon */
|
||||
os_idle_TCB.task_id = 255U;
|
||||
os_idle_TCB.priv_stack = 0U;
|
||||
rt_init_context (&os_idle_TCB, 0U, os_idle_demon);
|
||||
|
||||
/* Set up ready list: initially empty */
|
||||
os_rdy.cb_type = HCB;
|
||||
os_rdy.p_lnk = NULL;
|
||||
/* Set up delay list: initially empty */
|
||||
os_dly.cb_type = HCB;
|
||||
os_dly.p_dlnk = NULL;
|
||||
os_dly.p_blnk = NULL;
|
||||
os_dly.delta_time = 0U;
|
||||
|
||||
/* Fix SP and system variables to assume idle task is running */
|
||||
/* Transform main program into idle task by assuming idle TCB */
|
||||
#ifndef __CMSIS_RTOS
|
||||
rt_set_PSP (os_idle_TCB.tsk_stack+32U);
|
||||
#endif
|
||||
os_tsk.run = &os_idle_TCB;
|
||||
os_tsk.run->state = RUNNING;
|
||||
|
||||
/* Set the current thread to idle, so that on exit from this SVCall we do not
|
||||
* de-reference a NULL TCB. */
|
||||
rt_switch_req(&os_idle_TCB);
|
||||
|
||||
/* Initialize ps queue */
|
||||
os_psq->first = 0U;
|
||||
os_psq->last = 0U;
|
||||
os_psq->size = os_fifo_size;
|
||||
|
||||
rt_init_robin ();
|
||||
|
||||
#ifndef __CMSIS_RTOS
|
||||
/* Initialize SVC and PendSV */
|
||||
rt_svc_init ();
|
||||
|
||||
/* Initialize and start system clock timer */
|
||||
os_tick_irqn = os_tick_init ();
|
||||
if (os_tick_irqn >= 0) {
|
||||
OS_X_INIT((U32)os_tick_irqn);
|
||||
}
|
||||
|
||||
/* Start up first user task before entering the endless loop */
|
||||
rt_tsk_create (first_task, prio_stksz, stk, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_sys_start ----------------------------------*/
|
||||
|
||||
#ifdef __CMSIS_RTOS
|
||||
void rt_sys_start (void) {
|
||||
/* Start system */
|
||||
|
||||
/* Initialize SVC and PendSV */
|
||||
rt_svc_init ();
|
||||
|
||||
/* Initialize and start system clock timer */
|
||||
os_tick_irqn = os_tick_init ();
|
||||
if (os_tick_irqn >= 0) {
|
||||
OS_X_INIT((U32)os_tick_irqn);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,88 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_TASK.H
|
||||
* Purpose: Task functions and system start up.
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Definitions */
|
||||
|
||||
#include "cmsis_os.h"
|
||||
|
||||
/* Values for 'state' */
|
||||
#define INACTIVE 0U
|
||||
#define READY 1U
|
||||
#define RUNNING 2U
|
||||
#define WAIT_DLY 3U
|
||||
#define WAIT_ITV 4U
|
||||
#define WAIT_OR 5U
|
||||
#define WAIT_AND 6U
|
||||
#define WAIT_SEM 7U
|
||||
#define WAIT_MBX 8U
|
||||
#define WAIT_MUT 9U
|
||||
|
||||
/* Return codes */
|
||||
#define OS_R_TMO 0x01U
|
||||
#define OS_R_EVT 0x02U
|
||||
#define OS_R_SEM 0x03U
|
||||
#define OS_R_MBX 0x04U
|
||||
#define OS_R_MUT 0x05U
|
||||
|
||||
#define OS_R_OK 0x00U
|
||||
#define OS_R_NOK 0xFFU
|
||||
|
||||
/* Variables */
|
||||
extern struct OS_TSK os_tsk;
|
||||
extern struct OS_TCB os_idle_TCB;
|
||||
|
||||
/* Functions */
|
||||
extern void rt_switch_req (P_TCB p_new);
|
||||
extern void rt_dispatch (P_TCB next_TCB);
|
||||
extern void rt_block (U16 timeout, U8 block_state);
|
||||
extern void rt_tsk_pass (void);
|
||||
extern OS_TID rt_tsk_self (void);
|
||||
extern OS_RESULT rt_tsk_prio (OS_TID task_id, U8 new_prio);
|
||||
extern OS_TID rt_tsk_create (FUNCP task, U32 prio_stksz, void *stk, void *argv);
|
||||
extern OS_RESULT rt_tsk_delete (OS_TID task_id);
|
||||
#ifdef __CMSIS_RTOS
|
||||
extern void rt_sys_init (void);
|
||||
extern void rt_sys_start (void);
|
||||
#else
|
||||
extern void rt_sys_init (FUNCP first_task, U32 prio_stksz, void *stk);
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/** @}*/
|
|
@ -1,93 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_TIME.C
|
||||
* Purpose: Delay and interval wait functions
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_Task.h"
|
||||
#include "rt_Time.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Variables
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Free running system tick counter */
|
||||
U32 os_time;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------- rt_time_get -----------------------------------*/
|
||||
|
||||
U32 rt_time_get (void) {
|
||||
/* Get system time tick */
|
||||
return (os_time);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_dly_wait -----------------------------------*/
|
||||
|
||||
void rt_dly_wait (U16 delay_time) {
|
||||
/* Delay task by "delay_time" */
|
||||
rt_block (delay_time, WAIT_DLY);
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_itv_set ------------------------------------*/
|
||||
|
||||
void rt_itv_set (U16 interval_time) {
|
||||
/* Set interval length and define start of first interval */
|
||||
os_tsk.run->interval_time = interval_time;
|
||||
os_tsk.run->delta_time = interval_time + (U16)os_time;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------- rt_itv_wait -----------------------------------*/
|
||||
|
||||
void rt_itv_wait (void) {
|
||||
/* Wait for interval end and define start of next one */
|
||||
U16 delta;
|
||||
|
||||
delta = os_tsk.run->delta_time - (U16)os_time;
|
||||
os_tsk.run->delta_time += os_tsk.run->interval_time;
|
||||
if ((delta & 0x8000U) == 0U) {
|
||||
rt_block (delta, WAIT_ITV);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,52 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_TIME.H
|
||||
* Purpose: Delay and interval wait functions definitions
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Variables */
|
||||
extern U32 os_time;
|
||||
|
||||
/* Functions */
|
||||
extern U32 rt_time_get (void);
|
||||
extern void rt_dly_wait (U16 delay_time);
|
||||
extern void rt_itv_set (U16 interval_time);
|
||||
extern void rt_itv_wait (void);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/** @}*/
|
|
@ -1,135 +0,0 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_TIMER.C
|
||||
* Purpose: User timer functions
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "rt_TypeDef.h"
|
||||
#include "RTX_Config.h"
|
||||
#include "rt_Timer.h"
|
||||
#include "rt_MemBox.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
#ifndef __CMSIS_RTOS
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Global Variables
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* User Timer list pointer */
|
||||
struct OS_XTMR os_tmr;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/*--------------------------- rt_tmr_tick -----------------------------------*/
|
||||
|
||||
void rt_tmr_tick (void) {
|
||||
/* Decrement delta count of timer list head. Timers having the value of */
|
||||
/* zero are removed from the list and the callback function is called. */
|
||||
P_TMR p;
|
||||
|
||||
if (os_tmr.next == NULL) {
|
||||
return;
|
||||
}
|
||||
os_tmr.tcnt--;
|
||||
while ((os_tmr.tcnt == 0U) && ((p = os_tmr.next) != NULL)) {
|
||||
/* Call a user provided function to handle an elapsed timer */
|
||||
os_tmr_call (p->info);
|
||||
os_tmr.tcnt = p->tcnt;
|
||||
os_tmr.next = p->next;
|
||||
rt_free_box ((U32 *)m_tmr, p);
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------- rt_tmr_create ---------------------------------*/
|
||||
|
||||
OS_ID rt_tmr_create (U16 tcnt, U16 info) {
|
||||
/* Create an user timer and put it into the chained timer list using */
|
||||
/* a timeout count value of "tcnt". User parameter "info" is used as a */
|
||||
/* parameter for the user provided callback function "os_tmr_call ()". */
|
||||
P_TMR p_tmr, p;
|
||||
U32 delta,itcnt = tcnt;
|
||||
|
||||
if ((tcnt == 0U) || (m_tmr == NULL)) {
|
||||
return (NULL);
|
||||
}
|
||||
p_tmr = rt_alloc_box ((U32 *)m_tmr);
|
||||
if (!p_tmr) {
|
||||
return (NULL);
|
||||
}
|
||||
p_tmr->info = info;
|
||||
p = (P_TMR)&os_tmr;
|
||||
delta = p->tcnt;
|
||||
while ((delta < itcnt) && (p->next != NULL)) {
|
||||
p = p->next;
|
||||
delta += p->tcnt;
|
||||
}
|
||||
/* Right place found, insert timer into the list */
|
||||
p_tmr->next = p->next;
|
||||
p_tmr->tcnt = (U16)(delta - itcnt);
|
||||
p->next = p_tmr;
|
||||
p->tcnt -= p_tmr->tcnt;
|
||||
return (p_tmr);
|
||||
}
|
||||
|
||||
/*--------------------------- rt_tmr_kill -----------------------------------*/
|
||||
|
||||
OS_ID rt_tmr_kill (OS_ID timer) {
|
||||
/* Remove user timer from the chained timer list. */
|
||||
P_TMR p, p_tmr;
|
||||
|
||||
p_tmr = (P_TMR)timer;
|
||||
p = (P_TMR)&os_tmr;
|
||||
/* Search timer list for requested timer */
|
||||
while (p->next != p_tmr) {
|
||||
if (p->next == NULL) {
|
||||
/* Failed, "timer" is not in the timer list */
|
||||
return (p_tmr);
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
/* Timer was found, remove it from the list */
|
||||
p->next = p_tmr->next;
|
||||
p->tcnt += p_tmr->tcnt;
|
||||
rt_free_box ((U32 *)m_tmr, p_tmr);
|
||||
/* Timer killed */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
|
@ -1,50 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_TIMER.H
|
||||
* Purpose: User timer functions
|
||||
* Rev.: V4.70
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Variables */
|
||||
extern struct OS_XTMR os_tmr;
|
||||
|
||||
/* Functions */
|
||||
extern void rt_tmr_tick (void);
|
||||
extern OS_ID rt_tmr_create (U16 tcnt, U16 info);
|
||||
extern OS_ID rt_tmr_kill (OS_ID timer);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* end of file
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/** @}*/
|
|
@ -1,175 +0,0 @@
|
|||
|
||||
/** \addtogroup rtos */
|
||||
/** @{*/
|
||||
/*----------------------------------------------------------------------------
|
||||
* CMSIS-RTOS - RTX
|
||||
*----------------------------------------------------------------------------
|
||||
* Name: RT_TYPEDEF.H
|
||||
* Purpose: Type Definitions
|
||||
* Rev.: V4.79
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - 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.
|
||||
* - Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
#ifndef RT_TYPE_DEF_H
|
||||
#define RT_TYPE_DEF_H
|
||||
|
||||
/* Types */
|
||||
typedef char S8;
|
||||
typedef unsigned char U8;
|
||||
typedef short S16;
|
||||
typedef unsigned short U16;
|
||||
typedef int S32;
|
||||
typedef unsigned int U32;
|
||||
typedef long long S64;
|
||||
typedef unsigned long long U64;
|
||||
typedef unsigned char BIT;
|
||||
typedef unsigned int BOOL;
|
||||
typedef void (*FUNCP)(void);
|
||||
|
||||
typedef U32 OS_TID;
|
||||
typedef void *OS_ID;
|
||||
typedef U32 OS_RESULT;
|
||||
|
||||
typedef struct OS_TCB {
|
||||
/* General part: identical for all implementations. */
|
||||
U8 cb_type; /* Control Block Type */
|
||||
U8 state; /* Task state */
|
||||
U8 prio; /* Execution priority */
|
||||
U8 task_id; /* Task ID value for optimized TCB access */
|
||||
struct OS_TCB *p_lnk; /* Link pointer for ready/sem. wait list */
|
||||
struct OS_TCB *p_rlnk; /* Link pointer for sem./mbx lst backwards */
|
||||
struct OS_TCB *p_dlnk; /* Link pointer for delay list */
|
||||
struct OS_TCB *p_blnk; /* Link pointer for delay list backwards */
|
||||
U16 delta_time; /* Time until time out */
|
||||
U16 interval_time; /* Time interval for periodic waits */
|
||||
U16 events; /* Event flags */
|
||||
U16 waits; /* Wait flags */
|
||||
void **msg; /* Direct message passing when task waits */
|
||||
struct OS_MUCB *p_mlnk; /* Link pointer for mutex owner list */
|
||||
U8 prio_base; /* Base priority */
|
||||
|
||||
/* Hardware dependant part: specific for CM processor */
|
||||
U8 stack_frame; /* Stack frame: 0=Basic, 1=Extended, */
|
||||
U16 reserved; /* Two reserved bytes for alignment */
|
||||
/* (2=VFP/D16 stacked, 4=NEON/D32 stacked) */
|
||||
U32 priv_stack; /* Private stack size, 0= system assigned */
|
||||
U32 tsk_stack; /* Current task Stack pointer (R13) */
|
||||
U32 *stack; /* Pointer to Task Stack memory block */
|
||||
|
||||
/* Task entry point used for uVision debugger */
|
||||
FUNCP ptask; /* Task entry address */
|
||||
void *argv; /* Task argument */
|
||||
void *context; /* Pointer to thread context */
|
||||
} *P_TCB;
|
||||
#define TCB_STACKF 37 /* 'stack_frame' offset */
|
||||
#define TCB_TSTACK 44 /* 'tsk_stack' offset */
|
||||
|
||||
typedef struct OS_PSFE { /* Post Service Fifo Entry */
|
||||
void *id; /* Object Identification */
|
||||
U32 arg; /* Object Argument */
|
||||
} *P_PSFE;
|
||||
|
||||
typedef struct OS_PSQ { /* Post Service Queue */
|
||||
U8 first; /* FIFO Head Index */
|
||||
U8 last; /* FIFO Tail Index */
|
||||
U8 count; /* Number of stored items in FIFO */
|
||||
U8 size; /* FIFO Size */
|
||||
struct OS_PSFE q[1]; /* FIFO Content */
|
||||
} *P_PSQ;
|
||||
|
||||
typedef struct OS_TSK {
|
||||
P_TCB run; /* Current running task */
|
||||
P_TCB new_tsk; /* Scheduled task to run */
|
||||
} *P_TSK;
|
||||
|
||||
typedef struct OS_ROBIN { /* Round Robin Control */
|
||||
P_TCB task; /* Round Robin task */
|
||||
U16 time; /* Round Robin switch time */
|
||||
U16 tout; /* Round Robin timeout */
|
||||
} *P_ROBIN;
|
||||
|
||||
typedef struct OS_XCB {
|
||||
U8 cb_type; /* Control Block Type */
|
||||
struct OS_TCB *p_lnk; /* Link pointer for ready/sem. wait list */
|
||||
struct OS_TCB *p_rlnk; /* Link pointer for sem./mbx lst backwards */
|
||||
struct OS_TCB *p_dlnk; /* Link pointer for delay list */
|
||||
struct OS_TCB *p_blnk; /* Link pointer for delay list backwards */
|
||||
U16 delta_time; /* Time until time out */
|
||||
} *P_XCB;
|
||||
|
||||
typedef struct OS_MCB {
|
||||
U8 cb_type; /* Control Block Type */
|
||||
U8 state; /* State flag variable */
|
||||
U8 isr_st; /* State flag variable for isr functions */
|
||||
struct OS_TCB *p_lnk; /* Chain of tasks waiting for message */
|
||||
U16 first; /* Index of the message list begin */
|
||||
U16 last; /* Index of the message list end */
|
||||
U16 count; /* Actual number of stored messages */
|
||||
U16 size; /* Maximum number of stored messages */
|
||||
void *msg[1]; /* FIFO for Message pointers 1st element */
|
||||
} *P_MCB;
|
||||
|
||||
typedef struct OS_SCB {
|
||||
U8 cb_type; /* Control Block Type */
|
||||
U8 mask; /* Semaphore token mask */
|
||||
U16 tokens; /* Semaphore tokens */
|
||||
struct OS_TCB *p_lnk; /* Chain of tasks waiting for tokens */
|
||||
} *P_SCB;
|
||||
|
||||
typedef struct OS_MUCB {
|
||||
U8 cb_type; /* Control Block Type */
|
||||
U16 level; /* Call nesting level */
|
||||
struct OS_TCB *p_lnk; /* Chain of tasks waiting for mutex */
|
||||
struct OS_TCB *owner; /* Mutex owner task */
|
||||
struct OS_MUCB *p_mlnk; /* Chain of mutexes by owner task */
|
||||
} *P_MUCB;
|
||||
|
||||
typedef struct OS_XTMR {
|
||||
struct OS_TMR *next;
|
||||
U16 tcnt;
|
||||
} *P_XTMR;
|
||||
|
||||
typedef struct OS_TMR {
|
||||
struct OS_TMR *next; /* Link pointer to Next timer */
|
||||
U16 tcnt; /* Timer delay count */
|
||||
U16 info; /* User defined call info */
|
||||
} *P_TMR;
|
||||
|
||||
typedef struct OS_BM {
|
||||
void *free; /* Pointer to first free memory block */
|
||||
void *end; /* Pointer to memory block end */
|
||||
U32 blk_size; /* Memory block size */
|
||||
} *P_BM;
|
||||
|
||||
/* Definitions */
|
||||
#define __TRUE 1U
|
||||
#define __FALSE 0U
|
||||
#define NULL ((void *) 0)
|
||||
|
||||
#endif
|
||||
|
||||
/** @}*/
|
Loading…
Reference in New Issue