未验证 提交 697bf139 编写于 作者: A a1012112796 提交者: GitHub

[enhancement] Add string information for error (#3186)

* [enhancement]Add string information for error

* Update src/kservice.c

* Update src/kservice.c
Co-authored-by: mysterywolf's avatarMan, Jianting (Meco) <920369182@qq.com>

* remove %m
Signed-off-by: Na1012112796 <1012112796@qq.com>
Co-authored-by: mysterywolf's avatarMeco Man <920369182@qq.com>
上级 5b00165f
......@@ -229,15 +229,14 @@ long list_thread(void)
thread->error);
#else
ptr = (rt_uint8_t *)thread->stack_addr;
while (*ptr == '#')ptr ++;
rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n",
while (*ptr == '#') ptr ++;
rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %s\n",
thread->stack_size + ((rt_ubase_t)thread->stack_addr - (rt_ubase_t)thread->sp),
thread->stack_size,
(thread->stack_size - ((rt_ubase_t) ptr - (rt_ubase_t) thread->stack_addr)) * 100
/ thread->stack_size,
thread->remaining_tick,
thread->error);
rt_strerror(thread->error));
#endif
}
}
......
......@@ -592,6 +592,7 @@ rt_device_t rt_console_get_device(void);
rt_err_t rt_get_errno(void);
void rt_set_errno(rt_err_t no);
int *_rt_errno(void);
const char *rt_strerror(rt_err_t error);
#if !defined(RT_USING_NEWLIB) && !defined(_WIN32)
#ifndef errno
#define errno *_rt_errno()
......
......@@ -53,6 +53,40 @@ RT_WEAK void rt_hw_us_delay(rt_uint32_t us)
"Please consider implementing rt_hw_us_delay() in another file."));
}
static const char* rt_errno_strs[] =
{
"OK",
"ERROR",
"ETIMOUT",
"ERSFULL",
"ERSEPTY",
"ENOMEM",
"ENOSYS",
"EBUSY",
"EIO",
"EINTRPT",
"EINVAL",
"EUNKNOW"
};
/**
* This function return a pointer to a string that contains the
* message of error.
*
* @param error the errorno code
* @return a point to error message string
*/
const char *rt_strerror(rt_err_t error)
{
if (error < 0)
error = -error;
return (error > RT_EINVAL + 1) ?
rt_errno_strs[RT_EINVAL + 1] :
rt_errno_strs[error];
}
RTM_EXPORT(rt_strerror);
/**
* This function gets the global errno for the current thread.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册