mirror of
https://gitee.com/cosyos/cosyos.git
synced 2026-09-26 13:13:37 +08:00
删除文件 Port/Cortex-M
This commit is contained in:
@@ -1,126 +0,0 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Port
|
||||
* @file port_cmx_iar.s
|
||||
* @brief CMSIS Cortex-M Core Port File for IAR Compiler
|
||||
* @author 迟凯峰
|
||||
* @version V2.4.2
|
||||
* @date 2026.07.04
|
||||
******************************************************************************/
|
||||
|
||||
用户须知
|
||||
|
||||
; 该文件是专门为 IAR-EWARM 适配的高性能移植版本,原因是 port_cmx_s.c 文件
|
||||
; 虽然支持 EWARM,但对于 ARMv7-M 及以上架构来说,性能上是有少许损失的,这源于
|
||||
; EWARM 内联汇编的局限性。
|
||||
; 如果您的处理器架构是 ARMv7-M 或以上,并采用 EWARM 来编译您的项目,同时
|
||||
; 又追求卓越性能,可移除 port_cmx_s.c 文件,并替换为该文件进行编译。
|
||||
; 注意,该文件仅支持 ARMv7-M 及以上架构,mcucfg_cmx.h 中,互斥访问方案 也
|
||||
; 必须选择为高性能的 互斥访问指令。
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
INCLUDE syscfg.h
|
||||
INCLUDE mcucfg_cm0.h
|
||||
INCLUDE mcucfg_cm3.h
|
||||
|
||||
SECTION .text:CODE:REORDER:NOROOT(2)
|
||||
THUMB
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
; PendSV软中断
|
||||
|
||||
PUBLIC OS_PendSV_Handler
|
||||
OS_PendSV_Handler:
|
||||
EXTERN sPendSV_Handler
|
||||
EXTERN s_task_current
|
||||
EXTERN s_task_news
|
||||
PRESERVE8
|
||||
|
||||
push {lr}
|
||||
bl sPendSV_Handler
|
||||
; 直接返回吗?
|
||||
cbz r0, __RETURN
|
||||
; 保护现场吗?
|
||||
ldr r1, =s_task_current
|
||||
IF (SYSCFG_DEBUGGING == 1)
|
||||
subs r0, #1
|
||||
cbz r0, __RESTORE
|
||||
ENDIF
|
||||
mrs r0, psp
|
||||
isb
|
||||
; 任务PC监控
|
||||
IF (SYSCFG_TASKPC_MONITOR == 1)
|
||||
EXTERN s_taskmgr_sign
|
||||
EXTERN s_pc
|
||||
ldr r2, =s_taskmgr_sign
|
||||
ldrb r2, [r2]
|
||||
cbz r2, __PROTECTING
|
||||
ldr r2, [r0,#24]
|
||||
ldr r3, =s_pc
|
||||
str r2, [r3]
|
||||
ENDIF
|
||||
; 保护现场
|
||||
__PROTECTING IF (MCUCFG_ASPEN_LSPEN == 1)
|
||||
vstmdb r0!, {s16-s31}
|
||||
ENDIF
|
||||
stmdb r0!, {r4-r11}
|
||||
ldr r2, [r1]
|
||||
str r0, [r2]
|
||||
dsb
|
||||
; 恢复现场
|
||||
__RESTORE ldr r3, =s_task_news
|
||||
ldr r3, [r3]
|
||||
str r3, [r1]
|
||||
ldr r0, [r3]
|
||||
ldmia r0!, {r4-r11}
|
||||
IF (MCUCFG_ASPEN_LSPEN == 1)
|
||||
vldmia r0!, {s16-s31}
|
||||
ENDIF
|
||||
msr psp, r0
|
||||
; 返回
|
||||
__RETURN pop {pc}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
; 中断FIFO服务装载器
|
||||
|
||||
IF (MCUCFG_PENDSVFIFO_DEPTH > 0)
|
||||
|
||||
PUBLIC mPendSV_FIFOLoader
|
||||
mPendSV_FIFOLoader:
|
||||
EXTERN mPendSV_FIFO_0
|
||||
EXTERN mPendSV_FIFO_1
|
||||
EXTERN m_fifo_lock
|
||||
; FIFO选择
|
||||
ldr r2, =m_fifo_lock
|
||||
ldrb r3, [r2]
|
||||
cbz r3, __FIFO1
|
||||
__FIFO0 ldr r1, =mPendSV_FIFO_0
|
||||
b __COUNT
|
||||
__FIFO1 ldr r1, =mPendSV_FIFO_1
|
||||
; FIFO计数
|
||||
__COUNT /* 1、互斥访问指令 */
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX == 1)
|
||||
__LOOP ldrex r2, [r1]
|
||||
adds r2, #1
|
||||
strex r3, r2, [r1]
|
||||
cmp r3, #0
|
||||
bne __LOOP
|
||||
#else
|
||||
#error 互斥访问方案 未选择 互斥访问指令!
|
||||
#endif
|
||||
; FIFO溢出
|
||||
cmp r2, #MCUCFG_PENDSVFIFO_DEPTH
|
||||
bhi __OVER
|
||||
; FIFO装载
|
||||
lsls r2, r2, #2
|
||||
str r0, [r1, r2]
|
||||
|
||||
__OVER bx lr
|
||||
|
||||
ENDIF
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
ALIGN
|
||||
END
|
||||
@@ -1,235 +0,0 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Port
|
||||
* @file cmsis_specific.h
|
||||
* @brief CMSIS compiler specific defines
|
||||
* @author 迟凯峰
|
||||
* @version V2.0.0
|
||||
* @date 2025.08.04
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CMSIS_SPECIFIC_H
|
||||
#define __CMSIS_SPECIFIC_H
|
||||
|
||||
/*
|
||||
* Arm Compiler 4/5
|
||||
*/
|
||||
#if defined ( __CC_ARM )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE __inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static __inline
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE static __forceinline
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
#ifndef __NOINLINE
|
||||
#define __NOINLINE __attribute__((noinline))
|
||||
#endif
|
||||
#define __UNUSED(X) (void)X
|
||||
|
||||
|
||||
/*
|
||||
* Arm Compiler 6.6 LTM / above 6.10.1 (armclang)
|
||||
*/
|
||||
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE __inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static __inline
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
#ifndef __NOINLINE
|
||||
#define __NOINLINE __attribute__((noinline))
|
||||
#endif
|
||||
#define __UNUSED(X) (void)X
|
||||
|
||||
|
||||
/*
|
||||
* GNU Compiler
|
||||
*/
|
||||
#elif defined ( __GNUC__ )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
#ifndef __NOINLINE
|
||||
#define __NOINLINE __attribute__((noinline))
|
||||
#endif
|
||||
#define __UNUSED(X) (void)X
|
||||
|
||||
|
||||
/*
|
||||
* IAR Compiler
|
||||
*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline
|
||||
#endif
|
||||
#ifndef __FORCEINLINE
|
||||
#define __FORCEINLINE _Pragma("inline=forced")
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#if (__VER__ >= 8000000)
|
||||
#define __WEAK __attribute__((weak))
|
||||
#else
|
||||
#define __WEAK _Pragma("__weak")
|
||||
#endif
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#if (__VER__ >= 7080000)/* If Version < V8, Needs IAR language extensions */
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#else
|
||||
#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
|
||||
#define __ALIGNED(x)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef __NOINLINE
|
||||
#define __NOINLINE //_Pragma("optimize = no_inline")
|
||||
#endif
|
||||
#define __UNUSED(X) (void)X
|
||||
|
||||
|
||||
/*
|
||||
* TI Arm Compiler
|
||||
*/
|
||||
#elif defined ( __TI_ARM__ )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE __STATIC_INLINE
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
#ifndef __NOINLINE
|
||||
#define __NOINLINE
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* TASKING Compiler
|
||||
*/
|
||||
#elif defined ( __TASKING__ )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE __STATIC_INLINE
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#define __ALIGNED(x) __align(x)
|
||||
#endif
|
||||
#ifndef __NOINLINE
|
||||
#define __NOINLINE
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* COSMIC Compiler
|
||||
*/
|
||||
#elif defined ( __CSMC__ )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM _asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE __STATIC_INLINE
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __weak
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
|
||||
#define __ALIGNED(x)
|
||||
#endif
|
||||
#ifndef __NOINLINE
|
||||
#define __NOINLINE
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Unknown Compiler
|
||||
*/
|
||||
#else
|
||||
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,85 +0,0 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Config
|
||||
* @file mcucfg_cm0.h
|
||||
* @brief CMSIS Cortex-M Core Config File
|
||||
* @author 迟凯峰
|
||||
* @version V2.0.0
|
||||
* @date 2025.08.04
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __MCUCFG_CM0_H
|
||||
#define __MCUCFG_CM0_H
|
||||
|
||||
#include "mcucfg_cmx.h"
|
||||
#if (MCUCFG_SYSINT == 0)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 如果在 mcucfg_cmx.h 中,系统中断配置为 TIMn_IRQHandler + XXXx_IRQHandler,
|
||||
// 用户需配置下方的用户定义项。
|
||||
|
||||
//////////////////////////////////* 用户定义 *//////////////////////////////////
|
||||
|
||||
/* 系统中断配置 */
|
||||
// 默认配置仅为示例,给用户以参考和提示。
|
||||
|
||||
// PendSV_Handler替代中断-名称
|
||||
#define MCUCFG_XXXx_IRQHandler EXTI0_1_IRQHandler
|
||||
|
||||
// PendSV_Handler替代中断-中断向量号
|
||||
#define MCUCFG_XXXx_IRQn EXTI0_1_IRQn
|
||||
|
||||
// SysTick_Handler替代中断-中断向量号
|
||||
#define MCUCFG_TIMn_IRQn TIM14_IRQn
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
/* 系统滴答替代定时器-补充说明 */
|
||||
// 您需自行手动配置和系统滴答替代定时器有关的一切事宜,包括使能更新中断;
|
||||
// 例外的是,定时器中断的优先级将由CosyOS根据中断向量号自动配置为最低级。
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
/* 系统滴答替代定时器-额外配置 */
|
||||
// 虽然系统滴答替代定时器需要用户自行手动配置,但仍需额外配置下方定义项,
|
||||
// 用于 CosyOS-任务管理器 的CPU使用率统计、滴答时间统计等功能。
|
||||
// 当然,如果您不打算使用 CosyOS-任务管理器,可不用配置。
|
||||
// 默认配置仅为示例,给用户以参考和提示。
|
||||
|
||||
// 替代定时器-计数方式
|
||||
// <1=> 从零向上计数至重装载值溢出 <2=> 从重装载值向下计数至零溢出
|
||||
// <3=> 从重装载值向上计数至零溢出 <4=> 从零向下计数至重装载值溢出
|
||||
// 告知CosyOS您所配置的定时器计数方式。
|
||||
#define MCUCFG_SYSTICK_COUNTMODE 1
|
||||
|
||||
// 替代定时器-位数
|
||||
// 如果定时器计数方式配置为3或4,应正确配置该定义。
|
||||
#define MCUCFG_SYSTICK_BITS 16
|
||||
|
||||
// 替代定时器-当前值
|
||||
// 应配置为可读的当前值寄存器。
|
||||
#define MCUCFG_SYSTICK_CURRVALUE (TIM14->CNT)
|
||||
|
||||
// 替代定时器-重装载值
|
||||
// 如果该值为常量可配置为常量,否则应配置为可读的重装载值寄存器。
|
||||
#define MCUCFG_SYSTICK_LOADVALUE (SYSCFG_SYSTICK_CYCLE - 1) //=(TIM14->ARR)
|
||||
|
||||
// 替代定时器-时钟
|
||||
// 告知CosyOS您所配置的定时器时钟,单位为兆赫(MHZ)。
|
||||
#define MCUCFG_SYSTICK_CLK 1 //=(系统时钟 / (TIM14->PSC + 1))
|
||||
|
||||
//////////////////////////////////* 系统定义 *//////////////////////////////////
|
||||
|
||||
// 以下为系统定义,用户不可随意修改。
|
||||
|
||||
#define OS_PendSV_Handler MCUCFG_XXXx_IRQHandler
|
||||
#define MCUCFG_SYSTICK_AUTOCONFIG 0
|
||||
|
||||
#if (MCUCFG_XXXx_IRQn / 32 != MCUCFG_TIMn_IRQn / 32)
|
||||
#error 参数非法,(MCUCFG_XXXx_IRQn / 32) 未能等于 (MCUCFG_TIMn_IRQn / 32)!
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,85 +0,0 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Config
|
||||
* @file mcucfg_cm3.h
|
||||
* @brief CMSIS Cortex-M Core Config File
|
||||
* @author 迟凯峰
|
||||
* @version V2.0.0
|
||||
* @date 2025.08.04
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __MCUCFG_CM3_H
|
||||
#define __MCUCFG_CM3_H
|
||||
|
||||
#include "mcucfg_cmx.h"
|
||||
#if (MCUCFG_SYSINT == 3)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 如果在 mcucfg_cmx.h 中,系统中断配置为 SysTick_Handler + PendSV_Handler,
|
||||
// 用户需配置下方的用户定义项。
|
||||
|
||||
//////////////////////////////////* 用户定义 *//////////////////////////////////
|
||||
|
||||
/* 系统滴答-配置方式 */
|
||||
// <0=> 手动配置 <1=> 自动配置
|
||||
// 手动配置:您需自行手动配置和系统滴答有关的一切事宜;
|
||||
// 例外的是,滴答中断优先级将由CosyOS自动配置为最低级。
|
||||
// 自动配置:CosyOS会自动为您处理好一切事宜,开箱即用。
|
||||
#define MCUCFG_SYSTICK_AUTOCONFIG 1
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#if (MCUCFG_SYSTICK_AUTOCONFIG == 1)
|
||||
/* 自动配置-额外配置 */
|
||||
// 如果系统滴答配置方式为自动配置,需额外配置下方定义项。
|
||||
|
||||
// 系统时钟频率
|
||||
// 告知CosyOS您所配置的系统时钟,单位为兆赫(MHZ)。
|
||||
#define MCUCFG_SYSCLK 168
|
||||
|
||||
// 系统滴答时钟源
|
||||
// <0=> 外部时钟 <1=> 内核时钟
|
||||
// 在此配置系统滴答时钟源,您无需再额外配置。
|
||||
#define MCUCFG_SYSTICK_CLKSOURCE 1
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#else
|
||||
/* 手动配置-额外配置 */
|
||||
// 如果系统滴答配置方式为手动配置,用户仍需额外配置下方定义项,
|
||||
// 用于 CosyOS-任务管理器 的CPU使用率统计、滴答时间统计等功能。
|
||||
// 当然,如果您不打算使用 CosyOS-任务管理器,可不用配置。
|
||||
// 默认配置仅为示例,给用户以参考和提示。
|
||||
|
||||
// 系统滴答-计数方式
|
||||
// <1=> 从零向上计数至重装载值溢出 <2=> 从重装载值向下计数至零溢出
|
||||
// <3=> 从重装载值向上计数至零溢出 <4=> 从零向下计数至重装载值溢出
|
||||
// 告知CosyOS您所配置的定时器计数方式。
|
||||
#define MCUCFG_SYSTICK_COUNTMODE 2
|
||||
|
||||
// 系统滴答-位数
|
||||
// 如果定时器计数方式配置为3或4,应正确配置该定义。
|
||||
#define MCUCFG_SYSTICK_BITS 24
|
||||
|
||||
// 系统滴答-当前值
|
||||
// 应配置为可读的当前值寄存器。
|
||||
#define MCUCFG_SYSTICK_CURRVALUE (SysTick->VAL)
|
||||
|
||||
// 系统滴答-重装载值
|
||||
// 如果该值为常量可配置为常量,否则应配置为可读的重装载值寄存器。
|
||||
#define MCUCFG_SYSTICK_LOADVALUE (SysTick->LOAD)
|
||||
|
||||
// 系统滴答-时钟
|
||||
// 告知CosyOS您所配置的系统滴答时钟,单位为兆赫(MHZ)。
|
||||
#define MCUCFG_SYSTICK_CLK (系统时钟 / ((SysTick->CTRL & 4) ? 1 : 8))
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////* 系统定义 *//////////////////////////////////
|
||||
|
||||
// 以下为系统定义,用户不可随意修改。
|
||||
|
||||
#define OS_PendSV_Handler PendSV_Handler
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,113 +0,0 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Config
|
||||
* @file mcucfg_cmx.h
|
||||
* @brief CMSIS Cortex-M Core Config File
|
||||
* @author 迟凯峰
|
||||
* @version V2.4.2
|
||||
* @date 2026.07.04
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __MCUCFG_CMX_H
|
||||
#define __MCUCFG_CMX_H
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//*** <<< Use Configuration Wizard in Context Menu >>> ***//
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// <o> 系统中断配置
|
||||
// <3=> SysTick_Handler + PendSV_Handler <0=> TIMn_IRQHandler + XXXx_IRQHandler
|
||||
// <i> ------------------------------------------------------------------------
|
||||
// <i> SysTick_Handler + PendSV_Handler
|
||||
// <i> 要求MCU必须有BASEPRI寄存器,同时不能调用xMaskingPRI和xResumePRI进出全局临界区,也不允许私自使用BASEPRI寄存器。
|
||||
// <i> 如Cortex-M0/M0+等内核,都没有BASEPRI寄存器,就不能采用此方案。
|
||||
// <i> 又如虽使用了Cortex-M3/M4/M7等内核,但却想调用xMaskingPRI和xResumePRI来实现不同掩蔽范围的全局临界区保护,也不能采用此方案。
|
||||
// <i> 采用此方案,用户另需在 mcucfg_cm3.h 中继续配置其它的相关定义项。
|
||||
// <i> ------------------------------------------------------------------------
|
||||
// <i> TIMn_IRQHandler + XXXx_IRQHandler
|
||||
// <i> 用TIMn替代SysTick,TIMn_IRQHandler替代SysTick_Handler,XXXx_IRQHandler替代PendSV_Handler。
|
||||
// <i> CosyOS将不会使用SysTick、SysTick_Handler、PendSV_Handler、BASEPRI寄存器,如果MCU有BASEPRI寄存器,可调用xMaskingPRI和xResumePRI进出全局临界区。
|
||||
// <i> TIMn_IRQHandler 与 XXXx_IRQHandler 必须满足如下关系:TIMn_IRQn / 32 == XXXx_IRQn / 32。
|
||||
// <i> 采用此方案,用户另需在 mcucfg_cm0.h 中继续配置其它的相关定义项。
|
||||
#define MCUCFG_SYSINT 3
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// <o> 中断FIFO服务装载器-互斥访问方案
|
||||
// <1=> 互斥访问指令 <2=> 互斥访问机制 <0=> 关闭总中断
|
||||
// <i> ------------------------------------------------------------------------
|
||||
// <i> 一、互斥访问指令
|
||||
// <i> 仅适用于Cortex-M3/M4/M7等支持互斥访问指令[LDREX/STREX]的内核,可实现全局不关总中断、零中断延迟。
|
||||
// <i> ------------------------------------------------------------------------
|
||||
// <i> 二、互斥访问机制
|
||||
// <i> 仅推荐于Cortex-M0/M0+等不支持互斥访问指令[LDREX/STREX]的内核,可实现全局不关总中断、零中断延迟。
|
||||
// <i> 全局寄存器变量
|
||||
// <i> 首先需要定义一个全局寄存器变量(系统默认定义为r6),专用于互斥访问:
|
||||
// <i> 1、For Arm Compiler 4/5, CosyOS has already defined the register variable r6.
|
||||
// <i> 2、For Arm Compiler 6, please set -ffixed-r6, use Project > Options > C/C++ (AC6) > Misc Controls.
|
||||
// <i> 3、For GNU Compiler, CosyOS has already defined the register variable r6.
|
||||
// <i> 4、For IAR Compiler, please set --lock_regs=r6, use Project > Options > C/C++ Compiler > Extra Options.
|
||||
// <i> 5、For Other Compiler, CosyOS暂不能提供有效定义全局寄存器变量的方法,建议选择其它方案。
|
||||
// <i> 服务调用规约
|
||||
// <i> 仅允许用户在连续两级中断优先级的用户中断中调用【中断FIFO服务】,推荐的方案是:
|
||||
// <i> 1、所有用户中断都不要使用最低优先级(中断优先级号:3);
|
||||
// <i> 2、中断优先级号:2、1 的用户中断中可以随意调用【中断FIFO服务】;
|
||||
// <i> 3、中断优先级号:0和负值的用户中断中不允许调用【中断FIFO服务】。
|
||||
// <i> 注:中断优先级号为负值的中断通常仅包括 Reset_Handler、NMI_Handler、HardFault_Handler。
|
||||
// <i> 用户需严格遵守上述的服务调用规约,否则可能会对系统可靠性造成不利影响。
|
||||
// <i> ------------------------------------------------------------------------
|
||||
// <i> 零、关闭总中断
|
||||
// <i> 适用于所有ARM内核,并具有极短的、确定的关闭总中断时间,包括关闭总中断、再次开启总中断在内,
|
||||
// <i> 共10个指令周期(嵌套方式);如果是非嵌套方式,仅为7个指令周期。
|
||||
// <i> 内核关闭总中断仅发生在 port_cmx_s.c 中,“中断FIFO服务装载器” 中的 “__COUNT” 段。
|
||||
// <i> ------------------------------------------------------------------------
|
||||
// <i> 配置技巧:
|
||||
// <i> 用户可优先选择 “互斥访问指令” 编译尝试,如果内核不支持该指令,编译器会给出明确提示,此时再更换其它方案。
|
||||
#define MCUCFG_PENDSVFIFO_MUTEX 1
|
||||
|
||||
// <q> 关闭总中断-嵌套方式
|
||||
// <i> 当“中断FIFO服务装载器-互斥访问方案”选择关闭总中断时,是否采用嵌套方式?
|
||||
// <i> 如果用户在中断中使用了中断锁(xDisableIRQ/xResumeIRQ)或自行关闭总中断(操作PRIMASK),推荐采用嵌套方式。
|
||||
// <i> 否则可关闭嵌套方式,缩短内核关闭总中断时间(将缩短至7个指令周期)。
|
||||
#define MCUCFG_PENDSVFIFO_MUTEX0 1
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// <o> PendSV_FIFO深度
|
||||
// <i> 此项参数取决于您在中断中调用的FIFO服务的总数及中断的频率。
|
||||
// <i> 对于Cortex-M来说,PendSV_FIFO的最大深度可为255。
|
||||
// <i> 可开启PendSV_FIFO监控功能,监控历史上的最大值,再适当增大,以确保其不会溢出。
|
||||
#define MCUCFG_PENDSVFIFO_DEPTH 32
|
||||
|
||||
// <o> 中断FIFO服务处理器-最大并发执行数
|
||||
// <i> 中断FIFO服务处理器在一次运行中,允许执行服务的最大数量。
|
||||
// <i> 如果超出这个数值,中断FIFO服务处理器将主动退出运行,而后继续执行任务调度/切换。
|
||||
// <i> 该功能可防止因中断FIFO服务的多阶段持续并发而导致的中断FIFO服务处理器死锁(永远有执行不完的服务),
|
||||
// <i> 并最终导致任务不能调度运行。
|
||||
// <i> 该值通常建议在“PendSV_FIFO深度值的2~10倍之间”选取,不建议过大或过小。
|
||||
// <i> 可开启PendSV_FIFO监控功能,监控“实际并发执行数”在历史上的最大值,如果过大说明设计存在不合理因素,
|
||||
// <i> 应设法予以解决。
|
||||
#define MCUCFG_PENDSVFIFO_COUNT 256
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// <q> 浮点寄存器上下文自动保存
|
||||
// <i> 是否启用浮点寄存器的上下文自动保存功能?
|
||||
// <i> 如果存在并且启用了硬件浮点单元,同时在多个任务和中断中都要进行浮点运算,可考虑开启该选项。
|
||||
#define MCUCFG_ASPEN_LSPEN 0
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//*** <<< end of configuration section >>> ***//
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if (MCUCFG_PENDSVFIFO_DEPTH > 255)
|
||||
#error PendSV_FIFO深度溢出!
|
||||
#endif
|
||||
|
||||
#define MCUCFG_OSZEROINSTALL 0
|
||||
#define mSysTick_Clear()
|
||||
#define mUserReg_SAVEc()
|
||||
#define mUserReg_RESc()
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,161 +0,0 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Port
|
||||
* @file port_cmx.c
|
||||
* @brief CMSIS Cortex-M Core Port File
|
||||
* @author 迟凯峰
|
||||
* @version V2.4.2
|
||||
* @date 2026.07.04
|
||||
******************************************************************************/
|
||||
|
||||
#include "os_var.h"
|
||||
#ifdef __PORT_CMX_H
|
||||
|
||||
|
||||
/*
|
||||
* 栈监控(涵盖主栈和任务栈)
|
||||
*/
|
||||
|
||||
#if (SYSCFG_DEBUGGING == __ENABLED__)
|
||||
|
||||
#include <string.h>
|
||||
s_u32_t m_msp; // main stack initial pointer
|
||||
s_u32_t m_stacksize; // main stack size
|
||||
s_u32_t m_stacklen_max = 0; // main stack used length of maximum
|
||||
static s_u8_t const stack_data[32] = {"CosyOS is an RTOS come on China."};
|
||||
|
||||
void m_stack_check_init(s_u8_t *addr, s_u32_t size)
|
||||
{
|
||||
s_u32_t i;
|
||||
s_u32_t c = size / sizeof(stack_data);
|
||||
s_u8_t *p = addr - size;
|
||||
for(i = 0; i < c; i++){
|
||||
memcpy(p, stack_data, sizeof(stack_data));
|
||||
p += sizeof(stack_data);
|
||||
}
|
||||
}
|
||||
|
||||
s_u32_t m_stack_check(s_u8_t *addr, s_u32_t size)
|
||||
{
|
||||
s_u32_t i;
|
||||
s_u32_t c = size / sizeof(stack_data);
|
||||
s_u8_t *p = addr - size;
|
||||
for(i = 0; i < c; i++){
|
||||
if(!memcmp(p, stack_data, sizeof(stack_data))){
|
||||
p += sizeof(stack_data);
|
||||
}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (s_u32_t)(addr - p);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* 中断FIFO服务
|
||||
*/
|
||||
|
||||
#if (MCUCFG_PENDSVFIFO_DEPTH > 0)
|
||||
|
||||
#if (SYSCFG_PENDSVFIFO_MONITOR == __ENABLED__)
|
||||
s_u32_t mPendSV_FIFO_DepthMAX = 0;
|
||||
s_u16_t mPendSV_FIFO_CountMAX = 0;
|
||||
#endif
|
||||
void *mPendSV_FIFO_0[MCUCFG_PENDSVFIFO_DEPTH + 1]; /*!< FIFO0 */
|
||||
void *mPendSV_FIFO_1[MCUCFG_PENDSVFIFO_DEPTH + 1]; /*!< FIFO1 */
|
||||
bool volatile m_fifo_lock = true; /*!< FIFO互斥访问锁:入FIFO与出FIFO的互斥
|
||||
if(m_fifo_lock == true) {中断FIFO服务装载器入FIFO0,中断FIFO服务处理器出FIFO1}
|
||||
if(m_fifo_lock == false){中断FIFO服务装载器入FIFO1,中断FIFO服务处理器出FIFO0} */
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX == 2) /*!< 互斥访问机制 */
|
||||
void *mPendSV_FIFO_X; /*!< FIFO替身计数器 */
|
||||
#endif
|
||||
|
||||
/* 中断FIFO服务处理器 */
|
||||
void mPendSV_FIFOHandler(void)
|
||||
{
|
||||
register void **p;
|
||||
register void *sv;
|
||||
register s_u32_t i;
|
||||
register s_u16_t j = 0;
|
||||
|
||||
__FIFO_0:
|
||||
p = mPendSV_FIFO_0;
|
||||
/* 独占访问FIFO0 */
|
||||
m_fifo_lock = false;
|
||||
__DMB();
|
||||
if(true){
|
||||
i = (s_u32_t)mPendSV_FIFO_0[0];
|
||||
mPendSV_FIFO_0[0] = OS_NULL;
|
||||
#if (SYSCFG_PENDSVFIFO_MONITOR == __ENABLED__)
|
||||
if(i > mPendSV_FIFO_DepthMAX){
|
||||
mPendSV_FIFO_DepthMAX = i;
|
||||
}
|
||||
#endif
|
||||
if(i > MCUCFG_PENDSVFIFO_DEPTH){
|
||||
i = MCUCFG_PENDSVFIFO_DEPTH;
|
||||
#if (SYSCFG_PENDSVFIFO_MONITOR == __ENABLED__)
|
||||
s_fault.overflow_pendsvfifo = true;
|
||||
#endif
|
||||
}
|
||||
j += i;
|
||||
do{
|
||||
sv = *++p;
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX <= 1)
|
||||
(*sPendSV_FIFOHandler[*(s_u8_t const *)sv])(sv);
|
||||
#else
|
||||
if(sv != OS_NULL){
|
||||
*p = OS_NULL;
|
||||
(*sPendSV_FIFOHandler[*(s_u8_t const *)sv])(sv);
|
||||
}
|
||||
#endif
|
||||
}while(--i);
|
||||
__DMB();
|
||||
}
|
||||
|
||||
OS_NOP(1);
|
||||
|
||||
p = mPendSV_FIFO_1;
|
||||
/* 独占访问FIFO1 */
|
||||
m_fifo_lock = true;
|
||||
__DMB();
|
||||
if(mPendSV_FIFO_1[0]){
|
||||
i = (s_u32_t)mPendSV_FIFO_1[0];
|
||||
mPendSV_FIFO_1[0] = OS_NULL;
|
||||
#if (SYSCFG_PENDSVFIFO_MONITOR == __ENABLED__)
|
||||
if(i > mPendSV_FIFO_DepthMAX){
|
||||
mPendSV_FIFO_DepthMAX = i;
|
||||
}
|
||||
#endif
|
||||
if(i > MCUCFG_PENDSVFIFO_DEPTH){
|
||||
i = MCUCFG_PENDSVFIFO_DEPTH;
|
||||
#if (SYSCFG_PENDSVFIFO_MONITOR == __ENABLED__)
|
||||
s_fault.overflow_pendsvfifo = true;
|
||||
#endif
|
||||
}
|
||||
j += i;
|
||||
do{
|
||||
sv = *++p;
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX <= 1)
|
||||
(*sPendSV_FIFOHandler[*(s_u8_t const *)sv])(sv);
|
||||
#else
|
||||
if(sv != OS_NULL){
|
||||
*p = OS_NULL;
|
||||
(*sPendSV_FIFOHandler[*(s_u8_t const *)sv])(sv);
|
||||
}
|
||||
#endif
|
||||
}while(--i);
|
||||
__DMB();
|
||||
}
|
||||
|
||||
if(mPendSV_FIFO_0[0] && j < MCUCFG_PENDSVFIFO_COUNT) goto __FIFO_0;
|
||||
#if (SYSCFG_PENDSVFIFO_MONITOR == __ENABLED__)
|
||||
if(mPendSV_FIFO_CountMAX < j) mPendSV_FIFO_CountMAX = j;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,445 +0,0 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Port
|
||||
* @file port_cmx.h
|
||||
* @brief CMSIS Cortex-M Core Port File
|
||||
* @author 迟凯峰
|
||||
* @version V2.4.2
|
||||
* @date 2026.07.04
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __PORT_CMX_H
|
||||
#define __PORT_CMX_H
|
||||
|
||||
/* INCLUDE */
|
||||
#include <stdbool.h>
|
||||
#include "os_base.h"
|
||||
#include "os_def.h"
|
||||
#include "syscfg.h"
|
||||
#include "mcucfg_cm0.h"
|
||||
#include "mcucfg_cm3.h"
|
||||
#include SYSCFG_STANDARDHEAD
|
||||
#include "cmsis_specific.h"
|
||||
|
||||
|
||||
/* Memory */
|
||||
#define _SYS_MEM_
|
||||
#define _CODE_MEM_
|
||||
#define _CONST_MEM_
|
||||
#define _STACK_MEM_
|
||||
#define _XDATA_MEM_
|
||||
#define _STATIC_MEM_
|
||||
#define _MALLOC_MEM_
|
||||
#define _OBJ_MEM_
|
||||
#define _RTC_MEM_
|
||||
#define _QUE_MEM_
|
||||
#define _DEBUG_MEM_
|
||||
|
||||
|
||||
/* Register */
|
||||
#define _SYS_REG_
|
||||
|
||||
|
||||
/* Typedef */
|
||||
#define m_boolvoid_tf
|
||||
typedef unsigned long long int s_u64_t;
|
||||
typedef bool m_bit_t;
|
||||
typedef s_u32_t m_sp_t;
|
||||
typedef s_u32_t m_tick_t;
|
||||
typedef s_u32_t m_pc_t;
|
||||
typedef s_u32_t m_tqcount_t;
|
||||
typedef s_u32_t m_fetion_t;
|
||||
typedef s_u32_t m_group_t;
|
||||
typedef s_u32_t m_stacksize_t;
|
||||
typedef s_u32_t m_stacklen_t;
|
||||
typedef s_u32_t m_rtccount_t;
|
||||
|
||||
|
||||
/* Extern */
|
||||
#if (MCUCFG_PENDSVFIFO_DEPTH > 0)
|
||||
extern s_u32_t mPendSV_FIFO_DepthMAX;
|
||||
extern s_u16_t mPendSV_FIFO_CountMAX;
|
||||
extern void *mPendSV_FIFO_0[MCUCFG_PENDSVFIFO_DEPTH + 1];
|
||||
extern void *mPendSV_FIFO_1[MCUCFG_PENDSVFIFO_DEPTH + 1];
|
||||
extern bool volatile m_fifo_lock;
|
||||
extern void mPendSV_FIFOLoader (void *sv);
|
||||
extern void mPendSV_FIFOHandler(void);
|
||||
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX == 2)
|
||||
extern void *mPendSV_FIFO_X;
|
||||
#define mPendSV_FIFO_rx r6
|
||||
|
||||
/*
|
||||
* Arm Compiler 4/5
|
||||
*/
|
||||
#if defined ( __CC_ARM )
|
||||
/* For Arm Compiler 4/5, CosyOS has already defined the register variable r6. */
|
||||
register void **mPendSV_FIFO_REGx __ASM(sDefStr(mPendSV_FIFO_rx));
|
||||
|
||||
/*
|
||||
* Arm Compiler 6.6 LTM / above 6.10.1 (armclang)
|
||||
*/
|
||||
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
/* For Arm Compiler 6, please set -ffixed-r6, use Project > Options > C/C++ (AC6) > Misc Controls. */
|
||||
|
||||
/*
|
||||
* GNU Compiler
|
||||
*/
|
||||
#elif defined ( __GNUC__ )
|
||||
/* For GNU Compiler, CosyOS has already defined the register variable r6. */
|
||||
__extension__ register void **mPendSV_FIFO_REGx __ASM(sDefStr(mPendSV_FIFO_rx));
|
||||
|
||||
/*
|
||||
* IAR Compiler
|
||||
*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
/* For IAR Compiler, please set --lock_regs=r6, use Project > Options > C/C++ Compiler > Extra Options. */
|
||||
|
||||
/*
|
||||
* Other Compiler
|
||||
*/
|
||||
#else
|
||||
/* For Other Compiler, please reset the option in mcucfg_cmx.h > 互斥访问方案. */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* CONST & ATTRIBUTE */
|
||||
#define MCUCFG_ISA __ARM__
|
||||
#define MCUCFG_PCLEN 4
|
||||
#define MCUCFG_TASK_ATTRIBUTE
|
||||
#define MCUCFG_OSIT_ATTRIBUTE
|
||||
#define MCUCFG_SYSTICK_ATTRIBUTE
|
||||
#define MCUCFG_TERNARYMASK
|
||||
|
||||
#define MCUCFG_STACK_ALIGN __ALIGNED(8)
|
||||
#define MCUCFG_TASKSTACK_REALLOC __DISABLED__
|
||||
#if (MCUCFG_ASPEN_LSPEN == __ENABLED__)
|
||||
#define MCUCFG_CALLER_PUSH_FPU (18 * 4) /** \push {s0-s15,FPSCR,UNKNOW} */
|
||||
#define MCUCFG_CALLEE_PUSH_FPU (16 * 4) /** \vstmdb {s16-s31} */
|
||||
#else
|
||||
#define MCUCFG_CALLER_PUSH_FPU 0
|
||||
#define MCUCFG_CALLEE_PUSH_FPU 0
|
||||
#endif
|
||||
#define MCUCFG_CALLER_PUSH_REG (8 * 4) /** \push {r0-r3,r12,r14(lr),r15(pc),xPSR} */
|
||||
#define MCUCFG_CALLEE_PUSH_REG (8 * 4) /** \stmdb {r4-r11} */
|
||||
#define MCUCFG_CALLER_PUSH (MCUCFG_CALLER_PUSH_FPU + MCUCFG_CALLER_PUSH_REG)
|
||||
#define MCUCFG_CALLEE_PUSH (MCUCFG_CALLEE_PUSH_FPU + MCUCFG_CALLEE_PUSH_REG)
|
||||
#define MCUCFG_BASICSTACKSIZE (MCUCFG_CALLER_PUSH + MCUCFG_CALLEE_PUSH)
|
||||
|
||||
|
||||
/* TaskCtrl */
|
||||
#define mTaskCtrl_Head_ m_sp_t psp;
|
||||
#define mTaskCtrl_Tail_ m_sp_t psp_top;
|
||||
|
||||
|
||||
/*
|
||||
* SysTick
|
||||
*/
|
||||
#if (MCUCFG_SYSTICK_AUTOCONFIG == __ENABLED__)
|
||||
/* 自动配置 */
|
||||
#define MCUCFG_SYSTICK_COUNTMODE 2 /*!< 计数方式,2:从重装载值向下计数至零溢出 */
|
||||
#define MCUCFG_SYSTICK_LIMITVALUE (1UL << 24) /*!< 极限值 */
|
||||
#define MCUCFG_SYSTICK_CURRVALUE (SysTick->VAL) /*!< 当前值寄存器 */
|
||||
#define MCUCFG_SYSTICK_CLKDIV (MCUCFG_SYSTICK_CLKSOURCE ? 1 : 8)
|
||||
#define MCUCFG_SYSTICK_CLK (MCUCFG_SYSCLK / MCUCFG_SYSTICK_CLKDIV)
|
||||
#define MCUCFG_SYSTICK_COUNT1CYC (SYSCFG_SYSTICK_CYCLE * MCUCFG_SYSTICK_CLK * 1UL)
|
||||
#define MCUCFG_SYSTICK_LOADVALUE (MCUCFG_SYSTICK_COUNT1CYC - 1)
|
||||
#define MCUCFG_SYSTICK_MAXVALUE MCUCFG_SYSTICK_LOADVALUE
|
||||
#define MCUCFG_SYSTICK_MINVALUE 0
|
||||
#if (MCUCFG_SYSCLK % MCUCFG_SYSTICK_CLKDIV)
|
||||
#warning 系统滴答时钟不为整数。
|
||||
#endif
|
||||
#if (MCUCFG_SYSTICK_COUNT1CYC > MCUCFG_SYSTICK_LIMITVALUE)
|
||||
#error 系统滴答定时器溢出。
|
||||
#endif
|
||||
#define mSysTick_SetLOAD() SysTick->LOAD = MCUCFG_SYSTICK_LOADVALUE
|
||||
#define mSysTick_SetCTRL() SysTick->CTRL = ((MCUCFG_SYSTICK_CLKSOURCE ? 0x04 : 0x00) | 0x02 | 0x01)
|
||||
#define mSysTick_INIT() \
|
||||
do{ \
|
||||
mSysTick_SetPRI(); \
|
||||
mSysTick_SetLOAD(); \
|
||||
mSysTick_SetCTRL(); \
|
||||
}while(false)
|
||||
|
||||
#else
|
||||
/* 手动配置 */
|
||||
#if (MCUCFG_SYSTICK_COUNTMODE == 1 || MCUCFG_SYSTICK_COUNTMODE == 2)
|
||||
#define MCUCFG_SYSTICK_MAXVALUE (MCUCFG_SYSTICK_LOADVALUE)
|
||||
#define MCUCFG_SYSTICK_MINVALUE 0
|
||||
#define MCUCFG_SYSTICK_COUNT1CYC (MCUCFG_SYSTICK_LOADVALUE + 1UL)
|
||||
|
||||
#elif (MCUCFG_SYSTICK_COUNTMODE == 3 || MCUCFG_SYSTICK_COUNTMODE == 4)
|
||||
#define MCUCFG_SYSTICK_LIMITVALUE (1UL << MCUCFG_SYSTICK_BITS)
|
||||
#define MCUCFG_SYSTICK_MAXVALUE (MCUCFG_SYSTICK_LIMITVALUE)
|
||||
#define MCUCFG_SYSTICK_MINVALUE (MCUCFG_SYSTICK_LOADVALUE)
|
||||
#define MCUCFG_SYSTICK_COUNT1CYC (MCUCFG_SYSTICK_MAXVALUE - MCUCFG_SYSTICK_MINVALUE)
|
||||
#endif
|
||||
|
||||
#define mSysTick_INIT() mSysTick_SetPRI()
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* SysTick_Handler + PendSV_Handler
|
||||
*/
|
||||
#if (MCUCFG_SYSINT == 3)
|
||||
/* SysTick */
|
||||
#define mSysTick_SetPRI() *(volatile s_u8_t *)0xE000ED23 = 0xFF
|
||||
|
||||
/* PendSV */
|
||||
#define mPendSV_SetPRI() *(volatile s_u8_t *)0xE000ED22 = 0xFF
|
||||
#define mPendSV_Set() *(volatile s_u32_t *)0xE000ED04 = 0x10000000
|
||||
#define mPendSV_Clear()
|
||||
#define mPendSV_INIT() mPendSV_SetPRI()
|
||||
|
||||
/* 内核锁 */
|
||||
__STATIC_FORCEINLINE void __mu_disable_sysirq(void)
|
||||
{
|
||||
__set_BASEPRI(0xFF);
|
||||
__ASM("dsb");
|
||||
__ASM("isb");
|
||||
}
|
||||
|
||||
__STATIC_FORCEINLINE void __mu_enable_sysirq(void)
|
||||
{
|
||||
__ASM("dsb");
|
||||
__set_BASEPRI(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* TIMn_IRQHandler + XXXx_IRQHandler
|
||||
*/
|
||||
#elif (MCUCFG_SYSINT == 0)
|
||||
/* SysTick */
|
||||
#define mSysTick_SetPRI() \
|
||||
*(volatile s_u32_t *)(0xE000E400 + MCUCFG_TIMn_IRQn / 4 * 4)|= 0xFFUL << (MCUCFG_TIMn_IRQn % 4) * 8
|
||||
|
||||
/* PendSV */
|
||||
#define mPendSV_SetPRI() \
|
||||
*(volatile s_u32_t *)(0xE000E400 + MCUCFG_XXXx_IRQn / 4 * 4)|= 0xFFUL << (MCUCFG_XXXx_IRQn % 4) * 8
|
||||
|
||||
#define mPendSV_Set() \
|
||||
*(volatile s_u32_t *)(0xE000E200 + MCUCFG_XXXx_IRQn / 32 * 4) = 0x01UL << (MCUCFG_XXXx_IRQn % 32)
|
||||
/*
|
||||
#define mPendSV_Clear() \
|
||||
*(volatile s_u32_t *)(0xE000E280 + MCUCFG_XXXx_IRQn / 32 * 4) = 0x01UL << (MCUCFG_XXXx_IRQn % 32)
|
||||
*/
|
||||
#define mPendSV_Clear()
|
||||
#define mPendSV_INIT() mPendSV_SetPRI()
|
||||
|
||||
/* 内核锁 */
|
||||
#define mSysINT_Disable() \
|
||||
*(volatile s_u32_t *)(0xE000E180 + MCUCFG_XXXx_IRQn / 32 * 4) = (0x01UL << (MCUCFG_XXXx_IRQn % 32)) \
|
||||
| (0x01UL << (MCUCFG_TIMn_IRQn % 32))
|
||||
#define mSysINT_Enable() \
|
||||
*(volatile s_u32_t *)(0xE000E100 + MCUCFG_XXXx_IRQn / 32 * 4) = (0x01UL << (MCUCFG_XXXx_IRQn % 32)) \
|
||||
| (0x01UL << (MCUCFG_TIMn_IRQn % 32))
|
||||
__STATIC_FORCEINLINE void __mu_disable_sysirq(void)
|
||||
{
|
||||
mSysINT_Disable();
|
||||
__ASM("dsb");
|
||||
__ASM("isb");
|
||||
}
|
||||
|
||||
__STATIC_FORCEINLINE void __mu_enable_sysirq(void)
|
||||
{
|
||||
__ASM("dsb");
|
||||
mSysINT_Enable();
|
||||
}
|
||||
|
||||
#endif
|
||||
#define mSysIRQ_Disable() __mu_disable_sysirq()
|
||||
#define mSysIRQ_Enable() __mu_enable_sysirq()
|
||||
|
||||
|
||||
/* CCR:栈8字节对齐 */
|
||||
#define mCCR_Set() \
|
||||
do{ \
|
||||
*(volatile s_u32_t *)0xE000ED14 |= 0x0200; \
|
||||
}while(false)
|
||||
|
||||
|
||||
/*
|
||||
* FPU
|
||||
*/
|
||||
|
||||
/* CPACR: CP11|CP10 */
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) \
|
||||
&& (defined (__FPU_USED ) && (__FPU_USED == 1U)))
|
||||
#define mCPACR_Set() \
|
||||
do{ \
|
||||
*(volatile s_u32_t *)0xE000ED88 |= (0x0FUL << 20); \
|
||||
}while(false)
|
||||
#else
|
||||
#define mCPACR_Set()
|
||||
#endif
|
||||
|
||||
/* FPCCR: ASPEN|LSPEN */
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) \
|
||||
&& (defined (__FPU_USED ) && (__FPU_USED == 1U)))
|
||||
#if (MCUCFG_ASPEN_LSPEN == 1)
|
||||
#define mFPCCR_Set() \
|
||||
do{ \
|
||||
*(volatile s_u32_t *)0xE000EF34 |= (0x03UL << 30); \
|
||||
}while(false)
|
||||
#else
|
||||
#define mFPCCR_Set() \
|
||||
do{ \
|
||||
*(volatile s_u32_t *)0xE000EF34 &=~(0x03UL << 30); \
|
||||
}while(false)
|
||||
#endif
|
||||
#else
|
||||
#define mFPCCR_Set()
|
||||
#endif
|
||||
|
||||
/* FPSCR */
|
||||
#if ((MCUCFG_ASPEN_LSPEN == 1) \
|
||||
&& ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) \
|
||||
&& (defined (__FPU_USED ) && (__FPU_USED == 1U))))
|
||||
#define mFPSCR_INIT() \
|
||||
do{ \
|
||||
*(volatile s_u32_t *)(node_news->psp - 8) = __get_FPSCR(); \
|
||||
}while(false)
|
||||
#else
|
||||
#define mFPSCR_INIT()
|
||||
#endif
|
||||
|
||||
|
||||
/* CosyOS初始化 */
|
||||
#define mCosyOS_INIT() \
|
||||
do{ \
|
||||
__ASM("cpsid i"); \
|
||||
mCCR_Set(); \
|
||||
mCPACR_Set(); \
|
||||
mFPCCR_Set(); \
|
||||
mPendSV_INIT(); \
|
||||
mSysTick_INIT(); \
|
||||
__set_PSP(__get_MSP() - 2 * MCUCFG_BASICSTACKSIZE); \
|
||||
__set_CONTROL(0x02); \
|
||||
__ASM("dsb"); \
|
||||
__ASM("isb"); \
|
||||
__ASM("cpsie i"); \
|
||||
}while(false)
|
||||
|
||||
|
||||
/* CosyOS低功耗 */
|
||||
#define mCosyOS_IDLE() __WFI()
|
||||
|
||||
|
||||
/* 中断FIFO服务-装载 */
|
||||
#define mPendSV_FIFOLoad() \
|
||||
do{ \
|
||||
mPendSV_FIFOLoader(&u_psv); \
|
||||
mPendSV_Set(); \
|
||||
}while(false)
|
||||
|
||||
#define mPendSV_FIFOHandle() \
|
||||
if(mPendSV_FIFO_0[0]) mPendSV_FIFOHandler()
|
||||
|
||||
|
||||
/* 事件标志组-中断中写多标志位 */
|
||||
#define miWriteFlagBits() \
|
||||
if(!u_psv.value){ \
|
||||
do{}while(false)
|
||||
|
||||
|
||||
/* 任务栈 */
|
||||
#define MCUCFG_TASKSTACK_MODE __MSP_PSP__
|
||||
|
||||
#define mTaskStack_Init() \
|
||||
do{ \
|
||||
node_news->psp_top = (m_sp_t)node_news->bsp + node_news->stacksize; \
|
||||
if(node_news->psp_top % 8){ \
|
||||
node_news->psp_top /= 8; \
|
||||
node_news->psp_top *= 8; \
|
||||
node_news->stacksize = node_news->psp_top - (m_sp_t)node_news->bsp; \
|
||||
} \
|
||||
mTaskStack_CheckInit(); \
|
||||
mTaskStack_Reset(); \
|
||||
}while(false)
|
||||
|
||||
#define mTaskStack_Reset() \
|
||||
do{ \
|
||||
node_news->psp = node_news->psp_top; \
|
||||
mFPSCR_INIT(); /* FPSCR */ \
|
||||
*(volatile s_u32_t *)(node_news->psp - MCUCFG_CALLER_PUSH_FPU - 4) = 0x01000000; /* xPSR */ \
|
||||
*(volatile s_u32_t *)(node_news->psp - MCUCFG_CALLER_PUSH_FPU - 8) = (s_u32_t)node_news->entry; /* r15(pc) */ \
|
||||
node_news->psp -= MCUCFG_BASICSTACKSIZE; \
|
||||
}while(false)
|
||||
|
||||
/* 栈监控 */
|
||||
#if (SYSCFG_DEBUGGING == __ENABLED__)
|
||||
|
||||
extern s_u32_t m_msp;
|
||||
extern s_u32_t m_stacksize;
|
||||
extern s_u32_t m_stacklen_max;
|
||||
void m_stack_check_init(s_u8_t *addr, s_u32_t size);
|
||||
s_u32_t m_stack_check (s_u8_t *addr, s_u32_t size);
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#define mMainStack_CheckInit() \
|
||||
do{ \
|
||||
extern uint32_t CSTACK$$Base; \
|
||||
extern uint32_t CSTACK$$Limit; \
|
||||
m_msp = (uint32_t)&CSTACK$$Limit; \
|
||||
m_stacksize = (uint32_t)&CSTACK$$Limit - (uint32_t)&CSTACK$$Base; \
|
||||
m_stack_check_init((s_u8_t *)(m_msp - 64), m_stacksize - 64); \
|
||||
}while(false)
|
||||
#else
|
||||
#define mMainStack_CheckInit(size) \
|
||||
do{ \
|
||||
m_msp = __get_MSP(); \
|
||||
m_stacksize = size; \
|
||||
m_stack_check_init((s_u8_t *)(m_msp - 64), size - 64); \
|
||||
}while(false)
|
||||
#endif
|
||||
|
||||
#define mTaskStack_Check0() s_task_current->psp_top - __get_PSP() + MCUCFG_CALLEE_PUSH
|
||||
#define mMainStack_Check() m_stack_check((s_u8_t *)m_msp, m_stacksize)
|
||||
#define mTaskStack_Check() m_stack_check((s_u8_t *)(s_task_current->psp_top), s_task_current->stacksize)
|
||||
#define mTaskStack_CheckInit() m_stack_check_init((s_u8_t *)(node_news->psp_top), node_news->stacksize)
|
||||
|
||||
#else
|
||||
#define mTaskStack_CheckInit()
|
||||
#endif
|
||||
|
||||
|
||||
/* 全局临界区 */
|
||||
__STATIC_INLINE s_u32_t __mx_disable_irq(void)
|
||||
{
|
||||
register s_u32_t oldirq = __get_PRIMASK();
|
||||
__ASM("cpsid i");
|
||||
__ASM("nop");
|
||||
return oldirq;
|
||||
}
|
||||
|
||||
#define mxDisableIRQ() __mx_disable_irq()
|
||||
#define mxResumeIRQ(oldirq) __set_PRIMASK(oldirq)
|
||||
|
||||
#if ((MCUCFG_SYSINT == 0) \
|
||||
&& ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) \
|
||||
|| (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) \
|
||||
|| (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) \
|
||||
|| (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1))))
|
||||
__STATIC_INLINE s_u32_t __mx_masking_pri(s_u32_t newpri)
|
||||
{
|
||||
register s_u32_t oldpri = __get_BASEPRI();
|
||||
__set_BASEPRI_MAX(newpri << 4);
|
||||
__ASM("dsb");
|
||||
__ASM("isb");
|
||||
return oldpri;
|
||||
}
|
||||
|
||||
#define mxMaskingPRI(newpri) __mx_masking_pri(newpri)
|
||||
#define mxResumePRI(oldpri) __set_BASEPRI(oldpri)
|
||||
#endif
|
||||
|
||||
|
||||
/* 内存访问屏障 */
|
||||
#define __mx_MMB() __DMB()
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,412 +0,0 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Port
|
||||
* @file port_cmx_s.c
|
||||
* @brief CMSIS Cortex-M Core Port File for Arm / GNU / IAR Compiler
|
||||
* @author 迟凯峰
|
||||
* @version V2.4.2
|
||||
* @date 2026.07.04
|
||||
******************************************************************************/
|
||||
|
||||
#include "os_var.h"
|
||||
#ifdef __PORT_CMX_H
|
||||
|
||||
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) \
|
||||
|| (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) \
|
||||
|| (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) \
|
||||
|| (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) \
|
||||
|| (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)))
|
||||
#define __CMX_ISA 7
|
||||
#else
|
||||
#define __CMX_ISA 6
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Arm Compiler 4/5
|
||||
*/
|
||||
#if (defined ( __CC_ARM ))
|
||||
|
||||
/* PendSV软中断 */
|
||||
__ASM void OS_PendSV_Handler(void)
|
||||
{
|
||||
IMPORT sPendSV_Handler
|
||||
IMPORT s_task_current
|
||||
IMPORT s_task_news
|
||||
PRESERVE8
|
||||
THUMB
|
||||
|
||||
push {lr}
|
||||
bl sPendSV_Handler
|
||||
/* 直接返回吗?*/
|
||||
#if (__CMX_ISA == 6)
|
||||
cmp r0, #0
|
||||
beq __RETURN
|
||||
#else
|
||||
cbz r0, __RETURN
|
||||
#endif
|
||||
/* 保护现场吗?*/
|
||||
ldr r1, =s_task_current
|
||||
subs r0, #1
|
||||
#if (__CMX_ISA == 6)
|
||||
cmp r0, #0
|
||||
beq __RESTORE
|
||||
#else
|
||||
cbz r0, __RESTORE
|
||||
#endif
|
||||
mrs r0, psp
|
||||
isb
|
||||
/* 任务PC监控 */
|
||||
#if (SYSCFG_TASKPC_MONITOR == 1)
|
||||
IMPORT s_taskmgr_sign
|
||||
IMPORT s_pc
|
||||
ldr r2, =s_taskmgr_sign
|
||||
ldrb r2, [r2]
|
||||
#if (__CMX_ISA == 6)
|
||||
cmp r2, #0
|
||||
beq __PROTECTING
|
||||
#else
|
||||
cbz r2, __PROTECTING
|
||||
#endif
|
||||
ldr r2, [r0,#24]
|
||||
ldr r3, =s_pc
|
||||
str r2, [r3]
|
||||
#endif
|
||||
/* 保护现场 */
|
||||
__PROTECTING
|
||||
#if (MCUCFG_ASPEN_LSPEN == 1)
|
||||
vstmdb r0!, {s16-s31}
|
||||
#endif
|
||||
#if (__CMX_ISA == 6)
|
||||
subs r0, #32
|
||||
ldr r2, [r1]
|
||||
str r0, [r2]
|
||||
stmia r0!, {r4-r7}
|
||||
mov r4, r8
|
||||
mov r5, r9
|
||||
mov r6, r10
|
||||
mov r7, r11
|
||||
stmia r0!, {r4-r7}
|
||||
#else
|
||||
stmdb r0!, {r4-r11}
|
||||
ldr r2, [r1]
|
||||
str r0, [r2]
|
||||
#endif
|
||||
dsb
|
||||
/* 恢复现场 */
|
||||
__RESTORE ldr r3, =s_task_news
|
||||
ldr r3, [r3]
|
||||
str r3, [r1]
|
||||
ldr r0, [r3]
|
||||
#if (__CMX_ISA == 6)
|
||||
adds r0, #16
|
||||
ldmia r0!, {r4-r7}
|
||||
mov r11, r7
|
||||
mov r10, r6
|
||||
mov r9, r5
|
||||
mov r8, r4
|
||||
mov r1, r0
|
||||
subs r1, #32
|
||||
ldmia r1!, {r4-r7}
|
||||
#else
|
||||
ldmia r0!, {r4-r11}
|
||||
#endif
|
||||
#if (MCUCFG_ASPEN_LSPEN == 1)
|
||||
vldmia r0!, {s16-s31}
|
||||
#endif
|
||||
msr psp, r0
|
||||
/* 返回 */
|
||||
__RETURN pop {pc}
|
||||
|
||||
ALIGN
|
||||
}
|
||||
|
||||
|
||||
/* 中断FIFO服务装载器 */
|
||||
#if (MCUCFG_PENDSVFIFO_DEPTH > 0)
|
||||
__ASM void mPendSV_FIFOLoader(void *sv)
|
||||
{
|
||||
IMPORT mPendSV_FIFO_0
|
||||
IMPORT mPendSV_FIFO_1
|
||||
IMPORT m_fifo_lock
|
||||
THUMB
|
||||
/* FIFO选择 */
|
||||
ldr r2, =m_fifo_lock
|
||||
ldrb r3, [r2]
|
||||
#if (__CMX_ISA == 6)
|
||||
cmp r3, #0
|
||||
beq __FIFO1
|
||||
#else
|
||||
cbz r3, __FIFO1
|
||||
#endif
|
||||
__FIFO0 ldr r1, =mPendSV_FIFO_0
|
||||
b __COUNT
|
||||
__FIFO1 ldr r1, =mPendSV_FIFO_1
|
||||
/* FIFO计数 */
|
||||
__COUNT /* 0、关闭总中断 */
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX == 0)
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX0 == 1)
|
||||
mrs r3, primask // cycles:4
|
||||
#endif
|
||||
cpsid i // cycles:1
|
||||
ldr r2, [r1] // cycles:2
|
||||
adds r2, #1 // cycles:1
|
||||
str r2, [r1] // cycles:2
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX0 == 1)
|
||||
msr primask, r3 // cycles:4
|
||||
#else
|
||||
cpsie i // cycles:1
|
||||
#endif
|
||||
|
||||
/* 1、互斥访问指令 */
|
||||
#elif (MCUCFG_PENDSVFIFO_MUTEX == 1)
|
||||
__LOOP ldrex r2, [r1]
|
||||
adds r2, #1
|
||||
strex r3, r2, [r1]
|
||||
cmp r3, #0
|
||||
bne __LOOP
|
||||
|
||||
/* 2、互斥访问机制 */
|
||||
#elif (MCUCFG_PENDSVFIFO_MUTEX == 2)
|
||||
IMPORT mPendSV_FIFO_X
|
||||
#define rx mPendSV_FIFO_rx
|
||||
mov r12, rx
|
||||
movs r2, #1
|
||||
ldrh r3, [r1, #2]
|
||||
strh r2, [r1, #2]
|
||||
dmb
|
||||
__LOOP mov rx, r1
|
||||
ldrh r2, [rx]
|
||||
adds r2, #1
|
||||
strh r2, [rx]
|
||||
cmp rx, r1
|
||||
bne __LOOP
|
||||
|
||||
cmp r3, #0
|
||||
beq __RESrx
|
||||
ldr rx, =mPendSV_FIFO_X
|
||||
b __OVERFLOW
|
||||
__RESrx strh r3, [r1, #2]
|
||||
mov rx, r12
|
||||
#undef rx
|
||||
#endif
|
||||
/* FIFO溢出 */
|
||||
__OVERFLOW cmp r2, #MCUCFG_PENDSVFIFO_DEPTH
|
||||
bhi __OVER
|
||||
/* FIFO装载 */
|
||||
lsls r2, r2, #2
|
||||
str r0, [r1, r2]
|
||||
|
||||
__OVER bx lr
|
||||
|
||||
ALIGN
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* IAR Compiler
|
||||
* GNU Compiler
|
||||
* Arm Compiler 6.6 LTM / above 6.10.1 (armclang)
|
||||
*/
|
||||
#elif ((defined ( __GNUC__ )) \
|
||||
|| (defined ( __ICCARM__ )) \
|
||||
|| (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)))
|
||||
|
||||
#if !defined (__ICCARM__)
|
||||
s_u8_t sPendSV_Handler(void);
|
||||
extern s_taskctrl_tsp s_task_news;
|
||||
#else
|
||||
#include "os_handler.c"
|
||||
#endif
|
||||
|
||||
/* PendSV软中断 */
|
||||
void OS_PendSV_Handler(void)
|
||||
{
|
||||
#if defined (__GNUC__)
|
||||
__ASM volatile(".syntax unified");
|
||||
#endif
|
||||
#if !defined (__ICCARM__)
|
||||
__ASM volatile(".THUMB");
|
||||
#endif
|
||||
__ASM volatile(
|
||||
"push {lr} \n"
|
||||
"bl sPendSV_Handler \n"
|
||||
/* 直接返回吗?*/
|
||||
#if ((__CMX_ISA == 6) || defined (__ICCARM__))
|
||||
"cmp r0, #0 \n"
|
||||
"beq __RETURN \n"
|
||||
#else
|
||||
"cbz r0, __RETURN \n"
|
||||
#endif
|
||||
/* 保护现场吗?*/
|
||||
"ldr r1, =s_task_current \n"
|
||||
"subs r0, #1 \n"
|
||||
#if ((__CMX_ISA == 6) || defined (__ICCARM__))
|
||||
"cmp r0, #0 \n"
|
||||
"beq __RESTORE \n"
|
||||
#else
|
||||
"cbz r0, __RESTORE \n"
|
||||
#endif
|
||||
"mrs r0, psp \n"
|
||||
"isb \n"
|
||||
/* 任务PC监控 */
|
||||
#if (SYSCFG_TASKPC_MONITOR == 1)
|
||||
"ldr r2, =s_taskmgr_sign \n"
|
||||
"ldrb r2, [r2] \n"
|
||||
#if ((__CMX_ISA == 6) || defined (__ICCARM__))
|
||||
"cmp r2, #0 \n"
|
||||
"beq __PROTECTING \n"
|
||||
#else
|
||||
"cbz r2, __PROTECTING \n"
|
||||
#endif
|
||||
"ldr r2, [r0,#24] \n"
|
||||
"ldr r3, =s_pc \n"
|
||||
"str r2, [r3] \n"
|
||||
#endif
|
||||
/* 保护现场 */
|
||||
"__PROTECTING: \n"
|
||||
#if (MCUCFG_ASPEN_LSPEN == 1)
|
||||
"vstmdb r0!, {s16-s31} \n"
|
||||
#endif
|
||||
#if (__CMX_ISA == 6)
|
||||
"subs r0, #32 \n"
|
||||
"ldr r2, [r1] \n"
|
||||
"str r0, [r2] \n"
|
||||
"stmia r0!, {r4-r7} \n"
|
||||
"mov r4, r8 \n"
|
||||
"mov r5, r9 \n"
|
||||
"mov r6, r10 \n"
|
||||
"mov r7, r11 \n"
|
||||
"stmia r0!, {r4-r7} \n"
|
||||
#else
|
||||
"stmdb r0!, {r4-r11} \n"
|
||||
"ldr r2, [r1] \n"
|
||||
"str r0, [r2] \n"
|
||||
#endif
|
||||
"dsb \n"
|
||||
/* 恢复现场 */
|
||||
"__RESTORE: ldr r3, =s_task_news \n"
|
||||
"ldr r3, [r3] \n"
|
||||
"str r3, [r1] \n"
|
||||
"ldr r0, [r3] \n"
|
||||
#if (__CMX_ISA == 6)
|
||||
"adds r0, #16 \n"
|
||||
"ldmia r0!, {r4-r7} \n"
|
||||
"mov r11, r7 \n"
|
||||
"mov r10, r6 \n"
|
||||
"mov r9, r5 \n"
|
||||
"mov r8, r4 \n"
|
||||
"mov r1, r0 \n"
|
||||
"subs r1, #32 \n"
|
||||
"ldmia r1!, {r4-r7} \n"
|
||||
#else
|
||||
"ldmia r0!, {r4-r11} \n"
|
||||
#endif
|
||||
#if (MCUCFG_ASPEN_LSPEN == 1)
|
||||
"vldmia r0!, {s16-s31} \n"
|
||||
#endif
|
||||
"msr psp, r0 \n"
|
||||
/* 返回 */
|
||||
"__RETURN: pop {pc}"
|
||||
);
|
||||
#if !defined (__ICCARM__)
|
||||
__ASM volatile(".ALIGN");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* 中断FIFO服务装载器 */
|
||||
#if (MCUCFG_PENDSVFIFO_DEPTH > 0)
|
||||
void mPendSV_FIFOLoader(void *sv)
|
||||
{
|
||||
#if defined (__GNUC__)
|
||||
__ASM volatile(".syntax unified");
|
||||
#endif
|
||||
#if !defined (__ICCARM__)
|
||||
__ASM volatile(".THUMB");
|
||||
#endif
|
||||
__ASM volatile(
|
||||
/* FIFO选择 */
|
||||
"ldr r2, =m_fifo_lock \n"
|
||||
"ldrb r3, [r2] \n"
|
||||
#if ((__CMX_ISA == 6) || defined (__ICCARM__))
|
||||
"cmp r3, #0 \n"
|
||||
"beq __FIFO1 \n"
|
||||
#else
|
||||
"cbz r3, __FIFO1 \n"
|
||||
#endif
|
||||
"__FIFO0: ldr r1, =mPendSV_FIFO_0 \n"
|
||||
"b __COUNT \n"
|
||||
"__FIFO1: ldr r1, =mPendSV_FIFO_1 \n"
|
||||
/* FIFO计数 */
|
||||
"__COUNT: \n" /* 0、关闭总中断 */
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX == 0)
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX0 == 1)
|
||||
"mrs r3, primask \n" // cycles:4
|
||||
#endif
|
||||
"cpsid i \n" // cycles:1
|
||||
"ldr r2, [r1] \n" // cycles:2
|
||||
"adds r2, #1 \n" // cycles:1
|
||||
"str r2, [r1] \n" // cycles:2
|
||||
#if (MCUCFG_PENDSVFIFO_MUTEX0 == 1)
|
||||
"msr primask, r3 \n" // cycles:4
|
||||
#else
|
||||
"cpsie i \n" // cycles:1
|
||||
#endif
|
||||
|
||||
/* 1、互斥访问指令 */
|
||||
#elif (MCUCFG_PENDSVFIFO_MUTEX == 1)
|
||||
"__LOOP: ldrex r2, [r1] \n"
|
||||
"adds r2, #1 \n"
|
||||
"strex r3, r2, [r1] \n"
|
||||
"cmp r3, #0 \n"
|
||||
"bne __LOOP \n"
|
||||
|
||||
/* 2、互斥访问机制 */
|
||||
#elif (MCUCFG_PENDSVFIFO_MUTEX == 2)
|
||||
#define rx mPendSV_FIFO_rx
|
||||
"mov r12, "sDefStr(rx \n)
|
||||
"movs r2, #1 \n"
|
||||
"ldrh r3, [r1, #2] \n"
|
||||
"strh r2, [r1, #2] \n"
|
||||
"dmb \n"
|
||||
"__LOOP: mov "sDefStr(rx)", r1 \n"
|
||||
"ldrh r2, "sDefStr([rx] \n)
|
||||
"adds r2, #1 \n"
|
||||
"strh r2, "sDefStr([rx] \n)
|
||||
"cmp "sDefStr(rx)", r1 \n"
|
||||
"bne __LOOP \n"
|
||||
|
||||
"cmp r3, #0 \n"
|
||||
"beq __RESrx \n"
|
||||
"ldr "sDefStr(rx)", =mPendSV_FIFO_X \n"
|
||||
"b __OVERFLOW \n"
|
||||
"__RESrx: strh r3, [r1, #2] \n"
|
||||
"mov "sDefStr(rx)", r12 \n"
|
||||
#undef rx
|
||||
#endif
|
||||
/* FIFO溢出 */
|
||||
"__OVERFLOW: cmp r2, #"sDefStr(MCUCFG_PENDSVFIFO_DEPTH \n)
|
||||
"bhi __OVER \n"
|
||||
/* FIFO装载 */
|
||||
"lsls r2, r2, #2 \n"
|
||||
"str r0, [r1, r2] \n"
|
||||
|
||||
"__OVER: bx lr"
|
||||
);
|
||||
#if !defined (__ICCARM__)
|
||||
__ASM volatile(".ALIGN");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Unknown Compiler
|
||||
*/
|
||||
#else
|
||||
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user