mirror of
https://gitee.com/cosyos/cosyos.git
synced 2026-10-06 04:59:34 +08:00
256 lines
6.6 KiB
C
256 lines
6.6 KiB
C
/**************************************************************************//**
|
|
* @item CosyOS-III Kernel
|
|
* @file os_debug.c
|
|
* @brief DEBUG接口
|
|
* @details DEBUG接口,串口发送和接收解析。
|
|
* @author 迟凯峰
|
|
* @version v3.1.3
|
|
* @date 2026.09.14
|
|
******************************************************************************/
|
|
|
|
#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_(char const *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 len s_debug_recvlen
|
|
s_u8_t i;
|
|
s_u16_t temp;
|
|
char *p = s_debug_recvptr;
|
|
|
|
if(s_memcmp(p + len - 2, "\r\n", 2)) goto __ACK_ERR;
|
|
p[len - 2] = '\0';
|
|
while(*p == ' ') p++; // 忽略空格
|
|
if((*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z')){
|
|
if(!s_memcmp(p, "exit", 4)){
|
|
p += 4;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
if(*p == '\0'){
|
|
s_taskmgr_sign = false;
|
|
goto __ACK_OK;
|
|
}
|
|
}
|
|
else if(!s_memcmp(p, "taskmgr", 7)){
|
|
p += 7;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
if(*p == '\0'){
|
|
if(s_taskmgr_sign) goto __ACK_OK;
|
|
s_taskmgr_sign = true;
|
|
s_taskmgr_upspeed = 0;
|
|
s_timqry_handle[OS_TMID_TASKMGR]->timer = s_timqry_handle[OS_TMID_TASKMGR]->reload;
|
|
goto __ACK_OK;
|
|
}
|
|
else if(!s_memcmp(p, "/s=", 3)){
|
|
p += 3;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
for(i = 0; i < 5; i++){
|
|
if(p[i] >= '0' && p[i] <= '9');
|
|
else break;
|
|
}
|
|
if(i >= 2 && p[i] == '\0'){
|
|
temp = _atoi_(p);
|
|
if(temp >= 50 && temp <= 5000){
|
|
s_timqry_handle[OS_TMID_TASKMGR]->reload = (temp * 1000UL) / SYSCFG_SYSTICK_CYCLE;
|
|
goto __ACK_OK;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if(!s_memcmp(p, "resume ", 7)){
|
|
p += 7;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
s_debug_cmd.cmd = OS_SVID_RESUMETASK;
|
|
s_strcpy(s_debug_cmd.name, p);
|
|
return;
|
|
}
|
|
else if(!s_memcmp(p, "suspend ", 8)){
|
|
p += 8;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
s_debug_cmd.cmd = OS_SVID_SUSPENDTASK;
|
|
s_strcpy(s_debug_cmd.name, p);
|
|
return;
|
|
}
|
|
else if(!s_memcmp(p, "delete ", 7)){
|
|
p += 7;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
s_debug_cmd.cmd = OS_SVID_DELETETASK;
|
|
s_strcpy(s_debug_cmd.name, p);
|
|
return;
|
|
}
|
|
else if(!s_memcmp(p, "clrblk ", 7)){
|
|
p += 7;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
s_debug_cmd.cmd = OS_SVID_CLEARBLOCK;
|
|
s_strcpy(s_debug_cmd.name, p);
|
|
return;
|
|
}
|
|
else if(!s_memcmp(p, "reset ", 6)){
|
|
p += 6;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
for(i = 0; i < 255; i++){
|
|
if(p[i] == ',') break;
|
|
s_debug_cmd.name[i] = p[i];
|
|
}
|
|
s_debug_cmd.name[i] = '\0';
|
|
p += i + 1;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
for(i = 0; i < 2; i++){
|
|
if(p[i] >= '0' && p[i] <= '9');
|
|
else break;
|
|
}
|
|
if(i >= 1 && p[i] == '\0'){
|
|
temp = _atoi_(p);
|
|
if(temp == OS_STATUS_READY || temp == OS_STATUS_BLOCKED || temp == OS_STATUS_SUSPENDED){
|
|
s_debug_cmd.cmd = OS_SVID_RESETTASK;
|
|
s_debug_cmd.rand = temp;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
else if(!s_memcmp(p, "setpri ", 7)){
|
|
p += 7;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
for(i = 0; i < 255; i++){
|
|
if(p[i] == ',') break;
|
|
s_debug_cmd.name[i] = p[i];
|
|
}
|
|
s_debug_cmd.name[i] = '\0';
|
|
p += i + 1;
|
|
while(*p == ' ') p++; // 忽略空格
|
|
for(i = 0; i < 4; i++){
|
|
if(p[i] >= '0' && p[i] <= '9');
|
|
else break;
|
|
}
|
|
if(i >= 1 && p[i] == '\0'){
|
|
temp = _atoi_(p);
|
|
if(temp < SYSCFG_TASKPRIORITY){
|
|
s_debug_cmd.cmd = OS_SVID_SETTASKPRI;
|
|
s_debug_cmd.rand = temp;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
__ACK_ERR:
|
|
s_debug_sendtype |= OS_DEBUG_SEND_CMDLINE;
|
|
s_strcpy(s_cmdline_sendbuff, "ACK:error\r\n");
|
|
#if (SYSCFG_DEBUG_SENDLEN == __ENABLED__)
|
|
s_cmdline_sendlen = 4 + 5 + 2;
|
|
#endif
|
|
return;
|
|
|
|
__ACK_OK:
|
|
s_debug_sendtype |= OS_DEBUG_SEND_CMDLINE;
|
|
s_strcpy(s_cmdline_sendbuff, "ACK:ok\r\n");
|
|
#if (SYSCFG_DEBUG_SENDLEN == __ENABLED__)
|
|
s_cmdline_sendlen = 4 + 2 + 2;
|
|
#endif
|
|
|
|
#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"
|
|
#elif (SYSCFG_DEBUG_ENCODING == 0)
|
|
#define _taskname "系统调试器"
|
|
#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_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
|
|
}
|
|
else 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
|
|
}
|
|
uSuspendTasking();
|
|
}
|
|
}
|
|
#undef _taskname
|
|
|
|
#endif
|