mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/include/can: Add loopback operation mode
tests/candev: Add loopback mode for testing purpose
This commit is contained in:
parent
a38cd1477e
commit
905723be59
@ -805,6 +805,12 @@ static int _set(candev_t *candev, canopt_t opt, void *value, size_t value_len)
|
||||
can->BTR |= CAN_BTR_SILM;
|
||||
res += set_mode(can, mode);
|
||||
break;
|
||||
case CANOPT_STATE_LOOPBACK:
|
||||
DEBUG("candev_stm32 %p: Loopback\n", (void *)dev);
|
||||
res = set_mode(can, MODE_INIT);
|
||||
can->BTR |= CAN_BTR_LBKM;
|
||||
res += set_mode(can, MODE_NORMAL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -63,9 +63,9 @@ typedef enum {
|
||||
CANOPT_STATE_SLEEP, /**< sleep mode */
|
||||
CANOPT_STATE_LISTEN_ONLY, /**< listen only mode */
|
||||
CANOPT_STATE_ON, /**< power on, rx / tx mode */
|
||||
CANOPT_STATE_LOOPBACK, /**< loopback mode */
|
||||
} canopt_state_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Structure to pass a CAN option
|
||||
*/
|
||||
|
@ -48,6 +48,11 @@ static candev_mcp2515_t mcp2515_dev;
|
||||
/* add includes for other candev drivers here */
|
||||
#endif
|
||||
|
||||
/* Default is not using loopback test mode */
|
||||
#ifndef CONFIG_USE_LOOPBACK_MODE
|
||||
#define CONFIG_USE_LOOPBACK_MODE 0
|
||||
#endif
|
||||
|
||||
#define RX_RINGBUFFER_SIZE 128 /* Needs to be a power of 2! */
|
||||
static isrpipe_t rxbuf;
|
||||
static uint8_t rx_ringbuf[RX_RINGBUFFER_SIZE];
|
||||
@ -222,6 +227,18 @@ int main(void)
|
||||
|
||||
candev->driver->init(candev);
|
||||
|
||||
if (IS_ACTIVE(CONFIG_USE_LOOPBACK_MODE)) {
|
||||
puts("Switching to loopback mode");
|
||||
/* set to loopback test mode */
|
||||
canopt_state_t mode = CANOPT_STATE_LOOPBACK;
|
||||
candev->driver->set(candev, CANOPT_STATE, &mode, sizeof(mode));
|
||||
|
||||
/* do not care, receive all message id */
|
||||
struct can_filter filter;
|
||||
filter.can_mask = 0;
|
||||
candev->driver->set_filter(candev, &filter);
|
||||
}
|
||||
|
||||
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user