mirror of
https://gitee.com/cosyos/cosyos.git
synced 2026-08-17 16:52:27 +08:00
120 lines
2.7 KiB
C
120 lines
2.7 KiB
C
/**************************************************************************//**
|
|
* @item CosyOS-III Kernel
|
|
* @file os_debug.c
|
|
* @brief DEBUG接口
|
|
* @details DEBUG接口,串口发送和接收解析。
|
|
* @author 迟凯峰
|
|
* @version V1.0.0
|
|
* @date 2025.02.08
|
|
******************************************************************************/
|
|
|
|
#include "os_var.h"
|
|
#if SYSCFG_DEBUGGING == __ENABLED__
|
|
#include "os_api.h"
|
|
#include "sv_create.h"
|
|
#include "sv_task.h"
|
|
#include "ur_api.h"
|
|
#include <string.h>
|
|
|
|
#if MCUCFG_ISA != __ARM__
|
|
/**
|
|
\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;
|
|
}
|
|
}
|
|
#else
|
|
#define _atoi_ atoi
|
|
#endif
|
|
|
|
/**
|
|
\brief 接收解析
|
|
\details DEBUG接口,串口接收解析。
|
|
\param 无
|
|
\return 无
|
|
*/
|
|
static void _debug_recv_(void)
|
|
{
|
|
#define hptr s_debug_recvbuff
|
|
s_u16_t temp;
|
|
char strtmp[8];
|
|
char _XDATA_MEM_ *mptr = hptr;
|
|
char _XDATA_MEM_ *tptr = hptr + s_strlen(hptr) - 2;
|
|
if(!s_strcmp(tptr, "\r\n")){
|
|
if(!s_strcmp(hptr, "taskmgr\r\n")){
|
|
s_sign_taskmgr = true;
|
|
}
|
|
else if(!s_strcmp(hptr, "exit\r\n")){
|
|
s_sign_taskmgr = false;
|
|
}
|
|
else if(!s_memcmp(hptr, "taskmgr /s=", 11)){
|
|
mptr += 11;
|
|
s_memcpy(strtmp, mptr, tptr - mptr);
|
|
strtmp[tptr - mptr] = '\0';
|
|
temp = _atoi_(strtmp);
|
|
if(temp >= 50 && temp <= 5000){
|
|
mSysIRQ_Disable;
|
|
s_timqry_handle[OS_TMID_TASKMGR]->reload = (1000UL * temp) / SYSCFG_SYSTICKCYCLE;
|
|
mSysIRQ_Enable;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
uCreateTask_TimInt
|
|
(
|
|
OS_TMID_DEBUGGER, false,
|
|
Debugger, SYSCFG_TASKPRIORITY - 2, MCUCFG_STACKSIZE_DEBUGGER, 0, 0
|
|
)
|
|
{
|
|
while(true){
|
|
s_debug_recvptr[0] = '\0';
|
|
_debug_recv_();
|
|
s_debug_recvptr = s_debug_recvbuff;
|
|
uSuspendTasking;
|
|
}
|
|
}
|
|
|
|
uCreateHook_TimQry(OS_TMID_DEBUGHOOK, s_debug_sendtype, false, debug_hook)
|
|
{
|
|
if(s_debug_sendtype & OS_DEBUG_SEND_TASKMGR){
|
|
s_debug_sendtype &= ~OS_DEBUG_SEND_TASKMGR;
|
|
s_debug_sendptr = s_taskmgr_sendbuff;
|
|
}/*
|
|
else if(s_debug_sendtype & OS_DEBUG_SEND_CMDLINE){
|
|
s_debug_sendtype &= ~OS_DEBUG_SEND_CMDLINE;
|
|
s_debug_sendptr = s_cmdline_sendbuff;
|
|
}*/
|
|
SYSCFG_DEBUGSEND;
|
|
}
|
|
|
|
#endif
|