Skip to content

Commit d3101b1

Browse files
Alexander Wachtercarlescufi
authored andcommitted
drivers: can: Add syscall handlers for CAN API
This commit adds generic syscall handlers for the CAN API Signed-off-by: Alexander Wachter <[email protected]>
1 parent 023e451 commit d3101b1

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

drivers/can/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zephyr_sources_ifdef(CONFIG_USERSPACE can_handlers.c)

drivers/can/can_handlers.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2018 Alexander Wachter
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <syscall_handler.h>
8+
#include <can.h>
9+
10+
_SYSCALL_HANDLER(can_configure, dev, mode, bitrate) {
11+
12+
_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN);
13+
14+
return _impl_can_configure((struct device *)dev, mode, bitrate);
15+
}
16+
17+
_SYSCALL_HANDLER(can_send, dev, msg) {
18+
_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN);
19+
20+
/* We need to be able to read the data */
21+
_SYSCALL_MEMORY_ARRAY_READ(msg->data, msg->dlc, sizeof(msg->data));
22+
23+
return _impl_can_send((struct device *)dev, (struct can_msg *)msg)
24+
}
25+
26+
_SYSCALL_HANDLER(can_attach_msgq, dev, msgq, filter) {
27+
_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN);
28+
29+
/* We need to be able to write the data */
30+
_SYSCALL_MEMORY_WRITE(msgq, sizeof(msgq));
31+
_SYSCALL_MEMORY_WRITE(msgq->buffer_start,
32+
msgq->buffer_end - msgq->buffer_start);
33+
34+
return _impl_can_attach_msgq((struct device *)dev,
35+
(struct k_msgq *)msgq,
36+
(const struct can_filter *) filter);
37+
}
38+
39+
_SYSCALL_HANDLER(can_attach_isr, dev, isr, filter) {
40+
_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN);
41+
42+
return _impl_can_attach_isr((struct device *)dev,
43+
(can_rx_callback_t)isr,
44+
(const struct can_filter *) filter);
45+
}
46+
47+
_SYSCALL_HANDLER(can_detach, dev, filter_id) {
48+
_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN);
49+
50+
return _impl_can_detach((struct device *)dev, (int)filter_id);
51+
}

0 commit comments

Comments
 (0)