Skip to content

Commit

Permalink
tests/conn_can: make test support CAN FD
Browse files Browse the repository at this point in the history
Increase Shell buffer size for 64 bytes payload length of CAN FD frame.
This also implies to increase main thread stack size and especially for
native architectures.
Add two new sub-commands to test_can command:
* fdsend: to send a CAN FD frame
* fdsendrtr: to send a CAN FD RTR frame (payload length = 0).

Signed-off-by: Gilles DOFFE <[email protected]>
  • Loading branch information
gdoffe committed Apr 5, 2024
1 parent 2cef808 commit 7066104
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
6 changes: 6 additions & 0 deletions tests/sys/conn_can/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ include $(RIOTBASE)/Makefile.include
ifndef CONFIG_GNRC_PKTBUF_SIZE
CFLAGS += -DCONFIG_GNRC_PKTBUF_SIZE=4096
endif

ifneq (,$(filter native native64,$(BOARD)))
CFLAGS += -DTHREAD_STACKSIZE_MAIN=8192
else
CFLAGS += -DTHREAD_STACKSIZE_MAIN=2048
endif
41 changes: 35 additions & 6 deletions tests/sys/conn_can/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include "can/can_trx.h"

#define SHELL_BUFSIZE 512 /* Needed for CAN FD frame */

#ifdef MODULE_TJA1042
#include "tja1042.h"
tja1042_trx_t tja1042 = { .trx.driver = &tja1042_driver,
Expand Down Expand Up @@ -95,6 +97,10 @@ static void print_usage(void)
puts("test_can list");
puts("test_can send ifnum can_id [B1 [B2 [B3 [B4 [B5 [B6 [B7 [B8]]]]]]]]");
puts("test_can sendrtr ifnum can_id length(0..8)");
#ifdef MODULE_FDCAN
puts("test_can fdsend ifnum can_id [B1 [B2 [B3 [B4 [B5 [B6 [B7 ... [B64]]]]]]]]");
puts("test_can fdsendrtr ifnum can_id length(0..64)");
#endif
printf("test_can recv ifnum user_id timeout can_id1 [can_id2..can_id%d]\n",
MAX_FILTER);
puts("test_can close user_id");
Expand Down Expand Up @@ -130,7 +136,7 @@ static int _list(int argc, char **argv) {
return 0;
}

static int _send(int argc, char **argv, bool rtr)
static int _send(int argc, char **argv, bool rtr, bool is_fd)
{
if (argc < 5) {
print_usage();
Expand All @@ -150,10 +156,25 @@ static int _send(int argc, char **argv, bool rtr)
frame.can_id = strtoul(argv[3], NULL, 16);
frame.len = argc - 4;
}
if (frame.len > 8) {

#ifdef MODULE_FDCAN
if (is_fd) {
frame.flags |= CANFD_FDF;
if (frame.len > DEFAULT_CAN_MAX_DLEN) {
puts("Invalid length");
return 1;
}
}
else if (frame.len > CAN_MAX_DLEN) {
puts("Invalid length");
return 1;
}
#else
if (frame.len > DEFAULT_CAN_MAX_DLEN) {
puts("Invalid length");
return 1;
}
#endif

if (rtr) {
for (int i = 0; i < frame.len; i++) {
Expand Down Expand Up @@ -541,11 +562,19 @@ static int _can_handler(int argc, char **argv)
return _list(argc, argv);
}
else if (strncmp(argv[1], "send", 5) == 0) {
return _send(argc, argv, false);
return _send(argc, argv, false, false);
}
else if (strncmp(argv[1], "sendrtr", 8) == 0) {
return _send(argc, argv, true);
return _send(argc, argv, true, false);
}
#ifdef MODULE_FDCAN
else if (strncmp(argv[1], "fdsend", 5) == 0) {
return _send(argc, argv, false, true);
}
else if (strncmp(argv[1], "fdsendrtr", 8) == 0) {
return _send(argc, argv, true, true);
}
#endif
else if (strncmp(argv[1], "recv", 5) == 0) {
return _receive(argc, argv);
}
Expand Down Expand Up @@ -736,8 +765,8 @@ int main(void)
(void*)i, "receive_thread");
}

char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
char line_buf[SHELL_BUFSIZE];
shell_run(_commands, line_buf, SHELL_BUFSIZE);

return 0;
}

0 comments on commit 7066104

Please sign in to comment.