net/can: can protocol uses a separate buffer to cache can data

To avoid memory waste, can add support for using an independent iob buffer
The IP protocol often configures CONFIG_IOB_BUFSIZE to be relatively large,
such as 512, for higher throughput. However, the buffer required by CAN is
fixed at a length of 16 or 64. If the system's IOB is directly used,
a lot of memory will be wasted.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-04-15 22:36:17 +08:00
committed by Alan C. Assis
parent 48e9b4fc7a
commit 3e025b5a03
12 changed files with 228 additions and 13 deletions
+43
View File
@@ -44,6 +44,7 @@
#include <nuttx/config.h>
#include <nuttx/can.h>
#include <nuttx/mm/iob.h>
#include <nuttx/net/netconfig.h>
#include <stdint.h>
@@ -126,6 +127,48 @@ extern "C"
struct net_driver_s; /* Forward reference */
int can_input(FAR struct net_driver_s *dev);
/****************************************************************************
* Name: can_iob_timedalloc
*
* Description:
* Allocate an CAN I/O buffer from the CAN buffer pool.
*
****************************************************************************/
#if CONFIG_NET_CAN_NBUFFERS > 0
FAR struct iob_s *can_iob_timedalloc(unsigned int timeout);
#else
#define can_iob_timedalloc(t) net_iobtimedalloc(true, t)
#endif
/****************************************************************************
* Name: can_iob_clone
*
* Description:
* Clone an I/O buffer from the CAN buffer pool.
*
****************************************************************************/
#if CONFIG_NET_CAN_NBUFFERS > 0
FAR struct iob_s *can_iob_clone(FAR struct net_driver_s *dev);
#else
#define can_iob_clone(d) netdev_iob_clone(d, false)
#endif
/****************************************************************************
* Name: can_iob_navail
*
* Description:
* Return the number of available CAN I/O buffers.
*
****************************************************************************/
#if CONFIG_NET_CAN_NBUFFERS > 0
int can_iob_navail(void);
#else
#define can_iob_navail() iob_navail(false)
#endif
#undef EXTERN
#ifdef __cplusplus
}