From f9b632d52d07d668405909bdc8a6201cf6891e88 Mon Sep 17 00:00:00 2001 From: GuEe-GUI <2991707448@qq.com> Date: Thu, 6 Jun 2024 13:34:06 +0800 Subject: [PATCH] [DM/MISC] Add error no for ptr When the driver request a API gets RT_NULL which return value is ptr, they could not know why get a RT_NULL. some API return RT_NULL, is not error internal maybe, it just not supported for this platform, but the driver still could work ok, the API can return (RT_NULL + -RT_EEMPTY) to driver. on the other hand, the driver can do more behaviors by error no. When the API return the -RT_EBUSY, driver can wait for a moment and retry. When the API return the -RT_ENOSYS, driver can try the next mode or request's name. Signed-off-by: GuEe-GUI --- components/drivers/include/drivers/misc.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/drivers/include/drivers/misc.h b/components/drivers/include/drivers/misc.h index 1e017d8be2..9579773e9a 100644 --- a/components/drivers/include/drivers/misc.h +++ b/components/drivers/include/drivers/misc.h @@ -54,6 +54,12 @@ #define rt_offsetof(s, field) ((rt_size_t)&((s *)0)->field) +#define rt_err_ptr(err) ((void *)(rt_base_t)(err)) +#define rt_ptr_err(ptr) ((rt_err_t)(rt_base_t)(ptr)) +#define rt_is_err_value(ptr) ((rt_ubase_t)(void *)(ptr) >= (rt_ubase_t)-4095) +#define rt_is_err(ptr) rt_is_err_value(ptr) +#define rt_is_err_or_null(ptr) (!(ptr) || rt_is_err_value((rt_ubase_t)(ptr))) + #define rt_upper_32_bits(n) ((rt_uint32_t)(((n) >> 16) >> 16)) #define rt_lower_32_bits(n) ((rt_uint32_t)((n) & 0xffffffff)) #define rt_upper_16_bits(n) ((rt_uint16_t)((n) >> 16))