diff --git a/components/drivers/include/ipc/ringblk_buf.h b/components/drivers/include/ipc/ringblk_buf.h index 653fa2a60b..94fc2cfff3 100644 --- a/components/drivers/include/ipc/ringblk_buf.h +++ b/components/drivers/include/ipc/ringblk_buf.h @@ -84,6 +84,8 @@ rt_size_t rt_rbb_get_buf_size(rt_rbb_t rbb); rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size); void rt_rbb_blk_put(rt_rbb_blk_t block); rt_rbb_blk_t rt_rbb_blk_get(rt_rbb_t rbb); +rt_size_t rt_rbb_blk_size(rt_rbb_blk_t block); +rt_uint8_t *rt_rbb_blk_buf(rt_rbb_blk_t block); void rt_rbb_blk_free(rt_rbb_t rbb, rt_rbb_blk_t block); /* rbb block queue API */ diff --git a/components/drivers/src/ringblk_buf.c b/components/drivers/src/ringblk_buf.c index 1a74bf1d24..74ced674fe 100644 --- a/components/drivers/src/ringblk_buf.c +++ b/components/drivers/src/ringblk_buf.c @@ -18,8 +18,10 @@ * @param rbb ring block buffer object * @param buf buffer * @param buf_size buffer size - * @param block_set - * @param blk_max_num + * @param block_set block set + * @param blk_max_num max block number + * + * @note When your application need align access, please make the buffer address is aligned. */ void rt_rbb_init(rt_rbb_t rbb, rt_uint8_t *buf, rt_size_t buf_size, rt_rbb_blk_t block_set, rt_size_t blk_max_num) { @@ -123,6 +125,8 @@ static rt_rbb_blk_t find_empty_blk_in_set(rt_rbb_t rbb) * @param rbb ring block buffer object * @param blk_size block size * + * @note When your application need align access, please make the blk_szie is aligned. + * * @return != NULL: allocated block * NULL: allocate failed */ @@ -133,7 +137,7 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size) rt_rbb_blk_t head, tail, new = NULL; RT_ASSERT(rbb); - RT_ASSERT(blk_size < 1L << 24); + RT_ASSERT(blk_size < (1L << 24)); level = rt_hw_interrupt_disable(); @@ -277,6 +281,36 @@ __exit: } RTM_EXPORT(rt_rbb_blk_get); +/** + * return the block size + * + * @param block the block + * + * @return block size + */ +rt_size_t rt_rbb_blk_size(rt_rbb_blk_t block) +{ + RT_ASSERT(block); + + return block->size; +} +RTM_EXPORT(rt_rbb_blk_size); + +/** + * return the block buffer + * + * @param block the block + * + * @return block buffer + */ +rt_uint8_t *rt_rbb_blk_buf(rt_rbb_blk_t block) +{ + RT_ASSERT(block); + + return block->buf; +} +RTM_EXPORT(rt_rbb_blk_buf); + /** * free the block *