重命名 Demo 为 Demo-Build

This commit is contained in:
零中断延迟的RTOS
2025-10-20 08:48:41 +00:00
committed by Gitee
parent ab148c623e
commit 8807da5be0
18 changed files with 0 additions and 0 deletions
View File
+171
View File
@@ -0,0 +1,171 @@
/**************************************************************************//**
* @item CosyOS-III Demo
* @file demo_debug.c
* @brief 例程-DEBUG for STC32G
* @author 迟凯峰
* @version V1.0.1
* @date 2025.08.08
******************************************************************************/
#if 0 /* 编译开关 */
#include "CosyOS.H"
#if (SYSCFG_DEBUGGING == __ENABLED__)
/*
* 用户定义
*/
/*-------------------------------------------------------------*
| DEBUG_MODE | 输出(UART SEND)| 输入(UART RECV)| 推荐等级 |
|------------+------------------+------------------+----------|
| 0 | printf(中断) | 串口接收中断 | * |
|------------+------------------+------------------+----------|
| 1 | 串口发送中断 | 串口接收中断 | *** |
|------------+------------------+------------------+----------|
| 2 | DMA串口发送中断 | DMA串口接收中断 | ***** |
*-------------------------------------------------------------*/
#define DEBUG_MODE 0
/* DEBUG RECV 缓存SIZE */
#define DEBUG_RECV_BUFF 32
////////////////////////////////////////////////////////////////////////////////
// 1、例程中使用了UART1做为DEBUG专用串口,用户如需更换其它串口请自行调整。
// 2、下方的DEBUG配置函数 Debug_Config(),不能够取代基本的串口初始化工作,
// 用户在main函数中,在调用该函数之前,需先行初始化串口。
////////////////////////////////////////////////////////////////////////////////
static char xdata u_debug_recv_buff[DEBUG_RECV_BUFF];
static char xdata *u_debug_recv_p = u_debug_recv_buff;
#if (DEBUG_MODE == 0)
#include <stdio.h>
#include "STC32G_UART.h"
#elif (DEBUG_MODE == 1)
static char xdata *u_debug_send_p;
#elif (DEBUG_MODE == 2)
static char xdata DMA_UR1R_SBUF;
#endif
void Debug_Config(void)
{
#if (DEBUG_MODE == 0)
if(~PSH && ~PS){
PS = 1;
}
REN = 1;
ES = 1;
#elif (DEBUG_MODE == 1)
if(~PSH && ~PS){
PS = 1;
}
REN = 1;
ES = 1;
#elif (DEBUG_MODE == 2)
REN = 1;
ES = 0;
DMA_UR1T_CFG |= 0x80 | 0x04 | 0x01;
DMA_UR1T_CR |= 0x80;
DMA_UR1R_RXAL = (unsigned int)&DMA_UR1R_SBUF;
DMA_UR1R_RXAH = (unsigned int)&DMA_UR1R_SBUF >> 8;
DMA_UR1R_AMT = 0;
DMA_UR1R_AMTH = 0;
DMA_UR1R_CFG |= 0x80 | 0x04 | 0x01;
DMA_UR1R_CR |= 0x80 | 0x20 | 0x01;
#endif
}
#if (SYSCFG_DEBUG_SENDLEN == __DISABLED__)
void debug_hook(char _XDATA_MEM_ *p)
#else
void debug_hook(char _XDATA_MEM_ *p, s_u16_t len)
#endif
{
#if (DEBUG_MODE == 0)
printf("%s", p);
#elif (DEBUG_MODE == 1)
u_debug_send_p = p;
TI = 1;
#elif (DEBUG_MODE == 2)
len--;
DMA_UR1T_TXAL = (unsigned int)p;
DMA_UR1T_TXAH = (unsigned int)p >> 8;
DMA_UR1T_AMT = len;
DMA_UR1T_AMTH = len >> 8;
DMA_UR1T_CR |= 0x40;
#endif
}
#if (DEBUG_MODE <= 1)
void UART1_Isr(void) interrupt 4
{
if(TI){
TI = 0;
#if (DEBUG_MODE == 0)
if(COM1.TX_send != COM1.TX_write){
SBUF = TX1_Buffer[COM1.TX_send];
if(++COM1.TX_send >= COM_TX1_Lenth){
COM1.TX_send = 0;
}
}
else{
COM1.B_TX_busy = 0;
xDebugSend_Complete();
}
#elif (DEBUG_MODE == 1)
if(*u_debug_send_p){
SBUF = *u_debug_send_p++;
}
else{
xDebugSend_Complete();
}
#endif
}
if(RI){
RI = 0;
if(u_debug_recv_p - u_debug_recv_buff < DEBUG_RECV_BUFF - 1){
*u_debug_recv_p++ = SBUF;
if(SBUF == '\n'){
xDebugRecv_Handler(u_debug_recv_buff, u_debug_recv_p - u_debug_recv_buff);
u_debug_recv_p = u_debug_recv_buff;
}
}
else{
u_debug_recv_p = u_debug_recv_buff;
}
}
}
#elif (DEBUG_MODE == 2)
void DMA_UR1T_Isr(void) interrupt 50
{
DMA_UR1T_STA &=~0x01;
xDebugSend_Complete();
}
void DMA_UR1R_Isr(void) interrupt 51
{
DMA_UR1R_STA &=~0x01;
if(u_debug_recv_p - u_debug_recv_buff < DEBUG_RECV_BUFF - 1){
*u_debug_recv_p++ = DMA_UR1R_SBUF;
if(DMA_UR1R_SBUF == '\n'){
xDebugRecv_Handler(u_debug_recv_buff, u_debug_recv_p - u_debug_recv_buff);
u_debug_recv_p = u_debug_recv_buff;
}
}
else{
u_debug_recv_p = u_debug_recv_buff;
}
DMA_UR1R_CR |= 0x20 | 0x01;
}
#endif
#endif
#endif
+36
View File
@@ -0,0 +1,36 @@
/**************************************************************************//**
* @item CosyOS-III Demo
* @file demo_int.c
* @brief 例程-系统中断 for STC32G
* @author 迟凯峰
* @version V1.0.2
* @date 2025.08.08
******************************************************************************/
#if 0 /* 编译开关 */
#include "CosyOS.H" // 用户的各个c文件中应包含此文件
/**
* \brief 系统中断配置
* \note CosyOS for 80251,SysTick中断 固定采用 定时器0中断。
* \note 在 mcucfg_80251.h 中,PendSV中断 配置为 INT0中断。
*/
/**
* \brief TIM0_Isr 由CosyOS托管,原函数应屏蔽掉。
*//*
void TIM0_Isr(void) interrupt 1
{
}*/
/**
* \brief INT0_Isr 由CosyOS托管,原函数应屏蔽掉。
*//*
void INT0_Isr(void) interrupt 0
{
}*/
#endif
+48
View File
@@ -0,0 +1,48 @@
/**************************************************************************//**
* @item CosyOS-III Demo
* @file demo_main.c
* @brief 例程-主函数 for STC32G
* @author 迟凯峰
* @version V1.0.2
* @date 2025.08.08
******************************************************************************/
#if 0 /* 编译开关 */
#include "CosyOS.H" // 用户的各个c文件中应包含此文件
#include <stdio.h> // for printf
int main(void)
{
/* USER INIT CODE BEGIN */
/* USER INIT CODE END */
/* USER INIT PendSV中断 */// 确保该中断不会被硬件触发,优先级必须为最低级。
if(1){
IPH &=~PX0H;
PX0 = 0;
}// 在 mcucfg_80251.h 中,PendSV中断 配置为 INT0中断。
/* USER DEBUG CONFIG */// for CosyOS-Taskmgr
#if (SYSCFG_DEBUGGING == 1)
if(1){
void Debug_Config(void);
Debug_Config();
}// defined in demo_debug.c
#endif
/* USER 启动 CosyOS */// 在main函数的末尾处
if(1){
#if 1 // 建议前期调试时开启,如果CosyOS启动失败会返回错误码提示用户!
unsigned char _ecode = uStartCosyOS();
printf("CosyOS startup failed, error code: %d.\r\n", (int)_ecode);
#else
uStartCosyOS();
#endif
}
while(1);
}
#endif
+24
View File
@@ -0,0 +1,24 @@
经 CosyOS-III Cube 升级安装之后的系统构建
CosyOS-配置 / syscfg.h -> 系统配置>>标准头文件,应首先被正确定义。
而后,在 C251、A251 标签页中,可能需要添加标准头文件的包含路径。
不出意外的话,您的项目现在已经可以正常编译了。
但在未来,仍需重点关注如下内容:
1、系统配置
CosyOS-配置 / syscfg.h [Keil支持图形]
2、MCU配置
CosyOS-配置 / mcucfg_80251.h [Keil支持图形]
3、启动文件配置
CosyOS-移植 / startup_80251.s [Keil支持图形]
启动文件关乎硬件栈配置、内存零安装等重要功能,但往往却被用户忽略。
4、移植文件配置
CosyOS-移植 / port_80251s.s
其中的用户定义部分,与PendSV中断配置、用户自定义任务切换现场保护
等功能息息相关,在未来可能需要适当调整。