Skip to content

Commit

Permalink
[DM/MISC] Add error no for ptr
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
GuEe-GUI authored and Rbb666 committed Sep 11, 2024
1 parent 0df9a9f commit f9b632d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions components/drivers/include/drivers/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit f9b632d

Please sign in to comment.