zhhyu7 opened a new pull request, #17667:
URL: https://github.com/apache/nuttx/pull/17667
## Summary
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.
## Impact
net/can and can device driver
## Testing
qemu:local
test code:
```
#include <nuttx/can/can.h>
#include <nuttx/config.h>
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#define CAN_RCV_BUF_MAX 1024
void dump_can_msg(struct can_msg_s* msg, bool tx)
{
if(tx)
printf("---> TX: ");
else
printf("<--- RX: ");
printf("ID 0x%02x, Data ", msg->cm_hdr.ch_id);
for(int i=0;i<can_dlc2bytes(msg->cm_hdr.ch_dlc);i++)
{
printf(" 0x%02x ", msg->cm_data[i]);
}
printf("\n");
}
void build_tx_msg(struct can_msg_s* msg)
{
static uint32_t echo_cnt = 0x120;
memset(msg, 0, sizeof(struct can_msg_s));
msg->cm_hdr.ch_id = 0x123;
msg->cm_hdr.ch_dlc = 8;
msg->cm_data[0] = echo_cnt & 0xff;
msg->cm_data[1] = (echo_cnt >> 8) & 0xff;
echo_cnt++;
}
int main(int argc, FAR char *argv[])
{
printf("Hello, World!!\n");
char buf[CAN_RCV_BUF_MAX];
int nbytes;
int ret;
struct can_msg_s* rxmsg;
struct can_msg_s txmsg;
int fd = open("/dev/can0", O_RDWR | O_CLOEXEC);
if (fd < 0) {
printf("open failed\n");
return -1;
}
while(1)
{
sleep(1);
build_tx_msg(&txmsg);
dump_can_msg(&txmsg, true);
ret = write(fd, &txmsg, sizeof(struct can_msg_s));
if(ret < 0)
{
printf("write failed\n");
return -1;
}
nbytes = read(fd, buf, CAN_RCV_BUF_MAX);
if(nbytes < 0)
{
printf("read failed\n");
return -1;
}
rxmsg = (struct can_msg_s*)buf;
dump_can_msg(rxmsg, false);
}
close(fd);
return 0;
}
```
test log:
```
NuttShell (NSH) NuttX-12.11.0
vela> hello
Hello, World!!
---> TX: ID 0x123, Data 0x20 0x01 0x00 0x00 0x00 0x00 0x00 0x00
<--- RX: ID 0x07, Data 0x20 0x01 0x00 0x00
...
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]