mirror of
https://gitee.com/cosyos/cosyos.git
synced 2026-03-23 13:42:29 +08:00
147
System/os_debug.c
Normal file
147
System/os_debug.c
Normal file
@@ -0,0 +1,147 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Kernel
|
||||
* @file os_debug.c
|
||||
* @brief DEBUG接口
|
||||
* @details DEBUG接口,串口发送和接收解析。
|
||||
* @author 迟凯峰
|
||||
* @version V2.3.2
|
||||
* @date 2026.03.08
|
||||
******************************************************************************/
|
||||
|
||||
#include "os_var.h"
|
||||
#if (SYSCFG_DEBUGGING == __ENABLED__)
|
||||
#include "os_api.h"
|
||||
#include "sv_com.h"
|
||||
#include "sv_create.h"
|
||||
#include "sv_task.h"
|
||||
#include "ur_api.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
\brief 字符串转整型
|
||||
\param[in] str 字符串指针
|
||||
\return 转换后的整型数据
|
||||
\note Keil C51/C251 标准库中的 atoi() 是非线程安全的,故额外定义此函数,
|
||||
专用于DEBUG接口的串口接收解析。
|
||||
*/
|
||||
static int _atoi_(const char* str)
|
||||
{
|
||||
if(str == OS_NULL || !*str){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
int a = 0;
|
||||
int k = 1;
|
||||
s_u8_t i = s_strlen(str);
|
||||
while(i--){
|
||||
if(str[i] >= '0' && str[i] <= '9'){
|
||||
a += (str[i] - '0') * k;
|
||||
k *= 10;
|
||||
}
|
||||
else if(str[i] == '+'){
|
||||
return a;
|
||||
}
|
||||
else if(str[i] == '-'){
|
||||
return -a;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
\brief 接收解析
|
||||
\details DEBUG接口,串口接收解析。
|
||||
\return 无
|
||||
*/
|
||||
void os_debug_recv(void)
|
||||
{
|
||||
#define p s_debug_recvptr
|
||||
#define len s_debug_recvlen
|
||||
p[len] = '\0';
|
||||
if(len == 9 && !s_memcmp(p, "taskmgr\r\n", 9)){
|
||||
s_taskmgr_sign = true;
|
||||
s_taskmgr_upspeed = 0;
|
||||
s_timqry_handle[OS_TMID_TASKMGR]->timer = s_timqry_handle[OS_TMID_TASKMGR]->reload;
|
||||
}
|
||||
else if(len == 6 && !s_memcmp(p, "exit\r\n", 6)){
|
||||
s_taskmgr_sign = false;
|
||||
}
|
||||
else if(len >= 15 && !s_memcmp(p, "taskmgr /s=", 11)){
|
||||
s_u8_t i;
|
||||
char *mptr = p + 11;
|
||||
for(i = 0; i < 5; i++){
|
||||
if(mptr[i] >= '0' && mptr[i] <= '9');
|
||||
else break;
|
||||
}
|
||||
if(i >= 2 && !s_memcmp(mptr + i, "\r\n", 2)){
|
||||
s_u16_t temp;
|
||||
mptr[i] = '\0';
|
||||
temp = _atoi_(mptr);
|
||||
if(temp >= 50 && temp <= 5000){
|
||||
s_timqry_handle[OS_TMID_TASKMGR]->reload = (temp * 1000UL) / SYSCFG_SYSTICK_CYCLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
#undef p
|
||||
#undef len
|
||||
}
|
||||
|
||||
/**
|
||||
\brief 系统调试器
|
||||
\details 负责系统DEBUG信息的输出,具体包括命令行和任务管理器。
|
||||
\param[in] 定时器ID OS_TMID_DEBUGGER
|
||||
\param[in] 定时查询事件 s_debug_sendtype
|
||||
\param[in] 自动重装载 false
|
||||
\param[in] 任务名称 Debugger
|
||||
\param[in] 任务优先级 SYSCFG_TASKPRIORITY - 1
|
||||
\param[in] 任务栈大小 SYSCFG_STACKSIZE_DEBUGGER
|
||||
\param[in] 安全运行时 0
|
||||
\param[in] 任务名称文本<br>
|
||||
遗产模式:"Debugger"<br>
|
||||
标准/兼容模式:[中文:"系统调试器",英文:"Debugger"]
|
||||
\return 无
|
||||
\note 定时查询任务
|
||||
*/
|
||||
#if (SYSCFG_DEBUG_LANGUAGE == 0)
|
||||
#define _taskname "Debugger"
|
||||
#else
|
||||
#define _taskname "\xCF\xB5\xCD\xB3\xB5\xF7\xCA\xD4\xC6\xF7" /*!< "系统调试器" */
|
||||
#endif
|
||||
uCreateTask_TimQry
|
||||
(
|
||||
OS_TMID_DEBUGGER, s_debug_sendtype, false,
|
||||
Debugger, SYSCFG_TASKPRIORITY - 1, SYSCFG_STACKSIZE_DEBUGGER, 0, _taskname
|
||||
)
|
||||
{
|
||||
#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
|
||||
while(true){
|
||||
if(s_debug_sendtype & OS_DEBUG_SEND_TASKMGR){
|
||||
s_debug_sendtype &= ~OS_DEBUG_SEND_TASKMGR;
|
||||
#if (SYSCFG_DEBUG_SENDLEN == __DISABLED__)
|
||||
debug_hook(s_taskmgr_sendbuff);
|
||||
#else
|
||||
debug_hook(s_taskmgr_sendbuff, s_taskmgr_sendlen);
|
||||
#endif
|
||||
}/*
|
||||
else if(s_debug_sendtype & OS_DEBUG_SEND_CMDLINE){
|
||||
s_debug_sendtype &= ~OS_DEBUG_SEND_CMDLINE;
|
||||
#if (SYSCFG_DEBUG_SENDLEN == __DISABLED__)
|
||||
debug_hook(s_cmdline_sendbuff);
|
||||
#else
|
||||
debug_hook(s_cmdline_sendbuff, s_cmdline_sendlen);
|
||||
#endif
|
||||
}*/
|
||||
uSuspendTasking();
|
||||
}
|
||||
}
|
||||
#undef _taskname
|
||||
|
||||
#endif
|
||||
72
System/os_starter.c
Normal file
72
System/os_starter.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Kernel
|
||||
* @file os_starter.c
|
||||
* @brief 任务启动器(Starter)
|
||||
* @author 迟凯峰
|
||||
* @version V2.3.2
|
||||
* @date 2026.03.08
|
||||
******************************************************************************/
|
||||
|
||||
#include "os_var.h"
|
||||
#include "os_api.h"
|
||||
#include "sv_com.h"
|
||||
#include "sv_create.h"
|
||||
#include "sv_task.h"
|
||||
#include "ur_api.h"
|
||||
|
||||
/**
|
||||
\brief 任务启动器
|
||||
\param[in] 任务名称 Starter
|
||||
\param[in] 任务优先级 SYSCFG_TASKPRIORITY - (SYSCFG_DEBUGGING ? 3 : 1)
|
||||
\param[in] 任务栈大小 SYSCFG_STACKSIZE_STARTER
|
||||
\param[in] 安全运行时 0
|
||||
\param[in] 任务名称文本<br>
|
||||
遗产模式:"Starter"<br>
|
||||
标准/兼容模式:[中文:"任务启动器",英文:"Starter"]
|
||||
\return 无
|
||||
*/
|
||||
#if (SYSCFG_DEBUG_LANGUAGE == 0)
|
||||
#define _taskname "Starter"
|
||||
#else
|
||||
#define _taskname "\xC8\xCE\xCE\xF1\xC6\xF4\xB6\xAF\xC6\xF7" /*!< "任务启动器" */
|
||||
#endif
|
||||
sCat2Str
|
||||
(
|
||||
SYSCFG_STARTERCREATE,
|
||||
CreateTask(Starter, SYSCFG_TASKPRIORITY - (SYSCFG_DEBUGGING ? 3 : 1), SYSCFG_STACKSIZE_STARTER, 0, _taskname)
|
||||
)
|
||||
{
|
||||
// uScheduleLock();
|
||||
if(true){
|
||||
uExtTask(Sysidle);
|
||||
uStartTask_Ready(Sysidle);
|
||||
}
|
||||
#if (OS_TIMINTTOTAL > 0 || OS_TIMQRYTOTAL > 0)
|
||||
if(true){
|
||||
s_u8_t i;
|
||||
#if (OS_TIMINTTOTAL > 0)
|
||||
i = OS_TIMINTTOTAL;
|
||||
while(i--){
|
||||
if(s_timint_handle[i]->hookortask){
|
||||
sStartTask_TimInt(i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if (OS_TIMQRYTOTAL > 0)
|
||||
i = OS_TIMQRYTOTAL;
|
||||
while(i--){
|
||||
if(s_timqry_handle[i]->hookortask){
|
||||
sStartTask_TimQry(i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
// uScheduleUnlock();
|
||||
if(true){
|
||||
void start_hook(void);
|
||||
start_hook();
|
||||
}
|
||||
uDeleteTasking();
|
||||
}
|
||||
#undef _taskname
|
||||
55
System/os_sysidle.c
Normal file
55
System/os_sysidle.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/**************************************************************************//**
|
||||
* @item CosyOS-III Kernel
|
||||
* @file os_sysidle.c
|
||||
* @brief 系统空闲任务(Sysidle)
|
||||
* @author 迟凯峰
|
||||
* @version V2.3.2
|
||||
* @date 2026.03.08
|
||||
******************************************************************************/
|
||||
|
||||
#include "os_var.h"
|
||||
#include "os_api.h"
|
||||
#include "sv_create.h"
|
||||
#include "sv_task.h"
|
||||
#include "ur_api.h"
|
||||
|
||||
/**
|
||||
\brief 系统空闲任务
|
||||
\param[in] 任务名称 Sysidle
|
||||
\param[in] 任务优先级 0
|
||||
\param[in] 任务栈大小 SYSCFG_STACKSIZE_SYSIDLE
|
||||
\param[in] 安全运行时 0
|
||||
\param[in] 任务名称文本<br>
|
||||
遗产模式:"Sysidle"<br>
|
||||
标准/兼容模式:[中文:"系统空闲",英文:"Sysidle"]
|
||||
\return 无
|
||||
*/
|
||||
#if (SYSCFG_DEBUG_LANGUAGE == 0)
|
||||
#define _taskname "Sysidle"
|
||||
#else
|
||||
#define _taskname "\xCF\xB5\xCD\xB3\xBF\xD5\xCF\xD0" /*!< "系统空闲" */
|
||||
#endif
|
||||
uCreateTask(Sysidle, 0, SYSCFG_STACKSIZE_SYSIDLE, 0, _taskname)
|
||||
{
|
||||
void idle_hook(void);
|
||||
while(true){
|
||||
#if (SYSCFG_SOFTRTC == __ENABLED__)
|
||||
static s_u8_t _RTC_MEM_ year = 0xFF;
|
||||
if(year != s_rtc.year){
|
||||
year = s_rtc.year;
|
||||
s_month2day = year ? ((year & 3) ? 28 : 29) : ((s_rtc.yeah & 3) ? 28 : 29);
|
||||
}
|
||||
#endif
|
||||
#if (SYSCFG_SAFERUNTIME == __ENABLED__)
|
||||
s_timeout_sign = false;
|
||||
#endif
|
||||
#if (SYSCFG_IDLEHOOK == __ENABLED__)
|
||||
idle_hook();
|
||||
#endif
|
||||
#if (SYSCFG_LOWPOWERMODE == __ENABLED__)
|
||||
mCosyOS_IDLE();
|
||||
#endif
|
||||
OS_NOP(4);
|
||||
}
|
||||
}
|
||||
#undef _taskname
|
||||
686
System/os_taskmgr.c
Normal file
686
System/os_taskmgr.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user