/**************************************************************************//**
 * @item     CosyOS-III Port
 * @file     port_x32.h
 * @brief    32 bits Micro-Controller Public Port File
 * @author   迟凯峰
 * @version  v3.0.0
 * @date     2026.07.21
 ******************************************************************************/

#ifndef __PORT_X32_H
#define __PORT_X32_H

/* INCLUDE */
#include "syscfg.h"
#include "os_def.h"
#include <stdbool.h>


/* LAJI */
#define _SYS_REG_
#define _SYS_MEM_
#define _OBJ_MEM_
#define _RTC_MEM_
#define _QUE_MEM_
#define _CODE_MEM_
#define _CONST_MEM_
#define _STACK_MEM_
#define _XDATA_MEM_
#define _DEBUG_MEM_
#define _STATIC_MEM_
#define _MALLOC_MEM_


/* Typedef */
#define m_boolvoid_tf
typedef char  s_s8_t;
typedef short s_s16_t;
typedef int   s_s32_t;
typedef unsigned char  s_u8_t;
typedef unsigned short s_u16_t;
typedef unsigned int   s_u32_t;
typedef bool     m_bit_t;
typedef s_u32_t  m_sp_t;
typedef s_u32_t  m_pc_t;
typedef s_u32_t  m_tick_t;
typedef s_u32_t  m_group_t;
typedef s_u32_t  m_fetion_t;
typedef s_u32_t  m_tqcount_t;
typedef s_u32_t  m_rtccount_t;
typedef s_u32_t  m_stacklen_t;
typedef s_u32_t  m_stacksize_t;


/* CONST & ATTRIBUTE */
#define MCUCFG_PCLEN        4
#define MCUCFG_TASK_ATTRIBUTE
#define MCUCFG_OSIT_ATTRIBUTE
#define MCUCFG_SYSTICK_ATTRIBUTE
#define MCUCFG_TERNARY_MASK


/* 中断FIFO服务-声明 */
#if (SYSCFG_PENDSVFIFO_DEPTH > 0)
extern  bool     volatile  m_fifo_lock;
extern  s_u32_t  mPendSV_FIFO_DepthMAX;
extern  s_u16_t  mPendSV_FIFO_CountMAX;
extern  void    *mPendSV_FIFO_0[SYSCFG_PENDSVFIFO_DEPTH + 1];
extern  void    *mPendSV_FIFO_1[SYSCFG_PENDSVFIFO_DEPTH + 1];
extern  void     mPendSV_FIFOLoader (void *sv);
extern  void     mPendSV_FIFOHandler(void);
#endif

/* 中断FIFO服务-装载 */
#define mPendSV_FIFOLoad() \
do{ \
	mPendSV_FIFOLoader(&u_psv); \
	mPendSV_Set(); \
}while(false)

/* 中断FIFO服务-处理 */
#define mPendSV_FIFOHandle() \
	if(mPendSV_FIFO_0[0]) mPendSV_FIFOHandler()


/* 事件标志组-中断中写多标志位 */
#define miWriteFlagBits() \
	if(!u_psv.value){ \
		do{}while(false)


/* 内核锁 */
#define mSysIRQ_Disable() __mu_disable_sysirq()
#define mSysIRQ_Enable()  __mu_enable_sysirq()


#endif
