Skip to content

Commit 8af4bb7

Browse files
henrikbrixandersencarlescufi
authored andcommitted
drivers: can: rename API functions for better consistency
Rename a few CAN API functions for clarity and consistency with other Zephyr RTOS APIs. CAN_DEFINE_MSGQ() becomes CAN_MSGQ_DEFINE() to match K_MSGQ_DEFINE(). can_attach_isr() becomes can_add_rx_filter() since a filter callback function is not an interrupt service routine (although it is called in isr context). The word "attach" is replaced with "add" since filters are added, not attached. This matches the terminology used is other Zephyr APIs better. can_detach() becomes can_remove_rx_filter() to pair with can_add_rx_filter(). can_attach_msgq() becomes can_add_rx_filter_msgq() and documentation is updated to mention its relationship with can_add_rx_filter(). can_register_state_change_isr() becomes can_set_state_change_callback() since a state change callback function is not an interrupt service routine (although it is called in isr context). The word "register" is replaced with "set" since only one state change callback can be in place. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent 4792151 commit 8af4bb7

File tree

26 files changed

+579
-533
lines changed

26 files changed

+579
-533
lines changed

doc/reference/canbus/controller.rst

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -205,24 +205,24 @@ Receiving
205205
*********
206206

207207
Frames are only received when they match a filter.
208-
The following code snippets show how to receive frames by attaching filters.
208+
The following code snippets show how to receive frames by adding filters.
209209

210210
Here we have an example for a receiving callback as used for
211-
:c:func:`can_attach_isr`. The argument arg is passed when the filter is
212-
attached.
211+
:c:func:`can_add_rx_filter`. The user data argument is passed when the filter is
212+
added.
213213

214214
.. code-block:: C
215215
216-
void rx_callback_function(struct zcan_frame *frame, void *arg)
216+
void rx_callback_function(struct zcan_frame *frame, void *user_data)
217217
{
218218
... do something with the frame ...
219219
}
220220
221-
The following snippet shows how to attach a filter with an interrupt callback.
221+
The following snippet shows how to add a filter with a callback function.
222222
It is the most efficient but also the most critical way to receive messages.
223223
The callback function is called from an interrupt context, which means that the
224224
callback function should be as short as possible and must not block.
225-
Attaching ISRs is not allowed from userspace context.
225+
Adding callback functions is not allowed from userspace context.
226226

227227
The filter for this example is configured to match the identifier 0x123 exactly.
228228

@@ -240,15 +240,15 @@ The filter for this example is configured to match the identifier 0x123 exactly.
240240
241241
can_dev = device_get_binding("CAN_0");
242242
243-
filter_id = can_attach_isr(can_dev, rx_callback_function, callback_arg, &my_filter);
243+
filter_id = can_add_rx_filter(can_dev, rx_callback_function, callback_arg, &my_filter);
244244
if (filter_id < 0) {
245-
LOG_ERR("Unable to attach isr [%d]", filter_id);
245+
LOG_ERR("Unable to add rx filter [%d]", filter_id);
246246
}
247247
248-
Here an example for :c:func:`can_attach_msgq` is shown. With this function, it
249-
is possible to receive frames synchronously. This function can be called from
250-
userspace context.
251-
The size of the message queue should be as big as the expected backlog.
248+
Here an example for :c:func:`can_add_rx_filter_msgq` is shown. With this
249+
function, it is possible to receive frames synchronously. This function can be
250+
called from userspace context. The size of the message queue should be as big
251+
as the expected backlog.
252252

253253
The filter for this example is configured to match the extended identifier
254254
0x1234567 exactly.
@@ -262,16 +262,16 @@ The filter for this example is configured to match the extended identifier
262262
.rtr_mask = 1,
263263
.id_mask = CAN_EXT_ID_MASK
264264
};
265-
CAN_DEFINE_MSGQ(my_can_msgq, 2);
265+
CAN_MSGQ_DEFINE(my_can_msgq, 2);
266266
struct zcan_frame rx_frame;
267267
int filter_id;
268268
const struct device *can_dev;
269269
270270
can_dev = device_get_binding("CAN_0");
271271
272-
filter_id = can_attach_msgq(can_dev, &my_can_msgq, &my_filter);
272+
filter_id = can_add_rx_filter_msgq(can_dev, &my_can_msgq, &my_filter);
273273
if (filter_id < 0) {
274-
LOG_ERR("Unable to attach isr [%d]", filter_id);
274+
LOG_ERR("Unable to add rx msgq [%d]", filter_id);
275275
return;
276276
}
277277
@@ -280,11 +280,11 @@ The filter for this example is configured to match the extended identifier
280280
... do something with the frame ...
281281
}
282282
283-
:c:func:`can_detach` removes the given filter.
283+
:c:func:`can_remove_rx_filter` removes the given filter.
284284

285285
.. code-block:: C
286286
287-
can_detach(can_dev, filter_id);
287+
can_remove_rx_filter(can_dev, filter_id);
288288
289289
Setting the bitrate
290290
*******************

drivers/can/can_common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ static void can_msgq_put(struct zcan_frame *frame, void *arg)
4040
}
4141
}
4242

43-
int z_impl_can_attach_msgq(const struct device *dev, struct k_msgq *msg_q,
44-
const struct zcan_filter *filter)
43+
int z_impl_can_add_rx_filter_msgq(const struct device *dev, struct k_msgq *msgq,
44+
const struct zcan_filter *filter)
4545
{
4646
const struct can_driver_api *api = dev->api;
4747

48-
return api->attach_isr(dev, can_msgq_put, msg_q, filter);
48+
return api->add_rx_filter(dev, can_msgq_put, msgq, filter);
4949
}
5050

5151
static inline void can_work_buffer_init(struct can_frame_buffer *buffer)
@@ -140,7 +140,7 @@ int can_attach_workq(const struct device *dev, struct k_work_q *work_q,
140140
work->cb_arg = user_data;
141141
can_work_buffer_init(&work->buf);
142142

143-
return api->attach_isr(dev, can_work_isr_put, work, filter);
143+
return api->add_rx_filter(dev, can_work_isr_put, work, filter);
144144
}
145145

146146

drivers/can/can_handlers.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,30 @@ static inline int z_vrfy_can_send(const struct device *dev,
5555
}
5656
#include <syscalls/can_send_mrsh.c>
5757

58-
static inline int z_vrfy_can_attach_msgq(const struct device *dev,
59-
struct k_msgq *msgq,
60-
const struct zcan_filter *filter)
58+
static inline int z_vrfy_can_add_rx_filter_msgq(const struct device *dev,
59+
struct k_msgq *msgq,
60+
const struct zcan_filter *filter)
6161
{
6262
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
6363

6464
Z_OOPS(Z_SYSCALL_MEMORY_READ((struct zcan_filter *)filter,
6565
sizeof(struct zcan_filter)));
6666
Z_OOPS(Z_SYSCALL_OBJ(msgq, K_OBJ_MSGQ));
6767

68-
return z_impl_can_attach_msgq((const struct device *)dev,
69-
(struct k_msgq *)msgq,
70-
(const struct zcan_filter *) filter);
68+
return z_impl_can_add_rx_filter_msgq((const struct device *)dev,
69+
(struct k_msgq *)msgq,
70+
(const struct zcan_filter *)filter);
7171
}
72-
#include <syscalls/can_attach_msgq_mrsh.c>
72+
#include <syscalls/can_add_rx_filter_msgq_mrsh.c>
7373

74-
static inline void z_vrfy_can_detach(const struct device *dev, int filter_id)
74+
static inline void z_vrfy_can_remove_rx_filter(const struct device *dev, int filter_id)
7575
{
7676

77-
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, detach));
77+
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, remove_rx_filter));
7878

79-
z_impl_can_detach((const struct device *)dev, (int)filter_id);
79+
z_impl_can_remove_rx_filter((const struct device *)dev, (int)filter_id);
8080
}
81-
#include <syscalls/can_detach_mrsh.c>
81+
#include <syscalls/can_remove_rx_filter_mrsh.c>
8282

8383
static inline
8484
enum can_state z_vrfy_can_get_state(const struct device *dev,

drivers/can/can_loopback.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ static inline int get_free_filter(struct can_loopback_filter *filters)
147147
return -ENOSPC;
148148
}
149149

150-
int can_loopback_attach_isr(const struct device *dev, can_rx_callback_t isr,
151-
void *cb_arg,
152-
const struct zcan_filter *filter)
150+
int can_loopback_add_rx_filter(const struct device *dev, can_rx_callback_t cb,
151+
void *cb_arg, const struct zcan_filter *filter)
153152
{
154153
struct can_loopback_data *data = dev->data;
155154
struct can_loopback_filter *loopback_filter;
@@ -175,21 +174,21 @@ int can_loopback_attach_isr(const struct device *dev, can_rx_callback_t isr,
175174

176175
loopback_filter = &data->filters[filter_id];
177176

178-
loopback_filter->rx_cb = isr;
177+
loopback_filter->rx_cb = cb;
179178
loopback_filter->cb_arg = cb_arg;
180179
loopback_filter->filter = *filter;
181180
k_mutex_unlock(&data->mtx);
182181

183-
LOG_DBG("Filter attached. ID: %d", filter_id);
182+
LOG_DBG("Filter added. ID: %d", filter_id);
184183

185184
return filter_id;
186185
}
187186

188-
void can_loopback_detach(const struct device *dev, int filter_id)
187+
void can_loopback_remove_rx_filter(const struct device *dev, int filter_id)
189188
{
190189
struct can_loopback_data *data = dev->data;
191190

192-
LOG_DBG("Detach filter ID: %d", filter_id);
191+
LOG_DBG("Remove filter ID: %d", filter_id);
193192
k_mutex_lock(&data->mtx, K_FOREVER);
194193
data->filters[filter_id].rx_cb = NULL;
195194
k_mutex_unlock(&data->mtx);
@@ -236,11 +235,11 @@ int can_loopback_recover(const struct device *dev, k_timeout_t timeout)
236235
}
237236
#endif /* CONFIG_CAN_AUTO_BUS_OFF_RECOVERY */
238237

239-
static void can_loopback_register_state_change_isr(const struct device *dev,
240-
can_state_change_isr_t isr)
238+
static void can_loopback_set_state_change_callback(const struct device *dev,
239+
can_state_change_callback_t cb)
241240
{
242241
ARG_UNUSED(dev);
243-
ARG_UNUSED(isr);
242+
ARG_UNUSED(cb);
244243
}
245244

246245
int can_loopback_get_core_clock(const struct device *dev, uint32_t *rate)
@@ -261,13 +260,13 @@ static const struct can_driver_api can_loopback_driver_api = {
261260
.set_mode = can_loopback_set_mode,
262261
.set_timing = can_loopback_set_timing,
263262
.send = can_loopback_send,
264-
.attach_isr = can_loopback_attach_isr,
265-
.detach = can_loopback_detach,
263+
.add_rx_filter = can_loopback_add_rx_filter,
264+
.remove_rx_filter = can_loopback_remove_rx_filter,
266265
.get_state = can_loopback_get_state,
267266
#ifndef CONFIG_CAN_AUTO_BUS_OFF_RECOVERY
268267
.recover = can_loopback_recover,
269268
#endif
270-
.register_state_change_isr = can_loopback_register_state_change_isr,
269+
.set_state_change_callback = can_loopback_set_state_change_callback,
271270
.get_core_clock = can_loopback_get_core_clock,
272271
.get_max_filters = can_loopback_get_max_filters,
273272
.timing_min = {

0 commit comments

Comments
 (0)