summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorGuEe-GUI <[email protected]>2024-06-06 13:34:06 +0800
committerRbb666 <[email protected]>2024-09-11 14:34:13 +0800
commitf9b632d52d07d668405909bdc8a6201cf6891e88 (patch)
treed7d09bec50deb94f106201a933cc837aede4972b /components/drivers
parent0df9a9f0cc487958aa79cbec9694276c0653631a (diff)
[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 <[email protected]>
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/include/drivers/misc.h6
1 files changed, 6 insertions, 0 deletions
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))